forked from DarkGamerYT/Bedrock-Tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
78 lines (66 loc) · 2.27 KB
/
index.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
const { app, BrowserWindow, globalShortcut, ipcMain } = require( "electron" );
const fs = require( "node:fs" );
const path = require( "node:path" );
const { autoUpdater } = require( "electron-updater" );
require( "@electron/remote/main" ).initialize();
let mainWin;
let debug = false;
app.on( "window-all-closed", () => app.quit() );
app.on(
"ready", () => {
console.log(
"\x1B[0m" + new Date().toLocaleTimeString() + " \x1B[33m\x1B[1m[INFO] \x1B[0m- Starting..."
);
const appPath = app.getPath("userData");
const settingsPath = path.join(appPath, "settings.json");
if (!fs.existsSync( appPath )) fs.mkdirSync( appPath );
if (!fs.existsSync( settingsPath )) fs.writeFileSync(settingsPath, JSON.stringify({ debug: false }, null, "\t"));
const settings = JSON.parse(fs.readFileSync( settingsPath , "utf-8" ));
debug = settings?.debug || false;
if (!debug) registerShortcuts();
createWindow();
autoUpdater.autoInstallOnAppQuit = true;
autoUpdater.autoDownload = false;
autoUpdater.allowPrerelease = true;
autoUpdater.on(
"update-available", (a) => {
ipcMain.on( "allow-update", () => autoUpdater.downloadUpdate() );
if (!mainWin.isDestroyed()) mainWin.webContents.send( "update-available", a );
},
);
autoUpdater.checkForUpdates().catch(() => {});
},
);
const registerShortcuts = () => {
globalShortcut.register( "Control+R", () => false );
globalShortcut.register( "Control+Shift+R", () => false );
};
const createWindow = () => {
const win = new BrowserWindow({
title: "Bedrock Tools (Beta)",
icon: "build/icon.png",
minWidth: 1040,
minHeight: 600,
width: 1080,
height: 660,
frame: false,
autoHideMenuBar: true,
resizable: true,
titleBarStyle: "hidden",
webPreferences: {
devTools: debug,
preload: path.join( __dirname, "src/engine.js" ),
webSecurity: true,
nodeIntegration: true,
contextIsolation: false,
// https://stackoverflow.com/questions/69059668/enableremotemodule-is-missing-from-electron-v14-typescript-type-definitions
// @ts-expect-error - missing the type definition
enableRemoteModule: true,
},
});
mainWin = win;
require( "@electron/remote/main" ).enable( win.webContents );
app.setAppUserModelId( "Bedrock Tools" );
win.loadFile(path.join( __dirname, "index.html" ));
win.show();
};