Skip to content
This repository has been archived by the owner on Jun 26, 2024. It is now read-only.

Commit

Permalink
Set donwload path #244
Browse files Browse the repository at this point in the history
  • Loading branch information
trazyn committed Aug 3, 2018
1 parent 0df11ba commit f40e16c
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 3 deletions.
1 change: 1 addition & 0 deletions config/webpack.config.base.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ export default {
resolve: {
extensions: ['.js', '.jsx', '.json'],
alias: {
root: path.join(config.client, '../'),
config: path.join(config.client, '../config'),
common: path.join(config.client, '../common'),
app: path.join(config.client, './'),
Expand Down
26 changes: 26 additions & 0 deletions src/js/components/Preferences/classes.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,5 +141,31 @@ export default theme => {
connected: {
background: colors.pallet.mint,
},

downloads: {
display: 'flex',
justifyContent: 'space-between',
alignItems: 'center',

'& input': {
display: 'none',
},

'& button': {
padding: '8px 12px',
textTransform: 'uppercase',
border: 0,
borderRadius: 1,
background: 'none',
color: 'rgb(117, 117, 117)',
cursor: 'pointer',
outline: 0,
transition: '.2s',
},

'& button:hover': {
background: 'rgba(0, 0, 0, .1)',
}
}
};
};
22 changes: 22 additions & 0 deletions src/js/components/Preferences/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ class Preferences extends Component {
return connected && `${username}:${password}` === connected;
}

choiceDownloadDir(e) {
e.preventDefault();
this.downloads.click();
}

renderOptions() {
var { classes, preferences } = this.props;
var {
Expand Down Expand Up @@ -74,6 +79,8 @@ class Preferences extends Component {
enginers,
proxy,
setProxy,
downloads,
setDownloads,
} = preferences;

return (
Expand Down Expand Up @@ -199,6 +206,21 @@ class Preferences extends Component {
placeholder="http://your.proxy.com:port"
/>
</label>

<label className={classes.downloads}>
<aside>
<input
webkitdirectory="true"
onChange={e => setDownloads(e.target.files[0])}
ref={ele => (this.downloads = ele)}
type="file"
/>
<h4>Downloads</h4>
<p onClick={e => this.choiceDownloadDir(e)}>{downloads}</p>
</aside>

<button onClick={e => this.choiceDownloadDir(e)}>Change</button>
</label>
</article>

<article>
Expand Down
15 changes: 13 additions & 2 deletions src/js/stores/preferences.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@

import path from 'path';
import { observable, action } from 'mobx';
import { ipcRenderer } from 'electron';
import { remote, ipcRenderer } from 'electron';
import axios from 'axios';

import pkg from 'root/package.json';
import controller from './controller';
import config from 'config/index';
import theme from 'config/theme.js';
Expand Down Expand Up @@ -35,6 +37,7 @@ class Preferences {
'kuwo': true,
};
@observable proxy = '';
@observable downloads = path.join(remote.app.getPath('music'), pkg.name);

@action async init() {
var preferences = await storage.get('preferences');
Expand All @@ -53,6 +56,7 @@ class Preferences {
lastfm = self.lastfm,
enginers = self.enginers,
proxy = self.proxy,
downloads = self.downloads,
} = preferences;

self.showTray = !!showTray;
Expand All @@ -69,6 +73,7 @@ class Preferences {
self.lastfm = lastfm;
self.enginers = enginers;
self.proxy = proxy;
self.downloads = downloads;

// Save preferences
self.save();
Expand All @@ -78,7 +83,7 @@ class Preferences {
}

@action async save() {
var { showTray, alwaysOnTop, showNotification, autoPlay, naturalScroll, port, volume, highquality, backgrounds, autoupdate, scrobble, lastfm, enginers, proxy } = self;
var { showTray, alwaysOnTop, showNotification, autoPlay, naturalScroll, port, volume, highquality, backgrounds, autoupdate, scrobble, lastfm, enginers, proxy, downloads } = self;

await storage.set('preferences', {
showTray,
Expand All @@ -95,6 +100,7 @@ class Preferences {
lastfm,
enginers,
proxy,
downloads,
});

ipcRenderer.send('update-preferences', {
Expand Down Expand Up @@ -170,6 +176,11 @@ class Preferences {
self.save();
}

@action setDownloads(downloads) {
self.downloads = downloads.path;
self.save();
}

@action setProxy(proxy) {
if (!/^http(s)?:\/\/\w+/i.test(proxy)) {
proxy = '';
Expand Down
3 changes: 2 additions & 1 deletion submodules/downloader/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,12 @@ async function writeFile(url, filepath, cb) {

async function download(task) {
try {
var preferences = await storage.get('preferences');
var song = task.payload;
var src = song.data.src;
var imagefile = (await tmp.file()).path;
var trackfile = path.join(
_DOWNLOAD_DIR,
preferences.downloads || _DOWNLOAD_DIR,
`${song.artists.map(e => e.name).join()} - ${song.name.replace(/\/|\\/g, '/')}.${src.replace(/\?.*/, '').match(/^http.*\.(.*)$/)[1]}`
);
var notificationOptions = {
Expand Down

0 comments on commit f40e16c

Please sign in to comment.