mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-07-22 16:25:58 +00:00
* fix(desktop): restore closed main window on second launch * fix(desktop): reset deep-link readiness when main window closes
28 lines
667 B
TypeScript
28 lines
667 B
TypeScript
type MainWindowLike = {
|
|
isDestroyed: () => boolean
|
|
}
|
|
|
|
type EnsureMainWindowOptions<T extends MainWindowLike> = {
|
|
isReady: boolean
|
|
createWindow: () => unknown
|
|
focusWindow: (window: T) => unknown
|
|
focusExisting?: boolean
|
|
}
|
|
|
|
export function ensureMainWindow<T extends MainWindowLike>(
|
|
window: T | null | undefined,
|
|
{ isReady, createWindow, focusWindow, focusExisting = true }: EnsureMainWindowOptions<T>
|
|
) {
|
|
if (!window || window.isDestroyed()) {
|
|
// a closed electron window stays truthy, so replace it before invoking native methods.
|
|
if (isReady) {
|
|
createWindow()
|
|
}
|
|
|
|
return
|
|
}
|
|
|
|
if (focusExisting) {
|
|
focusWindow(window)
|
|
}
|
|
}
|