-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
49 lines (40 loc) · 1.24 KB
/
main.js
File metadata and controls
49 lines (40 loc) · 1.24 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
const { app, BrowserWindow, ipcMain ,dialog} = require('electron');
const { exec } = require('child_process');
const path = require('path');
const fs = require('fs');
const dataPath = path.join(app.getPath('userData'), 'workspaces.json');
function createWindow() {
const win = new BrowserWindow({
width: 800,
height: 600,
webPreferences: { preload: path.join(__dirname, 'preload.js') }
});
win.loadFile('index.html');
}
app.whenReady().then(createWindow);
ipcMain.on('save-workspaces', (_, data) => {
fs.writeFileSync(dataPath, JSON.stringify(data, null, 2));
});
ipcMain.handle('load-workspaces', () => {
if (!fs.existsSync(dataPath)) return [];
const raw = fs.readFileSync(dataPath);
return JSON.parse(raw);
});
ipcMain.handle("pick-file", async () => {
const result = await dialog.showOpenDialog({
properties: ["openFile"]
});
if (result.canceled) return null;
return result.filePaths[0];
});
ipcMain.on('start-workspace', (_, workspace) => {
workspace.actions.forEach(a => {
if (a.type === 'chrome') {
exec(`start chrome "${a.value}"`);
} else if (a.type === 'vscode') {
exec(`code "${a.value}"`);
} else if (a.type === 'terminal') {
exec(`start cmd /K "${a.value}"`);
}
});
});