2022-08-03 16:48:39 +06:00
|
|
|
const { app, BrowserWindow, dialog, ipcMain } = require("electron");
|
2022-07-31 12:45:09 +06:00
|
|
|
const { autoUpdater } = require("electron-updater");
|
2022-09-02 00:25:25 +06:00
|
|
|
autoUpdater.autoDownload = false;
|
2022-08-27 12:02:54 +06:00
|
|
|
let win, secondaryWindow;
|
2022-07-31 12:45:09 +06:00
|
|
|
|
|
|
|
function createWindow() {
|
2022-08-02 23:27:08 +06:00
|
|
|
let isTransparent = false;
|
|
|
|
if (process.platform == "linux") {
|
|
|
|
isTransparent = true;
|
|
|
|
}
|
|
|
|
|
2022-08-05 17:37:17 +06:00
|
|
|
win = new BrowserWindow({
|
2022-07-31 12:45:09 +06:00
|
|
|
show: false,
|
|
|
|
icon: __dirname + "/public/icon.png",
|
2022-08-02 23:27:08 +06:00
|
|
|
spellcheck: false,
|
|
|
|
transparent: isTransparent,
|
|
|
|
webPreferences: {
|
2022-08-05 17:37:17 +06:00
|
|
|
nodeIntegration: true,
|
2022-09-02 20:17:30 +06:00
|
|
|
contextIsolation: false
|
2022-08-05 17:37:17 +06:00
|
|
|
},
|
2022-07-31 12:45:09 +06:00
|
|
|
});
|
|
|
|
|
2022-08-05 17:37:17 +06:00
|
|
|
win.loadFile("html/index.html");
|
2022-07-31 12:45:09 +06:00
|
|
|
win.maximize();
|
2022-08-27 21:19:29 +06:00
|
|
|
// win.setMenu(null)
|
2022-07-31 12:45:09 +06:00
|
|
|
win.show();
|
2022-08-05 18:16:42 +06:00
|
|
|
// win.webContents.openDevTools();
|
2022-09-02 00:25:25 +06:00
|
|
|
autoUpdater.checkForUpdates();
|
2022-07-25 22:15:38 +06:00
|
|
|
}
|
|
|
|
|
|
|
|
app.whenReady().then(() => {
|
2022-09-02 00:25:25 +06:00
|
|
|
// Logging
|
|
|
|
console.log("Locale:" + app.getLocale());
|
|
|
|
console.log("Version: " + app.getVersion());
|
|
|
|
|
2022-07-31 12:45:09 +06:00
|
|
|
createWindow();
|
|
|
|
app.on("activate", () => {
|
|
|
|
if (BrowserWindow.getAllWindows().length === 0) {
|
|
|
|
createWindow();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
if (process.platform === "win32") {
|
|
|
|
app.setAppUserModelId(app.name);
|
|
|
|
}
|
|
|
|
});
|
2022-07-25 22:15:38 +06:00
|
|
|
|
2022-09-03 23:22:49 +06:00
|
|
|
ipcMain.on("restart", () => {
|
|
|
|
app.relaunch();
|
|
|
|
app.exit();
|
|
|
|
})
|
|
|
|
|
2022-09-02 00:25:25 +06:00
|
|
|
ipcMain.on("get-version", () => {
|
|
|
|
const version = app.getVersion();
|
|
|
|
secondaryWindow.webContents.send("version", version);
|
|
|
|
});
|
|
|
|
|
2022-08-27 12:02:54 +06:00
|
|
|
ipcMain.on("load-page", (event, file) => {
|
|
|
|
secondaryWindow = new BrowserWindow({
|
|
|
|
webPreferences: {
|
|
|
|
nodeIntegration: true,
|
|
|
|
contextIsolation: false,
|
|
|
|
},
|
|
|
|
parent: win,
|
|
|
|
modal: true,
|
|
|
|
show: false,
|
|
|
|
});
|
|
|
|
secondaryWindow.loadFile(file);
|
2022-09-02 00:25:25 +06:00
|
|
|
// secondaryWindow.setMenu(null);
|
2022-09-03 23:22:49 +06:00
|
|
|
// secondaryWindow.maximize();
|
2022-08-27 12:02:54 +06:00
|
|
|
secondaryWindow.show();
|
|
|
|
});
|
|
|
|
|
|
|
|
ipcMain.on("close-secondary", () => {
|
|
|
|
secondaryWindow.close();
|
|
|
|
secondaryWindow = null;
|
2022-08-05 17:37:17 +06:00
|
|
|
});
|
2022-08-03 16:48:39 +06:00
|
|
|
|
2022-08-05 17:37:17 +06:00
|
|
|
ipcMain.on("select-location", () => {
|
2022-08-27 13:07:12 +06:00
|
|
|
const location = dialog.showOpenDialogSync(secondaryWindow, {
|
2022-08-05 17:37:17 +06:00
|
|
|
properties: ["openFile", "openDirectory"],
|
|
|
|
});
|
2022-08-03 16:48:39 +06:00
|
|
|
|
2022-08-05 17:37:17 +06:00
|
|
|
if (location) {
|
2022-08-27 13:07:12 +06:00
|
|
|
secondaryWindow.webContents.send("downloadPath", location);
|
2022-08-03 16:48:39 +06:00
|
|
|
}
|
2022-08-05 17:37:17 +06:00
|
|
|
});
|
2022-08-03 16:48:39 +06:00
|
|
|
|
2022-07-31 12:45:09 +06:00
|
|
|
app.on("window-all-closed", () => {
|
|
|
|
if (process.platform !== "darwin") {
|
|
|
|
app.quit();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
// Auto updater events
|
|
|
|
autoUpdater.on("update-available", (_event, releaseNotes, releaseName) => {
|
|
|
|
const dialogOpts = {
|
2022-08-02 23:27:08 +06:00
|
|
|
type: "info",
|
2022-09-02 00:25:25 +06:00
|
|
|
buttons: ["Update", "No"],
|
|
|
|
title: "Update Available",
|
|
|
|
detail: process.platform === "win32" ? releaseNotes : releaseName,
|
|
|
|
message: "A new version is available, do you want to update?",
|
2022-08-02 23:27:08 +06:00
|
|
|
};
|
2022-09-02 00:25:25 +06:00
|
|
|
dialog.showMessageBox(dialogOpts, (buttonIndex) => {
|
|
|
|
if (buttonIndex === 0) {
|
|
|
|
autoUpdater.downloadUpdate();
|
|
|
|
}
|
|
|
|
});
|
2022-08-02 23:27:08 +06:00
|
|
|
});
|
2022-07-31 12:45:09 +06:00
|
|
|
|
|
|
|
autoUpdater.on("update-downloaded", (_event, releaseNotes, releaseName) => {
|
|
|
|
const dialogOpts = {
|
2022-08-02 23:27:08 +06:00
|
|
|
type: "info",
|
|
|
|
buttons: ["Restart", "Later"],
|
2022-09-02 00:25:25 +06:00
|
|
|
title: "Update Ready",
|
|
|
|
message: "Install and restart now?",
|
2022-07-31 12:45:09 +06:00
|
|
|
};
|
|
|
|
dialog.showMessageBox(dialogOpts).then((returnValue) => {
|
2022-09-02 00:25:25 +06:00
|
|
|
if (returnValue.response === 0) {
|
|
|
|
autoUpdater.quitAndInstall();
|
|
|
|
} else {
|
|
|
|
autoUpdater.autoInstallOnAppQuit();
|
|
|
|
}
|
2022-08-02 23:27:08 +06:00
|
|
|
});
|
2022-07-31 19:14:15 +06:00
|
|
|
});
|