|
|
@@ -450,6 +450,29 @@ ipcMain.on("readConfig", (event, message) => {
|
|
|
}
|
|
|
})
|
|
|
|
|
|
+ipcMain.handle("saveFile", async (event, message) => {
|
|
|
+ try {
|
|
|
+ // 确保download目录存在
|
|
|
+ const downloadDir = path.join(__dirname, 'download');
|
|
|
+ if (!fs.existsSync(downloadDir)) {
|
|
|
+ fs.mkdirSync(downloadDir, { recursive: true });
|
|
|
+ console.log('创建download目录:', downloadDir);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 构建完整的文件路径
|
|
|
+ const filePath = path.join(downloadDir, message.filename);
|
|
|
+
|
|
|
+ // 保存文件内容
|
|
|
+ fs.writeFileSync(filePath, message.content);
|
|
|
+
|
|
|
+ console.log('文件保存成功:', filePath);
|
|
|
+ return { success: true, path: filePath };
|
|
|
+ } catch (error) {
|
|
|
+ console.error('保存文件失败:', error);
|
|
|
+ return { success: false, error: error.message };
|
|
|
+ }
|
|
|
+});
|
|
|
+
|
|
|
|
|
|
ipcMain.on("saveConfig", (event, message) => {
|
|
|
fs.writeFileSync('./config.json', JSON.stringify(message))
|