-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
106 lines (92 loc) · 3.21 KB
/
Copy pathmain.js
File metadata and controls
106 lines (92 loc) · 3.21 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
const { app, BrowserWindow, ipcMain, Menu } = require('electron');
const { exec, execSync } = require('child_process');
const path = require('path');
const fs = require('fs');
const isWindows = process.platform === 'win32';
let mainWindow;
// 窗口初始化和ipcMain监听渲染器
app.on('ready', () => {
mainWindow = new BrowserWindow({
width: 800,
height: 600,
frame: true, // 设置为false以去除标题栏
autoHideMenuBar: false, // 隐藏菜单栏
webPreferences: {
nodeIntegration: true,
contextIsolation: false
}
});
// 完全删除菜单栏
Menu.setApplicationMenu(null);
mainWindow.loadFile('index.html');
const restore_command = isWindows
? `powershell -Command "cp backup/compare.cpp.bak compare.cpp; cp backup/input_generator.cpp.bak input_generator.cpp"`
: `cp backup/compare.cpp.bak compare.cpp && cp backup/input_generator.cpp.bak input_generator.cpp`
exec(restore_command, (error, stdout, stderr) => {
if (error) {
console.error(`Error: ${error}`);
return;
}
});
ipcMain.on('run-compare', (event, input) => {
// exec('make', (error, stdout, stderr) => {
// if (error) {
// console.error(`Error compiling: ${error}`);
// event.reply('compare-result', `Error: Compilation failed. ${stderr}`);
// return;
// }
// });
// exec('make run', (error, stdout, stderr) => {
// if (error) {
// console.error(`Execution error: ${error}`);
// event.reply('compare-result', `Error: ${stderr}`);
// } else {
// event.reply('compare-result', stdout);
// }
// });
try {
execSync('make');
event.reply('compare-result', 'Compilation succeeded.');
} catch (error) {
console.error(`Error compiling: ${error}`);
event.reply('compare-result', `Error: Compilation failed. ${error.stderr}`);
}
try {
const stdout = execSync('make run', {stdio: 'pipe'}).toString();
event.reply('compare-result', `${stdout}`);
} catch (error) {
console.error(`Error executing: ${error}`);
const errorMessage = error.stderr ? error.stderr.toString() : 'No error output available.';
event.reply('compare-result', `Error: Execution failed. ${errorMessage}`);
}
});
});
app.on('window-all-closed', () => {
store_command = isWindows
? `powershell -Command "mv -Force compare.cpp backup/compare.cpp.bak; mv -Force input_generator.cpp backup/input_generator.cpp.bak"`
: `mv -f compare.cpp backup/compare.cpp.bak && mv -f input_generator.cpp backup/input_generator.cpp.bak`
exec(store_command, (error, stdout, stderr) => {
if (error) {
console.error(`Error: ${error}`);
return;
}
});
app.quit();
});
ipcMain.on('get-root-path', (event) => {
const rootPath = __dirname;
event.reply('send-root-path', rootPath);
});
ipcMain.on('compare-codes', (event, data) => {
const { code1, code2 } = data;
fs.writeFileSync('code1.cpp', code1);
fs.writeFileSync('code2.cpp', code2);
});
ipcMain.on('write_ig', (event, data) => {
const { ig } = data;
fs.writeFileSync('input_generator.cpp', ig);
});
ipcMain.on('write_c', (event, data) => {
const { c } = data;
fs.writeFileSync('compare.cpp', c);
})