2022-08-31 06:33:37 +05:00
|
|
|
/*
|
|
|
|
|
This file is part of the Notesnook project (https://notesnook.com/)
|
|
|
|
|
|
|
|
|
|
Copyright (C) 2022 Streetwriters (Private) Limited
|
|
|
|
|
|
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
2022-10-19 15:27:21 +05:00
|
|
|
/* global MAC_APP_STORE, RELEASE */
|
|
|
|
|
|
|
|
|
|
import "isomorphic-fetch";
|
|
|
|
|
import { app, BrowserWindow, nativeTheme, shell } from "electron";
|
|
|
|
|
import { join } from "path";
|
|
|
|
|
import { platform } from "os";
|
|
|
|
|
import { isDevelopment } from "./utils";
|
|
|
|
|
import { registerProtocol, PROTOCOL_URL } from "./protocol";
|
|
|
|
|
import { configureAutoUpdater } from "./autoupdate";
|
|
|
|
|
import { getBackgroundColor, getTheme, setTheme } from "./config/theme";
|
|
|
|
|
import getZoomFactor from "./ipc/calls/getZoomFactor";
|
|
|
|
|
import { logger } from "./logger";
|
|
|
|
|
import { setupMenu } from "./menu";
|
|
|
|
|
import { WindowState } from "./config/windowstate";
|
|
|
|
|
import { sendMessageToRenderer } from "./ipc/utils";
|
|
|
|
|
import { EVENTS } from "./events";
|
|
|
|
|
import "./ipc/index.js";
|
|
|
|
|
|
|
|
|
|
if (!RELEASE) {
|
2021-07-07 00:56:34 +05:00
|
|
|
require("electron-reloader")(module);
|
2022-08-30 16:13:11 +05:00
|
|
|
}
|
2021-07-07 00:56:34 +05:00
|
|
|
|
2022-06-06 10:39:54 +05:00
|
|
|
// only run a single instance
|
2022-10-19 13:12:08 +05:00
|
|
|
|
|
|
|
|
if (!MAC_APP_STORE && !app.requestSingleInstanceLock()) {
|
2022-06-06 10:39:54 +05:00
|
|
|
app.exit();
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-01 13:07:17 +05:00
|
|
|
/**
|
|
|
|
|
* @type {BrowserWindow}
|
|
|
|
|
*/
|
2021-07-07 00:56:34 +05:00
|
|
|
let mainWindow;
|
|
|
|
|
|
|
|
|
|
async function createWindow() {
|
2021-11-18 14:41:22 +05:00
|
|
|
const mainWindowState = new WindowState({});
|
2021-12-01 13:07:17 +05:00
|
|
|
setTheme(getTheme());
|
2021-07-07 00:56:34 +05:00
|
|
|
mainWindow = new BrowserWindow({
|
2021-11-18 14:41:22 +05:00
|
|
|
x: mainWindowState.x,
|
|
|
|
|
y: mainWindowState.y,
|
|
|
|
|
width: mainWindowState.width,
|
|
|
|
|
height: mainWindowState.height,
|
2021-08-02 20:44:56 +05:00
|
|
|
backgroundColor: getBackgroundColor(),
|
2021-07-07 00:56:34 +05:00
|
|
|
autoHideMenuBar: true,
|
2022-10-19 15:27:21 +05:00
|
|
|
icon: join(
|
2021-07-07 00:56:34 +05:00
|
|
|
__dirname,
|
2022-10-19 15:27:21 +05:00
|
|
|
platform() === "win32" ? "app.ico" : "favicon-72x72.png"
|
2021-07-07 00:56:34 +05:00
|
|
|
),
|
|
|
|
|
webPreferences: {
|
2021-08-05 10:02:56 +05:00
|
|
|
zoomFactor: getZoomFactor(),
|
2021-07-07 00:56:34 +05:00
|
|
|
devTools: true, // isDev,
|
|
|
|
|
nodeIntegration: false, //true,
|
|
|
|
|
enableRemoteModule: false,
|
|
|
|
|
contextIsolation: true,
|
2022-01-04 11:38:46 +05:00
|
|
|
nativeWindowOpen: true,
|
2021-09-29 12:51:19 +05:00
|
|
|
spellcheck: false,
|
2022-08-26 16:19:39 +05:00
|
|
|
preload: __dirname + "/preload.js"
|
|
|
|
|
}
|
2021-07-07 00:56:34 +05:00
|
|
|
});
|
2021-11-18 14:41:22 +05:00
|
|
|
mainWindowState.manage(mainWindow);
|
2021-08-05 23:16:31 +05:00
|
|
|
global.win = mainWindow;
|
2021-09-29 14:03:12 +05:00
|
|
|
setupMenu(mainWindow);
|
2021-07-07 00:56:34 +05:00
|
|
|
|
|
|
|
|
if (isDevelopment())
|
|
|
|
|
mainWindow.webContents.openDevTools({ mode: "right", activate: true });
|
|
|
|
|
|
2021-08-05 12:05:16 +05:00
|
|
|
try {
|
2022-10-19 15:27:21 +05:00
|
|
|
await mainWindow.loadURL(
|
|
|
|
|
isDevelopment() ? "http://localhost:3000" : PROTOCOL_URL
|
|
|
|
|
);
|
2021-08-05 12:05:16 +05:00
|
|
|
} catch (e) {
|
|
|
|
|
logger.error(e);
|
|
|
|
|
}
|
2021-07-07 00:56:34 +05:00
|
|
|
|
|
|
|
|
mainWindow.on("closed", () => {
|
|
|
|
|
mainWindow = null;
|
2021-12-16 09:24:53 +05:00
|
|
|
global.win = null;
|
2021-07-07 00:56:34 +05:00
|
|
|
});
|
2021-12-01 13:07:17 +05:00
|
|
|
|
2022-01-03 15:05:56 +05:00
|
|
|
mainWindow.webContents.setWindowOpenHandler((details) => {
|
2022-01-04 11:38:46 +05:00
|
|
|
shell.openExternal(details.url);
|
|
|
|
|
return { action: "deny" };
|
2022-01-03 15:05:56 +05:00
|
|
|
});
|
|
|
|
|
|
2021-12-01 13:07:17 +05:00
|
|
|
nativeTheme.on("updated", () => {
|
|
|
|
|
if (getTheme() === "system") {
|
|
|
|
|
sendMessageToRenderer(EVENTS.themeChanged, {
|
2022-08-26 16:19:39 +05:00
|
|
|
theme: nativeTheme.shouldUseDarkColors ? "dark" : "light"
|
2021-12-01 13:07:17 +05:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
});
|
2021-07-07 00:56:34 +05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
app.commandLine.appendSwitch("lang", "en-US");
|
|
|
|
|
app.on("ready", async () => {
|
2021-08-05 12:05:16 +05:00
|
|
|
logger.info("App ready. Opening window.");
|
|
|
|
|
|
2021-07-07 00:56:34 +05:00
|
|
|
registerProtocol();
|
|
|
|
|
await createWindow();
|
|
|
|
|
configureAutoUpdater();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
app.on("window-all-closed", () => {
|
2022-10-26 10:55:10 +05:00
|
|
|
if (process.platform !== "darwin" || MAC_APP_STORE) {
|
2021-07-07 00:56:34 +05:00
|
|
|
app.quit();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
app.on("activate", () => {
|
|
|
|
|
if (mainWindow === null) {
|
|
|
|
|
createWindow();
|
|
|
|
|
}
|
|
|
|
|
});
|