|
1 | | -const { app, BrowserWindow, ipcMain, Menu } = require('electron'); |
| 1 | +const { app, BrowserWindow, ipcMain, Menu, shell } = require('electron'); |
2 | 2 | const path = require('path'); |
3 | 3 | const fs = require('fs'); |
4 | 4 |
|
| 5 | +// Handle Windows Squirrel events manually for Start Menu shortcut |
| 6 | +if (process.platform === 'win32') { |
| 7 | + const squirrelCommand = process.argv[1]; |
| 8 | + |
| 9 | + if (squirrelCommand === '--squirrel-install' || squirrelCommand === '--squirrel-updated') { |
| 10 | + // Create Start Menu shortcut |
| 11 | + const updateDotExe = path.resolve(path.dirname(process.execPath), '..', 'update.exe'); |
| 12 | + const exeName = path.basename(process.execPath); |
| 13 | + const startMenuDir = path.join(process.env.APPDATA, 'Microsoft', 'Windows', 'Start Menu', 'Programs'); |
| 14 | + const shortcutPath = path.join(startMenuDir, 'Script Scroller.lnk'); |
| 15 | + |
| 16 | + shell.writeShortcutLink(shortcutPath, 'create', { |
| 17 | + target: updateDotExe, |
| 18 | + args: '--processStart "' + exeName + '"', |
| 19 | + description: 'Beautiful transparent teleprompter for video creators', |
| 20 | + icon: process.execPath, |
| 21 | + iconIndex: 0, |
| 22 | + appUserModelId: 'com.scriptscroller.app' |
| 23 | + }); |
| 24 | + |
| 25 | + app.quit(); |
| 26 | + return; |
| 27 | + } |
| 28 | + |
| 29 | + if (squirrelCommand === '--squirrel-uninstall') { |
| 30 | + // Remove Start Menu shortcut |
| 31 | + const startMenuDir = path.join(process.env.APPDATA, 'Microsoft', 'Windows', 'Start Menu', 'Programs'); |
| 32 | + const shortcutPath = path.join(startMenuDir, 'Script Scroller.lnk'); |
| 33 | + |
| 34 | + try { |
| 35 | + if (fs.existsSync(shortcutPath)) { |
| 36 | + fs.unlinkSync(shortcutPath); |
| 37 | + } |
| 38 | + } catch (err) { |
| 39 | + console.error('Error removing shortcut:', err); |
| 40 | + } |
| 41 | + |
| 42 | + app.quit(); |
| 43 | + return; |
| 44 | + } |
| 45 | + |
| 46 | + if (squirrelCommand === '--squirrel-obsolete' || squirrelCommand === '--squirrel-firstrun') { |
| 47 | + app.quit(); |
| 48 | + return; |
| 49 | + } |
| 50 | +} |
| 51 | + |
5 | 52 | let mainWindow; |
6 | 53 | const stateFile = path.join(app.getPath('userData'), 'window-state.json'); |
7 | 54 |
|
|
0 commit comments