-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathelectron-main.js
More file actions
133 lines (116 loc) · 3.37 KB
/
electron-main.js
File metadata and controls
133 lines (116 loc) · 3.37 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
const { app, BrowserWindow, ipcMain, dialog } = require('electron');
const path = require('path');
const fs = require('fs').promises;
let mainWindow;
// File system API handlers
ipcMain.handle('dialog:openDirectory', async () => {
const result = await dialog.showOpenDialog(mainWindow, {
properties: ['openDirectory']
});
if (!result.canceled && result.filePaths.length > 0) {
return result.filePaths[0];
}
return null;
});
ipcMain.handle('fs:writeFile', async (event, filePath, data) => {
try {
await fs.writeFile(filePath, data);
return { success: true };
} catch (error) {
return { success: false, error: error.message };
}
});
ipcMain.handle('fs:readFile', async (event, filePath) => {
try {
const data = await fs.readFile(filePath, 'utf-8');
return { success: true, data };
} catch (error) {
return { success: false, error: error.message };
}
});
ipcMain.handle('fs:copyFile', async (event, source, destination) => {
try {
await fs.copyFile(source, destination);
return { success: true };
} catch (error) {
return { success: false, error: error.message };
}
});
ipcMain.handle('fs:readdir', async (event, dirPath) => {
try {
const files = await fs.readdir(dirPath);
return { success: true, files };
} catch (error) {
return { success: false, error: error.message };
}
});
ipcMain.handle('fs:mkdir', async (event, dirPath) => {
try {
await fs.mkdir(dirPath, { recursive: true });
return { success: true };
} catch (error) {
return { success: false, error: error.message };
}
});
ipcMain.handle('fs:unlink', async (event, filePath) => {
try {
await fs.unlink(filePath);
return { success: true };
} catch (error) {
return { success: false, error: error.message };
}
});
ipcMain.handle('fs:stat', async (event, filePath) => {
try {
const stats = await fs.stat(filePath);
return { success: true, stats: {
isFile: stats.isFile(),
isDirectory: stats.isDirectory(),
size: stats.size,
mtime: stats.mtime
}};
} catch (error) {
return { success: false, error: error.message };
}
});
ipcMain.handle('fs:rmdir', async (event, dirPath) => {
try {
await fs.rm(dirPath, { recursive: true, force: true });
return { success: true };
} catch (error) {
return { success: false, error: error.message };
}
});
function createWindow() {
mainWindow = new BrowserWindow({
width: 1400,
height: 900,
minWidth: 800,
minHeight: 600,
webPreferences: {
preload: path.join(__dirname, 'preload.js'),
contextIsolation: true,
nodeIntegration: false
},
icon: path.join(__dirname, 'favicon.ico')
});
mainWindow.loadFile('index.html');
// Open DevTools in development
// mainWindow.webContents.openDevTools();
mainWindow.on('closed', () => {
mainWindow = null;
});
}
app.whenReady().then(() => {
createWindow();
app.on('activate', () => {
if (BrowserWindow.getAllWindows().length === 0) {
createWindow();
}
});
});
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
app.quit();
}
});