Repository navigation
Expand file tree
/
Copy pathmain.js
More file actions
66 lines (56 loc) · 2.03 KB
/
Copy pathmain.js
File metadata and controls
66 lines (56 loc) · 2.03 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
const { app, BrowserWindow, ipcMain, dialog } = require('electron');
const path = require('path');
const core = require('./patch-core');
let mainWindow;
function createWindow() {
mainWindow = new BrowserWindow({
width: 480,
height: 380,
resizable: false,
maximizable: false,
minimizable: false,
title: 'ZCode Русификатор v6.4.0',
autoHideMenuBar: true,
webPreferences: {
preload: path.join(__dirname, 'preload.js'),
contextIsolation: true,
nodeIntegration: false,
},
});
mainWindow.setMenuBarVisibility(false);
mainWindow.loadFile('index.html');
}
app.whenReady().then(createWindow);
app.on('window-all-closed', () => app.quit());
function sendProgress(step, total, msg, type) {
if (mainWindow && !mainWindow.isDestroyed()) {
mainWindow.webContents.send('progress', { step, total, msg, type });
}
}
// Auto-detect the install folder so the user usually does not have to browse.
ipcMain.handle('detect-dir', async () => core.detectZcodeDir());
ipcMain.handle('select-directory', async () => {
const res = await dialog.showOpenDialog(mainWindow, {
title: 'Выберите папку с ZCode (корень установки)',
properties: ['openDirectory'],
defaultPath: core.detectZcodeDir() || app.getPath('home'),
});
return res.canceled ? null : res.filePaths[0];
});
ipcMain.handle('select-asar', async () => {
const res = await dialog.showOpenDialog(mainWindow, {
title: 'Выберите app.asar (необязательно)',
properties: ['openFile'],
filters: [{ name: 'ASAR', extensions: ['asar'] }],
});
return res.canceled ? null : res.filePaths[0];
});
// Accepts any folder the user typed OR selected; core normalizes it.
ipcMain.handle('check-zcode', async (e, dir) => core.checkZcode(dir));
ipcMain.handle('patch-zcode', async (e, dir, asarSource) => {
return core.patch(dir, {
asarSource: asarSource || undefined,
onProgress: sendProgress,
});
});
ipcMain.handle('restore-zcode', async (e, dir) => core.restore(dir));