-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
161 lines (136 loc) · 4.04 KB
/
main.js
File metadata and controls
161 lines (136 loc) · 4.04 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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
const { app, BrowserWindow, ipcMain, Menu, shell } = require('electron');
const path = require('path');
const fs = require('fs');
// Handle Windows Squirrel events manually for Start Menu shortcut
if (process.platform === 'win32') {
const squirrelCommand = process.argv[1];
if (squirrelCommand === '--squirrel-install' || squirrelCommand === '--squirrel-updated') {
// Create Start Menu shortcut
const updateDotExe = path.resolve(path.dirname(process.execPath), '..', 'update.exe');
const exeName = path.basename(process.execPath);
const startMenuDir = path.join(process.env.APPDATA, 'Microsoft', 'Windows', 'Start Menu', 'Programs');
const shortcutPath = path.join(startMenuDir, 'Script Scroller.lnk');
shell.writeShortcutLink(shortcutPath, 'create', {
target: updateDotExe,
args: '--processStart "' + exeName + '"',
description: 'Beautiful transparent teleprompter for video creators',
icon: process.execPath,
iconIndex: 0,
appUserModelId: 'com.scriptscroller.app'
});
app.quit();
return;
}
if (squirrelCommand === '--squirrel-uninstall') {
// Remove Start Menu shortcut
const startMenuDir = path.join(process.env.APPDATA, 'Microsoft', 'Windows', 'Start Menu', 'Programs');
const shortcutPath = path.join(startMenuDir, 'Script Scroller.lnk');
try {
if (fs.existsSync(shortcutPath)) {
fs.unlinkSync(shortcutPath);
}
} catch (err) {
console.error('Error removing shortcut:', err);
}
app.quit();
return;
}
if (squirrelCommand === '--squirrel-obsolete' || squirrelCommand === '--squirrel-firstrun') {
app.quit();
return;
}
}
let mainWindow;
const stateFile = path.join(app.getPath('userData'), 'window-state.json');
// Load saved state
function loadState() {
try {
if (fs.existsSync(stateFile)) {
return JSON.parse(fs.readFileSync(stateFile, 'utf8'));
}
} catch (err) {
console.error('Error loading state:', err);
}
return null;
}
// Save state
function saveState(state) {
try {
const bounds = mainWindow.getBounds();
const fullState = {
...state,
bounds: bounds
};
fs.writeFileSync(stateFile, JSON.stringify(fullState, null, 2));
} catch (err) {
console.error('Error saving state:', err);
}
}
function createWindow() {
const savedState = loadState();
const defaultBounds = { width: 900, height: 900, x: undefined, y: undefined };
const bounds = savedState?.bounds || defaultBounds;
mainWindow = new BrowserWindow({
width: bounds.width,
height: bounds.height,
x: bounds.x,
y: bounds.y,
minWidth: 850,
minHeight: 850,
frame: false, // No title bar
transparent: true, // Transparent background
alwaysOnTop: true, // Always stay on top
resizable: true,
webPreferences: {
nodeIntegration: true,
contextIsolation: false
}
});
mainWindow.loadFile('teleprompter.html');
// Remove menu bar
Menu.setApplicationMenu(null);
mainWindow.on('closed', () => {
mainWindow = null;
});
}
app.whenReady().then(createWindow);
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
app.quit();
}
});
app.on('activate', () => {
if (BrowserWindow.getAllWindows().length === 0) {
createWindow();
}
});
// Handle window control
ipcMain.on('minimize-window', () => {
if (mainWindow) mainWindow.minimize();
});
ipcMain.on('close-window', () => {
if (mainWindow) mainWindow.close();
});
// Handle window size constraints
ipcMain.on('remove-size-constraints', () => {
if (mainWindow) {
mainWindow.setMinimumSize(0, 0);
}
});
ipcMain.on('resize-to-minimum', () => {
if (mainWindow) {
mainWindow.setMinimumSize(850, 850);
const currentBounds = mainWindow.getBounds();
if (currentBounds.width < 850 || currentBounds.height < 850) {
mainWindow.setSize(850, 850);
}
}
});
// Handle state saving
ipcMain.on('save-state', (event, state) => {
saveState(state);
});
// Handle state retrieval
ipcMain.handle('get-state', () => {
return loadState();
});