1
0
mirror of https://github.com/upscayl/upscayl.git synced 2024-12-18 10:26:04 +01:00
upscayl/electron/commands/select-folder.ts

50 lines
1.4 KiB
TypeScript
Raw Normal View History

2023-11-10 12:41:35 +01:00
import { app, dialog } from "electron";
2024-04-09 20:11:24 +02:00
import {
savedBatchUpscaylFolderPath,
setSavedBatchUpscaylFolderPath,
} from "../utils/config-variables";
2023-09-10 11:14:04 +02:00
import logit from "../utils/logit";
2023-11-10 12:41:35 +01:00
import settings from "electron-settings";
2023-11-23 06:39:46 +01:00
import { featureFlags } from "../../common/feature-flags";
2023-09-10 11:14:04 +02:00
const selectFolder = async (event, message) => {
2023-11-10 12:41:35 +01:00
let closeAccess;
const folderBookmarks = await settings.get("folder-bookmarks");
2023-11-23 06:39:46 +01:00
if (featureFlags.APP_STORE_BUILD && folderBookmarks) {
2023-11-10 12:41:35 +01:00
logit("🚨 Folder Bookmarks: ", folderBookmarks);
try {
closeAccess = app.startAccessingSecurityScopedResource(
2024-04-09 20:11:24 +02:00
folderBookmarks as string,
2023-11-10 12:41:35 +01:00
);
} catch (error) {
logit("📁 Folder Bookmarks Error: ", error);
}
}
2023-11-02 16:03:21 +01:00
const {
canceled,
filePaths: folderPaths,
bookmarks,
} = await dialog.showOpenDialog({
2023-09-10 11:14:04 +02:00
properties: ["openDirectory"],
2024-04-09 20:11:24 +02:00
defaultPath: savedBatchUpscaylFolderPath,
2023-11-02 16:03:21 +01:00
securityScopedBookmarks: true,
2023-09-10 11:14:04 +02:00
});
2023-11-23 06:39:46 +01:00
if (featureFlags.APP_STORE_BUILD && bookmarks && bookmarks.length > 0) {
2023-11-10 12:41:35 +01:00
console.log("🚨 Setting folder Bookmark: ", bookmarks);
await settings.set("folder-bookmarks", bookmarks[0]);
2023-11-02 16:03:21 +01:00
}
2023-09-10 11:14:04 +02:00
if (canceled) {
logit("🚫 Select Folder Operation Cancelled");
return null;
} else {
2024-04-09 20:11:24 +02:00
setSavedBatchUpscaylFolderPath(folderPaths[0]);
logit("📁 Selected Folder Path: ", savedBatchUpscaylFolderPath);
2023-09-10 11:14:04 +02:00
return folderPaths[0];
}
};
export default selectFolder;