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-10-25 17:14:22 +05:30
|
|
|
import { app, ipcMain, protocol } from "electron";
|
2024-10-04 14:45:54 +05:30
|
|
|
import { ELECTRON_COMMANDS } from "../common/electron-commands";
|
2023-09-10 14:44:04 +05:30
|
|
|
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 07:55:14 +05:30
|
|
|
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";
|
2023-09-11 07:55:14 +05:30
|
|
|
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";
|
2024-10-04 14:45:54 +05:30
|
|
|
import { FEATURE_FLAGS } from "../common/feature-flags";
|
2023-11-10 17:11:35 +05:30
|
|
|
import settings from "electron-settings";
|
2023-09-10 14:44:04 +05:30
|
|
|
|
|
|
|
// INITIALIZATION
|
2023-03-31 16:03:48 +05:30
|
|
|
log.initialize({ preload: true });
|
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-11 07:55:14 +05:30
|
|
|
|
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-11 07:55:14 +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
|
|
|
|
2024-08-31 16:35:53 +05:30
|
|
|
log.info(
|
|
|
|
"🆙 Upscayl version:",
|
|
|
|
app.getVersion(),
|
2024-10-04 14:45:54 +05:30
|
|
|
FEATURE_FLAGS.APP_STORE_BUILD && "MAC-APP-STORE",
|
2024-08-31 16:35:53 +05:30
|
|
|
);
|
2024-01-16 12:00:07 +05:30
|
|
|
log.info("🚀 UPSCAYL EXEC PATH: ", execPath);
|
2023-09-13 18:44:46 +05:30
|
|
|
log.info("🚀 MODELS PATH: ", modelsPath);
|
2023-11-04 15:32:44 +05:30
|
|
|
|
2023-11-10 17:11:35 +05:30
|
|
|
let closeAccess;
|
|
|
|
const folderBookmarks = await settings.get("folder-bookmarks");
|
2024-10-04 14:45:54 +05:30
|
|
|
if (FEATURE_FLAGS.APP_STORE_BUILD && folderBookmarks) {
|
2023-11-10 17:11:35 +05:30
|
|
|
logit("🚨 Folder Bookmarks: ", folderBookmarks);
|
|
|
|
try {
|
|
|
|
closeAccess = app.startAccessingSecurityScopedResource(
|
2024-04-09 00:17:08 +05:30
|
|
|
folderBookmarks as string,
|
2023-11-10 17:11:35 +05:30
|
|
|
);
|
|
|
|
} catch (error) {
|
|
|
|
logit("📁 Folder Bookmarks Error: ", error);
|
|
|
|
}
|
2023-11-04 15:32:44 +05:30
|
|
|
}
|
2023-09-11 07:55:14 +05:30
|
|
|
});
|
2023-09-10 23:24:08 +05:30
|
|
|
|
2023-09-11 07:55:14 +05:30
|
|
|
// Quit the app once all windows are closed
|
|
|
|
app.on("window-all-closed", () => {
|
2023-09-16 16:04:35 +05:30
|
|
|
app.quit();
|
2023-09-10 23:12:18 +05:30
|
|
|
});
|
2023-04-23 13:26:49 +05:30
|
|
|
|
2023-10-15 15:07:04 +05:30
|
|
|
// ! ENABLE THIS FOR MACOS APP STORE BUILD
|
2024-10-04 14:45:54 +05:30
|
|
|
if (FEATURE_FLAGS.APP_STORE_BUILD) {
|
2023-10-25 17:14:22 +05:30
|
|
|
logit("🚀 APP STORE BUILD ENABLED");
|
2023-10-21 19:13:03 +05:30
|
|
|
app.commandLine.appendSwitch("in-process-gpu");
|
|
|
|
}
|
2023-10-15 15:07:04 +05:30
|
|
|
|
2024-10-04 14:45:54 +05:30
|
|
|
ipcMain.on(ELECTRON_COMMANDS.STOP, stop);
|
2023-09-09 15:43:16 +05:30
|
|
|
|
2024-10-04 14:45:54 +05:30
|
|
|
ipcMain.on(ELECTRON_COMMANDS.OPEN_FOLDER, openFolder);
|
2022-12-02 19:51:42 +05:30
|
|
|
|
2024-10-04 14:45:54 +05:30
|
|
|
ipcMain.handle(ELECTRON_COMMANDS.SELECT_FOLDER, selectFolder);
|
2023-08-10 15:14:44 +05:30
|
|
|
|
2024-10-04 14:45:54 +05:30
|
|
|
ipcMain.handle(ELECTRON_COMMANDS.SELECT_FILE, selectFile);
|
2023-08-10 15:14:44 +05:30
|
|
|
|
2024-10-04 14:45:54 +05:30
|
|
|
ipcMain.on(ELECTRON_COMMANDS.GET_MODELS_LIST, getModelsList);
|
2023-08-10 15:14:44 +05:30
|
|
|
|
2024-10-04 14:45:54 +05:30
|
|
|
ipcMain.handle(
|
|
|
|
ELECTRON_COMMANDS.SELECT_CUSTOM_MODEL_FOLDER,
|
|
|
|
customModelsSelect,
|
|
|
|
);
|
2023-08-10 15:14:44 +05:30
|
|
|
|
2024-10-04 14:45:54 +05:30
|
|
|
ipcMain.on(ELECTRON_COMMANDS.UPSCAYL, imageUpscayl);
|
2023-08-10 15:14:44 +05:30
|
|
|
|
2024-10-04 14:45:54 +05:30
|
|
|
ipcMain.on(ELECTRON_COMMANDS.FOLDER_UPSCAYL, batchUpscayl);
|
2023-09-10 14:44:04 +05:30
|
|
|
|
2024-10-04 14:45:54 +05:30
|
|
|
ipcMain.on(ELECTRON_COMMANDS.DOUBLE_UPSCAYL, doubleUpscayl);
|
2022-09-18 13:38:55 +05:30
|
|
|
|
2024-10-04 14:45:54 +05:30
|
|
|
if (!FEATURE_FLAGS.APP_STORE_BUILD) {
|
2023-10-25 17:14:22 +05:30
|
|
|
autoUpdater.on("update-downloaded", autoUpdate);
|
|
|
|
}
|