-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain-with-background.js
More file actions
79 lines (66 loc) · 2 KB
/
main-with-background.js
File metadata and controls
79 lines (66 loc) · 2 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
const { app, BrowserWindow } = require('electron');
const path = require('path');
let mainWindow;
function createWindow() {
mainWindow = new BrowserWindow({
width: 420,
height: 420,
frame: false,
transparent: true,
alwaysOnTop: true,
skipTaskbar: false,
resizable: true,
hasShadow: false,
show: true,
webPreferences: {
nodeIntegration: false,
contextIsolation: true,
enableRemoteModule: false,
webSecurity: false,
preload: path.join(__dirname, 'preload.js')
}
});
// Set app name
app.setName('Floating Orb (Glass)');
// Open DevTools for debugging (remove in production)
// mainWindow.webContents.openDevTools();
// Log when window is ready
mainWindow.webContents.on('did-finish-load', () => {
console.log('Window loaded successfully');
});
mainWindow.webContents.on('did-fail-load', (event, errorCode, errorDescription) => {
console.error('Failed to load:', errorCode, errorDescription);
});
// Load the app - use dist/ for packaged app, localhost for dev
if (app.isPackaged) {
mainWindow.loadFile(path.join(__dirname, 'dist', 'index-with-background.html'));
} else {
mainWindow.loadURL('http://localhost:3000/index-with-background.html');
}
// Position window in center of screen
const { screen } = require('electron');
const primaryDisplay = screen.getPrimaryDisplay();
const { width, height } = primaryDisplay.workAreaSize;
const x = Math.floor((width - 420) / 2);
const y = Math.floor((height - 420) / 2);
mainWindow.setPosition(x, y);
mainWindow.show();
mainWindow.focus();
console.log('Window positioned at:', x, y, 'Screen size:', width, height);
mainWindow.on('closed', () => {
mainWindow = null;
});
}
app.whenReady().then(() => {
createWindow();
app.on('activate', () => {
if (BrowserWindow.getAllWindows().length === 0) {
createWindow();
}
});
});
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
app.quit();
}
});