1
0
mirror of https://github.com/upscayl/upscayl.git synced 2024-12-18 10:26:04 +01:00
upscayl/electron/index.ts

70 lines
2.1 KiB
TypeScript
Raw Normal View History

2023-09-10 19:42:18 +02:00
import prepareNext from "electron-next";
2022-11-11 21:39:28 +01:00
import { autoUpdater } from "electron-updater";
2023-03-31 12:33:48 +02:00
import log from "electron-log";
2023-09-11 04:28:33 +02:00
import { app, ipcMain, protocol, net } from "electron";
2023-09-10 11:14:04 +02:00
import COMMAND from "./constants/commands";
import logit from "./utils/logit";
import openFolder from "./commands/open-folder";
import stop from "./commands/stop";
import selectFolder from "./commands/select-folder";
import selectFile from "./commands/select-file";
import getModelsList from "./commands/get-models-list";
import customModelsSelect from "./commands/custom-models-select";
import imageUpscayl from "./commands/image-upscayl";
import { createMainWindow } from "./main-window";
2023-09-10 19:42:18 +02:00
import electronIsDev from "electron-is-dev";
2023-09-10 20:00:49 +02:00
import { execPath, modelsPath } from "./utils/get-resource-paths";
import batchUpscayl from "./commands/batch-upscayl";
import doubleUpscayl from "./commands/double-upscayl";
2023-09-11 04:28:33 +02:00
import autoUpdate from "./commands/auto-update";
2023-09-11 05:57:16 +02:00
import sharp from "sharp";
2023-09-10 11:14:04 +02:00
// INITIALIZATION
2023-03-31 12:33:48 +02:00
log.initialize({ preload: true });
2023-09-11 05:57:16 +02:00
sharp.cache(false);
2023-09-10 19:42:18 +02:00
logit("🚃 App Path: ", app.getAppPath());
2023-03-31 12:33:48 +02:00
2023-09-10 19:42:18 +02:00
app.whenReady().then(async () => {
await prepareNext("./renderer");
createMainWindow();
2023-09-10 19:42:18 +02:00
log.info("🚀 UPSCAYL EXEC PATH: ", execPath("realesrgan"));
log.info("🚀 MODELS PATH: ", modelsPath);
2023-09-10 19:42:18 +02:00
protocol.handle("file:", (request) => {
const pathname = decodeURI(request.url);
return net.fetch(pathname);
});
2023-09-10 19:42:18 +02:00
if (!electronIsDev) {
autoUpdater.checkForUpdates();
}
});
2023-09-10 19:54:08 +02:00
// Quit the app once all windows are closed
app.on("window-all-closed", () => {
if (process.platform !== "darwin") {
app.quit();
2023-09-10 19:54:08 +02:00
}
2023-09-10 19:42:18 +02:00
});
2023-04-23 09:56:49 +02:00
ipcMain.on(COMMAND.STOP, stop);
2023-09-09 12:13:16 +02:00
2023-09-10 11:14:04 +02:00
ipcMain.on(COMMAND.OPEN_FOLDER, openFolder);
2022-12-02 15:21:42 +01:00
2023-09-10 11:14:04 +02:00
ipcMain.handle(COMMAND.SELECT_FOLDER, selectFolder);
2023-08-10 11:44:44 +02:00
2023-09-10 11:14:04 +02:00
ipcMain.handle(COMMAND.SELECT_FILE, selectFile);
2023-08-10 11:44:44 +02:00
2023-09-10 11:14:04 +02:00
ipcMain.on(COMMAND.GET_MODELS_LIST, getModelsList);
2023-08-10 11:44:44 +02:00
2023-09-10 11:14:04 +02:00
ipcMain.handle(COMMAND.SELECT_CUSTOM_MODEL_FOLDER, customModelsSelect);
2023-08-10 11:44:44 +02:00
2023-09-10 11:14:04 +02:00
ipcMain.on(COMMAND.UPSCAYL, imageUpscayl);
2023-08-10 11:44:44 +02:00
ipcMain.on(COMMAND.FOLDER_UPSCAYL, batchUpscayl);
2023-09-10 11:14:04 +02:00
ipcMain.on(COMMAND.DOUBLE_UPSCAYL, doubleUpscayl);
2023-09-11 04:28:33 +02:00
autoUpdater.on("update-downloaded", autoUpdate);