1
0
mirror of https://github.com/upscayl/upscayl.git synced 2024-12-01 02:27:16 +01:00
upscayl/electron/commands/select-folder.ts
2023-11-10 17:11:35 +05:30

46 lines
1.2 KiB
TypeScript

import { app, dialog } from "electron";
import { folderPath, setFolderPath } from "../utils/config-variables";
import logit from "../utils/logit";
import settings from "electron-settings";
const selectFolder = async (event, message) => {
let closeAccess;
const folderBookmarks = await settings.get("folder-bookmarks");
if (folderBookmarks) {
logit("🚨 Folder Bookmarks: ", folderBookmarks);
try {
closeAccess = app.startAccessingSecurityScopedResource(
folderBookmarks as string
);
} catch (error) {
logit("📁 Folder Bookmarks Error: ", error);
}
}
const {
canceled,
filePaths: folderPaths,
bookmarks,
} = await dialog.showOpenDialog({
properties: ["openDirectory"],
defaultPath: folderPath,
securityScopedBookmarks: true,
});
if (bookmarks && bookmarks.length > 0) {
console.log("🚨 Setting folder Bookmark: ", bookmarks);
await settings.set("folder-bookmarks", bookmarks[0]);
}
if (canceled) {
logit("🚫 Select Folder Operation Cancelled");
return null;
} else {
setFolderPath(folderPaths[0]);
logit("📁 Selected Folder Path: ", folderPath);
return folderPaths[0];
}
};
export default selectFolder;