fix(main): harden startup chain, updater/sftp timeouts, host-key guard, shell env scrub
This commit is contained in:
1 parent
7aca8c5cb0
commit
ee667cdc2b
6 files changed
+197
-59
No files matched your search
@@ -1,9 +1,33 @@
|
||||
import { BrowserWindow, globalShortcut } from 'electron'
|
||||
|
||||
/**
|
||||
* Chords the app owns outright: Ctrl+L is the panic lock, captured in the main
|
||||
* window's before-input-event. The settings recorder (SettingsTabs.tsx,
|
||||
* RESERVED_EXACT_ACCELERATORS) refuses to save it, but that guard only covers
|
||||
* values entered after it existed — a shortcut persisted by an older build
|
||||
* still arrives here, and a global registration intercepts the key at the OS
|
||||
* level even while the window is focused, silently killing the lock shortcut.
|
||||
* Normalized (modifier aliases + case folded) so every spelling is caught.
|
||||
*/
|
||||
const RESERVED_ACCELERATORS = new Set(['control+l', 'commandorcontrol+l'])
|
||||
|
||||
function normalizeAccelerator(accelerator: string): string {
|
||||
return accelerator
|
||||
.split('+')
|
||||
.map((part) => {
|
||||
const p = part.trim().toLowerCase()
|
||||
if (p === 'ctrl') return 'control'
|
||||
if (p === 'cmdorctrl' || p === 'commandorctrl') return 'commandorcontrol'
|
||||
return p
|
||||
})
|
||||
.join('+')
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the global show/hide toggle for the main window.
|
||||
*
|
||||
* - accelerator '' / undefined => disabled (no global key bound).
|
||||
* - A reserved chord (Ctrl+L) is skipped: see RESERVED_ACCELERATORS.
|
||||
* - Passing an invalid accelerator string makes Electron's register() throw;
|
||||
* we swallow that here so a bad user-supplied value never crashes the app.
|
||||
* - register() returning false means the accelerator is already taken by
|
||||
@@ -15,6 +39,13 @@ export function applyGlobalShortcut(accelerator: string | undefined): void {
|
||||
globalShortcut.unregisterAll()
|
||||
if (!accelerator) return
|
||||
|
||||
if (RESERVED_ACCELERATORS.has(normalizeAccelerator(accelerator))) {
|
||||
console.warn(
|
||||
`[global-shortcut] "${accelerator}" is reserved for the Ctrl+L lock shortcut; not registering`
|
||||
)
|
||||
return
|
||||
}
|
||||
|
||||
const handler = (): void => {
|
||||
const win = BrowserWindow.getAllWindows()[0]
|
||||
if (!win || win.isDestroyed()) return
|
||||
|
||||
Reference in new issue
Block a user