Skip to content

Commit

Permalink
style: update api key input field formatting and validation
Browse files Browse the repository at this point in the history
  • Loading branch information
kangfenmao committed Dec 3, 2024
1 parent f5d37a4 commit a4d1bcf
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
1 change: 0 additions & 1 deletion src/main/ipc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
16 changes: 9 additions & 7 deletions src/main/services/ShortcutService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -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))
}
})
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,10 @@ const ProviderSetting: FC<Props> = ({ provider: _provider }) => {
</div>
)

const formatApiKeys = (value: string) => {
return value.replaceAll(',', ',').replaceAll(' ', ',').replaceAll(' ', '').replaceAll('\n', ',')
}

return (
<SettingContainer theme={theme}>
<SettingTitle>
Expand All @@ -192,7 +196,7 @@ const ProviderSetting: FC<Props> = ({ provider: _provider }) => {
<Input.Password
value={apiKey}
placeholder={t('settings.provider.api_key')}
onChange={(e) => setApiKey(e.target.value.replaceAll(',', ',').replaceAll(' ', ''))}
onChange={(e) => setApiKey(formatApiKeys(e.target.value))}
onBlur={onUpdateApiKey}
spellCheck={false}
type="password"
Expand Down

0 comments on commit a4d1bcf

Please sign in to comment.