mirror of
				https://github.com/zadam/trilium.git
				synced 2025-11-04 13:39:01 +01:00 
			
		
		
		
	feat(command_palette): hide electron-only actions on web
This commit is contained in:
		
							parent
							
								
									1565a0fd80
								
							
						
					
					
						commit
						237a4e9a74
					
				@ -2,6 +2,7 @@ import appContext, { type CommandNames } from "../components/app_context.js";
 | 
				
			|||||||
import type NoteTreeWidget from "../widgets/note_tree.js";
 | 
					import type NoteTreeWidget from "../widgets/note_tree.js";
 | 
				
			||||||
import { t, translationsInitializedPromise } from "./i18n.js";
 | 
					import { t, translationsInitializedPromise } from "./i18n.js";
 | 
				
			||||||
import keyboardActions, { Action } from "./keyboard_actions.js";
 | 
					import keyboardActions, { Action } from "./keyboard_actions.js";
 | 
				
			||||||
 | 
					import utils from "./utils.js";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export interface CommandDefinition {
 | 
					export interface CommandDefinition {
 | 
				
			||||||
    id: string;
 | 
					    id: string;
 | 
				
			||||||
@ -171,6 +172,11 @@ class CommandRegistry {
 | 
				
			|||||||
                continue;
 | 
					                continue;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            // Skip Electron-only actions if not in Electron environment
 | 
				
			||||||
 | 
					            if (action.isElectronOnly && !utils.isElectron()) {
 | 
				
			||||||
 | 
					                continue;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            // Get the primary shortcut (first one in the list)
 | 
					            // Get the primary shortcut (first one in the list)
 | 
				
			||||||
            const primaryShortcut = action.effectiveShortcuts?.[0];
 | 
					            const primaryShortcut = action.effectiveShortcuts?.[0];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -13,6 +13,7 @@ export interface Action {
 | 
				
			|||||||
    friendlyName: string;
 | 
					    friendlyName: string;
 | 
				
			||||||
    description?: string;
 | 
					    description?: string;
 | 
				
			||||||
    iconClass?: string;
 | 
					    iconClass?: string;
 | 
				
			||||||
 | 
					    isElectronOnly?: boolean;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const keyboardActionsLoaded = server.get<Action[]>("keyboard-actions").then((actions) => {
 | 
					const keyboardActionsLoaded = server.get<Action[]>("keyboard-actions").then((actions) => {
 | 
				
			||||||
 | 
				
			|||||||
@ -275,6 +275,7 @@ function getDefaultKeyboardActions() {
 | 
				
			|||||||
            friendlyName: t("keyboard_action_names.open-new-tab"),
 | 
					            friendlyName: t("keyboard_action_names.open-new-tab"),
 | 
				
			||||||
            iconClass: "bx bx-plus",
 | 
					            iconClass: "bx bx-plus",
 | 
				
			||||||
            defaultShortcuts: isElectron ? ["CommandOrControl+T"] : [],
 | 
					            defaultShortcuts: isElectron ? ["CommandOrControl+T"] : [],
 | 
				
			||||||
 | 
					            isElectronOnly: true,
 | 
				
			||||||
            description: t("keyboard_actions.open-new-tab"),
 | 
					            description: t("keyboard_actions.open-new-tab"),
 | 
				
			||||||
            scope: "window"
 | 
					            scope: "window"
 | 
				
			||||||
        },
 | 
					        },
 | 
				
			||||||
@ -283,6 +284,7 @@ function getDefaultKeyboardActions() {
 | 
				
			|||||||
            friendlyName: t("keyboard_action_names.close-active-tab"),
 | 
					            friendlyName: t("keyboard_action_names.close-active-tab"),
 | 
				
			||||||
            iconClass: "bx bx-minus",
 | 
					            iconClass: "bx bx-minus",
 | 
				
			||||||
            defaultShortcuts: isElectron ? ["CommandOrControl+W"] : [],
 | 
					            defaultShortcuts: isElectron ? ["CommandOrControl+W"] : [],
 | 
				
			||||||
 | 
					            isElectronOnly: true,
 | 
				
			||||||
            description: t("keyboard_actions.close-active-tab"),
 | 
					            description: t("keyboard_actions.close-active-tab"),
 | 
				
			||||||
            scope: "window"
 | 
					            scope: "window"
 | 
				
			||||||
        },
 | 
					        },
 | 
				
			||||||
@ -291,6 +293,7 @@ function getDefaultKeyboardActions() {
 | 
				
			|||||||
            friendlyName: t("keyboard_action_names.reopen-last-tab"),
 | 
					            friendlyName: t("keyboard_action_names.reopen-last-tab"),
 | 
				
			||||||
            iconClass: "bx bx-undo",
 | 
					            iconClass: "bx bx-undo",
 | 
				
			||||||
            defaultShortcuts: isElectron ? ["CommandOrControl+Shift+T"] : [],
 | 
					            defaultShortcuts: isElectron ? ["CommandOrControl+Shift+T"] : [],
 | 
				
			||||||
 | 
					            isElectronOnly: true,
 | 
				
			||||||
            description: t("keyboard_actions.reopen-last-tab"),
 | 
					            description: t("keyboard_actions.reopen-last-tab"),
 | 
				
			||||||
            scope: "window"
 | 
					            scope: "window"
 | 
				
			||||||
        },
 | 
					        },
 | 
				
			||||||
@ -299,6 +302,7 @@ function getDefaultKeyboardActions() {
 | 
				
			|||||||
            friendlyName: t("keyboard_action_names.activate-next-tab"),
 | 
					            friendlyName: t("keyboard_action_names.activate-next-tab"),
 | 
				
			||||||
            iconClass: "bx bx-skip-next",
 | 
					            iconClass: "bx bx-skip-next",
 | 
				
			||||||
            defaultShortcuts: isElectron ? ["CommandOrControl+Tab", "CommandOrControl+PageDown"] : [],
 | 
					            defaultShortcuts: isElectron ? ["CommandOrControl+Tab", "CommandOrControl+PageDown"] : [],
 | 
				
			||||||
 | 
					            isElectronOnly: true,
 | 
				
			||||||
            description: t("keyboard_actions.activate-next-tab"),
 | 
					            description: t("keyboard_actions.activate-next-tab"),
 | 
				
			||||||
            scope: "window"
 | 
					            scope: "window"
 | 
				
			||||||
        },
 | 
					        },
 | 
				
			||||||
@ -307,6 +311,7 @@ function getDefaultKeyboardActions() {
 | 
				
			|||||||
            friendlyName: t("keyboard_action_names.activate-previous-tab"),
 | 
					            friendlyName: t("keyboard_action_names.activate-previous-tab"),
 | 
				
			||||||
            iconClass: "bx bx-skip-previous",
 | 
					            iconClass: "bx bx-skip-previous",
 | 
				
			||||||
            defaultShortcuts: isElectron ? ["CommandOrControl+Shift+Tab", "CommandOrControl+PageUp"] : [],
 | 
					            defaultShortcuts: isElectron ? ["CommandOrControl+Shift+Tab", "CommandOrControl+PageUp"] : [],
 | 
				
			||||||
 | 
					            isElectronOnly: true,
 | 
				
			||||||
            description: t("keyboard_actions.activate-previous-tab"),
 | 
					            description: t("keyboard_actions.activate-previous-tab"),
 | 
				
			||||||
            scope: "window"
 | 
					            scope: "window"
 | 
				
			||||||
        },
 | 
					        },
 | 
				
			||||||
@ -748,6 +753,7 @@ function getDefaultKeyboardActions() {
 | 
				
			|||||||
            friendlyName: t("keyboard_action_names.open-developer-tools"),
 | 
					            friendlyName: t("keyboard_action_names.open-developer-tools"),
 | 
				
			||||||
            iconClass: "bx bx-bug-alt",
 | 
					            iconClass: "bx bx-bug-alt",
 | 
				
			||||||
            defaultShortcuts: isElectron ? ["CommandOrControl+Shift+I"] : [],
 | 
					            defaultShortcuts: isElectron ? ["CommandOrControl+Shift+I"] : [],
 | 
				
			||||||
 | 
					            isElectronOnly: true,
 | 
				
			||||||
            description: t("keyboard_actions.open-dev-tools"),
 | 
					            description: t("keyboard_actions.open-dev-tools"),
 | 
				
			||||||
            scope: "window"
 | 
					            scope: "window"
 | 
				
			||||||
        },
 | 
					        },
 | 
				
			||||||
@ -756,6 +762,7 @@ function getDefaultKeyboardActions() {
 | 
				
			|||||||
            friendlyName: t("keyboard_action_names.find-in-text"),
 | 
					            friendlyName: t("keyboard_action_names.find-in-text"),
 | 
				
			||||||
            iconClass: "bx bx-search",
 | 
					            iconClass: "bx bx-search",
 | 
				
			||||||
            defaultShortcuts: isElectron ? ["CommandOrControl+F"] : [],
 | 
					            defaultShortcuts: isElectron ? ["CommandOrControl+F"] : [],
 | 
				
			||||||
 | 
					            isElectronOnly: true,
 | 
				
			||||||
            description: t("keyboard_actions.find-in-text"),
 | 
					            description: t("keyboard_actions.find-in-text"),
 | 
				
			||||||
            scope: "window"
 | 
					            scope: "window"
 | 
				
			||||||
        },
 | 
					        },
 | 
				
			||||||
@ -780,6 +787,7 @@ function getDefaultKeyboardActions() {
 | 
				
			|||||||
            friendlyName: t("keyboard_action_names.zoom-out"),
 | 
					            friendlyName: t("keyboard_action_names.zoom-out"),
 | 
				
			||||||
            iconClass: "bx bx-zoom-out",
 | 
					            iconClass: "bx bx-zoom-out",
 | 
				
			||||||
            defaultShortcuts: isElectron ? ["CommandOrControl+-"] : [],
 | 
					            defaultShortcuts: isElectron ? ["CommandOrControl+-"] : [],
 | 
				
			||||||
 | 
					            isElectronOnly: true,
 | 
				
			||||||
            description: t("keyboard_actions.zoom-out"),
 | 
					            description: t("keyboard_actions.zoom-out"),
 | 
				
			||||||
            scope: "window"
 | 
					            scope: "window"
 | 
				
			||||||
        },
 | 
					        },
 | 
				
			||||||
@ -789,6 +797,7 @@ function getDefaultKeyboardActions() {
 | 
				
			|||||||
            iconClass: "bx bx-zoom-in",
 | 
					            iconClass: "bx bx-zoom-in",
 | 
				
			||||||
            description: t("keyboard_actions.zoom-in"),
 | 
					            description: t("keyboard_actions.zoom-in"),
 | 
				
			||||||
            defaultShortcuts: isElectron ? ["CommandOrControl+="] : [],
 | 
					            defaultShortcuts: isElectron ? ["CommandOrControl+="] : [],
 | 
				
			||||||
 | 
					            isElectronOnly: true,
 | 
				
			||||||
            scope: "window"
 | 
					            scope: "window"
 | 
				
			||||||
        },
 | 
					        },
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
@ -797,6 +806,7 @@ function getDefaultKeyboardActions() {
 | 
				
			|||||||
            iconClass: "bx bx-search-alt",
 | 
					            iconClass: "bx bx-search-alt",
 | 
				
			||||||
            description: t("keyboard_actions.reset-zoom-level"),
 | 
					            description: t("keyboard_actions.reset-zoom-level"),
 | 
				
			||||||
            defaultShortcuts: isElectron ? ["CommandOrControl+0"] : [],
 | 
					            defaultShortcuts: isElectron ? ["CommandOrControl+0"] : [],
 | 
				
			||||||
 | 
					            isElectronOnly: true,
 | 
				
			||||||
            scope: "window"
 | 
					            scope: "window"
 | 
				
			||||||
        },
 | 
					        },
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
 | 
				
			|||||||
@ -122,6 +122,11 @@ export interface ActionKeyboardShortcut {
 | 
				
			|||||||
     * e.g. CTRL-C in note tree does something a bit different from CTRL-C in the text editor.
 | 
					     * e.g. CTRL-C in note tree does something a bit different from CTRL-C in the text editor.
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    scope?: "window" | "note-tree" | "text-detail" | "code-detail";
 | 
					    scope?: "window" | "note-tree" | "text-detail" | "code-detail";
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					     * Whether the action is only available for the desktop application.
 | 
				
			||||||
 | 
					     * This is used to hide actions that are not available in the web version.
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
 | 
					    isElectronOnly?: boolean;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export type KeyboardShortcut = ActionKeyboardShortcut | KeyboardShortcutSeparator;
 | 
					export type KeyboardShortcut = ActionKeyboardShortcut | KeyboardShortcutSeparator;
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user