forked from codinit-dev/codinit-dev
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwindow.ts
More file actions
64 lines (55 loc) · 1.69 KB
/
Copy pathwindow.ts
File metadata and controls
64 lines (55 loc) · 1.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import { app, BrowserWindow } from 'electron';
import path from 'node:path';
import { isDev } from '../utils/constants';
import { store } from '../utils/store';
export function createWindow(rendererURL: string) {
console.log('Creating window with URL:', rendererURL);
const bounds = store.get('bounds');
console.log('restored bounds:', bounds);
const win = new BrowserWindow({
...{
width: 1200,
height: 800,
...bounds,
},
frame: false,
vibrancy: 'under-window',
visualEffectState: 'active',
webPreferences: {
preload: path.join(app.getAppPath(), 'build', 'electron', 'preload', 'index.cjs'),
nodeIntegration: false,
contextIsolation: true,
backgroundThrottling: false,
offscreen: false,
},
});
console.log('Window created, loading URL...');
win.loadURL(rendererURL).catch((err) => {
console.log('Failed to load URL:', err);
});
win.webContents.on('did-fail-load', (_, errorCode, errorDescription) => {
console.log('Failed to load:', errorCode, errorDescription);
});
win.webContents.on('did-finish-load', () => {
console.log('Window finished loading');
});
// Open devtools in development
if (isDev) {
win.webContents.openDevTools();
}
// Debounce window bounds saving to prevent excessive disk writes
let boundsTimeout: NodeJS.Timeout | null = null;
const boundsListener = () => {
if (boundsTimeout) {
clearTimeout(boundsTimeout);
}
boundsTimeout = setTimeout(() => {
const bounds = win.getBounds();
store.set('bounds', bounds);
boundsTimeout = null;
}, 500);
};
win.on('moved', boundsListener);
win.on('resized', boundsListener);
return win;
}