This commit is contained in:
Vanessa 2023-09-19 09:45:57 +08:00
parent f2f292c5fa
commit 56fe8371d1
13 changed files with 57 additions and 33 deletions

View file

@ -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"});
});
});

View file

@ -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) {

View file

@ -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;

View file

@ -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";

View file

@ -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
};

View file

@ -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));
});
}
}

View file

@ -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,

View file

@ -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) => {
<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", () => {
shell.showItemInFolder(path.join(exportPath));
showFileInFolder(path.join(exportPath));
hideMessage(msgId);
});
/// #endif

View file

@ -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

View file

@ -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 {

View file

@ -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");

View file

@ -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");

View file

@ -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,