-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.js
123 lines (106 loc) · 2.97 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
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
import { app, BrowserWindow, Menu, ipcMain, dialog } from 'electron';
import isDev from 'electron-is-dev'
import { server, getPort } from './expressApp.js';
import syncing from './src/syncing.js';
import settings from 'electron-settings';
const PORT = getPort();
let mainWindow;
let ChivesLightNodeSetting;
function createMainWindow() {
mainWindow = new BrowserWindow({
width: 1000,
height: 800,
webPreferences: {
nodeIntegration: true,
contextIsolation: false,
},
});
//Start Setting Page
mainWindow.loadFile('src/settings/index.html');
//Start Chives Light Node
ipcMain.on('start-chives-light-node', async (event, data) => {
ChivesLightNodeSetting = await settings.get('chives-light-node');
console.log("ChivesLightNodeSetting main.js", ChivesLightNodeSetting)
await syncing.initChivesLightNodeSetting(ChivesLightNodeSetting);
await syncing.initChivesLightNodeSql();
mainWindow.loadURL('http://localhost:' + PORT);
});
const template = [
{
label: 'About',
submenu: [
{
label: 'Website',
click: () => {
openNewURL('https://chivesweave.org/');
}
},
{
label: 'Github',
click: () => {
openNewURL('https://github.com/chives-network');
}
},
{
label: 'Discord',
click: () => {
openNewURL('https://discord.com/invite/8KrtgBRjZn');
}
},
{
label: 'Twitter',
click: () => {
openNewURL('https://twitter.com/chivesweave');
}
}
]
},
// 其他菜单...
];
const menu = Menu.buildFromTemplate(template);
Menu.setApplicationMenu(menu);
if (isDev) {
mainWindow.webContents.openDevTools();
}
mainWindow.on('closed', () => {
mainWindow = null;
app.quit();
});
}
function openNewURL(url) {
const newWindow = new BrowserWindow({ width: 800, height: 600 });
newWindow.loadURL(url);
}
app.whenReady().then(()=>{
createMainWindow();
});
app.on('activate', () => {
if (BrowserWindow.getAllWindows().length === 0) {
createMainWindow();
}
});
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
server.close(() => {
app.quit();
});
}
});
ipcMain.on('open-folder-dialog', async (event) => {
const result = await dialog.showOpenDialog(mainWindow, {
properties: ['openDirectory'],
});
if (!result.canceled && result.filePaths.length > 0) {
event.reply('selected-folder', result.filePaths[0]);
}
});
ipcMain.on('save-chives-light-node', async (event, data) => {
await settings.set('chives-light-node', data);
console.log("save-chives-light-node", data);
//mainWindow.webContents.send('data-chives-light-node', data);
});
ipcMain.on('get-chives-light-node', async (event) => {
const data = await settings.get('chives-light-node');
console.log("get-chives-light-node", data);
event.reply('data-chives-light-node', data);
});