mirror of
https://github.com/AgentSeal/codeburn.git
synced 2026-11-23 21:39:13 +00:00
The plugin runtime has not shipped for Windows, so `codeburn plugin list` never answers there and the section sat on "Loading plugins..." for as long as the app was open. A spinner that will never stop is worse than a sentence. Windows now gets a panel instead: the section's own glyph, one line saying plugins are coming, and one saying they arrive in a later Windows release and work today elsewhere. It loads nothing, and the check happens in a dispatcher above the loader rather than inside it, so the loader's hooks never mount and there is no CLI call, no spinner and no timer to unwind. Every other platform renders exactly what it did.
54 lines
2.3 KiB
TypeScript
54 lines
2.3 KiB
TypeScript
// Single source of truth for platform-aware shortcut behaviour. The preload
|
|
// exposes `window.codeburn.platform` (process.platform); when the bridge is
|
|
// absent (unit tests, vite in a plain browser) fall back to the user agent.
|
|
// All functions read platform state at call time, never at module load, so
|
|
// the preload bridge may appear after this module is imported.
|
|
|
|
function bridgePlatform(): string | undefined {
|
|
if (typeof window === 'undefined') return undefined
|
|
return (window as unknown as { codeburn?: { platform?: string } }).codeburn?.platform
|
|
}
|
|
|
|
function userAgentPlatform(): string | undefined {
|
|
if (typeof navigator === 'undefined') return undefined
|
|
if (/mac/i.test(navigator.userAgent)) return 'darwin'
|
|
const platform = navigator.platform
|
|
if (typeof platform === 'string' && /mac/i.test(platform)) return 'darwin'
|
|
return undefined
|
|
}
|
|
|
|
/** True when the Electron preload reports darwin (or the UA matches a Mac). */
|
|
export function isMacPlatform(): boolean {
|
|
const platform = bridgePlatform()
|
|
if (platform) return platform === 'darwin'
|
|
return userAgentPlatform() === 'darwin'
|
|
}
|
|
|
|
/** True when the Electron preload reports win32 (or the UA names Windows). */
|
|
export function isWindowsPlatform(): boolean {
|
|
const platform = bridgePlatform()
|
|
if (platform) return platform === 'win32'
|
|
if (typeof navigator === 'undefined') return false
|
|
return /windows/i.test(navigator.userAgent)
|
|
}
|
|
|
|
/** The modifier keycap label: '⌘' on mac, 'Ctrl+' elsewhere. */
|
|
export function modKeyLabel(): string {
|
|
return isMacPlatform() ? '⌘' : 'Ctrl+'
|
|
}
|
|
|
|
/** A full shortcut label, e.g. '⌘R' on mac, 'Ctrl+R' on Windows. */
|
|
export function shortcutLabel(key: string): string {
|
|
return modKeyLabel() + key
|
|
}
|
|
|
|
/**
|
|
* True when the event is the platform's modifier chord and no other modifier
|
|
* is held. On mac: Meta (Cmd) without Ctrl. Elsewhere: Ctrl without Meta.
|
|
* altKey stays rejected on every platform: AltGr on European layouts arrives
|
|
* as Ctrl+Alt, and Ctrl+Alt+<key> must not hijack a typed character.
|
|
*/
|
|
export function isModifierChord(event: { metaKey: boolean; ctrlKey: boolean; altKey: boolean; shiftKey: boolean }): boolean {
|
|
if (event.altKey || event.shiftKey) return false
|
|
return isMacPlatform() ? event.metaKey && !event.ctrlKey : event.ctrlKey && !event.metaKey
|
|
}
|