1
0
mirror of https://github.com/upscayl/upscayl.git synced 2025-01-19 17:28:44 +01:00
upscayl/electron/index.ts

73 lines
2.2 KiB
TypeScript
Raw Normal View History

2023-09-10 23:12:18 +05:30
import prepareNext from "electron-next";
2022-11-12 02:09:28 +05:30
import { autoUpdater } from "electron-updater";
2023-03-31 16:03:48 +05:30
import log from "electron-log";
2023-09-11 07:58:33 +05:30
import { app, ipcMain, protocol, net } from "electron";
2023-09-10 14:44:04 +05:30
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 23:12:18 +05:30
import electronIsDev from "electron-is-dev";
2023-09-10 23:30:49 +05:30
import { execPath, modelsPath } from "./utils/get-resource-paths";
import batchUpscayl from "./commands/batch-upscayl";
import doubleUpscayl from "./commands/double-upscayl";
2023-09-11 07:58:33 +05:30
import autoUpdate from "./commands/auto-update";
2023-09-11 09:27:16 +05:30
import sharp from "sharp";
2023-09-10 14:44:04 +05:30
// INITIALIZATION
2023-03-31 16:03:48 +05:30
log.initialize({ preload: true });
2023-09-11 09:27:16 +05:30
sharp.cache(false);
2023-09-10 23:12:18 +05:30
logit("🚃 App Path: ", app.getAppPath());
2023-03-31 16:03:48 +05:30
2023-09-13 18:44:46 +05:30
app.on("ready", async () => {
2023-09-10 23:12:18 +05:30
await prepareNext("./renderer");
2023-09-13 18:44:46 +05:30
app.whenReady().then(() => {
protocol.registerFileProtocol("file", (request, callback) => {
const pathname = decodeURI(request.url.replace("file:///", ""));
callback(pathname);
});
2023-09-10 23:12:18 +05:30
});
2023-09-13 18:44:46 +05:30
createMainWindow();
2023-09-10 23:12:18 +05:30
if (!electronIsDev) {
autoUpdater.checkForUpdates();
}
2023-09-13 18:44:46 +05:30
log.info("🚀 UPSCAYL EXEC PATH: ", execPath("realesrgan"));
log.info("🚀 MODELS PATH: ", modelsPath);
});
2023-09-10 23:24:08 +05:30
// Quit the app once all windows are closed
app.on("window-all-closed", () => {
if (process.platform !== "darwin") {
app.quit();
2023-09-10 23:24:08 +05:30
}
2023-09-10 23:12:18 +05:30
});
2023-04-23 13:26:49 +05:30
ipcMain.on(COMMAND.STOP, stop);
2023-09-09 15:43:16 +05:30
2023-09-10 14:44:04 +05:30
ipcMain.on(COMMAND.OPEN_FOLDER, openFolder);
2022-12-02 19:51:42 +05:30
2023-09-10 14:44:04 +05:30
ipcMain.handle(COMMAND.SELECT_FOLDER, selectFolder);
2023-08-10 15:14:44 +05:30
2023-09-10 14:44:04 +05:30
ipcMain.handle(COMMAND.SELECT_FILE, selectFile);
2023-08-10 15:14:44 +05:30
2023-09-10 14:44:04 +05:30
ipcMain.on(COMMAND.GET_MODELS_LIST, getModelsList);
2023-08-10 15:14:44 +05:30
2023-09-10 14:44:04 +05:30
ipcMain.handle(COMMAND.SELECT_CUSTOM_MODEL_FOLDER, customModelsSelect);
2023-08-10 15:14:44 +05:30
2023-09-10 14:44:04 +05:30
ipcMain.on(COMMAND.UPSCAYL, imageUpscayl);
2023-08-10 15:14:44 +05:30
ipcMain.on(COMMAND.FOLDER_UPSCAYL, batchUpscayl);
2023-09-10 14:44:04 +05:30
ipcMain.on(COMMAND.DOUBLE_UPSCAYL, doubleUpscayl);
2023-09-11 07:58:33 +05:30
autoUpdater.on("update-downloaded", autoUpdate);