Vanessa 2025-04-14 13:31:04 +08:00
parent c3bb1fc76f
commit 68b94077c6
2 changed files with 37 additions and 10 deletions

View File

@ -1734,3 +1734,23 @@ export const sendGlobalShortcut = (app: App) => {
}); });
/// #endif /// #endif
}; };
export const sendUnregisterGlobalShortcut = (app:App) => {
/// #if !BROWSER
ipcRenderer.send(Constants.SIYUAN_CMD, {
cmd: "unregisterGlobalShortcut",
accelerator: window.siyuan.config.keymap.general.toggleWin.custom
});
app.plugins.forEach(plugin => {
plugin.commands.forEach(command => {
if (command.globalCallback) {
ipcRenderer.send(Constants.SIYUAN_CMD, {
cmd: "unregisterGlobalShortcut",
accelerator: command.customHotkey
});
}
});
});
/// #endif
}

View File

@ -7,6 +7,7 @@ import {confirmDialog} from "../dialog/confirmDialog";
import {App} from "../index"; import {App} from "../index";
/// #if !BROWSER /// #if !BROWSER
import {ipcRenderer} from "electron"; import {ipcRenderer} from "electron";
import {sendUnregisterGlobalShortcut} from "../boot/globalEvent/keydown";
/// #endif /// #endif
import {sendGlobalShortcut} from "../boot/globalEvent/keydown"; import {sendGlobalShortcut} from "../boot/globalEvent/keydown";
@ -61,7 +62,7 @@ export const keymap = {
const dockKeymap = window.siyuan.config.keymap.plugin[item.name][toolbarItem.name]; const dockKeymap = window.siyuan.config.keymap.plugin[item.name][toolbarItem.name];
const keyValue = updateHotkeyTip(dockKeymap.custom); const keyValue = updateHotkeyTip(dockKeymap.custom);
commandHTML += `<label class="b3-list-item b3-list-item--narrow b3-list-item--hide-action"> commandHTML += `<label class="b3-list-item b3-list-item--narrow b3-list-item--hide-action">
<span class="b3-list-item__text">${toolbarItem.tip||window.siyuan.languages[toolbarItem.lang]}</span> <span class="b3-list-item__text">${toolbarItem.tip || window.siyuan.languages[toolbarItem.lang]}</span>
<span data-type="reset" class="b3-list-item__action b3-tooltips b3-tooltips__w" aria-label="${window.siyuan.languages.reset}"> <span data-type="reset" class="b3-list-item__action b3-tooltips b3-tooltips__w" aria-label="${window.siyuan.languages.reset}">
<svg><use xlink:href="#iconUndo"></use></svg> <svg><use xlink:href="#iconUndo"></use></svg>
</span> </span>
@ -219,6 +220,14 @@ export const keymap = {
if (plugin.name === keys[1]) { if (plugin.name === keys[1]) {
plugin.commands.forEach(command => { plugin.commands.forEach(command => {
if (command.langKey === keys[2]) { if (command.langKey === keys[2]) {
/// #if !BROWSER
if (command.globalCallback && command.customHotkey && command.customHotkey !== newHotkey) {
ipcRenderer.send(Constants.SIYUAN_CMD, {
cmd: "unregisterGlobalShortcut",
accelerator: command.customHotkey
});
}
/// #endif
command.customHotkey = newHotkey; command.customHotkey = newHotkey;
} }
}); });
@ -234,6 +243,7 @@ export const keymap = {
fetchPost("/api/setting/setKeymap", { fetchPost("/api/setting/setKeymap", {
data data
}, () => { }, () => {
/// #if !BROWSER
ipcRenderer.send(Constants.SIYUAN_CMD, { ipcRenderer.send(Constants.SIYUAN_CMD, {
cmd: "writeLog", cmd: "writeLog",
msg: "user update keymap:" + JSON.stringify(window.siyuan.config.keymap) msg: "user update keymap:" + JSON.stringify(window.siyuan.config.keymap)
@ -245,6 +255,7 @@ export const keymap = {
}); });
} }
sendGlobalShortcut(app); sendGlobalShortcut(app);
/// #endif
}); });
}, },
search(value: string, keymapString: string) { search(value: string, keymapString: string) {
@ -336,10 +347,7 @@ export const keymap = {
}); });
/// #if !BROWSER /// #if !BROWSER
searchKeymapElement.addEventListener("focus", () => { searchKeymapElement.addEventListener("focus", () => {
ipcRenderer.send(Constants.SIYUAN_CMD, { sendUnregisterGlobalShortcut(app);
cmd: "unregisterGlobalShortcut",
accelerator: window.siyuan.config.keymap.general.toggleWin.custom
});
}); });
/// #endif /// #endif
searchKeymapElement.addEventListener("blur", () => { searchKeymapElement.addEventListener("blur", () => {
@ -366,6 +374,7 @@ export const keymap = {
fetchPost("/api/setting/setKeymap", { fetchPost("/api/setting/setKeymap", {
data: Constants.SIYUAN_KEYMAP, data: Constants.SIYUAN_KEYMAP,
}, () => { }, () => {
/// #if !BROWSER
ipcRenderer.send(Constants.SIYUAN_CMD, { ipcRenderer.send(Constants.SIYUAN_CMD, {
cmd: "writeLog", cmd: "writeLog",
msg: "user reset keymap" msg: "user reset keymap"
@ -376,8 +385,9 @@ export const keymap = {
accelerator: window.siyuan.config.keymap.general.toggleWin.custom accelerator: window.siyuan.config.keymap.general.toggleWin.custom
}); });
} }
window.location.reload();
sendGlobalShortcut(app); sendGlobalShortcut(app);
/// #endif
window.location.reload();
}); });
}); });
}); });
@ -497,10 +507,7 @@ export const keymap = {
}); });
/// #if !BROWSER /// #if !BROWSER
item.addEventListener("focus", () => { item.addEventListener("focus", () => {
ipcRenderer.send(Constants.SIYUAN_CMD, { sendUnregisterGlobalShortcut(app);
cmd: "unregisterGlobalShortcut",
accelerator: window.siyuan.config.keymap.general.toggleWin.custom
});
}); });
/// #endif /// #endif
}); });