Rebind the studio's keys from a settings dialog

The studio's keys were a fixed table, so the views, map toggles, zoom and node editor undo and redo could not be changed. The keys now come from a store the user rebinds in a settings dialog, saved to studio.json in the app's user data folder; tooltips, the view list, the hover card and the help dialog read the live keys, and a new key that another shortcut already uses is warned about.

v3: 8930afbb3
This commit is contained in:
piexel committed 2026-11-10 12:32:42 +01:00
1 parent eb2113b835
commit a8aaa3c3cf
16 files changed
+698 -75

No files matched your search

+31 -3
View File
@@ -1,10 +1,13 @@
import { app, BrowserWindow, clipboard, ipcMain, nativeTheme, shell } from 'electron'
import { readdir, readFile } from 'node:fs/promises'
import { mkdir, readdir, readFile, writeFile } from 'node:fs/promises'
import { homedir } from 'node:os'
import { join } from 'node:path'
import type { BridgeConnection, ThemeChoice } from '../shared/bridge'
import { dirname, join } from 'node:path'
import type { BridgeConnection, StoredShortcuts, ThemeChoice } from '../shared/bridge'
const CONNECTION_FOLDER = join(homedir(), '.iris', 'studio', 'bridges')
const SETTINGS_FILE = 'studio.json'
const SHORTCUTS_KEY = 'shortcuts'
const SETTINGS_INDENT = 2
const LINK_PREFIX = 'iris-studio://'
const DARK_BACKGROUND = '#1e1f22'
const WINDOW_SIZE = { width: 1440, height: 880, minWidth: 820, minHeight: 520 }
@@ -54,6 +57,29 @@ async function readConnection(name: string): Promise<BridgeConnection | null> {
}
}
function settingsPath(): string {
return join(app.getPath('userData'), SETTINGS_FILE)
}
async function readSettings(): Promise<Record<string, unknown>> {
try {
const settings: unknown = JSON.parse(await readFile(settingsPath(), 'utf8'))
return typeof settings === 'object' && settings !== null && !Array.isArray(settings) ? (settings as Record<string, unknown>) : {}
} catch {
return {}
}
}
async function saveShortcuts(shortcuts: StoredShortcuts): Promise<void> {
try {
const settings = { ...(await readSettings()), [SHORTCUTS_KEY]: shortcuts }
await mkdir(dirname(settingsPath()), { recursive: true })
await writeFile(settingsPath(), JSON.stringify(settings, null, SETTINGS_INDENT))
} catch (failure) {
console.error(`Could not save the studio shortcuts to ${settingsPath()}`, failure)
}
}
function createWindow(): void {
window = new BrowserWindow({
...WINDOW_SIZE,
@@ -117,6 +143,8 @@ if (!app.requestSingleInstanceLock()) {
ipcMain.on('studio:set-theme', (_event, theme: ThemeChoice) => {
nativeTheme.themeSource = theme
})
ipcMain.handle('studio:load-shortcuts', async () => (await readSettings())[SHORTCUTS_KEY] ?? {})
ipcMain.on('studio:save-shortcuts', (_event, shortcuts: StoredShortcuts) => void saveShortcuts(shortcuts))
ipcMain.on('studio:copy-text', (_event, text: string) => clipboard.writeText(text))
void app.whenReady().then(createWindow)