From a4d1bcffd93badbfd93fe04b2e34f9296d510807 Mon Sep 17 00:00:00 2001 From: kangfenmao Date: Tue, 3 Dec 2024 12:12:28 +0800 Subject: [PATCH] style: update api key input field formatting and validation --- src/main/ipc.ts | 1 - src/main/services/ShortcutService.ts | 16 +++++++++------- .../ProviderSettings/ProviderSetting.tsx | 6 +++++- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/src/main/ipc.ts b/src/main/ipc.ts index 7703e5f5e..90303677f 100644 --- a/src/main/ipc.ts +++ b/src/main/ipc.ts @@ -138,7 +138,6 @@ export function registerIpc(mainWindow: BrowserWindow, app: Electron.App) { // shortcuts ipcMain.handle('shortcuts:update', (_, shortcuts: Shortcut[]) => { configManager.setShortcuts(shortcuts) - log.info('[ipc] shortcuts updated', shortcuts) // Refresh shortcuts registration if (mainWindow) { unregisterAllShortcuts() diff --git a/src/main/services/ShortcutService.ts b/src/main/services/ShortcutService.ts index b05a3de91..aed507b8a 100644 --- a/src/main/services/ShortcutService.ts +++ b/src/main/services/ShortcutService.ts @@ -55,7 +55,7 @@ export function registerShortcuts(window: BrowserWindow) { if (!shortcuts) return shortcuts.forEach((shortcut) => { - if (!shortcut.enabled || shortcut.shortcut.length === 0) { + if (shortcut.shortcut.length === 0) { return } @@ -74,20 +74,22 @@ export function registerShortcuts(window: BrowserWindow) { if (shortcut.key.includes('zoom')) { switch (shortcut.key) { case 'zoom_in': - globalShortcut.register('CommandOrControl+=', () => handler(window)) - globalShortcut.register('CommandOrControl+numadd', () => handler(window)) + globalShortcut.register('CommandOrControl+=', () => shortcut.enabled && handler(window)) + globalShortcut.register('CommandOrControl+numadd', () => shortcut.enabled && handler(window)) return case 'zoom_out': - globalShortcut.register('CommandOrControl+-', () => handler(window)) - globalShortcut.register('CommandOrControl+numsub', () => handler(window)) + globalShortcut.register('CommandOrControl+-', () => shortcut.enabled && handler(window)) + globalShortcut.register('CommandOrControl+numsub', () => shortcut.enabled && handler(window)) return case 'zoom_reset': - globalShortcut.register('CommandOrControl+0', () => handler(window)) + globalShortcut.register('CommandOrControl+0', () => shortcut.enabled && handler(window)) return } } - globalShortcut.register(accelerator, () => handler(window)) + if (shortcut.enabled) { + globalShortcut.register(accelerator, () => handler(window)) + } }) } diff --git a/src/renderer/src/pages/settings/ProviderSettings/ProviderSetting.tsx b/src/renderer/src/pages/settings/ProviderSettings/ProviderSetting.tsx index 4ef4de3c4..db24ca197 100644 --- a/src/renderer/src/pages/settings/ProviderSettings/ProviderSetting.tsx +++ b/src/renderer/src/pages/settings/ProviderSettings/ProviderSetting.tsx @@ -169,6 +169,10 @@ const ProviderSetting: FC = ({ provider: _provider }) => { ) + const formatApiKeys = (value: string) => { + return value.replaceAll(',', ',').replaceAll(' ', ',').replaceAll(' ', '').replaceAll('\n', ',') + } + return ( @@ -192,7 +196,7 @@ const ProviderSetting: FC = ({ provider: _provider }) => { setApiKey(e.target.value.replaceAll(',', ',').replaceAll(' ', ''))} + onChange={(e) => setApiKey(formatApiKeys(e.target.value))} onBlur={onUpdateApiKey} spellCheck={false} type="password"