Skip to content

Commit

Permalink
Folder browser (#10)
Browse files Browse the repository at this point in the history
* HOTFIX for 1.5.3, uses electron dialog for folder browsing

* fix for issue 9
  • Loading branch information
doughtnerd authored Jan 29, 2020
1 parent 7f586ee commit fc01c69
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 59 deletions.
45 changes: 11 additions & 34 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"email": "[email protected]",
"url": "https://github.com/Doughtnerd"
},
"version": "1.5.3",
"version": "1.5.4",
"main": "./src/electron.js",
"license": "(MIT OR Apache-2.0)",
"repository": {
Expand Down Expand Up @@ -36,7 +36,6 @@
"electron-log": "^4.0.3",
"electron-store": "~5.1.0",
"electron-updater": "^4.2.0",
"jszip": "~3.2.2",
"request": "^2.88.0",
"svelte-awesome": "~2.2.1",
"svelte-infinite-scroll": "~0.1.0"
Expand Down
32 changes: 25 additions & 7 deletions src/main/downloading/downloadManager.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
const { ipcMain } = require("electron");
const fs = require("fs");

const { ipcMain, dialog } = require("electron");
const { fork } = require("child_process");
const Store = require("electron-store");
const fs = require("fs");

const storage = new Store();

const { fork } = require("child_process");

const {
DOWNLOAD_ERROR,
DOWNLOAD_BEATMAP,
Expand Down Expand Up @@ -55,6 +53,17 @@ async function getDownloadDirectory() {
}
}

function openFolderBrowser(startingDirectory) {
let options = {
title: "Select Beat Saber install directory",
defaultPath: startingDirectory,
buttonLabel: "Choose folder",
properties: ["openDirectory"]
};

return dialog.showOpenDialog(options);
}

function register(mainWindow) {
const sendStatusToWindow = (channel, payload) => {
mainWindow.webContents.send(channel, payload);
Expand Down Expand Up @@ -83,8 +92,17 @@ function register(mainWindow) {
childProcess.send({ beatmap, downloadsFolder, songFolderName });
});

ipcMain.on(CHANGE_DOWNLOAD_DIRECTORY, (event, newDirectory) => {
storage.set(DOWNLOAD_DIRECTORY, newDirectory);
ipcMain.handle(CHANGE_DOWNLOAD_DIRECTORY, async (event, eventData) => {
const currentDirectory = await getDownloadDirectory();
const selection = await openFolderBrowser(currentDirectory);

if (!selection.canceled) {
const newDir = selection.filePaths[0];
storage.set(DOWNLOAD_DIRECTORY, newDir);
return newDir;
} else {
return currentDirectory;
}
});

ipcMain.handle(GET_DOWNLOAD_DIRECTORY, () => {
Expand Down
17 changes: 4 additions & 13 deletions src/render/pages/Settings.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@
import { appInfoStore } from "../stores/app-info.store";
import { availableThemesStore, themeStore } from "../stores/theme.store";
function handleOnChange(event) {
if (event.target.files[0] && event.target.files[0].path) {
downloads.changeDownloadDirectory(event.target.files[0].path);
}
function handleChangeDirectory(event) {
downloads.changeDownloadDirectory();
}
function handleThemeChange(event) {
Expand Down Expand Up @@ -46,12 +44,7 @@
</style>

<div class="container">
<input
bind:this={installLocInput}
type="file"
style="display: none"
webkitdirectory
on:change={handleOnChange} />

<PrimaryText>
<h1>App Version</h1>
</PrimaryText>
Expand All @@ -69,9 +62,7 @@
<button
class="primary"
id="folder-selection"
on:click={() => {
installLocInput.click();
}}>
on:click={handleChangeDirectory}>
Choose Location
</button>
</div>
Expand Down
7 changes: 4 additions & 3 deletions src/render/stores/downloads.store.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import {
GET_DOWNLOAD_DIRECTORY,
DOWNLOAD_BEATMAP,
DOWNLOAD_COMPLETE,
DOWNLOAD_ERROR
DOWNLOAD_ERROR,
CHANGE_DOWNLOAD_DIRECTORY
} from "../../constants/channelNames";

import { toastStore } from "./toast.store";
Expand Down Expand Up @@ -67,8 +68,8 @@ function createDownloadsStore() {
};
});
},
changeDownloadDirectory: async newDirectory => {
await window.api.invoke(CHANGE_DOWNLOAD_DIRECTORY, newDirectory);
changeDownloadDirectory: async () => {
const newDirectory = await window.api.invoke(CHANGE_DOWNLOAD_DIRECTORY);
store.update(current => ({
...current,
downloadDirectory: newDirectory
Expand Down

0 comments on commit fc01c69

Please sign in to comment.