mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-21 17:10:12 +01:00
This commit is contained in:
parent
fe4fe1aee6
commit
00fe7bffa4
5 changed files with 103 additions and 75 deletions
|
|
@ -49,6 +49,24 @@ try {
|
||||||
app.exit();
|
app.exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const hotKey2Electron = (key) => {
|
||||||
|
console.log(key)
|
||||||
|
if (!key) {
|
||||||
|
return key;
|
||||||
|
}
|
||||||
|
let electronKey = "";
|
||||||
|
if (key.indexOf("⌘") > -1) {
|
||||||
|
electronKey += "CommandOrControl+";
|
||||||
|
}
|
||||||
|
if (key.indexOf("⇧") > -1) {
|
||||||
|
electronKey += "Shift+";
|
||||||
|
}
|
||||||
|
if (key.indexOf("⌥") > -1) {
|
||||||
|
electronKey += "Alt+";
|
||||||
|
}
|
||||||
|
return electronKey + key.substr(key.length - 1);
|
||||||
|
};
|
||||||
|
|
||||||
const exitApp = (port, errorWindowId) => {
|
const exitApp = (port, errorWindowId) => {
|
||||||
let tray;
|
let tray;
|
||||||
let mainWindow;
|
let mainWindow;
|
||||||
|
|
@ -756,36 +774,52 @@ app.whenReady().then(() => {
|
||||||
});
|
});
|
||||||
ipcMain.on("siyuan-hotkey", (event, data) => {
|
ipcMain.on("siyuan-hotkey", (event, data) => {
|
||||||
globalShortcut.unregisterAll();
|
globalShortcut.unregisterAll();
|
||||||
if (!data.hotkey) {
|
if (!data.hotkeys || data.hotkeys.length === 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
globalShortcut.register(data.hotkey, () => {
|
data.hotkeys.forEach((item, index) => {
|
||||||
workspaces.forEach(item => {
|
const shortcut = hotKey2Electron(item);
|
||||||
const mainWindow = item.browserWindow;
|
if (!shortcut) {
|
||||||
if (mainWindow.isMinimized()) {
|
return;
|
||||||
mainWindow.restore();
|
}
|
||||||
mainWindow.show(); // 按 `Alt+M` 后隐藏窗口,再次按 `Alt+M` 显示窗口后会卡住不能编辑 https://github.com/siyuan-note/siyuan/issues/8456
|
if (index === 0) {
|
||||||
} else {
|
globalShortcut.register(shortcut, () => {
|
||||||
if (mainWindow.isVisible()) {
|
workspaces.forEach(workspaceItem => {
|
||||||
if (1 === workspaces.length) { // 改进 `Alt+M` 激活窗口 https://github.com/siyuan-note/siyuan/issues/7258
|
const mainWindow = workspaceItem.browserWindow;
|
||||||
if (!mainWindow.isFocused()) {
|
if (mainWindow.isMinimized()) {
|
||||||
mainWindow.show();
|
mainWindow.restore();
|
||||||
} else {
|
mainWindow.show(); // 按 `Alt+M` 后隐藏窗口,再次按 `Alt+M` 显示窗口后会卡住不能编辑 https://github.com/siyuan-note/siyuan/issues/8456
|
||||||
hideWindow(mainWindow);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
hideWindow(mainWindow);
|
if (mainWindow.isVisible()) {
|
||||||
|
if (1 === workspaces.length) { // 改进 `Alt+M` 激活窗口 https://github.com/siyuan-note/siyuan/issues/7258
|
||||||
|
if (!mainWindow.isFocused()) {
|
||||||
|
mainWindow.show();
|
||||||
|
} else {
|
||||||
|
hideWindow(mainWindow);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
hideWindow(mainWindow);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
mainWindow.show();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
mainWindow.show();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ("win32" === process.platform || "linux" === process.platform) {
|
if ("win32" === process.platform || "linux" === process.platform) {
|
||||||
resetTrayMenu(item.tray, data.languages, mainWindow);
|
resetTrayMenu(workspaceItem.tray, data.languages, mainWindow);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
} else {
|
||||||
|
globalShortcut.register(data.hotkey, () => {
|
||||||
|
BrowserWindow.getAllWindows().forEach(itemB => {
|
||||||
|
itemB.webContents.send("siyuan-hotkey", {
|
||||||
|
hotkey: item
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
})
|
||||||
});
|
});
|
||||||
ipcMain.on("siyuan-send_windows", (event, data) => {
|
ipcMain.on("siyuan-send_windows", (event, data) => {
|
||||||
BrowserWindow.getAllWindows().forEach(item => {
|
BrowserWindow.getAllWindows().forEach(item => {
|
||||||
|
|
|
||||||
|
|
@ -25,11 +25,9 @@ import {getDisplayName, getNotebookName, getTopPaths, movePathTo, moveToPath} fr
|
||||||
import {openFileById} from "../../editor/util";
|
import {openFileById} from "../../editor/util";
|
||||||
import {getAllDocks, getAllModels, getAllTabs} from "../../layout/getAll";
|
import {getAllDocks, getAllModels, getAllTabs} from "../../layout/getAll";
|
||||||
import {openGlobalSearch} from "../../search/util";
|
import {openGlobalSearch} from "../../search/util";
|
||||||
import {getColIndex} from "../../protyle/util/table";
|
|
||||||
import {focusBlock, focusByRange} from "../../protyle/util/selection";
|
import {focusBlock, focusByRange} from "../../protyle/util/selection";
|
||||||
import {initFileMenu, initNavigationMenu} from "../../menus/navigation";
|
import {initFileMenu, initNavigationMenu} from "../../menus/navigation";
|
||||||
import {bindMenuKeydown} from "../../menus/Menu";
|
import {bindMenuKeydown} from "../../menus/Menu";
|
||||||
import {showMessage} from "../../dialog/message";
|
|
||||||
import {Dialog} from "../../dialog";
|
import {Dialog} from "../../dialog";
|
||||||
import {unicode2Emoji} from "../../emoji";
|
import {unicode2Emoji} from "../../emoji";
|
||||||
import {deleteFiles} from "../../editor/deleteFile";
|
import {deleteFiles} from "../../editor/deleteFile";
|
||||||
|
|
@ -43,6 +41,8 @@ import {hintMoveBlock} from "../../protyle/hint/extend";
|
||||||
import {Backlink} from "../../layout/dock/Backlink";
|
import {Backlink} from "../../layout/dock/Backlink";
|
||||||
/// #if !BROWSER
|
/// #if !BROWSER
|
||||||
import {setZoom} from "../../layout/topBar";
|
import {setZoom} from "../../layout/topBar";
|
||||||
|
import {getCurrentWindow} from "@electron/remote";
|
||||||
|
import {ipcRenderer} from "electron";
|
||||||
/// #endif
|
/// #endif
|
||||||
import {openHistory} from "../../history/history";
|
import {openHistory} from "../../history/history";
|
||||||
import {openCard, openCardByData} from "../../card/openCard";
|
import {openCard, openCardByData} from "../../card/openCard";
|
||||||
|
|
@ -57,7 +57,6 @@ import {commandPanel} from "../../plugin/commandPanel";
|
||||||
import {toggleDockBar} from "../../layout/dock/util";
|
import {toggleDockBar} from "../../layout/dock/util";
|
||||||
import {workspaceMenu} from "../../menus/workspace";
|
import {workspaceMenu} from "../../menus/workspace";
|
||||||
|
|
||||||
|
|
||||||
const switchDialogEvent = (app: App, event: MouseEvent, switchDialog: Dialog) => {
|
const switchDialogEvent = (app: App, event: MouseEvent, switchDialog: Dialog) => {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
let target = event.target as HTMLElement;
|
let target = event.target as HTMLElement;
|
||||||
|
|
@ -816,7 +815,7 @@ const panelTreeKeydown = (app: App, event: KeyboardEvent) => {
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const windowKeyDown = (app: App, event: KeyboardEvent, switchDialog:Dialog) => {
|
export const windowKeyDown = (app: App, event: KeyboardEvent, switchDialog: Dialog) => {
|
||||||
|
|
||||||
if (document.querySelector(".av__mask") || document.getElementById("errorLog") || event.isComposing) {
|
if (document.querySelector(".av__mask") || document.getElementById("errorLog") || event.isComposing) {
|
||||||
return;
|
return;
|
||||||
|
|
@ -1302,3 +1301,21 @@ export const windowKeyDown = (app: App, event: KeyboardEvent, switchDialog:Dialo
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const sendGlobalShortcut = (app: App) => {
|
||||||
|
/// #if !BROWSER
|
||||||
|
const hotkeys = [window.siyuan.config.keymap.general.toggleWin.custom];
|
||||||
|
app.plugins.forEach(plugin => {
|
||||||
|
plugin.commands.forEach(command => {
|
||||||
|
if (command.globalCallback) {
|
||||||
|
hotkeys.push(command.customHotkey)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
ipcRenderer.send(Constants.SIYUAN_HOTKEY, {
|
||||||
|
languages: window.siyuan.languages["_trayMenu"],
|
||||||
|
id: getCurrentWindow().id,
|
||||||
|
hotkeys
|
||||||
|
});
|
||||||
|
/// #endif
|
||||||
|
};
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
import {exportLayout, JSONToLayout, resetLayout, resizeTopbar, resizeTabs} from "../layout/util";
|
import {exportLayout, JSONToLayout, resetLayout, resizeTopbar, resizeTabs} from "../layout/util";
|
||||||
import {hotKey2Electron, setStorageVal} from "../protyle/util/compatibility";
|
import {setStorageVal} from "../protyle/util/compatibility";
|
||||||
/// #if !BROWSER
|
/// #if !BROWSER
|
||||||
import {dialog, getCurrentWindow} from "@electron/remote";
|
import {dialog, getCurrentWindow} from "@electron/remote";
|
||||||
import {ipcRenderer, OpenDialogReturnValue, webFrame} from "electron";
|
import {ipcRenderer, OpenDialogReturnValue, webFrame} from "electron";
|
||||||
|
|
@ -27,6 +27,7 @@ import {openChangelog} from "./openChangelog";
|
||||||
import {getIdFromSYProtocol, isSYProtocol} from "../util/pathName";
|
import {getIdFromSYProtocol, isSYProtocol} from "../util/pathName";
|
||||||
import {App} from "../index";
|
import {App} from "../index";
|
||||||
import {initWindowEvent} from "./globalEvent/event";
|
import {initWindowEvent} from "./globalEvent/event";
|
||||||
|
import {sendGlobalShortcut} from "./globalEvent/keydown";
|
||||||
|
|
||||||
const matchKeymap = (keymap: Record<string, IKeymapItem>, key1: "general" | "editor", key2?: "general" | "insert" | "heading" | "list" | "table") => {
|
const matchKeymap = (keymap: Record<string, IKeymapItem>, key1: "general" | "editor", key2?: "general" | "insert" | "heading" | "list" | "table") => {
|
||||||
if (key1 === "general") {
|
if (key1 === "general") {
|
||||||
|
|
@ -105,13 +106,7 @@ export const onGetConfig = (isStart: boolean, app: App) => {
|
||||||
fetchPost("/api/setting/setKeymap", {
|
fetchPost("/api/setting/setKeymap", {
|
||||||
data: window.siyuan.config.keymap
|
data: window.siyuan.config.keymap
|
||||||
}, () => {
|
}, () => {
|
||||||
/// #if !BROWSER
|
sendGlobalShortcut(app);
|
||||||
ipcRenderer.send(Constants.SIYUAN_HOTKEY, {
|
|
||||||
languages: window.siyuan.languages["_trayMenu"],
|
|
||||||
id: getCurrentWindow().id,
|
|
||||||
hotkey: hotKey2Electron(window.siyuan.config.keymap.general.toggleWin.custom)
|
|
||||||
});
|
|
||||||
/// #endif
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
/// #if !BROWSER
|
/// #if !BROWSER
|
||||||
|
|
@ -121,11 +116,7 @@ export const onGetConfig = (isStart: boolean, app: App) => {
|
||||||
id: getCurrentWindow().id,
|
id: getCurrentWindow().id,
|
||||||
port: location.port
|
port: location.port
|
||||||
});
|
});
|
||||||
ipcRenderer.send(Constants.SIYUAN_HOTKEY, {
|
sendGlobalShortcut(app);
|
||||||
languages: window.siyuan.languages["_trayMenu"],
|
|
||||||
id: getCurrentWindow().id,
|
|
||||||
hotkey: hotKey2Electron(window.siyuan.config.keymap.general.toggleWin.custom)
|
|
||||||
});
|
|
||||||
webFrame.setZoomFactor(window.siyuan.storage[Constants.LOCAL_ZOOM]);
|
webFrame.setZoomFactor(window.siyuan.storage[Constants.LOCAL_ZOOM]);
|
||||||
/// #endif
|
/// #endif
|
||||||
if (!window.siyuan.config.uiLayout || (window.siyuan.config.uiLayout && !window.siyuan.config.uiLayout.left)) {
|
if (!window.siyuan.config.uiLayout || (window.siyuan.config.uiLayout && !window.siyuan.config.uiLayout.left)) {
|
||||||
|
|
@ -314,6 +305,21 @@ export const initWindow = (app: App) => {
|
||||||
ipcRenderer.on(Constants.SIYUAN_EXPORT_CLOSE, () => {
|
ipcRenderer.on(Constants.SIYUAN_EXPORT_CLOSE, () => {
|
||||||
window.siyuan.printWin.destroy();
|
window.siyuan.printWin.destroy();
|
||||||
});
|
});
|
||||||
|
ipcRenderer.on(Constants.SIYUAN_HOTKEY, (e, data) => {
|
||||||
|
let matchCommand = false;
|
||||||
|
app.plugins.find(item => {
|
||||||
|
item.commands.find(command => {
|
||||||
|
if (command.globalCallback && data === command.customHotkey) {
|
||||||
|
matchCommand = true;
|
||||||
|
command.globalCallback();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
if (matchCommand) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
ipcRenderer.on(Constants.SIYUAN_EXPORT_PDF, (e, ipcData) => {
|
ipcRenderer.on(Constants.SIYUAN_EXPORT_PDF, (e, ipcData) => {
|
||||||
dialog.showOpenDialog({
|
dialog.showOpenDialog({
|
||||||
title: window.siyuan.languages.export + " PDF",
|
title: window.siyuan.languages.export + " PDF",
|
||||||
|
|
|
||||||
|
|
@ -1,14 +1,11 @@
|
||||||
import {hotKey2Electron, isCtrl, isMac, updateHotkeyTip} from "../protyle/util/compatibility";
|
import {isCtrl, isMac, updateHotkeyTip} from "../protyle/util/compatibility";
|
||||||
import {Constants} from "../constants";
|
import {Constants} from "../constants";
|
||||||
import {showMessage} from "../dialog/message";
|
import {showMessage} from "../dialog/message";
|
||||||
import {fetchPost} from "../util/fetch";
|
import {fetchPost} from "../util/fetch";
|
||||||
import {exportLayout} from "../layout/util";
|
import {exportLayout} from "../layout/util";
|
||||||
/// #if !BROWSER
|
|
||||||
import {getCurrentWindow} from "@electron/remote";
|
|
||||||
import {ipcRenderer} from "electron";
|
|
||||||
/// #endif
|
|
||||||
import {confirmDialog} from "../dialog/confirmDialog";
|
import {confirmDialog} from "../dialog/confirmDialog";
|
||||||
import {App} from "../index";
|
import {App} from "../index";
|
||||||
|
import {sendGlobalShortcut} from "../boot/globalEvent/keydown";
|
||||||
|
|
||||||
export const keymap = {
|
export const keymap = {
|
||||||
element: undefined as Element,
|
element: undefined as Element,
|
||||||
|
|
@ -192,13 +189,7 @@ export const keymap = {
|
||||||
fetchPost("/api/setting/setKeymap", {
|
fetchPost("/api/setting/setKeymap", {
|
||||||
data
|
data
|
||||||
}, () => {
|
}, () => {
|
||||||
/// #if !BROWSER
|
sendGlobalShortcut(app);
|
||||||
ipcRenderer.send(Constants.SIYUAN_HOTKEY, {
|
|
||||||
languages: window.siyuan.languages["_trayMenu"],
|
|
||||||
id: getCurrentWindow().id,
|
|
||||||
hotkey: hotKey2Electron(window.siyuan.config.keymap.general.toggleWin.custom)
|
|
||||||
});
|
|
||||||
/// #endif
|
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
search(value: string, keymapString: string) {
|
search(value: string, keymapString: string) {
|
||||||
|
|
@ -298,13 +289,7 @@ export const keymap = {
|
||||||
data: Constants.SIYUAN_KEYMAP,
|
data: Constants.SIYUAN_KEYMAP,
|
||||||
}, () => {
|
}, () => {
|
||||||
window.location.reload();
|
window.location.reload();
|
||||||
/// #if !BROWSER
|
sendGlobalShortcut(app);
|
||||||
ipcRenderer.send(Constants.SIYUAN_HOTKEY, {
|
|
||||||
languages: window.siyuan.languages["_trayMenu"],
|
|
||||||
id: getCurrentWindow().id,
|
|
||||||
hotkey: hotKey2Electron(window.siyuan.config.keymap.general.toggleWin.custom)
|
|
||||||
});
|
|
||||||
/// #endif
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -129,20 +129,6 @@ export const updateHotkeyTip = (hotkey: string) => {
|
||||||
return keys.join("+");
|
return keys.join("+");
|
||||||
};
|
};
|
||||||
|
|
||||||
export const hotKey2Electron = (key: string) => {
|
|
||||||
let electronKey = "";
|
|
||||||
if (key.indexOf("⌘") > -1) {
|
|
||||||
electronKey += "CommandOrControl+";
|
|
||||||
}
|
|
||||||
if (key.indexOf("⇧") > -1) {
|
|
||||||
electronKey += "Shift+";
|
|
||||||
}
|
|
||||||
if (key.indexOf("⌥") > -1) {
|
|
||||||
electronKey += "Alt+";
|
|
||||||
}
|
|
||||||
return electronKey + key.substr(key.length - 1);
|
|
||||||
};
|
|
||||||
|
|
||||||
export const getLocalStorage = (cb: () => void) => {
|
export const getLocalStorage = (cb: () => void) => {
|
||||||
fetchPost("/api/storage/getLocalStorage", undefined, (response) => {
|
fetchPost("/api/storage/getLocalStorage", undefined, (response) => {
|
||||||
window.siyuan.storage = response.data;
|
window.siyuan.storage = response.data;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue