diff --git a/app/electron/main.js b/app/electron/main.js index d9fb18dcd..534379824 100644 --- a/app/electron/main.js +++ b/app/electron/main.js @@ -664,12 +664,15 @@ app.whenReady().then(() => { ipcMain.on("siyuan-first-quit", () => { app.exit(); }); - ipcMain.on("siyuan-show", (event) => { - showWindow(getWindowByContentId(event.sender.id)); - }); ipcMain.on("siyuan-cmd", (event, cmd) => { console.log(cmd) switch (cmd) { + case "openDevTools": + event.sender.openDevTools({mode: "bottom"}); + break; + case "show": + showWindow(getWindowByContentId(event.sender.id)); + break; case "hide": getWindowByContentId(event.sender.id).hide(); break; diff --git a/app/src/boot/onGetConfig.ts b/app/src/boot/onGetConfig.ts index 79d768d19..93baec780 100644 --- a/app/src/boot/onGetConfig.ts +++ b/app/src/boot/onGetConfig.ts @@ -282,7 +282,7 @@ export const initWindow = (app: App) => { action: [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT, Constants.CB_GET_ROOTSCROLL], zoomIn: focus, }); - ipcRenderer.send(Constants.SIYUAN_SHOW); + ipcRenderer.send(Constants.SIYUAN_CMD, "show"); } app.plugins.forEach(plugin => { plugin.eventBus.emit("open-siyuan-url-block", { diff --git a/app/src/constants.ts b/app/src/constants.ts index 2186ce79a..7ec6d6891 100644 --- a/app/src/constants.ts +++ b/app/src/constants.ts @@ -24,7 +24,6 @@ export abstract class Constants { public static readonly SIYUAN_DROP_EDITOR: string = "application/siyuan-editor"; // 渲染进程调主进程 - public static readonly SIYUAN_SHOW: string = "siyuan-show"; public static readonly SIYUAN_CMD: string = "siyuan-cmd"; public static readonly SIYUAN_CONFIG_TRAY: string = "siyuan-config-tray"; diff --git a/app/src/layout/status.ts b/app/src/layout/status.ts index 629193a08..6a63657f6 100644 --- a/app/src/layout/status.ts +++ b/app/src/layout/status.ts @@ -4,7 +4,7 @@ import {hasClosestByClassName} from "../protyle/util/hasClosest"; import {fetchPost} from "../util/fetch"; import {mountHelp} from "../util/mount"; /// #if !BROWSER -import {getCurrentWindow} from "@electron/remote"; +import { ipcRenderer } from "electron"; /// #endif /// #endif import {MenuItem} from "../menus/Menu"; @@ -87,7 +87,7 @@ export const initStatus = (isWindow = false) => { label: window.siyuan.languages.debug, icon: "iconBug", click: () => { - getCurrentWindow().webContents.openDevTools({mode: "bottom"}); + ipcRenderer.send(Constants.SIYUAN_CMD, "openDevTools"); } }).element); /// #endif diff --git a/app/src/protyle/header/Title.ts b/app/src/protyle/header/Title.ts index f3d5ce62e..c5b8b7b58 100644 --- a/app/src/protyle/header/Title.ts +++ b/app/src/protyle/header/Title.ts @@ -9,9 +9,6 @@ import {MenuItem} from "../../menus/Menu"; import { openFileAttr, } from "../../menus/commonMenuItem"; -/// #if !BROWSER -import { ipcRenderer } from "electron"; -/// #endif import {Constants} from "../../constants"; import {matchHotKey} from "../util/hotKey"; import {readText, writeText} from "../util/compatibility"; @@ -27,6 +24,7 @@ import {transaction} from "../wysiwyg/transaction"; import {hideTooltip} from "../../dialog/tooltip"; import {commonClick} from "../wysiwyg/commonClick"; import {openTitleMenu} from "./openTitleMenu"; +import {electronUndo} from "../undo"; export class Title { public element: HTMLElement; @@ -97,20 +95,9 @@ export class Title { event.stopPropagation(); return; } - /// #if !BROWSER - if (matchHotKey(window.siyuan.config.keymap.editor.general.undo.custom, event)) { - ipcRenderer.send(Constants.SIYUAN_CMD, "undo"); - event.preventDefault(); - event.stopPropagation(); + if (electronUndo(event)) { return; } - if (matchHotKey(window.siyuan.config.keymap.editor.general.redo.custom, event)) { - ipcRenderer.send(Constants.SIYUAN_CMD, "redo"); - event.preventDefault(); - event.stopPropagation(); - return; - } - /// #endif if (event.key === "ArrowDown") { const noContainerElement = getNoContainerElement(protyle.wysiwyg.element.firstElementChild); // https://github.com/siyuan-note/siyuan/issues/4923 diff --git a/app/src/protyle/undo/index.ts b/app/src/protyle/undo/index.ts index e3c39689b..24441342f 100644 --- a/app/src/protyle/undo/index.ts +++ b/app/src/protyle/undo/index.ts @@ -3,10 +3,8 @@ import {preventScroll} from "../scroll/preventScroll"; import {Constants} from "../../constants"; import {hideElements} from "../ui/hideElements"; import {scrollCenter} from "../../util/highlightById"; -/// #if !BROWSER -import {getCurrentWindow} from "@electron/remote"; -/// #endif import {matchHotKey} from "../util/hotKey"; +import { ipcRenderer } from "electron"; interface IOperations { doOperations: IOperation[], @@ -99,13 +97,13 @@ export class Undo { export const electronUndo = (event: KeyboardEvent) => { /// #if !BROWSER if (matchHotKey(window.siyuan.config.keymap.editor.general.undo.custom, event)) { - getCurrentWindow().webContents.undo(); + ipcRenderer.send(Constants.SIYUAN_CMD, "undo"); event.preventDefault(); event.stopPropagation(); return true; } if (matchHotKey(window.siyuan.config.keymap.editor.general.redo.custom, event)) { - getCurrentWindow().webContents.redo(); + ipcRenderer.send(Constants.SIYUAN_CMD, "redo"); event.preventDefault(); event.stopPropagation(); return true;