Skip to content

Commit

Permalink
feat(App): Set bulk import as default after osu dir setup (#448)
Browse files Browse the repository at this point in the history
  • Loading branch information
yadPe authored May 9, 2021
1 parent 0948254 commit c01f692
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
16 changes: 15 additions & 1 deletion src/App/modules/Settings/utils/useSettingsUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { remote, ipcRenderer } from 'electron';
import { error } from 'electron-log';
import { join } from 'path';
import { useSelector } from 'react-redux';
import config from '../../../../shared/config';
import { useDownloadQueue } from '../../../Providers/downloadManager';
import { useSetTheme } from '../../../Providers/ThemeProvider';
import { saveThemeAccentColor, setImportMethod, setOsuSongsPath, setOsuPath } from '../reducer/actions';
Expand All @@ -19,6 +20,15 @@ const checkOsuPath = async path => {
}
};

const isDirectory = async path => {
try {
const isDir = await ipcRenderer.invoke('is-dir', path);
return !!isDir;
} catch (e) {
return false;
}
};

const useSettingsUtils = ({ osuSongsPath, importMethod }) => {
const { setPath } = useDownloadQueue();
const { setAccentColor } = useSetTheme();
Expand All @@ -41,7 +51,11 @@ const useSettingsUtils = ({ osuSongsPath, importMethod }) => {
}
setOsuPath(filePaths[0]);
if (!currentOsuSongsPath) {
setOsuSongsPath(join(filePaths[0], 'Songs'));
const songsPath = join(filePaths[0], 'Songs');
if (await isDirectory(songsPath)) {
setOsuSongsPath(join(filePaths[0], 'Songs'));
setImportMethod(config.settings.importMethod.bulk);
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/App/modules/common/Beatmap/beatmap.skeleton.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const useStyle = createUseStyles({
buttons: {
margin: '15px auto 0 auto',
height: '30px',
width: '25%',
width: '213px',
},
});

Expand Down
9 changes: 9 additions & 0 deletions src/electron/ipcMessages.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,12 @@ ipcMain.handle('validate-osu-path', async (event, osuPath) => {
return false;
}
});

ipcMain.handle('is-dir', async (event, path) => {
try {
const isPathValid = await fs.stat(path);
return isPathValid.isDirectory();
} catch {
return false;
}
});

0 comments on commit c01f692

Please sign in to comment.