1
0
mirror of https://github.com/upscayl/upscayl.git synced 2025-02-15 02:12:34 +01:00
upscayl/electron/main-window.ts
Nayam Amarshe d048547ba1 Fix model
2024-12-20 09:07:34 +05:30

78 lines
2.1 KiB
TypeScript

import { app, BrowserWindow, shell } from "electron";
import { getPlatform } from "./utils/get-device-specs";
import { join } from "path";
import { ELECTRON_COMMANDS } from "../common/electron-commands";
import { fetchLocalStorage } from "./utils/config-variables";
import electronIsDev from "electron-is-dev";
import { format } from "url";
import { autoUpdater } from "electron-updater";
let mainWindow: BrowserWindow | undefined;
const createMainWindow = () => {
console.log("📂 DIRNAME", __dirname);
console.log("🚃 App Path: ", app.getAppPath());
mainWindow = new BrowserWindow({
icon: join(__dirname, "build", "icon.png"),
width: 1300,
height: 940,
minHeight: 500,
minWidth: 600,
show: false,
backgroundColor: "#171717",
webPreferences: {
nodeIntegration: true,
nodeIntegrationInWorker: true,
webSecurity: false,
preload: join(__dirname, "preload.js"),
},
titleBarStyle: getPlatform() === "mac" ? "hiddenInset" : "default",
});
const url = electronIsDev
? "http://localhost:8000"
: format({
pathname: join(__dirname, "../../renderer/out/index.html"),
protocol: "file:",
slashes: true,
});
mainWindow.loadURL(url);
mainWindow.webContents.setWindowOpenHandler(({ url }) => {
shell.openExternal(url);
return { action: "deny" };
});
mainWindow.once("ready-to-show", () => {
if (!mainWindow) return;
mainWindow.show();
});
fetchLocalStorage();
if (!electronIsDev) {
console.log("🚀 Checking for updates");
mainWindow.webContents
.executeJavaScript('localStorage.getItem("autoUpdate");', true)
.then((lastSaved: string | null) => {
if (lastSaved !== null && lastSaved === "true") {
autoUpdater.checkForUpdates();
} else {
console.log("🚀 Auto Update is disabled");
}
});
}
mainWindow.webContents.send(ELECTRON_COMMANDS.OS, getPlatform());
mainWindow.setMenuBarVisibility(false);
};
const getMainWindow = () => {
return mainWindow;
};
export { createMainWindow, getMainWindow };