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

View file

@ -11,7 +11,7 @@ import {Dialog} from "../../dialog";
import {getAllModels} from "../../layout/getAll"; import {getAllModels} from "../../layout/getAll";
import {hasClosestByClassName} from "../../protyle/util/hasClosest"; import {hasClosestByClassName} from "../../protyle/util/hasClosest";
import {getArticle, inputEvent, replace} from "../../search/util"; import {getArticle, inputEvent, replace} from "../../search/util";
import {showFileInFolder} from "../../util/pathName"; import {useShell} from "../../util/pathName";
import {assetInputEvent, renderPreview} from "../../search/assets"; import {assetInputEvent, renderPreview} from "../../search/assets";
import {initSearchMenu} from "../../menus/search"; import {initSearchMenu} from "../../menus/search";
import {writeText} from "../../protyle/util/compatibility"; import {writeText} from "../../protyle/util/compatibility";
@ -235,7 +235,7 @@ export const searchKeydown = (app: App, event: KeyboardEvent) => {
} }
} else { } else {
/// #if !BROWSER /// #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 /// #endif
} }
return true; return true;

View file

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

View file

@ -11,7 +11,7 @@ import {openSnippets} from "./util/snippets";
import {loadAssets} from "../util/assets"; import {loadAssets} from "../util/assets";
import {resetFloatDockSize} from "../layout/dock/util"; import {resetFloatDockSize} from "../layout/dock/util";
import {confirmDialog} from "../dialog/confirmDialog"; import {confirmDialog} from "../dialog/confirmDialog";
import {openPath} from "../util/pathName"; import {useShell} from "../util/pathName";
export const appearance = { export const appearance = {
element: undefined as Element, element: undefined as Element,
@ -234,13 +234,13 @@ export const appearance = {
}); });
/// #if !BROWSER /// #if !BROWSER
appearance.element.querySelector("#appearanceOpenIcon").addEventListener("click", () => { 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", () => { 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", () => { 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 /// #endif
appearance.element.querySelectorAll("select").forEach(item => { 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 {exportLayout, saveLayout} from "../layout/util";
import {Constants} from "../constants"; import {Constants} from "../constants";
/// #if !BROWSER /// #if !BROWSER
import {shell} from "electron";
import * as path from "path"; import * as path from "path";
/// #endif /// #endif
import {getFrontend, isBrowser} from "../util/functions"; import {getFrontend, isBrowser} from "../util/functions";
@ -19,7 +18,7 @@ import {uninstall} from "../plugin/uninstall";
import {afterLoadPlugin, loadPlugin, loadPlugins, reloadPlugin} from "../plugin/loader"; import {afterLoadPlugin, loadPlugin, loadPlugins, reloadPlugin} from "../plugin/loader";
import {loadAssets} from "../util/assets"; import {loadAssets} from "../util/assets";
import {addScript} from "../protyle/util/addScript"; import {addScript} from "../protyle/util/addScript";
import {openPath} from "../util/pathName"; import {useShell} from "../util/pathName";
export const bazaar = { export const bazaar = {
element: undefined as Element, element: undefined as Element,
@ -626,9 +625,9 @@ export const bazaar = {
/// #if !BROWSER /// #if !BROWSER
const dirName = dataObj.bazaarType; const dirName = dataObj.bazaarType;
if (dirName === "icons" || dirName === "themes") { 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 { } 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 /// #endif
event.preventDefault(); event.preventDefault();

View file

@ -6,7 +6,7 @@ import * as path from "path";
/// #endif /// #endif
import {isBrowser} from "../util/functions"; import {isBrowser} from "../util/functions";
import {showMessage} from "../dialog/message"; import {showMessage} from "../dialog/message";
import {showFileInFolder} from "../util/pathName"; import {useShell} from "../util/pathName";
import {Constants} from "../constants"; import {Constants} from "../constants";
import {openByMobile} from "../protyle/util/compatibility"; import {openByMobile} from "../protyle/util/compatibility";
import {exportLayout} from "../layout/util"; import {exportLayout} from "../layout/util";
@ -293,7 +293,7 @@ export const exportConfig = {
/// #if !BROWSER /// #if !BROWSER
pandocBinPathElement.addEventListener("click", () => { pandocBinPathElement.addEventListener("click", () => {
if (window.siyuan.config.export.pandocBin) { 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; 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_WORKSPACE: string = "siyuan-open-workspace";
public static readonly SIYUAN_OPEN_URL: string = "siyuan-open-url"; 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_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_OPEN_FILE: string = "siyuan-open-file";
public static readonly SIYUAN_EXPORT_PDF: string = "siyuan-export-pdf"; 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 {getDockByType} from "../layout/tabUtil";
import {getAllModels, getAllTabs} from "../layout/getAll"; import {getAllModels, getAllTabs} from "../layout/getAll";
import {highlightById, scrollCenter} from "../util/highlightById"; 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 {Constants} from "../constants";
import {setEditMode} from "../protyle/util/setEditMode"; import {setEditMode} from "../protyle/util/setEditMode";
import {Files} from "../layout/dock/Files"; import {Files} from "../layout/dock/Files";
@ -13,7 +13,7 @@ import {fetchPost, fetchSyncPost} from "../util/fetch";
import {focusBlock, focusByRange} from "../protyle/util/selection"; import {focusBlock, focusByRange} from "../protyle/util/selection";
import {onGet} from "../protyle/util/onGet"; import {onGet} from "../protyle/util/onGet";
/// #if !BROWSER /// #if !BROWSER
import {ipcRenderer, shell} from "electron"; import {ipcRenderer} from "electron";
/// #endif /// #endif
import {pushBack} from "../util/backForward"; import {pushBack} from "../util/backForward";
import {Asset} from "../asset"; import {Asset} from "../asset";
@ -695,9 +695,9 @@ export const openBy = (url: string, type: "folder" | "app") => {
if (url.startsWith("assets/")) { if (url.startsWith("assets/")) {
fetchPost("/api/asset/resolveAssetPath", {path: url.replace(/\.pdf\?page=\d{1,}$/, ".pdf")}, (response) => { fetchPost("/api/asset/resolveAssetPath", {path: url.replace(/\.pdf\?page=\d{1,}$/, ".pdf")}, (response) => {
if (type === "app") { if (type === "app") {
openPath(response.data); useShell("openPath", response.data);
} else if (type === "folder") { } else if (type === "folder") {
showFileInFolder(response.data); useShell("showItemInFolder", response.data);
} }
}); });
return; return;
@ -713,7 +713,7 @@ export const openBy = (url: string, type: "folder" | "app") => {
// 拖入文件名包含 `)` 、`(` 的文件以 `file://` 插入后链接解析错误 https://github.com/siyuan-note/siyuan/issues/5786 // 拖入文件名包含 `)` 、`(` 的文件以 `file://` 插入后链接解析错误 https://github.com/siyuan-note/siyuan/issues/5786
address = address.replace(/\\\)/g, ")").replace(/\\\(/g, "("); address = address.replace(/\\\)/g, ")").replace(/\\\(/g, "(");
if (type === "app") { if (type === "app") {
openPath(address); useShell("openPath", address);
} else if (type === "folder") { } else if (type === "folder") {
if ("windows" === window.siyuan.config.system.os) { if ("windows" === window.siyuan.config.system.os) {
if (!address.startsWith("\\\\")) { // \\ 开头的路径是 Windows 网络共享路径 https://github.com/siyuan-note/siyuan/issues/5980 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, "\\"); address = address.replace(/\\\\/g, "\\");
} }
} }
showFileInFolder(address); useShell("showItemInFolder", address);
} }
/// #endif /// #endif
}; };

View file

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

View file

@ -3,7 +3,7 @@ import {ipcRenderer} from "electron";
import * as path from "path"; import * as path from "path";
/// #endif /// #endif
import {fetchPost} from "../util/fetch"; 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 {openFileById} from "../editor/util";
import {Constants} from "../constants"; import {Constants} from "../constants";
import {openNewWindowById} from "../window/openNewWindow"; import {openNewWindowById} from "../window/openNewWindow";
@ -149,11 +149,11 @@ export const openEditorTab = (app: App, ids: string[], notebookId?: string, path
label: window.siyuan.languages.showInFolder, label: window.siyuan.languages.showInFolder,
click: () => { click: () => {
if (notebookId) { if (notebookId) {
showFileInFolder(path.join(window.siyuan.config.system.dataDir, notebookId, pathString)); useShell("showItemInFolder", path.join(window.siyuan.config.system.dataDir, notebookId, pathString));
} else { } else {
ids.forEach((id) => { ids.forEach((id) => {
fetchPost("/api/block/getBlockInfo", {id}, (response) => { 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"; import {ipcRenderer} from "electron";
/// #endif /// #endif
import {openHistory} from "../history/history"; 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 {fetchNewDailyNote, mountHelp, newDailyNote} from "../util/mount";
import {fetchPost} from "../util/fetch"; import {fetchPost} from "../util/fetch";
import {Constants} from "../constants"; import {Constants} from "../constants";
@ -354,7 +354,7 @@ export const workspaceMenu = (app: App, rect: DOMRect) => {
const genListHTML = () => { const genListHTML = () => {
let html = ""; let html = "";
window.siyuan.storage[Constants.LOCAL_LAYOUTS].sort((a: ISaveLayout, b: ISaveLayout) => { 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) => { }).forEach((item: ISaveLayout) => {
if (inputElement.value === "" || item.name.toLowerCase().indexOf(inputElement.value.toLowerCase()) > -1) { 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"}"> 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", icon: "iconFolder",
label: window.siyuan.languages.showInFolder, label: window.siyuan.languages.showInFolder,
click() { click() {
showFileInFolder(item.path); useShell("showItemInFolder", item.path);
} }
}, { }, {
id: "copyPath", id: "copyPath",

View file

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

View file

@ -10,7 +10,7 @@ import * as path from "path";
import {Constants} from "../../constants"; import {Constants} from "../../constants";
import {openCardByData} from "../../card/openCard"; import {openCardByData} from "../../card/openCard";
import {viewCards} from "../../card/viewCards"; 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 {makeCard, quickMakeCard} from "../../card/makeCard";
import {emitOpenMenu} from "../../plugin/EventBus"; import {emitOpenMenu} from "../../plugin/EventBus";
import * as dayjs from "dayjs"; import * as dayjs from "dayjs";
@ -244,7 +244,7 @@ export const openTitleMenu = (protyle: IProtyle, position: IPosition) => {
icon: "iconFolder", icon: "iconFolder",
label: window.siyuan.languages.showInFolder, label: window.siyuan.languages.showInFolder,
click: () => { 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); }).element);
/// #endif /// #endif

View file

@ -15,7 +15,7 @@ import {
getNotebookName, getNotebookName,
movePathTo, movePathTo,
pathPosix, pathPosix,
showFileInFolder useShell
} from "../util/pathName"; } from "../util/pathName";
import {Protyle} from "../protyle"; import {Protyle} from "../protyle";
import {onGet} from "../protyle/util/onGet"; import {onGet} from "../protyle/util/onGet";
@ -852,7 +852,7 @@ export const genSearch = (app: App, config: Config.IUILayoutTabSearchConfig, ele
clearTimeout(clickTimeout); clearTimeout(clickTimeout);
if (searchType === "asset") { if (searchType === "asset") {
/// #if !BROWSER /// #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 /// #endif
} else { } else {
const id = target.getAttribute("data-node-id"); 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 {Menu} from "../plugin/Menu";
import {hasClosestByClassName} from "../protyle/util/hasClosest"; import {hasClosestByClassName} from "../protyle/util/hasClosest";
export const showFileInFolder = (filePath: string) => { export const useShell = (cmd: "showItemInFolder" | "openPath", filePath: string) => {
/// #if !BROWSER /// #if !BROWSER
ipcRenderer.send(Constants.SIYUAN_OPEN_FOLDER, filePath); ipcRenderer.send(Constants.SIYUAN_CMD, {
/// #endif cmd,
}; filePath: filePath
});
export const openPath = (filePath: string) => {
/// #if !BROWSER
ipcRenderer.send(Constants.SIYUAN_OPEN_PATH, filePath);
/// #endif /// #endif
}; };