Repository navigation
Expand file tree
/
Copy pathmain.js
More file actions
96 lines (89 loc) · 3.02 KB
/
Copy pathmain.js
File metadata and controls
96 lines (89 loc) · 3.02 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
const { app, BrowserWindow, ipcMain, dialog } = require('electron');
const path = require('path');
const fs = require('fs');
const csv = require('csv-parser');
const { exec } = require('child_process');
ipcMain.handle('read-csv', async (event) => {
const results = [];
const filePath = path.join(__dirname, 'create-table/base_table.csv');
return new Promise((resolve, reject) => {
fs.access(filePath, fs.constants.F_OK, (err) => {
if (err) {
console.warn('base_table.csv not found, returning an empty array.');
resolve(results); // Return an empty array if file is not found
} else {
fs.createReadStream(filePath)
.pipe(csv())
.on('data', (data) => results.push(data))
.on('end', () => {
resolve(results);
})
.on('error', (error) => {
reject(error);
});
}
});
});
});
ipcMain.on('save-json', async (event, data) => {
const savePath = path.join(__dirname, 'xml-updater', 'updated_spreadsheet.json');
fs.writeFileSync(savePath, data);
exec('python3 xml-updater/xml-updater-2.py', (error, stdout, stderr) => {
if (error) {
console.error(`Error executing Python script: ${error.message}`);
return;
}
if (stderr) {
console.error(`Python script stderr: ${stderr}`);
return;
}
console.log(`Python script stdout: ${stdout}`);
});
});
ipcMain.handle('select-file', async (event) => {
const result = await dialog.showOpenDialog({
properties: ['openFile'],
filters: [{ name: 'CSV Files', extensions: ['csv'] }]
});
return result.filePaths[0];
});
ipcMain.handle('run-python-script', async (event, transcriptFilePath, markersFilePath) => {
const scriptPath = path.join(__dirname, 'create-table', 'create-table.py');
exec(`python3 ${scriptPath} ${transcriptFilePath} ${markersFilePath}`, (error, stdout, stderr) => {
if (error) {
console.error(`Error executing Python script: ${error.message}`);
return;
}
if (stderr) {
console.error(`Python script stderr: ${stderr}`);
return;
}
console.log(`Python script stdout: ${stdout}`);
});
});
function createWindow() {
const win = new BrowserWindow({
width: 1200,
height: 600,
webPreferences: {
preload: path.join(__dirname, 'preload.js'),
contextIsolation: true,
enableRemoteModule: false,
nodeIntegration: false
}
});
win.loadFile('index.html');
}
app.whenReady().then(() => {
createWindow();
app.on('activate', () => {
if (BrowserWindow.getAllWindows().length === 0) {
createWindow();
}
});
});
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
app.quit();
}
});