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-10-25 13:44:22 +02:00
|
|
|
import { app, ipcMain, protocol } from "electron";
|
2024-01-16 07:30:07 +01:00
|
|
|
import COMMAND from "../common/commands";
|
2023-09-10 11:14:04 +02:00
|
|
|
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";
|
2023-09-11 04:25:14 +02:00
|
|
|
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";
|
2023-09-11 04:25:14 +02:00
|
|
|
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-10-25 13:44:22 +02:00
|
|
|
import { featureFlags } from "../common/feature-flags";
|
2023-11-10 12:41:35 +01:00
|
|
|
import settings from "electron-settings";
|
2023-09-10 11:14:04 +02:00
|
|
|
|
|
|
|
// INITIALIZATION
|
2023-03-31 12:33:48 +02:00
|
|
|
log.initialize({ preload: true });
|
2023-09-10 19:42:18 +02:00
|
|
|
logit("🚃 App Path: ", app.getAppPath());
|
2023-03-31 12:33:48 +02:00
|
|
|
|
2023-09-13 15:14:46 +02:00
|
|
|
app.on("ready", async () => {
|
2023-09-10 19:42:18 +02:00
|
|
|
await prepareNext("./renderer");
|
2023-09-11 04:25:14 +02:00
|
|
|
|
2023-09-13 15:14:46 +02:00
|
|
|
app.whenReady().then(() => {
|
|
|
|
protocol.registerFileProtocol("file", (request, callback) => {
|
|
|
|
const pathname = decodeURI(request.url.replace("file:///", ""));
|
|
|
|
callback(pathname);
|
|
|
|
});
|
2023-09-10 19:42:18 +02:00
|
|
|
});
|
2023-09-11 04:25:14 +02:00
|
|
|
|
2023-09-13 15:14:46 +02:00
|
|
|
createMainWindow();
|
|
|
|
|
2023-09-10 19:42:18 +02:00
|
|
|
if (!electronIsDev) {
|
|
|
|
autoUpdater.checkForUpdates();
|
|
|
|
}
|
2023-09-13 15:14:46 +02:00
|
|
|
|
2024-08-31 13:05:53 +02:00
|
|
|
log.info(
|
|
|
|
"🆙 Upscayl version:",
|
|
|
|
app.getVersion(),
|
|
|
|
featureFlags.APP_STORE_BUILD && "MAC-APP-STORE",
|
|
|
|
);
|
2024-01-16 07:30:07 +01:00
|
|
|
log.info("🚀 UPSCAYL EXEC PATH: ", execPath);
|
2023-09-13 15:14:46 +02:00
|
|
|
log.info("🚀 MODELS PATH: ", modelsPath);
|
2023-11-04 11:02:44 +01:00
|
|
|
|
2023-11-10 12:41:35 +01:00
|
|
|
let closeAccess;
|
|
|
|
const folderBookmarks = await settings.get("folder-bookmarks");
|
2023-11-23 06:39:46 +01:00
|
|
|
if (featureFlags.APP_STORE_BUILD && folderBookmarks) {
|
2023-11-10 12:41:35 +01:00
|
|
|
logit("🚨 Folder Bookmarks: ", folderBookmarks);
|
|
|
|
try {
|
|
|
|
closeAccess = app.startAccessingSecurityScopedResource(
|
2024-04-08 20:47:08 +02:00
|
|
|
folderBookmarks as string,
|
2023-11-10 12:41:35 +01:00
|
|
|
);
|
|
|
|
} catch (error) {
|
|
|
|
logit("📁 Folder Bookmarks Error: ", error);
|
|
|
|
}
|
2023-11-04 11:02:44 +01:00
|
|
|
}
|
2023-09-11 04:25:14 +02:00
|
|
|
});
|
2023-09-10 19:54:08 +02:00
|
|
|
|
2023-09-11 04:25:14 +02:00
|
|
|
// Quit the app once all windows are closed
|
|
|
|
app.on("window-all-closed", () => {
|
2023-09-16 12:34:35 +02:00
|
|
|
app.quit();
|
2023-09-10 19:42:18 +02:00
|
|
|
});
|
2023-04-23 09:56:49 +02:00
|
|
|
|
2023-10-15 11:37:04 +02:00
|
|
|
// ! ENABLE THIS FOR MACOS APP STORE BUILD
|
2023-10-25 13:44:22 +02:00
|
|
|
if (featureFlags.APP_STORE_BUILD) {
|
|
|
|
logit("🚀 APP STORE BUILD ENABLED");
|
2023-10-21 15:43:03 +02:00
|
|
|
app.commandLine.appendSwitch("in-process-gpu");
|
|
|
|
}
|
2023-10-15 11:37:04 +02:00
|
|
|
|
2023-09-11 04:25:14 +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
|
|
|
|
2023-09-11 04:25:14 +02:00
|
|
|
ipcMain.on(COMMAND.FOLDER_UPSCAYL, batchUpscayl);
|
2023-09-10 11:14:04 +02:00
|
|
|
|
2023-09-11 04:25:14 +02:00
|
|
|
ipcMain.on(COMMAND.DOUBLE_UPSCAYL, doubleUpscayl);
|
2022-09-18 10:08:55 +02:00
|
|
|
|
2023-10-25 13:44:22 +02:00
|
|
|
if (!featureFlags.APP_STORE_BUILD) {
|
|
|
|
autoUpdater.on("update-downloaded", autoUpdate);
|
|
|
|
}
|