Skip to content

Commit c1fe6a7

Browse files
committed
fix: open javascript err
1 parent dd2167d commit c1fe6a7

1 file changed

Lines changed: 16 additions & 2 deletions

File tree

electron/main.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { BrowserWindow } from 'electron';
1010
export const __dirname = dirname(fileURLToPath(import.meta.url));
1111

1212
const CHUNK_SIZE = 64 * 1024;
13-
let window: any;
13+
let window: BrowserWindow | null = null;
1414

1515
process.env['ELECTRON_DISABLE_SECURITY_WARNINGS'] = 'true';
1616

@@ -49,7 +49,15 @@ const applyAppIcon = () => {
4949
return icon;
5050
};
5151

52-
const createWindow = () => {
52+
const createWindow = async () => {
53+
if (!app.isReady()) {
54+
await app.whenReady();
55+
}
56+
57+
if (window && !window.isDestroyed()) {
58+
return window;
59+
}
60+
5361
const appIcon = applyAppIcon();
5462

5563
window = new BrowserWindow({
@@ -73,6 +81,10 @@ const createWindow = () => {
7381
icon: appIcon
7482
});
7583

84+
window.on('closed', () => {
85+
window = null;
86+
});
87+
7688
const serveUrl = process.env.VITE_DEV_SERVER_URL;
7789

7890
if (app.isPackaged) {
@@ -85,6 +97,8 @@ const createWindow = () => {
8597
});
8698
window.webContents.openDevTools();
8799
}
100+
101+
return window;
88102
};
89103

90104
app.whenReady().then(() => {

0 commit comments

Comments
 (0)