-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
77 lines (66 loc) · 2.1 KB
/
main.js
File metadata and controls
77 lines (66 loc) · 2.1 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
const { app, BrowserWindow, ipcMain, dialog, Menu} = require('electron');
const path = require('path');
const fs = require('fs');
let mainWindow;
function createWindow() {
mainWindow = new BrowserWindow({
width: 1200,
height: 800,
webPreferences: {
nodeIntegration: false,
contextIsolation: true,
preload: path.join(__dirname, 'preload.js')
}
});
mainWindow.loadFile(path.join(__dirname, 'renderer/index.html'));
// Open DevTools in development mode
if (process.env.NODE_ENV === 'development') {
mainWindow.webContents.openDevTools();
}
}
Menu.setApplicationMenu(null);
// Create the browser window when the app is ready to ru
app.whenReady().then(createWindow);
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
app.quit();
}
});
app.on('activate', () => {
if (BrowserWindow.getAllWindows().length === 0) {
createWindow();
}
});
// Handle save report functionality
ipcMain.handle('save-report', async (event, reportData) => {
try {
const { filePath } = await dialog.showSaveDialog(mainWindow, {
title: 'Save Analysis Report',
defaultPath: path.join(app.getPath('documents'), 'code-analysis-report.html'),
filters: [
{ name: 'HTML Files', extensions: ['html'] },
{ name: 'Text Files', extensions: ['txt'] },
{ name: 'All Files', extensions: ['*'] }
]
});
if (filePath) {
fs.writeFileSync(filePath, reportData);
return { success: true, filePath };
}
return { success: false, message: 'Save operation cancelled' };
} catch (error) {
console.error('Error saving report:', error);
return { success: false, message: error.message };
}
});
// Handle code analysis requests from renderer
ipcMain.handle('analyze-code', async (event, { code, language }) => {
try {
// Import the appropriate analyzer based on language
const analyzer = require(`./src/analyzers/${language}.js`);
const results = await analyzer.analyze(code);
return { success: true, results };
} catch (error) {
return { success: false, error: error.message };
}
});