2022-02-17 19:48:08 +01:00
|
|
|
import { app, BrowserWindow, globalShortcut } from "electron";
|
2022-02-17 18:09:57 +01:00
|
|
|
|
|
|
|
import { createWindow, getWindow } from "./window";
|
|
|
|
import { createTray } from "./tray";
|
2022-02-17 19:48:08 +01:00
|
|
|
import autoUpdater from "./auto-updater";
|
2022-02-17 18:09:57 +01:00
|
|
|
import updateAutoLaunch from "./update-auto-launch";
|
2022-02-17 19:48:08 +01:00
|
|
|
import ipc, { emitMutedKeyPress } from "./ipc";
|
2022-02-19 01:48:56 +01:00
|
|
|
import settings from "./settings";
|
|
|
|
import { setLogLevel } from "./log";
|
2022-02-17 18:09:57 +01:00
|
|
|
|
|
|
|
function init() {
|
2022-02-18 23:03:05 +01:00
|
|
|
const appLock = app.requestSingleInstanceLock();
|
2022-02-17 18:09:57 +01:00
|
|
|
|
2022-02-18 23:03:05 +01:00
|
|
|
if (!appLock) {
|
|
|
|
console.log("Application already running");
|
|
|
|
app.quit();
|
|
|
|
return;
|
|
|
|
}
|
2022-02-17 18:09:57 +01:00
|
|
|
|
2022-02-18 23:03:05 +01:00
|
|
|
app.on("second-instance", () => {
|
|
|
|
// re-create window if closed
|
|
|
|
createWindow();
|
2022-02-17 18:09:57 +01:00
|
|
|
|
2022-02-18 23:03:05 +01:00
|
|
|
const mainWindow = getWindow();
|
2022-02-17 18:09:57 +01:00
|
|
|
|
2022-02-18 23:03:05 +01:00
|
|
|
// Someone tried to run a second instance, we should focus our window.
|
|
|
|
if (mainWindow) {
|
|
|
|
if (mainWindow.isMinimized()) {
|
|
|
|
mainWindow.restore();
|
|
|
|
}
|
2022-02-17 18:09:57 +01:00
|
|
|
|
2022-02-18 23:03:05 +01:00
|
|
|
mainWindow.focus();
|
|
|
|
}
|
|
|
|
});
|
2022-02-17 18:09:57 +01:00
|
|
|
|
2022-02-18 23:03:05 +01:00
|
|
|
// This method will be called when Electron has finished loading
|
2022-02-19 01:55:05 +01:00
|
|
|
app.whenReady().then(async () => {
|
2022-02-19 01:48:56 +01:00
|
|
|
await settings.init();
|
|
|
|
|
2022-02-19 01:55:05 +01:00
|
|
|
setLogLevel(settings.get("log_level") || "info");
|
2022-02-19 01:48:56 +01:00
|
|
|
|
2022-02-18 23:03:05 +01:00
|
|
|
autoUpdater.init();
|
2022-02-17 18:09:57 +01:00
|
|
|
|
2022-02-18 23:03:05 +01:00
|
|
|
// enable auto launch
|
|
|
|
updateAutoLaunch();
|
2022-02-17 18:09:57 +01:00
|
|
|
|
2022-02-18 23:03:05 +01:00
|
|
|
// Don't show the app in the doc
|
|
|
|
// if (app.dock) {
|
|
|
|
// app.dock.hide();
|
|
|
|
// }
|
2022-02-17 18:09:57 +01:00
|
|
|
|
2022-02-18 23:03:05 +01:00
|
|
|
createWindow();
|
|
|
|
createTray();
|
2022-02-17 19:48:08 +01:00
|
|
|
|
2022-02-18 23:03:05 +01:00
|
|
|
// load ipc handler
|
|
|
|
ipc();
|
2022-02-17 19:48:08 +01:00
|
|
|
|
2022-02-18 23:03:05 +01:00
|
|
|
globalShortcut.register("Alt+CommandOrControl+M", () => {
|
|
|
|
emitMutedKeyPress();
|
|
|
|
});
|
2022-02-17 19:48:08 +01:00
|
|
|
});
|
2022-02-17 18:09:57 +01:00
|
|
|
|
2022-02-18 23:03:05 +01:00
|
|
|
// Quit when all windows are closed.
|
|
|
|
app.on("window-all-closed", () => {
|
|
|
|
// macOs users have to press Cmd + Q to stop the app
|
|
|
|
if (process.platform !== "darwin") {
|
|
|
|
app.quit();
|
|
|
|
}
|
|
|
|
});
|
2022-02-17 18:09:57 +01:00
|
|
|
|
2022-02-18 23:03:05 +01:00
|
|
|
app.on("activate", () => {
|
|
|
|
// On macOS it's common to re-create a window in the app when the
|
|
|
|
// dock icon is clicked and there are no other windows open.
|
|
|
|
if (BrowserWindow.getAllWindows().length === 0) {
|
|
|
|
createWindow();
|
|
|
|
}
|
|
|
|
});
|
2022-02-17 18:09:57 +01:00
|
|
|
|
2022-02-18 23:03:05 +01:00
|
|
|
app.on("quit", () => {
|
|
|
|
// TODO
|
|
|
|
});
|
2022-02-17 18:09:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
export default {
|
2022-02-18 23:03:05 +01:00
|
|
|
init,
|
2022-02-17 18:09:57 +01:00
|
|
|
};
|