Keyboard short cuts (#6711)
Co-authored-by: Douwe Osinga <douwe@squareup.com>
This commit is contained in:
@@ -1,71 +1,67 @@
|
||||
import { app } from 'electron';
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
|
||||
export interface EnvToggles {
|
||||
GOOSE_SERVER__MEMORY: boolean;
|
||||
GOOSE_SERVER__COMPUTER_CONTROLLER: boolean;
|
||||
}
|
||||
|
||||
export interface ExternalGoosedConfig {
|
||||
enabled: boolean;
|
||||
url: string;
|
||||
secret: string;
|
||||
}
|
||||
|
||||
export interface KeyboardShortcuts {
|
||||
focusWindow: string | null;
|
||||
quickLauncher: string | null;
|
||||
newChat: string | null;
|
||||
newChatWindow: string | null;
|
||||
openDirectory: string | null;
|
||||
settings: string | null;
|
||||
find: string | null;
|
||||
findNext: string | null;
|
||||
findPrevious: string | null;
|
||||
alwaysOnTop: string | null;
|
||||
}
|
||||
|
||||
export type DefaultKeyboardShortcuts = {
|
||||
[K in keyof KeyboardShortcuts]: string;
|
||||
};
|
||||
|
||||
export interface Settings {
|
||||
envToggles: EnvToggles;
|
||||
showMenuBarIcon: boolean;
|
||||
showDockIcon: boolean;
|
||||
enableWakelock: boolean;
|
||||
spellcheckEnabled: boolean;
|
||||
externalGoosed?: ExternalGoosedConfig;
|
||||
globalShortcut?: string | null;
|
||||
keyboardShortcuts?: KeyboardShortcuts;
|
||||
}
|
||||
|
||||
const SETTINGS_FILE = path.join(app.getPath('userData'), 'settings.json');
|
||||
|
||||
const defaultSettings: Settings = {
|
||||
envToggles: {
|
||||
GOOSE_SERVER__MEMORY: false,
|
||||
GOOSE_SERVER__COMPUTER_CONTROLLER: false,
|
||||
},
|
||||
showMenuBarIcon: true,
|
||||
showDockIcon: true,
|
||||
enableWakelock: false,
|
||||
spellcheckEnabled: true,
|
||||
export const defaultKeyboardShortcuts: DefaultKeyboardShortcuts = {
|
||||
focusWindow: 'CommandOrControl+Alt+G',
|
||||
quickLauncher: 'CommandOrControl+Alt+Shift+G',
|
||||
newChat: 'CommandOrControl+T',
|
||||
newChatWindow: 'CommandOrControl+N',
|
||||
openDirectory: 'CommandOrControl+O',
|
||||
settings: 'CommandOrControl+,',
|
||||
find: 'CommandOrControl+F',
|
||||
findNext: 'CommandOrControl+G',
|
||||
findPrevious: 'CommandOrControl+Shift+G',
|
||||
alwaysOnTop: 'CommandOrControl+Shift+T',
|
||||
};
|
||||
|
||||
// Settings management
|
||||
export function loadSettings(): Settings {
|
||||
try {
|
||||
if (fs.existsSync(SETTINGS_FILE)) {
|
||||
const data = fs.readFileSync(SETTINGS_FILE, 'utf8');
|
||||
return JSON.parse(data);
|
||||
export function getKeyboardShortcuts(settings: Settings): KeyboardShortcuts {
|
||||
if (!settings.keyboardShortcuts && settings.globalShortcut !== undefined) {
|
||||
const focusShortcut = settings.globalShortcut;
|
||||
let launcherShortcut: string | null = null;
|
||||
|
||||
if (focusShortcut) {
|
||||
if (focusShortcut.includes('Shift')) {
|
||||
launcherShortcut = focusShortcut;
|
||||
} else {
|
||||
launcherShortcut = focusShortcut.replace(/\+([Gg])$/, '+Shift+$1');
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error loading settings:', error);
|
||||
}
|
||||
return defaultSettings;
|
||||
}
|
||||
|
||||
export function saveSettings(settings: Settings): void {
|
||||
try {
|
||||
fs.writeFileSync(SETTINGS_FILE, JSON.stringify(settings, null, 2));
|
||||
} catch (error) {
|
||||
console.error('Error saving settings:', error);
|
||||
}
|
||||
}
|
||||
|
||||
export function updateEnvironmentVariables(envToggles: EnvToggles): void {
|
||||
if (envToggles.GOOSE_SERVER__MEMORY) {
|
||||
process.env.GOOSE_SERVER__MEMORY = 'true';
|
||||
} else {
|
||||
delete process.env.GOOSE_SERVER__MEMORY;
|
||||
}
|
||||
|
||||
if (envToggles.GOOSE_SERVER__COMPUTER_CONTROLLER) {
|
||||
process.env.GOOSE_SERVER__COMPUTER_CONTROLLER = 'true';
|
||||
} else {
|
||||
delete process.env.GOOSE_SERVER__COMPUTER_CONTROLLER;
|
||||
return {
|
||||
...defaultKeyboardShortcuts,
|
||||
focusWindow: focusShortcut,
|
||||
quickLauncher: launcherShortcut,
|
||||
};
|
||||
}
|
||||
return settings.keyboardShortcuts || defaultKeyboardShortcuts;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user