-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
66 lines (56 loc) · 1.93 KB
/
main.js
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
const { app, BrowserWindow } = require('electron');
const { ipcMain } = require('electron');
const path = require('path');
const server = require('./server.js');
if (process.env.NODE_ENV === 'development') {
require('electron-reload')(__dirname, {
electron: path.join(__dirname, 'node_modules', '.bin', 'electron'),
hardResetMethod: 'exit',
});
}
function createWindow() {
const window = new BrowserWindow({
width: 1100,
height: 800,
webPreferences: {
nodeIntegration: false,
contextIsolation: true,
preload: path.join(__dirname, 'preload.js'),
}
});
window.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();
}
});
});
ipcMain.handle('reload-db', async (event) => {
server.load_db();
return 'Finished'
})
ipcMain.handle('count-rows', async (event, tableName, filterCols, filterVals) => {
return await server.count_rows(tableName, filterCols, filterVals);
})
ipcMain.handle('fetch-rows', async (event, tableName, fetchCols, filterCol, filterVal) => {
return await server.fetch_rows(tableName, fetchCols, filterCol, filterVal);
})
ipcMain.handle('delete-rows', async (event, tableName, filterCols, filterVals) => {
await server.delete_rows(tableName, filterCols, filterVals);
return 'Finished';
})
ipcMain.handle('insert-rows', async (event, tableName, colNames, rows) => {
var sql = `INSERT INTO ${tableName} (${colNames.join(', ')}) VALUES (${Array(colNames.length).fill('?').join(', ')})`
await server.insert_rows(sql, rows);
return 'Finished';
})
ipcMain.handle('save-file', server.save_file);
ipcMain.handle('open-file', server.open_file);