-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
750ac0f
commit 0112dd2
Showing
3 changed files
with
68 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { app, BrowserWindow, type BrowserWindowConstructorOptions } from 'electron'; | ||
import { join } from 'node:path'; | ||
|
||
export enum WindowId { | ||
Main = 'main' | ||
} | ||
|
||
const windowMap = new Map<WindowId, BrowserWindow>(); | ||
|
||
export function createWindow(id: WindowId, options?: BrowserWindowConstructorOptions) { | ||
const browserWindow = new BrowserWindow({ | ||
show: false, // Use the 'ready-to-show' event to show the instantiated BrowserWindow. | ||
webPreferences: { | ||
nodeIntegration: false, | ||
contextIsolation: true, | ||
sandbox: false, // Sandbox disabled because the demo of preload script depend on the Node.js api | ||
webviewTag: false, // The webview tag is not recommended. Consider alternatives like an iframe or Electron's BrowserView. @see https://www.electronjs.org/docs/latest/api/webview-tag#warning | ||
preload: join(app.getAppPath(), 'packages/preload/dist/index.mjs'), | ||
...options, | ||
}, | ||
}); | ||
|
||
// Setup window map | ||
windowMap.set(id, browserWindow); | ||
browserWindow.on('closed', () => { | ||
windowMap.delete(id); | ||
}); | ||
// Setup window map | ||
|
||
return browserWindow; | ||
} | ||
|
||
export function getWindowById(id: WindowId): BrowserWindow | undefined { | ||
return windowMap.get(id); | ||
} |