2026-04-07 00:43:40 -07:00
|
|
|
export interface ShortcutConfig {
|
2026-04-07 03:42:46 -07:00
|
|
|
generalAssist: string;
|
2026-04-07 00:43:40 -07:00
|
|
|
quickAsk: string;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const DEFAULTS: ShortcutConfig = {
|
2026-04-24 20:43:04 +02:00
|
|
|
generalAssist: 'CommandOrControl+Shift+S',
|
|
|
|
|
quickAsk: 'CommandOrControl+Alt+S',
|
2026-04-07 00:43:40 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const STORE_KEY = 'shortcuts';
|
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- lazily imported ESM module; matches folder-watcher.ts pattern
|
|
|
|
|
let store: any = null;
|
|
|
|
|
|
|
|
|
|
async function getStore() {
|
|
|
|
|
if (!store) {
|
|
|
|
|
const { default: Store } = await import('electron-store');
|
|
|
|
|
store = new Store({
|
|
|
|
|
name: 'keyboard-shortcuts',
|
|
|
|
|
defaults: { [STORE_KEY]: DEFAULTS },
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
return store;
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-24 20:43:04 +02:00
|
|
|
/** One-time fix if both shortcuts match the mistaken Alt+Shift pair. */
|
|
|
|
|
function wasRegressionAltPair(rest: Record<string, string>): boolean {
|
|
|
|
|
return rest.generalAssist === 'Alt+Shift+G' && rest.quickAsk === 'Alt+Shift+Q';
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-07 00:43:40 -07:00
|
|
|
export async function getShortcuts(): Promise<ShortcutConfig> {
|
|
|
|
|
const s = await getStore();
|
2026-04-24 19:14:37 +02:00
|
|
|
const raw = (s.get(STORE_KEY) as Record<string, string> | undefined) ?? {};
|
|
|
|
|
const { autocomplete: _drop, ...rest } = raw;
|
2026-04-24 20:43:04 +02:00
|
|
|
if (wasRegressionAltPair(rest)) {
|
|
|
|
|
const fixed = { ...DEFAULTS };
|
|
|
|
|
s.set(STORE_KEY, { ...fixed });
|
|
|
|
|
return fixed;
|
|
|
|
|
}
|
2026-04-24 19:14:37 +02:00
|
|
|
return { ...DEFAULTS, ...rest };
|
2026-04-07 00:43:40 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function setShortcuts(config: Partial<ShortcutConfig>): Promise<ShortcutConfig> {
|
|
|
|
|
const s = await getStore();
|
2026-04-24 19:14:37 +02:00
|
|
|
const raw = (s.get(STORE_KEY) as Record<string, string> | undefined) ?? {};
|
|
|
|
|
const { autocomplete: _drop, ...current } = raw;
|
|
|
|
|
const merged = { ...DEFAULTS, ...current, ...config };
|
2026-04-07 00:43:40 -07:00
|
|
|
s.set(STORE_KEY, merged);
|
|
|
|
|
return merged;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function getDefaults(): ShortcutConfig {
|
|
|
|
|
return { ...DEFAULTS };
|
|
|
|
|
}
|