-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
202 lines (174 loc) · 6.1 KB
/
main.js
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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
const { app, BrowserWindow, ipcMain, shell } = require('electron');
const path = require('path');
const Store = require('electron-store');
const { exec } = require('child_process');
// Set application name before app is ready
if (process.platform === 'darwin') {
const { name } = require('./package.json');
app.setName('Browser Launcher');
}
const store = new Store();
// Update browser paths mapping for all platforms
const BROWSER_PATHS = {
'Edge': {
'win32': {
'Canary': 'C:\\Users\\%USERNAME%\\AppData\\Local\\Microsoft\\Edge SxS\\Application\\msedge.exe',
'Dev': 'C:\\Program Files (x86)\\Microsoft\\Edge Dev\\Application\\msedge.exe',
'Beta': 'C:\\Program Files (x86)\\Microsoft\\Edge Beta\\Application\\msedge.exe',
'Stable': 'C:\\Program Files (x86)\\Microsoft\\Edge\\Application\\msedge.exe'
},
'darwin': {
'Canary': '/Applications/Microsoft Edge Canary.app',
'Dev': '/Applications/Microsoft Edge Dev.app',
'Beta': '/Applications/Microsoft Edge Beta.app',
'Stable': '/Applications/Microsoft Edge.app'
},
'linux': {
'Canary': '/usr/bin/microsoft-edge-canary',
'Dev': '/usr/bin/microsoft-edge-dev',
'Beta': '/usr/bin/microsoft-edge-beta',
'Stable': '/usr/bin/microsoft-edge-stable'
}
},
'Chrome': {
'win32': {
'Canary': 'C:\\Users\\%USERNAME%\\AppData\\Local\\Google\\Chrome SxS\\Application\\chrome.exe',
'Dev': 'C:\\Program Files\\Google\\Chrome Dev\\Application\\chrome.exe',
'Beta': 'C:\\Program Files\\Google\\Chrome Beta\\Application\\chrome.exe',
'Stable': 'C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe'
},
'darwin': {
'Canary': '/Applications/Google Chrome Canary.app',
'Dev': '/Applications/Google Chrome Dev.app',
'Beta': '/Applications/Google Chrome Beta.app',
'Stable': '/Applications/Google Chrome.app'
},
'linux': {
'Canary': '/usr/bin/google-chrome-canary',
'Dev': '/usr/bin/google-chrome-unstable',
'Beta': '/usr/bin/google-chrome-beta',
'Stable': '/usr/bin/google-chrome-stable'
}
}
};
function createWindow() {
const iconPath = path.join(__dirname, 'icons',
process.platform === 'win32' ? 'icon.ico' :
'icon.png'
);
const windowOptions = {
width: 800,
height: 600,
webPreferences: {
nodeIntegration: true,
contextIsolation: false
}
};
// Only set icon if file exists
if (require('fs').existsSync(iconPath)) {
windowOptions.icon = iconPath;
}
const mainWindow = new BrowserWindow(windowOptions);
mainWindow.loadFile('index.html');
}
app.whenReady().then(() => {
// Set the application icon for macOS
if (process.platform === 'darwin') {
const iconPath = path.join(__dirname, 'icons', 'icon.png');
try {
if (require('fs').existsSync(iconPath)) {
app.dock.setIcon(iconPath);
}
} catch (error) {
console.warn('Failed to set dock icon:', error);
}
}
createWindow();
});
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
app.quit();
}
});
app.on('activate', () => {
if (BrowserWindow.getAllWindows().length === 0) {
createWindow();
}
});
// IPC handlers for profile management
ipcMain.handle('save-profile', (event, profile) => {
let profiles = store.get('profiles') || [];
profiles.push(profile);
store.set('profiles', profiles);
return profiles;
});
ipcMain.handle('get-profiles', () => {
return store.get('profiles') || [];
});
ipcMain.handle('remove-profile', (event, index) => {
let profiles = store.get('profiles') || [];
profiles.splice(index, 1);
store.set('profiles', profiles);
return profiles;
});
ipcMain.handle('move-profile', (event, { fromIndex, toIndex }) => {
let profiles = store.get('profiles') || [];
const [removed] = profiles.splice(fromIndex, 1);
profiles.splice(toIndex, 0, removed);
store.set('profiles', profiles);
return profiles;
});
ipcMain.handle('update-profiles', (event, profiles) => {
store.set('profiles', profiles);
return profiles;
});
// Update the launch handler for cross-platform support
ipcMain.handle('launch-edge', (event, config) => {
const platform = process.platform;
const browserPath = BROWSER_PATHS[config.browser][platform]?.[config.channel];
if (!browserPath) {
throw new Error(`Invalid browser/channel combination or unsupported platform: ${config.browser} ${config.channel}`);
}
// Platform-specific launch commands
let killCommand, launchCommand;
switch (platform) {
case 'win32':
// Windows
killCommand = `taskkill /F /IM ${path.basename(browserPath)}`;
launchCommand = `"${browserPath}" ${config.arguments}`;
break;
case 'darwin':
// macOS
killCommand = `pkill -f "${browserPath}"`;
launchCommand = `open -a "${browserPath}" --args ${config.arguments}`;
break;
case 'linux':
// Linux
killCommand = `pkill -f "${browserPath}"`;
launchCommand = `"${browserPath}" ${config.arguments}`;
break;
default:
throw new Error(`Unsupported platform: ${platform}`);
}
// First close the target browser if it's running
exec(killCommand, (killError) => {
// Ignore kill error as the app might not be running
// Then launch browser with the configuration
exec(launchCommand, (error, stdout, stderr) => {
if (error) {
console.error(`Error launching browser: ${error}`);
return;
}
// Close the app after successful launch
// app.quit();
});
});
});
// Add version handler
ipcMain.handle('get-version', () => {
return app.getVersion();
});
// Add external URL handler
ipcMain.handle('open-external', (event, url) => {
shell.openExternal(url);
});