feat: Conditionally open file links using Electron shell on desktop and warn on mobile platforms.
This commit is contained in:
6
main.js
6
main.js
@@ -28,7 +28,6 @@ __export(main_exports, {
|
|||||||
});
|
});
|
||||||
module.exports = __toCommonJS(main_exports);
|
module.exports = __toCommonJS(main_exports);
|
||||||
var import_obsidian = require("obsidian");
|
var import_obsidian = require("obsidian");
|
||||||
var { shell } = require("electron");
|
|
||||||
var DEFAULT_SETTINGS = {
|
var DEFAULT_SETTINGS = {
|
||||||
mySetting: "default"
|
mySetting: "default"
|
||||||
};
|
};
|
||||||
@@ -212,7 +211,9 @@ var MenuPlugin = class extends import_obsidian.Plugin {
|
|||||||
a.addEventListener("click", (e) => {
|
a.addEventListener("click", (e) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
if (url.startsWith("file://")) {
|
if (url.startsWith("file://")) {
|
||||||
|
if (import_obsidian.Platform.isDesktop) {
|
||||||
try {
|
try {
|
||||||
|
const { shell } = require("electron");
|
||||||
let filePath = decodeURIComponent(url.substring(7));
|
let filePath = decodeURIComponent(url.substring(7));
|
||||||
if (filePath.startsWith("/") && filePath.charAt(2) === ":") {
|
if (filePath.startsWith("/") && filePath.charAt(2) === ":") {
|
||||||
filePath = filePath.substring(1);
|
filePath = filePath.substring(1);
|
||||||
@@ -221,6 +222,9 @@ var MenuPlugin = class extends import_obsidian.Plugin {
|
|||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Failed to open file:", error);
|
console.error("Failed to open file:", error);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
console.warn("File links are not supported on mobile.");
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
window.open(url, "_blank", "noopener,noreferrer");
|
window.open(url, "_blank", "noopener,noreferrer");
|
||||||
}
|
}
|
||||||
|
|||||||
11
main.ts
11
main.ts
@@ -1,6 +1,4 @@
|
|||||||
import { App, Plugin, PluginSettingTab, Setting, MarkdownRenderer } from 'obsidian';
|
import { App, Plugin, PluginSettingTab, Setting, MarkdownRenderer, Platform } from 'obsidian';
|
||||||
|
|
||||||
const { shell } = require('electron');
|
|
||||||
|
|
||||||
interface MenuPluginSettings {
|
interface MenuPluginSettings {
|
||||||
mySetting: string;
|
mySetting: string;
|
||||||
@@ -216,7 +214,9 @@ export default class MenuPlugin extends Plugin {
|
|||||||
a.addEventListener('click', (e) => {
|
a.addEventListener('click', (e) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
if (url.startsWith('file://')) {
|
if (url.startsWith('file://')) {
|
||||||
|
if (Platform.isDesktop) {
|
||||||
try {
|
try {
|
||||||
|
const { shell } = require('electron');
|
||||||
let filePath = decodeURIComponent(url.substring(7));
|
let filePath = decodeURIComponent(url.substring(7));
|
||||||
if (filePath.startsWith('/') && filePath.charAt(2) === ':') {
|
if (filePath.startsWith('/') && filePath.charAt(2) === ':') {
|
||||||
filePath = filePath.substring(1);
|
filePath = filePath.substring(1);
|
||||||
@@ -225,6 +225,11 @@ export default class MenuPlugin extends Plugin {
|
|||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Failed to open file:', error);
|
console.error('Failed to open file:', error);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
console.warn('File links are not supported on mobile.');
|
||||||
|
// Optionally show a notice to the user
|
||||||
|
// new Notice('File links are not supported on this device.');
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
window.open(url, '_blank', 'noopener,noreferrer');
|
window.open(url, '_blank', 'noopener,noreferrer');
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user