1
0
mirror of https://github.com/upscayl/upscayl.git synced 2024-12-21 03:45:52 +01:00
upscayl/electron/utils/config-variables.ts

126 lines
4.0 KiB
TypeScript
Raw Normal View History

2024-04-24 22:02:22 +02:00
/**
* This file contains all the global local storage variables that need to be accessed on startup or during the app lifecycle. These are the variables that are not sent by the renderer process but are the localstorage variables used by the main process.
* Our goal is to send as many variables as possible from the renderer process to the main process to avoid using local storage variables.
*/
2023-09-10 11:14:04 +02:00
import { ChildProcessWithoutNullStreams } from "child_process";
2023-09-18 20:30:43 +02:00
import { getMainWindow } from "../main-window";
import logit from "./logit";
2023-09-10 11:14:04 +02:00
2024-04-09 20:11:24 +02:00
/**
* The saved image path so that the select image dialog can open to the last used path.
*/
export let savedImagePath: string | undefined = "";
export function setSavedImagePath(value: string | undefined): void {
savedImagePath = value;
logit("🖼️ Updating Image Path: ", savedImagePath);
2023-09-10 11:14:04 +02:00
}
2024-04-09 20:11:24 +02:00
/**
* The saved folder path so that the select folder to upscayl dialog can open to the last used path.
*/
export let savedBatchUpscaylFolderPath: string | undefined = undefined;
export function setSavedBatchUpscaylFolderPath(
value: string | undefined,
): void {
savedBatchUpscaylFolderPath = value;
logit("📁 Updating Folder Path: ", savedBatchUpscaylFolderPath);
2023-09-10 11:14:04 +02:00
}
2024-04-24 21:52:17 +02:00
/**
* The saved custom models folder path so that we can load the list of custom models from that folder on startup.
*/
2024-04-09 20:11:24 +02:00
export let savedCustomModelsPath: string | undefined = undefined;
export function setSavedCustomModelsPath(value: string | undefined): void {
savedCustomModelsPath = value;
logit("📁 Updating Custom Models Folder Path: ", savedCustomModelsPath);
2023-09-10 11:14:04 +02:00
}
2024-04-24 21:52:17 +02:00
/**
* The stopped variable to stop the batch upscayl process.
*/
2024-04-09 20:11:24 +02:00
export let stopped = false;
2024-04-24 21:52:17 +02:00
/**
* The child processes array to store the spawned upscayl processes.
*/
2024-04-09 20:11:24 +02:00
export let childProcesses: {
2023-09-10 11:14:04 +02:00
process: ChildProcessWithoutNullStreams;
kill: () => boolean;
2024-04-09 20:11:24 +02:00
}[] = [];
2023-09-18 20:30:43 +02:00
2024-04-24 21:52:17 +02:00
/**
* The turn off notifications variable, so that we can load this value on startup.
*/
2024-04-09 20:11:24 +02:00
export let turnOffNotifications: boolean = false;
2024-01-16 08:33:43 +01:00
export function setTurnOffNotifications(value: boolean): void {
turnOffNotifications = value;
logit("🔕 Updating Turn Off Notifications: ", turnOffNotifications);
}
2024-04-09 20:11:24 +02:00
// SETTERS
export function setStopped(value: boolean): void {
stopped = value;
logit("🛑 Updating Stopped: ", stopped);
}
export function setChildProcesses(value: {
process: ChildProcessWithoutNullStreams;
kill: () => boolean;
}): void {
childProcesses.push(value);
logit(
"👶 Updating Child Processes: ",
JSON.stringify({
binary: childProcesses[0].process.spawnfile,
args: childProcesses[0].process.spawnargs,
}),
);
}
2023-09-18 20:30:43 +02:00
// LOCAL STORAGE
export function fetchLocalStorage(): void {
const mainWindow = getMainWindow();
if (!mainWindow) return;
// GET LAST IMAGE PATH TO LOCAL STORAGE
mainWindow.webContents
.executeJavaScript('localStorage.getItem("lastImagePath");', true)
.then((lastImagePath: string | null) => {
if (lastImagePath && lastImagePath.length > 0) {
2024-04-09 20:11:24 +02:00
setSavedImagePath(lastImagePath);
2023-09-18 20:30:43 +02:00
}
});
// GET LAST FOLDER PATH TO LOCAL STORAGE
mainWindow.webContents
2024-04-09 20:11:24 +02:00
.executeJavaScript(
'localStorage.getItem("lastSavedBatchUpscaylFolderPath");',
true,
)
.then((lastSavedBatchUpscaylFolderPath: string | null) => {
if (
lastSavedBatchUpscaylFolderPath &&
lastSavedBatchUpscaylFolderPath.length > 0
) {
setSavedBatchUpscaylFolderPath(lastSavedBatchUpscaylFolderPath);
2023-09-18 20:30:43 +02:00
}
});
// GET LAST CUSTOM MODELS FOLDER PATH TO LOCAL STORAGE
mainWindow.webContents
2024-04-09 20:11:24 +02:00
.executeJavaScript('localStorage.getItem("customModelsFolderPath");', true)
.then((value: string | null) => {
if (value && value.length > 0) {
setSavedCustomModelsPath(value);
2023-09-18 20:30:43 +02:00
}
});
2024-01-16 08:33:43 +01:00
// GET TURN OFF NOTIFICATIONS (BOOLEAN) FROM LOCAL STORAGE
mainWindow.webContents
.executeJavaScript('localStorage.getItem("turnOffNotifications");', true)
.then((lastSaved: string | null) => {
if (lastSaved !== null) {
setTurnOffNotifications(lastSaved === "true");
}
});
2023-09-10 11:14:04 +02:00
}