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
NayamAmarshe 95843ded88
Refactor Renderer Code (#987)
* Initial refactor

* Remove unused imports

* Update code

* Refactor and Update Code

- Change file names to kebab-caase
- Add new useTranslation Hook
- Change useLog hook name to useLogger
- Update translation hook to provide autocomplete

* Update import and component name

* Rename files and components

* Update locales

* Update electron commands

* Update var

* Change Lowercase

* Replace filter with map

* Add props

* Update flag check

* Add validate paths

* Update formats

* Update import

* Update function

* Update function and translation

* Update handlePaste
2024-10-04 14:45:54 +05:30

50 lines
1.4 KiB
TypeScript

import { app, dialog } from "electron";
import {
savedBatchUpscaylFolderPath,
setSavedBatchUpscaylFolderPath,
} from "../utils/config-variables";
import logit from "../utils/logit";
import settings from "electron-settings";
import { FEATURE_FLAGS } from "../../common/feature-flags";
const selectFolder = async (event, message) => {
let closeAccess;
const folderBookmarks = await settings.get("folder-bookmarks");
if (FEATURE_FLAGS.APP_STORE_BUILD && 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: savedBatchUpscaylFolderPath,
securityScopedBookmarks: true,
});
if (FEATURE_FLAGS.APP_STORE_BUILD && 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 {
setSavedBatchUpscaylFolderPath(folderPaths[0]);
logit("📁 Selected Folder Path: ", savedBatchUpscaylFolderPath);
return folderPaths[0];
}
};
export default selectFolder;