-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
executable file
·124 lines (108 loc) · 3.39 KB
/
main.js
File metadata and controls
executable file
·124 lines (108 loc) · 3.39 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
const { app, BrowserWindow, ipcMain, dialog } = require('electron');
const path = require('path');
const fs = require('fs');
let mainWindow;
function createWindow() {
mainWindow = new BrowserWindow({
width: 1400,
height: 900,
minWidth: 900,
minHeight: 600,
frame: false,
titleBarStyle: 'hidden',
backgroundColor: '#0a0a0f',
webPreferences: {
nodeIntegration: false,
contextIsolation: true,
preload: path.join(__dirname, 'preload.js')
},
icon: path.join(__dirname, 'assets', 'icon.png')
});
mainWindow.loadFile('index.html');
}
app.whenReady().then(createWindow);
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') app.quit();
});
app.on('activate', () => {
if (BrowserWindow.getAllWindows().length === 0) createWindow();
});
// Window controls
ipcMain.on('window-minimize', () => mainWindow.minimize());
ipcMain.on('window-maximize', () => {
if (mainWindow.isMaximized()) mainWindow.unmaximize();
else mainWindow.maximize();
});
ipcMain.on('window-close', () => mainWindow.close());
// File system operations
ipcMain.handle('fs-read-file', async (event, filePath) => {
try {
return { success: true, content: fs.readFileSync(filePath, 'utf8') };
} catch (e) {
return { success: false, error: e.message };
}
});
ipcMain.handle('fs-write-file', async (event, filePath, content) => {
try {
fs.mkdirSync(path.dirname(filePath), { recursive: true });
fs.writeFileSync(filePath, content, 'utf8');
return { success: true };
} catch (e) {
return { success: false, error: e.message };
}
});
ipcMain.handle('fs-create-folder', async (event, folderPath) => {
try {
fs.mkdirSync(folderPath, { recursive: true });
return { success: true };
} catch (e) {
return { success: false, error: e.message };
}
});
ipcMain.handle('fs-delete', async (event, targetPath) => {
try {
const stat = fs.statSync(targetPath);
if (stat.isDirectory()) fs.rmSync(targetPath, { recursive: true });
else fs.unlinkSync(targetPath);
return { success: true };
} catch (e) {
return { success: false, error: e.message };
}
});
ipcMain.handle('fs-rename', async (event, oldPath, newPath) => {
try {
fs.renameSync(oldPath, newPath);
return { success: true };
} catch (e) {
return { success: false, error: e.message };
}
});
ipcMain.handle('fs-read-dir', async (event, dirPath) => {
try {
const entries = fs.readdirSync(dirPath, { withFileTypes: true });
return {
success: true,
entries: entries.map(e => ({
name: e.name,
isDirectory: e.isDirectory(),
path: path.join(dirPath, e.name)
}))
};
} catch (e) {
return { success: false, error: e.message };
}
});
ipcMain.handle('dialog-open-folder', async () => {
const result = await dialog.showOpenDialog(mainWindow, {
properties: ['openDirectory']
});
return result.canceled ? null : result.filePaths[0];
});
ipcMain.handle('dialog-save-file', async (event, defaultPath) => {
const result = await dialog.showSaveDialog(mainWindow, { defaultPath });
return result.canceled ? null : result.filePath;
});
ipcMain.handle('path-join', async (event, ...args) => path.join(...args));
ipcMain.handle('path-dirname', async (event, p) => path.dirname(p));
ipcMain.handle('path-basename', async (event, p) => path.basename(p));
ipcMain.handle('path-extname', async (event, p) => path.extname(p));