mirror of
https://github.com/upscayl/upscayl.git
synced 2024-11-14 18:57:41 +01:00
57 lines
1.5 KiB
TypeScript
57 lines
1.5 KiB
TypeScript
import { MessageBoxOptions, dialog } from "electron";
|
|
import mainWindow from "../main-window";
|
|
import { getImagePath, setImagePath } from "../utils/config-variables";
|
|
import logit from "../utils/logit";
|
|
|
|
const selectFile = async () => {
|
|
if (!mainWindow) return;
|
|
const { canceled, filePaths } = await dialog.showOpenDialog({
|
|
properties: ["openFile", "multiSelections"],
|
|
title: "Select Image",
|
|
defaultPath: getImagePath(),
|
|
});
|
|
|
|
if (canceled) {
|
|
logit("🚫 File Operation Cancelled");
|
|
return null;
|
|
} else {
|
|
setImagePath(filePaths[0]);
|
|
|
|
let isValid = false;
|
|
// READ SELECTED FILES
|
|
filePaths.forEach((file) => {
|
|
// log.log("Files in Folder: ", file);
|
|
if (
|
|
file.endsWith(".png") ||
|
|
file.endsWith(".jpg") ||
|
|
file.endsWith(".jpeg") ||
|
|
file.endsWith(".webp") ||
|
|
file.endsWith(".JPG") ||
|
|
file.endsWith(".PNG") ||
|
|
file.endsWith(".JPEG") ||
|
|
file.endsWith(".WEBP")
|
|
) {
|
|
isValid = true;
|
|
}
|
|
});
|
|
|
|
if (!isValid) {
|
|
logit("❌ Invalid File Detected");
|
|
const options: MessageBoxOptions = {
|
|
type: "error",
|
|
title: "Invalid File",
|
|
message:
|
|
"The selected file is not a valid image. Make sure you select a '.png', '.jpg', or '.webp' file.",
|
|
};
|
|
dialog.showMessageBoxSync(mainWindow, options);
|
|
return null;
|
|
}
|
|
|
|
logit("📄 Selected File Path: ", filePaths[0]);
|
|
// CREATE input AND upscaled FOLDER
|
|
return filePaths[0];
|
|
}
|
|
};
|
|
|
|
export default selectFile;
|