-
Notifications
You must be signed in to change notification settings - Fork 912
desktop: configurable keyboard shortcuts #538
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Kitenite
merged 5 commits into
superset-sh:main
from
andreasasprou:configurable-keyboard-shortcuts
Dec 31, 2025
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
26feb54
desktop: configurable keyboard shortcuts
andreasasprou 21bf358
desktop: handle hotkeys export write errors
andreasasprou e1aa02e
fix(desktop): address PR review feedback for keyboard shortcuts
andreasasprou 7a337ec
merge: resolve conflict with upstream/main and fix lint
andreasasprou ad0aca0
merge: resolve conflict with origin/main
Kitenite File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,133 @@ | ||
| import { readFile, writeFile } from "node:fs/promises"; | ||
| import { type BrowserWindow, dialog } from "electron"; | ||
| import { appState } from "main/lib/app-state"; | ||
| import { | ||
| buildHotkeysStateFromExport, | ||
| createHotkeysExport, | ||
| getCurrentPlatform, | ||
| getHotkeysSummary, | ||
| type HotkeysExportFile, | ||
| type HotkeysState, | ||
| normalizeBindingsWithDefaults, | ||
| } from "shared/hotkeys"; | ||
| import { z } from "zod"; | ||
| import { publicProcedure, router } from "../.."; | ||
|
|
||
| const hotkeysExportSchema = z.object({ | ||
| schemaVersion: z.number(), | ||
| exportedAt: z.string(), | ||
| app: z.string(), | ||
| hotkeys: z | ||
| .object({ | ||
| darwin: z.record(z.string(), z.string().nullable()).optional(), | ||
| win32: z.record(z.string(), z.string().nullable()).optional(), | ||
| linux: z.record(z.string(), z.string().nullable()).optional(), | ||
| }) | ||
| .optional(), | ||
| }); | ||
|
|
||
| export type HotkeysImportResult = | ||
| | { canceled: true } | ||
| | { | ||
| canceled: false; | ||
| path: string; | ||
| state: HotkeysState; | ||
| summary: { assigned: number; disabled: number }; | ||
| raw: HotkeysExportFile; | ||
| } | ||
| | { canceled: false; error: string }; | ||
|
|
||
| type HotkeysExportResult = | ||
| | { canceled: true } | ||
| | { canceled: false; path: string } | ||
| | { canceled: false; error: string }; | ||
|
|
||
| export const createHotkeysRouter = (getWindow: () => BrowserWindow | null) => { | ||
| return router({ | ||
| export: publicProcedure.mutation(async (): Promise<HotkeysExportResult> => { | ||
| const window = getWindow(); | ||
| if (!window) { | ||
| return { canceled: false, error: "No window available" }; | ||
| } | ||
|
|
||
| const result = await dialog.showSaveDialog(window, { | ||
| title: "Export Keyboard Shortcuts", | ||
| defaultPath: "superset-hotkeys.json", | ||
| filters: [{ name: "JSON", extensions: ["json"] }], | ||
| }); | ||
|
|
||
| if (result.canceled || !result.filePath) { | ||
| return { canceled: true }; | ||
| } | ||
|
|
||
| const exportFile = createHotkeysExport(appState.data.hotkeysState); | ||
| try { | ||
| await writeFile( | ||
| result.filePath, | ||
| JSON.stringify(exportFile, null, 2), | ||
| "utf-8", | ||
| ); | ||
| } catch (error) { | ||
| const message = | ||
| error instanceof Error ? error.message : "Failed to write file"; | ||
| return { canceled: false, error: message }; | ||
| } | ||
|
|
||
| return { canceled: false, path: result.filePath }; | ||
| }), | ||
|
|
||
| import: publicProcedure.mutation(async (): Promise<HotkeysImportResult> => { | ||
| const window = getWindow(); | ||
| if (!window) { | ||
| return { canceled: false, error: "No window available" }; | ||
| } | ||
|
|
||
| const result = await dialog.showOpenDialog(window, { | ||
| title: "Import Keyboard Shortcuts", | ||
| properties: ["openFile"], | ||
| filters: [{ name: "JSON", extensions: ["json"] }], | ||
| }); | ||
|
|
||
| if (result.canceled || result.filePaths.length === 0) { | ||
| return { canceled: true }; | ||
| } | ||
|
|
||
| const filePath = result.filePaths[0]; | ||
|
|
||
| try { | ||
| const raw = await readFile(filePath, "utf-8"); | ||
| const parsed = hotkeysExportSchema.parse(JSON.parse(raw)); | ||
| const exportFile: HotkeysExportFile = { | ||
| schemaVersion: parsed.schemaVersion, | ||
| exportedAt: parsed.exportedAt, | ||
| app: parsed.app, | ||
| hotkeys: { | ||
| darwin: parsed.hotkeys?.darwin ?? {}, | ||
| win32: parsed.hotkeys?.win32 ?? {}, | ||
| linux: parsed.hotkeys?.linux ?? {}, | ||
| }, | ||
| }; | ||
|
|
||
| const state = buildHotkeysStateFromExport(exportFile); | ||
| const platform = getCurrentPlatform(); | ||
| const bindings = normalizeBindingsWithDefaults( | ||
| exportFile.hotkeys?.[platform] ?? {}, | ||
| platform, | ||
| ); | ||
| const summary = getHotkeysSummary(bindings); | ||
|
|
||
| return { | ||
| canceled: false, | ||
| path: filePath, | ||
| state, | ||
| summary, | ||
| raw: exportFile, | ||
| }; | ||
| } catch (error) { | ||
| const message = | ||
| error instanceof Error ? error.message : "Invalid hotkeys file"; | ||
| return { canceled: false, error: message }; | ||
| } | ||
| }), | ||
| }); | ||
| }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| import { EventEmitter } from "node:events"; | ||
|
|
||
| export interface HotkeysStateChangedEvent { | ||
| version: number; | ||
| updatedAt: string; | ||
| } | ||
|
|
||
| export const hotkeysEmitter = new EventEmitter(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.