|
|
|
@ -12,27 +12,31 @@ const {autoUpdater} = require("electron-updater");
|
|
|
|
process.env.ELECTRON_DISABLE_SECURITY_WARNINGS = "true";
|
|
|
|
process.env.ELECTRON_DISABLE_SECURITY_WARNINGS = "true";
|
|
|
|
const fs = require("fs");
|
|
|
|
const fs = require("fs");
|
|
|
|
const path = require("path");
|
|
|
|
const path = require("path");
|
|
|
|
|
|
|
|
|
|
|
|
autoUpdater.autoDownload = false;
|
|
|
|
autoUpdater.autoDownload = false;
|
|
|
|
|
|
|
|
/**@type {BrowserWindow} */
|
|
|
|
let win = null;
|
|
|
|
let win = null;
|
|
|
|
let secondaryWindow = null;
|
|
|
|
let secondaryWindow = null;
|
|
|
|
let tray = null;
|
|
|
|
let tray = null;
|
|
|
|
let isQuiting = false;
|
|
|
|
let isQuiting = false;
|
|
|
|
let indexIsOpen = true;
|
|
|
|
let indexIsOpen = true;
|
|
|
|
let trayEnabled = false;
|
|
|
|
let trayEnabled = false;
|
|
|
|
|
|
|
|
const configFile = path.join(app.getPath("userData"), "config.json");
|
|
|
|
|
|
|
|
|
|
|
|
function createWindow() {
|
|
|
|
function createWindow() {
|
|
|
|
|
|
|
|
const bounds = JSON.parse((getItem("bounds", configFile) || "{}"));
|
|
|
|
|
|
|
|
console.log("bounds:", bounds)
|
|
|
|
|
|
|
|
|
|
|
|
win = new BrowserWindow({
|
|
|
|
win = new BrowserWindow({
|
|
|
|
autoHideMenuBar: true,
|
|
|
|
autoHideMenuBar: true,
|
|
|
|
show: false,
|
|
|
|
show: false,
|
|
|
|
icon: __dirname + "/assets/images/icon.png",
|
|
|
|
icon: __dirname + "/assets/images/icon.png",
|
|
|
|
// @ts-ignore
|
|
|
|
|
|
|
|
spellcheck: false,
|
|
|
|
|
|
|
|
webPreferences: {
|
|
|
|
webPreferences: {
|
|
|
|
nodeIntegration: true,
|
|
|
|
nodeIntegration: true,
|
|
|
|
contextIsolation: false,
|
|
|
|
contextIsolation: false,
|
|
|
|
|
|
|
|
spellcheck: false,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
win.setBounds(bounds)
|
|
|
|
win.on("close", (event) => {
|
|
|
|
win.on("close", (event) => {
|
|
|
|
if (!isQuiting && trayEnabled) {
|
|
|
|
if (!isQuiting && trayEnabled) {
|
|
|
|
event.preventDefault();
|
|
|
|
event.preventDefault();
|
|
|
|
@ -41,11 +45,14 @@ function createWindow() {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
win.on("resize", (event) => {
|
|
|
|
|
|
|
|
setItem("bounds", JSON.stringify(win.getBounds()), configFile);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
win.loadFile("html/index.html");
|
|
|
|
win.loadFile("html/index.html");
|
|
|
|
win.maximize();
|
|
|
|
|
|
|
|
// win.setMenu(null)
|
|
|
|
// win.setMenu(null)
|
|
|
|
win.show();
|
|
|
|
win.show();
|
|
|
|
// win.webContents.openDevTools();
|
|
|
|
|
|
|
|
autoUpdater.checkForUpdates();
|
|
|
|
autoUpdater.checkForUpdates();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
let loadedLanguage;
|
|
|
|
let loadedLanguage;
|
|
|
|
@ -56,7 +63,6 @@ if (!gotTheLock) {
|
|
|
|
app.quit();
|
|
|
|
app.quit();
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
app.on("second-instance", (event, commandLine, workingDirectory) => {
|
|
|
|
app.on("second-instance", (event, commandLine, workingDirectory) => {
|
|
|
|
// Someone tried to run a second instance, we should focus our window.
|
|
|
|
|
|
|
|
if (win) {
|
|
|
|
if (win) {
|
|
|
|
win.show();
|
|
|
|
win.show();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -311,6 +317,12 @@ ipcMain.on("autoUpdate", (event, status) => {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ipcMain.on("progress", (_event, percentage) => {
|
|
|
|
|
|
|
|
if (win) {
|
|
|
|
|
|
|
|
win.setProgressBar(percentage)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
autoUpdater.on("update-downloaded", (_event, releaseNotes, releaseName) => {
|
|
|
|
autoUpdater.on("update-downloaded", (_event, releaseNotes, releaseName) => {
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* @type {Electron.MessageBoxOptions}
|
|
|
|
* @type {Electron.MessageBoxOptions}
|
|
|
|
@ -338,3 +350,39 @@ function i18n(phrase) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return translation;
|
|
|
|
return translation;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* @param {string} itemName
|
|
|
|
|
|
|
|
* @param {string} itemContent
|
|
|
|
|
|
|
|
* @param {string} configPath
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
function setItem(itemName, itemContent, configPath) {
|
|
|
|
|
|
|
|
let config = {};
|
|
|
|
|
|
|
|
if (fs.existsSync(configPath)) {
|
|
|
|
|
|
|
|
const fileContent = fs.readFileSync(configPath).toString();
|
|
|
|
|
|
|
|
config = JSON.parse(fileContent);
|
|
|
|
|
|
|
|
config[itemName] = itemContent;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
config[itemName] = itemContent;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fs.writeFileSync(configPath, JSON.stringify(config));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* @param {string} item
|
|
|
|
|
|
|
|
* @param {string} configPath
|
|
|
|
|
|
|
|
* @returns {string}
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
function getItem(item, configPath) {
|
|
|
|
|
|
|
|
if (fs.existsSync(configPath)) {
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
const configData = JSON.parse(fs.readFileSync(configPath, "utf8"));
|
|
|
|
|
|
|
|
return configData[item] || "";
|
|
|
|
|
|
|
|
} catch (err) {
|
|
|
|
|
|
|
|
return "";
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
return "";
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|