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

47 lines
1.3 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-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(
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-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 {
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;