Vanessa 2025-05-22 12:33:11 +08:00
parent bf08509986
commit efe9a3f908
15 changed files with 45 additions and 51 deletions

View file

@ -761,12 +761,6 @@ app.whenReady().then(() => {
const menu = Menu.buildFromTemplate(template);
menu.popup({window: BrowserWindow.fromWebContents(event.sender)});
});
ipcMain.on("siyuan-open-folder", (event, filePath) => {
shell.showItemInFolder(filePath);
});
ipcMain.on("siyuan-open-path", (event, filePath) => {
shell.openPath(filePath);
});
ipcMain.on("siyuan-first-quit", () => {
app.exit();
});
@ -874,6 +868,12 @@ app.whenReady().then(() => {
}
const currentWindow = getWindowByContentId(webContentsId);
switch (cmd) {
case "showItemInFolder":
shell.showItemInFolder(data.filePath);
break;
case "openPath":
shell.openPath(data.filePath);
break;
case "openDevTools":
event.sender.openDevTools({mode: "bottom"});
break;

View file

@ -11,7 +11,7 @@ import {Dialog} from "../../dialog";
import {getAllModels} from "../../layout/getAll";
import {hasClosestByClassName} from "../../protyle/util/hasClosest";
import {getArticle, inputEvent, replace} from "../../search/util";
import {showFileInFolder} from "../../util/pathName";
import {useShell} from "../../util/pathName";
import {assetInputEvent, renderPreview} from "../../search/assets";
import {initSearchMenu} from "../../menus/search";
import {writeText} from "../../protyle/util/compatibility";
@ -235,7 +235,7 @@ export const searchKeydown = (app: App, event: KeyboardEvent) => {
}
} else {
/// #if !BROWSER
showFileInFolder(path.join(window.siyuan.config.system.dataDir, currentList.lastElementChild.getAttribute("aria-label")));
useShell("showItemInFolder", path.join(window.siyuan.config.system.dataDir, currentList.lastElementChild.getAttribute("aria-label")));
/// #endif
}
return true;

View file

@ -12,7 +12,7 @@ import {showMessage} from "../dialog/message";
import {Dialog} from "../dialog";
import {confirmDialog} from "../dialog/confirmDialog";
import {setKey} from "../sync/syncGuide";
import {openPath} from "../util/pathName";
import {useShell} from "../util/pathName";
export const about = {
element: undefined as Element,
@ -209,7 +209,7 @@ ${checkUpdateHTML}
<span style="color:var(--b3-theme-background);font-family: cursive;">&nbsp;</span>
</div>
<div class='fn__hr'></div>
${window.siyuan.languages.about1} ${"harmony" === window.siyuan.config.system.container? " • " + window.siyuan.languages.feedback + " 845765@qq.com" : ""}
${window.siyuan.languages.about1} ${"harmony" === window.siyuan.config.system.container ? " • " + window.siyuan.languages.feedback + " 845765@qq.com" : ""}
</div>`;
},
bindEvent: () => {
@ -260,7 +260,7 @@ ${checkUpdateHTML}
if (url.startsWith("http")) {
shell.openExternal(url);
} else {
openPath(url);
useShell("openPath", url);
}
/// #else
window.open(url);

View file

@ -11,7 +11,7 @@ import {openSnippets} from "./util/snippets";
import {loadAssets} from "../util/assets";
import {resetFloatDockSize} from "../layout/dock/util";
import {confirmDialog} from "../dialog/confirmDialog";
import {openPath} from "../util/pathName";
import {useShell} from "../util/pathName";
export const appearance = {
element: undefined as Element,
@ -234,13 +234,13 @@ export const appearance = {
});
/// #if !BROWSER
appearance.element.querySelector("#appearanceOpenIcon").addEventListener("click", () => {
openPath(path.join(window.siyuan.config.system.confDir, "appearance", "icons"));
useShell("openPath", path.join(window.siyuan.config.system.confDir, "appearance", "icons"));
});
appearance.element.querySelector("#appearanceOpenTheme").addEventListener("click", () => {
openPath(path.join(window.siyuan.config.system.confDir, "appearance", "themes"));
useShell("openPath", path.join(window.siyuan.config.system.confDir, "appearance", "themes"));
});
appearance.element.querySelector("#appearanceOpenEmoji").addEventListener("click", () => {
openPath(path.join(window.siyuan.config.system.dataDir, "emojis"));
useShell("openPath", path.join(window.siyuan.config.system.dataDir, "emojis"));
});
/// #endif
appearance.element.querySelectorAll("select").forEach(item => {

View file

@ -6,7 +6,6 @@ import {highlightRender} from "../protyle/render/highlightRender";
import {exportLayout, saveLayout} from "../layout/util";
import {Constants} from "../constants";
/// #if !BROWSER
import {shell} from "electron";
import * as path from "path";
/// #endif
import {getFrontend, isBrowser} from "../util/functions";
@ -19,7 +18,7 @@ import {uninstall} from "../plugin/uninstall";
import {afterLoadPlugin, loadPlugin, loadPlugins, reloadPlugin} from "../plugin/loader";
import {loadAssets} from "../util/assets";
import {addScript} from "../protyle/util/addScript";
import {openPath} from "../util/pathName";
import {useShell} from "../util/pathName";
export const bazaar = {
element: undefined as Element,
@ -626,9 +625,9 @@ export const bazaar = {
/// #if !BROWSER
const dirName = dataObj.bazaarType;
if (dirName === "icons" || dirName === "themes") {
openPath(path.join(window.siyuan.config.system.confDir, "appearance", dirName, dataObj.name));
useShell("openPath", path.join(window.siyuan.config.system.confDir, "appearance", dirName, dataObj.name));
} else {
openPath(path.join(window.siyuan.config.system.dataDir, dirName, dataObj.name));
useShell("openPath", path.join(window.siyuan.config.system.dataDir, dirName, dataObj.name));
}
/// #endif
event.preventDefault();

View file

@ -6,7 +6,7 @@ import * as path from "path";
/// #endif
import {isBrowser} from "../util/functions";
import {showMessage} from "../dialog/message";
import {showFileInFolder} from "../util/pathName";
import {useShell} from "../util/pathName";
import {Constants} from "../constants";
import {openByMobile} from "../protyle/util/compatibility";
import {exportLayout} from "../layout/util";
@ -293,7 +293,7 @@ export const exportConfig = {
/// #if !BROWSER
pandocBinPathElement.addEventListener("click", () => {
if (window.siyuan.config.export.pandocBin) {
showFileInFolder(window.siyuan.config.export.pandocBin);
useShell("showItemInFolder", window.siyuan.config.export.pandocBin);
}
});
const pandocBinElement = exportConfig.element.querySelector("#pandocBin") as HTMLInputElement;

View file

@ -49,8 +49,6 @@ export abstract class Constants {
public static readonly SIYUAN_OPEN_WORKSPACE: string = "siyuan-open-workspace";
public static readonly SIYUAN_OPEN_URL: string = "siyuan-open-url";
public static readonly SIYUAN_OPEN_WINDOW: string = "siyuan-open-window";
public static readonly SIYUAN_OPEN_FOLDER: string = "siyuan-open-folder";
public static readonly SIYUAN_OPEN_PATH: string = "siyuan-open-path";
public static readonly SIYUAN_OPEN_FILE: string = "siyuan-open-file";
public static readonly SIYUAN_EXPORT_PDF: string = "siyuan-export-pdf";

View file

@ -5,7 +5,7 @@ import {getInstanceById, getWndByLayout, pdfIsLoading, setPanelFocus} from "../l
import {getDockByType} from "../layout/tabUtil";
import {getAllModels, getAllTabs} from "../layout/getAll";
import {highlightById, scrollCenter} from "../util/highlightById";
import {getDisplayName, openPath, pathPosix, showFileInFolder} from "../util/pathName";
import {getDisplayName, useShell, pathPosix} from "../util/pathName";
import {Constants} from "../constants";
import {setEditMode} from "../protyle/util/setEditMode";
import {Files} from "../layout/dock/Files";
@ -13,7 +13,7 @@ import {fetchPost, fetchSyncPost} from "../util/fetch";
import {focusBlock, focusByRange} from "../protyle/util/selection";
import {onGet} from "../protyle/util/onGet";
/// #if !BROWSER
import {ipcRenderer, shell} from "electron";
import {ipcRenderer} from "electron";
/// #endif
import {pushBack} from "../util/backForward";
import {Asset} from "../asset";
@ -695,9 +695,9 @@ export const openBy = (url: string, type: "folder" | "app") => {
if (url.startsWith("assets/")) {
fetchPost("/api/asset/resolveAssetPath", {path: url.replace(/\.pdf\?page=\d{1,}$/, ".pdf")}, (response) => {
if (type === "app") {
openPath(response.data);
useShell("openPath", response.data);
} else if (type === "folder") {
showFileInFolder(response.data);
useShell("showItemInFolder", response.data);
}
});
return;
@ -713,7 +713,7 @@ export const openBy = (url: string, type: "folder" | "app") => {
// 拖入文件名包含 `)` 、`(` 的文件以 `file://` 插入后链接解析错误 https://github.com/siyuan-note/siyuan/issues/5786
address = address.replace(/\\\)/g, ")").replace(/\\\(/g, "(");
if (type === "app") {
openPath(address);
useShell("openPath", address);
} else if (type === "folder") {
if ("windows" === window.siyuan.config.system.os) {
if (!address.startsWith("\\\\")) { // \\ 开头的路径是 Windows 网络共享路径 https://github.com/siyuan-note/siyuan/issues/5980
@ -721,7 +721,7 @@ export const openBy = (url: string, type: "folder" | "app") => {
address = address.replace(/\\\\/g, "\\");
}
}
showFileInFolder(address);
useShell("showItemInFolder", address);
}
/// #endif
};

View file

@ -4,7 +4,7 @@ import {FileFilter, ipcRenderer} from "electron";
import * as path from "path";
/// #endif
import {MenuItem} from "./Menu";
import {getDisplayName, getNotebookName, getTopPaths, openPath, pathPosix} from "../util/pathName";
import {getDisplayName, getNotebookName, getTopPaths, useShell, pathPosix} from "../util/pathName";
import {hideMessage, showMessage} from "../dialog/message";
import {fetchPost, fetchSyncPost} from "../util/fetch";
import {onGetnotebookconf} from "./onGetnotebookconf";
@ -362,7 +362,7 @@ export const initNavigationMenu = (app: App, liElement: HTMLElement) => {
icon: "iconFolder",
label: window.siyuan.languages.showInFolder,
click: () => {
openPath(path.join(window.siyuan.config.system.dataDir, notebookId));
useShell("openPath", path.join(window.siyuan.config.system.dataDir, notebookId));
}
}).element);
/// #endif

