1
0
mirror of https://github.com/upscayl/upscayl.git synced 2025-02-14 18:02:38 +01:00
upscayl/electron/commands/custom-models-select.ts

54 lines
1.6 KiB
TypeScript
Raw Normal View History

2023-09-10 14:44:04 +05:30
import { MessageBoxOptions, dialog } from "electron";
import {
2023-09-10 23:12:18 +05:30
customModelsFolderPath,
2023-09-10 14:44:04 +05:30
setCustomModelsFolderPath,
} from "../utils/config-variables";
import logit from "../utils/logit";
import slash from "../utils/slash";
import COMMAND from "../constants/commands";
import getModels from "../utils/get-models";
2023-09-10 23:12:18 +05:30
import { getMainWindow } from "../main-window";
2023-09-10 14:44:04 +05:30
const customModelsSelect = async (event, message) => {
2023-09-10 23:24:08 +05:30
const mainWindow = getMainWindow();
2023-09-10 14:44:04 +05:30
if (!mainWindow) return;
const { canceled, filePaths: folderPaths } = await dialog.showOpenDialog({
properties: ["openDirectory"],
title: "Select Custom Models Folder",
2023-09-10 23:12:18 +05:30
defaultPath: customModelsFolderPath,
2023-09-10 14:44:04 +05:30
});
if (canceled) {
logit("🚫 Select Custom Models Folder Operation Cancelled");
return null;
} else {
setCustomModelsFolderPath(folderPaths[0]);
if (
!folderPaths[0].endsWith(slash + "models") &&
!folderPaths[0].endsWith(slash + "models" + slash)
) {
logit("❌ Invalid Custom Models Folder Detected: Not a 'models' folder");
const options: MessageBoxOptions = {
type: "error",
title: "Invalid Folder",
message:
"Please make sure that the folder name is 'models' and nothing else.",
buttons: ["OK"],
};
dialog.showMessageBoxSync(options);
return null;
}
mainWindow.webContents.send(
COMMAND.CUSTOM_MODEL_FILES_LIST,
2023-09-10 23:12:18 +05:30
getModels(customModelsFolderPath)
2023-09-10 14:44:04 +05:30
);
2023-09-10 23:12:18 +05:30
logit("📁 Custom Folder Path: ", customModelsFolderPath);
return customModelsFolderPath;
2023-09-10 14:44:04 +05:30
}
};
export default customModelsSelect;