1
0
mirror of https://github.com/upscayl/upscayl.git synced 2024-12-11 07:16:14 +01:00
upscayl/electron/commands/select-folder.ts

46 lines
1.2 KiB
TypeScript
Raw Normal View History

2023-11-10 12:41:35 +01:00
import { app, dialog } from "electron";
2023-09-10 19:42:18 +02:00
import { folderPath, setFolderPath } 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-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");
if (folderBookmarks) {
logit("🚨 Folder Bookmarks: ", folderBookmarks);
try {
closeAccess = app.startAccessingSecurityScopedResource(
folderBookmarks as string
);
} 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"],
2023-09-10 19:42:18 +02:00
defaultPath: folderPath,
2023-11-02 16:03:21 +01:00
securityScopedBookmarks: true,
2023-09-10 11:14:04 +02:00
});
2023-11-02 16:03:21 +01:00
if (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 {
setFolderPath(folderPaths[0]);
2023-09-10 19:42:18 +02:00
logit("📁 Selected Folder Path: ", folderPath);
2023-09-10 11:14:04 +02:00
return folderPaths[0];
}
};
export default selectFolder;