diff --git a/app/electron/main.js b/app/electron/main.js index 6ec0670d5..5f6203f60 100644 --- a/app/electron/main.js +++ b/app/electron/main.js @@ -326,7 +326,7 @@ const boot = () => { currentWindow.show(); setTimeout(() => { // 等待界面js执行完毕 writeLog(siyuanOpenURL); - currentWindow.webContents.send("siyuan-openurl", siyuanOpenURL); + currentWindow.webContents.send("siyuan-open-url", siyuanOpenURL); }, 2000); } }); @@ -656,6 +656,9 @@ app.whenReady().then(() => { resetTrayMenu(tray, lang, mainWindow); }; + ipcMain.on("siyuan-open-folder", (event, filePath) => { + shell.showItemInFolder(filePath); + }); ipcMain.on("siyuan-first-quit", () => { app.exit(); }); @@ -692,7 +695,7 @@ app.whenReady().then(() => { ipcMain.on("siyuan-quit", (event, port) => { exitApp(port); }); - ipcMain.on("siyuan-openwindow", (event, data) => { + ipcMain.on("siyuan-open-window", (event, data) => { const mainWindow = BrowserWindow.fromId(data.id); const mainBounds = mainWindow.getBounds(); const mainScreen = screen.getDisplayNearestPoint({x: mainBounds.x, y: mainBounds.y}); @@ -832,9 +835,9 @@ app.whenReady().then(() => { } }); }); - ipcMain.on("siyuan-send_windows", (event, data) => { + ipcMain.on("siyuan-send-windows", (event, data) => { BrowserWindow.getAllWindows().forEach(item => { - item.webContents.send("siyuan-send_windows", data); + item.webContents.send("siyuan-send-windows", data); }); }); ipcMain.on("siyuan-auto-launch", (event, data) => { @@ -907,7 +910,7 @@ app.on("open-url", (event, url) => { // for macOS if (url.startsWith("siyuan://")) { workspaces.forEach(item => { if (item.browserWindow && !item.browserWindow.isDestroyed()) { - item.browserWindow.webContents.send("siyuan-openurl", url); + item.browserWindow.webContents.send("siyuan-open-url", url); } }); } @@ -950,7 +953,7 @@ app.on("second-instance", (event, argv) => { const siyuanURL = argv.find((arg) => arg.startsWith("siyuan://")); workspaces.forEach(item => { if (item.browserWindow && !item.browserWindow.isDestroyed() && siyuanURL) { - item.browserWindow.webContents.send("siyuan-openurl", siyuanURL); + item.browserWindow.webContents.send("siyuan-open-url", siyuanURL); } }); @@ -1037,6 +1040,6 @@ powerMonitor.on("shutdown", () => { powerMonitor.on("lock-screen", () => { writeLog("system lock-screen"); BrowserWindow.getAllWindows().forEach(item => { - item.webContents.send("siyuan-send_windows", {cmd: "lockscreenByMode"}); + item.webContents.send("siyuan-send-windows", {cmd: "lockscreenByMode"}); }); }); diff --git a/app/src/boot/onGetConfig.ts b/app/src/boot/onGetConfig.ts index b515186f7..25973caff 100644 --- a/app/src/boot/onGetConfig.ts +++ b/app/src/boot/onGetConfig.ts @@ -242,7 +242,7 @@ export const initWindow = (app: App) => { currentWindow.on("focus", winOnFocus); currentWindow.on("blur", winOnBlur); if (!isWindow()) { - ipcRenderer.on(Constants.SIYUAN_OPENURL, (event, url) => { + ipcRenderer.on(Constants.SIYUAN_OPEN_URL, (event, url) => { if (url.startsWith("siyuan://plugins/")) { const pluginId = url.replace("siyuan://plugins/", "").split("?")[0]; if (!pluginId) { diff --git a/app/src/config/exportConfig.ts b/app/src/config/exportConfig.ts index 690b1f2dd..b1a6e1fed 100644 --- a/app/src/config/exportConfig.ts +++ b/app/src/config/exportConfig.ts @@ -7,6 +7,7 @@ import * as path from "path"; /// #endif import {isBrowser} from "../util/functions"; import {showMessage} from "../dialog/message"; +import {showFileInFolder} from "../util/pathName"; export const exportConfig = { element: undefined as Element, @@ -204,7 +205,7 @@ export const exportConfig = { /// #if !BROWSER pandocBinPathElement.addEventListener("click", () => { if (window.siyuan.config.export.pandocBin) { - shell.showItemInFolder(window.siyuan.config.export.pandocBin); + showFileInFolder(window.siyuan.config.export.pandocBin); } }); const pandocBinElement = exportConfig.element.querySelector("#pandocBin") as HTMLInputElement; diff --git a/app/src/constants.ts b/app/src/constants.ts index 7f7ca80d7..8577b64bf 100644 --- a/app/src/constants.ts +++ b/app/src/constants.ts @@ -26,18 +26,21 @@ export abstract class Constants { // 渲染进程调主进程 public static readonly SIYUAN_SHOW: string = "siyuan-show"; public static readonly SIYUAN_CONFIG_TRAY: string = "siyuan-config-tray"; - public static readonly SIYUAN_OPEN_WORKSPACE: string = "siyuan-open-workspace"; public static readonly SIYUAN_QUIT: string = "siyuan-quit"; public static readonly SIYUAN_HOTKEY: string = "siyuan-hotkey"; public static readonly SIYUAN_INIT: string = "siyuan-init"; - public static readonly SIYUAN_OPENURL: string = "siyuan-openurl"; - public static readonly SIYUAN_OPENWINDOW: string = "siyuan-openwindow"; - public static readonly SIYUAN_SEND_WINDOWS: string = "siyuan-send_windows"; // 主窗口和各新窗口之间的通信,{cmd: "closetab"|"lockscreen"|"lockscreenByMode", data: {}}) + public static readonly SIYUAN_SEND_WINDOWS: string = "siyuan-send-windows"; // 主窗口和各新窗口之间的通信,{cmd: "closetab"|"lockscreen"|"lockscreenByMode", data: {}}) public static readonly SIYUAN_SAVE_CLOSE: string = "siyuan-save-close"; + public static readonly SIYUAN_AUTO_LAUNCH: string = "siyuan-auto-launch"; + + 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_EXPORT_PDF: string = "siyuan-export-pdf"; public static readonly SIYUAN_EXPORT_CLOSE: string = "siyuan-export-close"; public static readonly SIYUAN_EXPORT_PREVENT: string = "siyuan-export-prevent"; - public static readonly SIYUAN_AUTO_LAUNCH: string = "siyuan-auto-launch"; // custom public static readonly CUSTOM_SY_READONLY: string = "custom-sy-readonly"; diff --git a/app/src/editor/util.ts b/app/src/editor/util.ts index 3f00d0293..d8955db61 100644 --- a/app/src/editor/util.ts +++ b/app/src/editor/util.ts @@ -4,7 +4,7 @@ import {Wnd} from "../layout/Wnd"; import {getDockByType, getInstanceById, getWndByLayout, pdfIsLoading, setPanelFocus} from "../layout/util"; import {getAllModels, getAllTabs} from "../layout/getAll"; import {highlightById, scrollCenter} from "../util/highlightById"; -import {getDisplayName, pathPosix} from "../util/pathName"; +import {getDisplayName, pathPosix, showFileInFolder} from "../util/pathName"; import {Constants} from "../constants"; import {setEditMode} from "../protyle/util/setEditMode"; import {Files} from "../layout/dock/Files"; @@ -668,7 +668,7 @@ export const openBy = (url: string, type: "folder" | "app") => { if (type === "app") { shell.openPath(response.data); } else if (type === "folder") { - shell.showItemInFolder(response.data); + showFileInFolder(response.data); } }); return; @@ -691,7 +691,7 @@ export const openBy = (url: string, type: "folder" | "app") => { address = address.replace(/\\\\/g, "\\"); } } - shell.showItemInFolder(address); + showFileInFolder(address); } /// #endif }; diff --git a/app/src/menus/util.ts b/app/src/menus/util.ts index 2ac42dbdf..28c85c050 100644 --- a/app/src/menus/util.ts +++ b/app/src/menus/util.ts @@ -1,11 +1,10 @@ /// #if !BROWSER import {dialog} from "@electron/remote"; import {SaveDialogReturnValue} from "electron"; -import {shell} from "electron"; import * as path from "path"; /// #endif import {fetchPost} from "../util/fetch"; -import {getAssetName, pathPosix} from "../util/pathName"; +import {getAssetName, pathPosix, showFileInFolder} from "../util/pathName"; import {openFileById} from "../editor/util"; import {Constants} from "../constants"; import {openNewWindowById} from "../window/openNewWindow"; @@ -86,10 +85,10 @@ export const openEditorTab = (app: App, id: string, notebookId?: string, pathStr label: window.siyuan.languages.showInFolder, click: () => { if (notebookId) { - shell.showItemInFolder(path.join(window.siyuan.config.system.dataDir, notebookId, pathString)); + showFileInFolder(path.join(window.siyuan.config.system.dataDir, notebookId, pathString)); } else { fetchPost("/api/block/getBlockInfo", {id}, (response) => { - shell.showItemInFolder(path.join(window.siyuan.config.system.dataDir, response.data.box, response.data.path)); + showFileInFolder(path.join(window.siyuan.config.system.dataDir, response.data.box, response.data.path)); }); } } diff --git a/app/src/menus/workspace.ts b/app/src/menus/workspace.ts index e088fc66b..41ee51035 100644 --- a/app/src/menus/workspace.ts +++ b/app/src/menus/workspace.ts @@ -1,10 +1,10 @@ import {MenuItem} from "./Menu"; /// #if !BROWSER import {dialog, getCurrentWindow} from "@electron/remote"; -import {ipcRenderer, shell} from "electron"; +import {ipcRenderer} from "electron"; /// #endif import {openHistory} from "../history/history"; -import {getOpenNotebookCount, originalPath, pathPosix} from "../util/pathName"; +import {getOpenNotebookCount, originalPath, pathPosix, showFileInFolder} from "../util/pathName"; import {mountHelp, newDailyNote} from "../util/mount"; import {fetchPost} from "../util/fetch"; import {Constants} from "../constants"; @@ -449,7 +449,7 @@ const workspaceItem = (item: IWorkspace) => { iconHTML: Constants.ZWSP, label: window.siyuan.languages.showInFolder, click() { - shell.showItemInFolder(item.path); + showFileInFolder(item.path); } }, { iconHTML: Constants.ZWSP, diff --git a/app/src/protyle/export/util.ts b/app/src/protyle/export/util.ts index 4a9c84fa6..7a5b1c505 100644 --- a/app/src/protyle/export/util.ts +++ b/app/src/protyle/export/util.ts @@ -12,6 +12,7 @@ import {Constants} from "../../constants"; import {highlightRender} from "../render/highlightRender"; import {processRender} from "../util/processCode"; import {openByMobile, setStorageVal} from "../util/compatibility"; +import {showFileInFolder} from "../../util/pathName"; export const afterExport = (exportPath: string, msgId: string) => { /// #if !BROWSER @@ -19,7 +20,7 @@ export const afterExport = (exportPath: string, msgId: string) => {
`, 6000, "info", msgId); document.querySelector(`#message [data-id="${msgId}"] button`).addEventListener("click", () => { - shell.showItemInFolder(path.join(exportPath)); + showFileInFolder(path.join(exportPath)); hideMessage(msgId); }); /// #endif diff --git a/app/src/protyle/header/openTitleMenu.ts b/app/src/protyle/header/openTitleMenu.ts index 12786a893..4461f1eaa 100644 --- a/app/src/protyle/header/openTitleMenu.ts +++ b/app/src/protyle/header/openTitleMenu.ts @@ -17,7 +17,7 @@ import * as path from "path"; import {Constants} from "../../constants"; import {openCardByData} from "../../card/openCard"; import {viewCards} from "../../card/viewCards"; -import {getDisplayName, getNotebookName, pathPosix} from "../../util/pathName"; +import {getDisplayName, getNotebookName, pathPosix, showFileInFolder} from "../../util/pathName"; import {makeCard, quickMakeCard} from "../../card/makeCard"; import {emitOpenMenu} from "../../plugin/EventBus"; import * as dayjs from "dayjs"; @@ -247,7 +247,7 @@ export const openTitleMenu = (protyle: IProtyle, position: { window.siyuan.menus.menu.append(new MenuItem({ label: window.siyuan.languages.showInFolder, click: () => { - shell.showItemInFolder(path.join(window.siyuan.config.system.dataDir, protyle.notebookId, protyle.path)); + showFileInFolder(path.join(window.siyuan.config.system.dataDir, protyle.notebookId, protyle.path)); } }).element); /// #endif diff --git a/app/src/search/assets.ts b/app/src/search/assets.ts index 668b8e1b8..3a9a3f1be 100644 --- a/app/src/search/assets.ts +++ b/app/src/search/assets.ts @@ -12,6 +12,7 @@ import {getQueryTip} from "./util"; /// #endif import {MenuItem} from "../menus/Menu"; import {Dialog} from "../dialog"; +import {showFileInFolder} from "../util/pathName"; export const openSearchAsset = (element: Element, isStick: boolean) => { /// #if !MOBILE @@ -135,7 +136,7 @@ export const openSearchAsset = (element: Element, isStick: boolean) => { if (!isHistory) { if (currentList) { /// #if !BROWSER - shell.showItemInFolder(path.join(window.siyuan.config.system.dataDir, currentList.lastElementChild.getAttribute("aria-label"))); + showFileInFolder(path.join(window.siyuan.config.system.dataDir, currentList.lastElementChild.getAttribute("aria-label"))); /// #endif } } else { diff --git a/app/src/search/util.ts b/app/src/search/util.ts index 8d3287c62..97aaba77b 100644 --- a/app/src/search/util.ts +++ b/app/src/search/util.ts @@ -10,7 +10,14 @@ import {openFile, openFileById} from "../editor/util"; import {showMessage} from "../dialog/message"; import {reloadProtyle} from "../protyle/util/reload"; import {MenuItem} from "../menus/Menu"; -import {getDisplayName, getNotebookIcon, getNotebookName, movePathTo, pathPosix} from "../util/pathName"; +import { + getDisplayName, + getNotebookIcon, + getNotebookName, + movePathTo, + pathPosix, + showFileInFolder +} from "../util/pathName"; import {Protyle} from "../protyle"; import {onGet} from "../protyle/util/onGet"; import {addLoading} from "../protyle/ui/initUI"; @@ -796,7 +803,7 @@ export const genSearch = (app: App, config: ISearchOption, element: Element, clo clearTimeout(clickTimeout); if (isAsset) { /// #if !BROWSER - shell.showItemInFolder(path.join(window.siyuan.config.system.dataDir, target.lastElementChild.getAttribute("aria-label"))); + showFileInFolder(path.join(window.siyuan.config.system.dataDir, target.lastElementChild.getAttribute("aria-label"))); /// #endif } else { const id = target.getAttribute("data-node-id"); diff --git a/app/src/util/pathName.ts b/app/src/util/pathName.ts index b1bfc7e17..ea871ecac 100644 --- a/app/src/util/pathName.ts +++ b/app/src/util/pathName.ts @@ -6,8 +6,17 @@ import {getSearch, isMobile} from "./functions"; import {focusByRange} from "../protyle/util/selection"; import {unicode2Emoji} from "../emoji"; import {Constants} from "../constants"; +/// #if !BROWSER +import {ipcRenderer} from "electron"; +/// #endif import {showMessage} from "../dialog/message"; +export const showFileInFolder = (filePath: string) => { + /// #if !BROWSER + ipcRenderer.send(Constants.SIYUAN_OPEN_FOLDER, filePath); + /// #endif +}; + export const getIdZoomInByPath = () => { const searchParams = new URLSearchParams(window.location.search); const PWAURL = searchParams.get("url"); diff --git a/app/src/window/openNewWindow.ts b/app/src/window/openNewWindow.ts index f1195f4eb..7427482df 100644 --- a/app/src/window/openNewWindow.ts +++ b/app/src/window/openNewWindow.ts @@ -21,7 +21,7 @@ export const openNewWindow = (tab: Tab, options: windowOptions = {}) => { const json = {}; layoutToJSON(tab, json); /// #if !BROWSER - ipcRenderer.send(Constants.SIYUAN_OPENWINDOW, { + ipcRenderer.send(Constants.SIYUAN_OPEN_WINDOW, { position: options.position, width: options.width, height: options.height, @@ -61,7 +61,7 @@ export const openNewWindowById = (id: string, options: windowOptions = {}) => { json.children.scrollAttr.rootId = response.data.rootID; } /// #if !BROWSER - ipcRenderer.send(Constants.SIYUAN_OPENWINDOW, { + ipcRenderer.send(Constants.SIYUAN_OPEN_WINDOW, { position: options.position, width: options.width, height: options.height, @@ -76,7 +76,7 @@ export const openNewWindowById = (id: string, options: windowOptions = {}) => { zoomInId: id, }; /// #if !BROWSER - ipcRenderer.send(Constants.SIYUAN_OPENWINDOW, { + ipcRenderer.send(Constants.SIYUAN_OPEN_WINDOW, { position: options.position, width: options.width, height: options.height,