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-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-09 20:11:24 +02:00
|
|
|
export let savedOutputPath: string | undefined = undefined;
|
|
|
|
export function setSavedOutputPath(value: string | undefined): void {
|
|
|
|
savedOutputPath = value;
|
|
|
|
logit("📁 Updating Output Folder Path: ", savedOutputPath);
|
2023-09-10 11:14:04 +02:00
|
|
|
}
|
|
|
|
|
2024-04-09 20:11:24 +02:00
|
|
|
export let rememberOutputFolder = false;
|
|
|
|
export function setRememberOutputFolder(value: boolean): void {
|
|
|
|
rememberOutputFolder = value;
|
|
|
|
logit("💾 Updating Remember Output Folder: ", rememberOutputFolder);
|
2023-09-10 11:14:04 +02:00
|
|
|
}
|
|
|
|
|
2024-04-09 20:11:24 +02:00
|
|
|
export let savedCompression = 0;
|
2023-09-13 16:07:45 +02:00
|
|
|
export function setCompression(value: number): void {
|
2024-04-09 20:11:24 +02:00
|
|
|
savedCompression = value;
|
|
|
|
logit("📐 Updating Compression: ", savedCompression);
|
2023-09-10 11:14:04 +02:00
|
|
|
}
|
|
|
|
|
2024-04-09 20:11:24 +02:00
|
|
|
export let stopped = false;
|
|
|
|
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-09 20:11:24 +02:00
|
|
|
export let noImageProcessing: boolean = false;
|
2023-09-18 20:30:43 +02:00
|
|
|
export function setNoImageProcessing(value: boolean): void {
|
|
|
|
noImageProcessing = value;
|
|
|
|
logit("🖼️ Updating No Image Processing: ", noImageProcessing);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
export let customWidth: string | null = null;
|
2024-02-08 15:57:35 +01:00
|
|
|
export function setCustomWidth(value: string | null): void {
|
|
|
|
customWidth = value;
|
|
|
|
logit("📏 Updating Custom Width: ", customWidth);
|
|
|
|
}
|
|
|
|
|
2024-04-09 20:11:24 +02:00
|
|
|
export let useCustomWidth: boolean = false;
|
2024-02-08 15:57:35 +01:00
|
|
|
export function setUseCustomWidth(value: boolean): void {
|
|
|
|
useCustomWidth = value;
|
|
|
|
logit("📏 Updating Use Custom Width: ", useCustomWidth);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
});
|
|
|
|
// GET LAST CUSTOM MODELS FOLDER PATH TO LOCAL STORAGE
|
|
|
|
mainWindow.webContents
|
2024-04-09 20:11:24 +02:00
|
|
|
.executeJavaScript('localStorage.getItem("savedOutputPath");', true)
|
|
|
|
.then((savedOutputPath: string | null) => {
|
|
|
|
if (savedOutputPath && savedOutputPath.length > 0) {
|
|
|
|
setSavedOutputPath(savedOutputPath);
|
2023-09-18 20:30:43 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
// GET LAST SAVE OUTPUT FOLDER (BOOLEAN) TO LOCAL STORAGE
|
|
|
|
mainWindow.webContents
|
|
|
|
.executeJavaScript('localStorage.getItem("rememberOutputFolder");', true)
|
|
|
|
.then((lastSaveOutputFolder: boolean | null) => {
|
|
|
|
if (lastSaveOutputFolder !== null) {
|
2024-04-09 20:11:24 +02:00
|
|
|
setRememberOutputFolder(lastSaveOutputFolder);
|
2023-09-18 20:30:43 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
// GET IMAGE COMPRESSION (NUMBER) FROM LOCAL STORAGE
|
|
|
|
mainWindow.webContents
|
|
|
|
.executeJavaScript('localStorage.getItem("compression");', true)
|
|
|
|
.then((lastSavedCompression: string | null) => {
|
|
|
|
if (lastSavedCompression !== null) {
|
|
|
|
setCompression(parseInt(lastSavedCompression));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
// GET PROCESS IMAGE (BOOLEAN) FROM LOCAL STORAGE
|
|
|
|
mainWindow.webContents
|
|
|
|
.executeJavaScript('localStorage.getItem("noImageProcessing");', true)
|
|
|
|
.then((lastSaved: string | null) => {
|
|
|
|
if (lastSaved !== null) {
|
|
|
|
setNoImageProcessing(lastSaved === "true");
|
|
|
|
}
|
|
|
|
});
|
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");
|
|
|
|
}
|
|
|
|
});
|
2024-02-08 15:57:35 +01:00
|
|
|
|
|
|
|
// GET CUSTOM WIDTH (STRING) FROM LOCAL STORAGE
|
|
|
|
mainWindow.webContents
|
|
|
|
.executeJavaScript('localStorage.getItem("customWidth");', true)
|
|
|
|
.then((lastSaved: string | null) => {
|
|
|
|
if (lastSaved !== null) {
|
|
|
|
setCustomWidth(lastSaved);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
// GET USE CUSTOM WIDTH (BOOLEAN) FROM LOCAL STORAGE
|
|
|
|
mainWindow.webContents
|
|
|
|
.executeJavaScript('localStorage.getItem("useCustomWidth");', true)
|
|
|
|
.then((lastSaved: string | null) => {
|
|
|
|
if (lastSaved !== null) {
|
|
|
|
setUseCustomWidth(lastSaved === "true");
|
|
|
|
}
|
|
|
|
});
|
2023-09-10 11:14:04 +02:00
|
|
|
}
|