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
|
|
|
|
2023-09-10 19:42:18 +02:00
|
|
|
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;
|
2023-09-13 16:07:45 +02:00
|
|
|
export let compression = 0;
|
2023-09-10 19:42:18 +02:00
|
|
|
export let overwrite = false;
|
|
|
|
export let stopped = false;
|
|
|
|
export let childProcesses: {
|
2023-09-10 11:14:04 +02:00
|
|
|
process: ChildProcessWithoutNullStreams;
|
|
|
|
kill: () => boolean;
|
|
|
|
}[] = [];
|
2023-09-18 20:30:43 +02:00
|
|
|
export let noImageProcessing: boolean = false;
|
2023-09-10 11:14:04 +02:00
|
|
|
|
|
|
|
export function setImagePath(value: string | undefined): void {
|
2023-09-10 19:42:18 +02:00
|
|
|
imagePath = value;
|
2023-09-18 20:30:43 +02:00
|
|
|
logit("🖼️ Updating Image Path: ", imagePath);
|
2023-09-10 11:14:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
export function setFolderPath(value: string | undefined): void {
|
2023-09-10 19:42:18 +02:00
|
|
|
folderPath = value;
|
2023-09-18 20:30:43 +02:00
|
|
|
logit("📁 Updating Folder Path: ", folderPath);
|
2023-09-10 11:14:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
export function setCustomModelsFolderPath(value: string | undefined): void {
|
2023-09-10 19:42:18 +02:00
|
|
|
customModelsFolderPath = value;
|
2023-09-18 20:30:43 +02:00
|
|
|
logit("📁 Updating Custom Models Folder Path: ", customModelsFolderPath);
|
2023-09-10 11:14:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// SETTERS
|
|
|
|
export function setOutputFolderPath(value: string | undefined): void {
|
2023-09-10 19:42:18 +02:00
|
|
|
outputFolderPath = value;
|
2023-09-18 20:30:43 +02:00
|
|
|
logit("📁 Updating Output Folder Path: ", outputFolderPath);
|
2023-09-10 11:14:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
export function setSaveOutputFolder(value: boolean): void {
|
2023-09-10 19:42:18 +02:00
|
|
|
saveOutputFolder = value;
|
2023-09-18 20:30:43 +02:00
|
|
|
logit("💾 Updating Save Output Folder: ", saveOutputFolder);
|
2023-09-10 11:14:04 +02:00
|
|
|
}
|
|
|
|
|
2023-09-13 16:07:45 +02:00
|
|
|
export function setCompression(value: number): void {
|
|
|
|
compression = value;
|
2023-09-18 20:30:43 +02:00
|
|
|
logit("📐 Updating Compression: ", compression);
|
2023-09-10 11:14:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
export function setOverwrite(value: boolean): void {
|
2023-09-10 19:42:18 +02:00
|
|
|
overwrite = value;
|
2023-09-18 20:30:43 +02:00
|
|
|
logit("📝 Updating Overwrite: ", overwrite);
|
2023-09-10 11:14:04 +02:00
|
|
|
}
|
|
|
|
|
2023-09-10 19:42:18 +02:00
|
|
|
export function setStopped(value: boolean): void {
|
|
|
|
stopped = value;
|
2023-09-18 20:30:43 +02:00
|
|
|
logit("🛑 Updating Stopped: ", stopped);
|
2023-09-10 11:14:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
export function setChildProcesses(value: {
|
|
|
|
process: ChildProcessWithoutNullStreams;
|
|
|
|
kill: () => boolean;
|
|
|
|
}): void {
|
|
|
|
childProcesses.push(value);
|
2023-09-18 20:30:43 +02:00
|
|
|
logit("👶 Updating Child Processes: ", childProcesses);
|
|
|
|
}
|
|
|
|
|
|
|
|
export function setNoImageProcessing(value: boolean): void {
|
|
|
|
noImageProcessing = value;
|
|
|
|
logit("🖼️ Updating No Image Processing: ", noImageProcessing);
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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 OVERWRITE (BOOLEAN) FROM LOCAL STORAGE
|
|
|
|
mainWindow.webContents
|
|
|
|
.executeJavaScript('localStorage.getItem("overwrite");', true)
|
|
|
|
.then((lastSavedOverwrite: string | null) => {
|
|
|
|
if (lastSavedOverwrite !== null) {
|
|
|
|
setOverwrite(lastSavedOverwrite === "true");
|
|
|
|
}
|
|
|
|
});
|
|
|
|
// GET PROCESS IMAGE (BOOLEAN) FROM LOCAL STORAGE
|
|
|
|
mainWindow.webContents
|
|
|
|
.executeJavaScript('localStorage.getItem("noImageProcessing");', true)
|
|
|
|
.then((lastSaved: string | null) => {
|
|
|
|
if (lastSaved !== null) {
|
|
|
|
setNoImageProcessing(lastSaved === "true");
|
|
|
|
}
|
|
|
|
});
|
2023-09-10 11:14:04 +02:00
|
|
|
}
|