View file

@ -3,7 +3,7 @@ import {ipcRenderer} from "electron";
import * as path from "path";
/// #endif
import {fetchPost} from "../util/fetch";
import {getAssetName, pathPosix, showFileInFolder} from "../util/pathName";
import {getAssetName, pathPosix, useShell} from "../util/pathName";
import {openFileById} from "../editor/util";
import {Constants} from "../constants";
import {openNewWindowById} from "../window/openNewWindow";
@ -149,11 +149,11 @@ export const openEditorTab = (app: App, ids: string[], notebookId?: string, path
label: window.siyuan.languages.showInFolder,
click: () => {
if (notebookId) {
showFileInFolder(path.join(window.siyuan.config.system.dataDir, notebookId, pathString));
useShell("showItemInFolder", path.join(window.siyuan.config.system.dataDir, notebookId, pathString));
} else {
ids.forEach((id) => {
fetchPost("/api/block/getBlockInfo", {id}, (response) => {
showFileInFolder(path.join(window.siyuan.config.system.dataDir, response.data.box, response.data.path));
useShell("showItemInFolder", path.join(window.siyuan.config.system.dataDir, response.data.box, response.data.path));
});
});
}

View file

@ -3,7 +3,7 @@ import {MenuItem} from "./Menu";
import {ipcRenderer} from "electron";
/// #endif
import {openHistory} from "../history/history";
import {getOpenNotebookCount, originalPath, pathPosix, showFileInFolder} from "../util/pathName";
import {getOpenNotebookCount, originalPath, pathPosix, useShell} from "../util/pathName";
import {fetchNewDailyNote, mountHelp, newDailyNote} from "../util/mount";
import {fetchPost} from "../util/fetch";
import {Constants} from "../constants";
@ -354,7 +354,7 @@ export const workspaceMenu = (app: App, rect: DOMRect) => {
const genListHTML = () => {
let html = "";
window.siyuan.storage[Constants.LOCAL_LAYOUTS].sort((a: ISaveLayout, b: ISaveLayout) => {
return a.name.localeCompare(b.name, undefined, {numeric:true});
return a.name.localeCompare(b.name, undefined, {numeric: true});
}).forEach((item: ISaveLayout) => {
if (inputElement.value === "" || item.name.toLowerCase().indexOf(inputElement.value.toLowerCase()) > -1) {
html += `<div data-name="${item.name}" class="b3-list-item b3-list-item--narrow b3-list-item--hide-action ${html ? "" : "b3-list-item--focus"}">
@ -607,7 +607,7 @@ const workspaceItem = (item: IWorkspace) => {
icon: "iconFolder",
label: window.siyuan.languages.showInFolder,
click() {
showFileInFolder(item.path);
useShell("showItemInFolder", item.path);
}
}, {
id: "copyPath",

View file

@ -11,7 +11,7 @@ import {Constants} from "../../constants";
import {highlightRender} from "../render/highlightRender";
import {processRender} from "../util/processCode";
import {isIPhone, isSafari, openByMobile, setStorageVal} from "../util/compatibility";
import {showFileInFolder} from "../../util/pathName";
import {useShell} from "../../util/pathName";
import {isPaidUser} from "../../util/needSubscribe";
import {getCloudURL} from "../../config/util/about";
@ -21,7 +21,7 @@ export const afterExport = (exportPath: string, msgId: string) => {
<div class="fn__space"></div>
<button class="b3-button b3-button--white">${window.siyuan.languages.showInFolder}</button>`, 6000, "info", msgId);
document.querySelector(`#message [data-id="${msgId}"] button`).addEventListener("click", () => {
showFileInFolder(path.join(exportPath));
useShell("showItemInFolder", path.join(exportPath));
hideMessage(msgId);
});
/// #endif

View file

@ -10,7 +10,7 @@ import * as path from "path";
import {Constants} from "../../constants";
import {openCardByData} from "../../card/openCard";
import {viewCards} from "../../card/viewCards";
import {getDisplayName, getNotebookName, pathPosix, showFileInFolder} from "../../util/pathName";
import {getDisplayName, getNotebookName, pathPosix, useShell} from "../../util/pathName";
import {makeCard, quickMakeCard} from "../../card/makeCard";
import {emitOpenMenu} from "../../plugin/EventBus";
import * as dayjs from "dayjs";
@ -244,7 +244,7 @@ export const openTitleMenu = (protyle: IProtyle, position: IPosition) => {
icon: "iconFolder",
label: window.siyuan.languages.showInFolder,
click: () => {
showFileInFolder(path.join(window.siyuan.config.system.dataDir, protyle.notebookId, protyle.path));
useShell("showItemInFolder", path.join(window.siyuan.config.system.dataDir, protyle.notebookId, protyle.path));
}
}).element);
/// #endif

View file

@ -15,7 +15,7 @@ import {
getNotebookName,
movePathTo,
pathPosix,
showFileInFolder
useShell
} from "../util/pathName";
import {Protyle} from "../protyle";
import {onGet} from "../protyle/util/onGet";
@ -852,7 +852,7 @@ export const genSearch = (app: App, config: Config.IUILayoutTabSearchConfig, ele
clearTimeout(clickTimeout);
if (searchType === "asset") {
/// #if !BROWSER
showFileInFolder(path.join(window.siyuan.config.system.dataDir, target.lastElementChild.getAttribute("aria-label")));
useShell("showItemInFolder", path.join(window.siyuan.config.system.dataDir, target.lastElementChild.getAttribute("aria-label")));
/// #endif
} else {
const id = target.getAttribute("data-node-id");

View file

@ -15,15 +15,12 @@ import {matchHotKey} from "../protyle/util/hotKey";
import {Menu} from "../plugin/Menu";
import {hasClosestByClassName} from "../protyle/util/hasClosest";
export const showFileInFolder = (filePath: string) => {
export const useShell = (cmd: "showItemInFolder" | "openPath", filePath: string) => {
/// #if !BROWSER
ipcRenderer.send(Constants.SIYUAN_OPEN_FOLDER, filePath);
/// #endif
};
export const openPath = (filePath: string) => {
/// #if !BROWSER
ipcRenderer.send(Constants.SIYUAN_OPEN_PATH, filePath);
ipcRenderer.send(Constants.SIYUAN_CMD, {
cmd,
filePath: filePath
});
/// #endif
};