1
0
mirror of https://github.com/upscayl/upscayl.git synced 2025-01-20 09:42:48 +01:00
upscayl/electron/main-window.ts

62 lines
1.5 KiB
TypeScript
Raw Normal View History

import { BrowserWindow, shell } from "electron";
2023-09-10 23:30:49 +05:30
import { getPlatform } from "./utils/get-device-specs";
2023-09-10 14:44:04 +05:30
import { join } from "path";
import COMMAND from "../common/commands";
2023-10-25 17:14:22 +05:30
import { fetchLocalStorage } from "./utils/config-variables";
import electronIsDev from "electron-is-dev";
2023-09-13 18:44:46 +05:30
import { format } from "url";
2023-09-10 14:44:04 +05:30
2023-09-13 18:44:46 +05:30
let mainWindow: BrowserWindow | undefined;
2023-09-10 14:44:04 +05:30
2023-09-10 23:12:18 +05:30
const createMainWindow = () => {
2023-10-25 17:14:22 +05:30
console.log("📂 DIRNAME", __dirname);
2023-09-10 23:12:18 +05:30
mainWindow = new BrowserWindow({
icon: join(__dirname, "build", "icon.png"),
width: 1300,
height: 940,
minHeight: 500,
minWidth: 500,
show: false,
backgroundColor: "#171717",
webPreferences: {
nodeIntegration: true,
nodeIntegrationInWorker: true,
webSecurity: false,
preload: join(__dirname, "preload.js"),
},
titleBarStyle: getPlatform() === "mac" ? "hiddenInset" : "default",
});
2023-09-10 14:44:04 +05:30
const url = electronIsDev
? "http://localhost:8000"
2023-09-13 18:44:46 +05:30
: format({
2023-10-26 13:39:52 +05:30
pathname: join(__dirname, "../../renderer/out/index.html"),
2023-09-13 18:44:46 +05:30
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();
});
2023-09-19 00:00:43 +05:30
fetchLocalStorage();
mainWindow.webContents.send(COMMAND.OS, getPlatform());
2023-09-10 23:12:18 +05:30
mainWindow.setMenuBarVisibility(false);
};
const getMainWindow = () => {
return mainWindow;
};
2023-09-10 14:44:04 +05:30
2023-09-10 23:12:18 +05:30
export { createMainWindow, getMainWindow };