mirror of
https://github.com/upscayl/upscayl.git
synced 2024-12-14 00:22:59 +01:00
183 lines
5.9 KiB
TypeScript
183 lines
5.9 KiB
TypeScript
import { ChildProcessWithoutNullStreams } from "child_process";
|
|
import { getMainWindow } from "../main-window";
|
|
import logit from "./logit";
|
|
|
|
export let imagePath: string | undefined = "";
|
|
export let folderPath: string | undefined = undefined;
|
|
export let customModelsFolderPath: string | undefined = undefined;
|
|
export let outputFolderPath: string | undefined = undefined;
|
|
export let saveOutputFolder = false;
|
|
export let compression = 0;
|
|
export let stopped = false;
|
|
export let childProcesses: {
|
|
process: ChildProcessWithoutNullStreams;
|
|
kill: () => boolean;
|
|
}[] = [];
|
|
export let noImageProcessing: boolean = false;
|
|
export let turnOffNotifications: boolean = false;
|
|
export let customWidth: string | null = null;
|
|
export let useCustomWidth: boolean = false;
|
|
|
|
export function setImagePath(value: string | undefined): void {
|
|
imagePath = value;
|
|
logit("🖼️ Updating Image Path: ", imagePath);
|
|
}
|
|
|
|
export function setFolderPath(value: string | undefined): void {
|
|
folderPath = value;
|
|
logit("📁 Updating Folder Path: ", folderPath);
|
|
}
|
|
|
|
export function setCustomModelsFolderPath(value: string | undefined): void {
|
|
customModelsFolderPath = value;
|
|
logit("📁 Updating Custom Models Folder Path: ", customModelsFolderPath);
|
|
}
|
|
|
|
// SETTERS
|
|
export function setOutputFolderPath(value: string | undefined): void {
|
|
outputFolderPath = value;
|
|
logit("📁 Updating Output Folder Path: ", outputFolderPath);
|
|
}
|
|
|
|
export function setSaveOutputFolder(value: boolean): void {
|
|
saveOutputFolder = value;
|
|
logit("💾 Updating Save Output Folder: ", saveOutputFolder);
|
|
}
|
|
|
|
export function setCompression(value: number): void {
|
|
compression = value;
|
|
logit("📐 Updating Compression: ", compression);
|
|
}
|
|
|
|
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,
|
|
}),
|
|
);
|
|
}
|
|
|
|
export function setNoImageProcessing(value: boolean): void {
|
|
noImageProcessing = value;
|
|
logit("🖼️ Updating No Image Processing: ", noImageProcessing);
|
|
}
|
|
|
|
export function setTurnOffNotifications(value: boolean): void {
|
|
turnOffNotifications = value;
|
|
logit("🔕 Updating Turn Off Notifications: ", turnOffNotifications);
|
|
}
|
|
|
|
export function setCustomWidth(value: string | null): void {
|
|
customWidth = value;
|
|
logit("📏 Updating Custom Width: ", customWidth);
|
|
}
|
|
|
|
export function setUseCustomWidth(value: boolean): void {
|
|
useCustomWidth = value;
|
|
logit("📏 Updating Use Custom Width: ", useCustomWidth);
|
|
}
|
|
|
|
// 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) {
|
|
setImagePath(lastImagePath);
|
|
}
|
|
});
|
|
// GET LAST FOLDER PATH TO LOCAL STORAGE
|
|
mainWindow.webContents
|
|
.executeJavaScript('localStorage.getItem("lastFolderPath");', true)
|
|
.then((lastFolderPath: string | null) => {
|
|
if (lastFolderPath && lastFolderPath.length > 0) {
|
|
setFolderPath(lastFolderPath);
|
|
}
|
|
});
|
|
// GET LAST CUSTOM MODELS FOLDER PATH TO LOCAL STORAGE
|
|
mainWindow.webContents
|
|
.executeJavaScript(
|
|
'localStorage.getItem("lastCustomModelsFolderPath");',
|
|
true,
|
|
)
|
|
.then((lastCustomModelsFolderPath: string | null) => {
|
|
if (lastCustomModelsFolderPath && lastCustomModelsFolderPath.length > 0) {
|
|
setCustomModelsFolderPath(lastCustomModelsFolderPath);
|
|
}
|
|
});
|
|
// GET LAST CUSTOM MODELS FOLDER PATH TO LOCAL STORAGE
|
|
mainWindow.webContents
|
|
.executeJavaScript('localStorage.getItem("lastOutputFolderPath");', true)
|
|
.then((lastOutputFolderPath: string | null) => {
|
|
if (lastOutputFolderPath && lastOutputFolderPath.length > 0) {
|
|
setOutputFolderPath(lastOutputFolderPath);
|
|
}
|
|
});
|
|
// GET LAST SAVE OUTPUT FOLDER (BOOLEAN) TO LOCAL STORAGE
|
|
mainWindow.webContents
|
|
.executeJavaScript('localStorage.getItem("rememberOutputFolder");', true)
|
|
.then((lastSaveOutputFolder: boolean | null) => {
|
|
if (lastSaveOutputFolder !== null) {
|
|
setSaveOutputFolder(lastSaveOutputFolder);
|
|
}
|
|
});
|
|
// 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");
|
|
}
|
|
});
|
|
|
|
// 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");
|
|
}
|
|
});
|
|
|
|
// 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");
|
|
}
|
|
});
|
|
}
|