Download & other bug fixes

This commit is contained in:
exttex 2020-10-01 14:30:00 +02:00
parent 80f6cbf870
commit 9b4aca64e3
8 changed files with 42 additions and 24 deletions

View File

@ -14,8 +14,7 @@ function assetPath(a) {
return path.join(__dirname, 'assets', a); return path.join(__dirname, 'assets', a);
} }
async function createWindow() { async function startServer() {
//Start server
settings = await createServer(true, (e) => { settings = await createServer(true, (e) => {
//Server error //Server error
shouldExit = true; shouldExit = true;
@ -28,7 +27,9 @@ async function createWindow() {
buttons: ['Close'] buttons: ['Close']
}); });
}); });
}
async function createWindow() {
//Create window //Create window
win = new BrowserWindow({ win = new BrowserWindow({
width: settings.width, width: settings.width,
@ -62,6 +63,7 @@ async function createWindow() {
if (shouldExit) { if (shouldExit) {
win = null; win = null;
tray = null; tray = null;
app.quit();
return true; return true;
} }
@ -81,23 +83,30 @@ async function createWindow() {
//Create window //Create window
app.on('ready', async () => { app.on('ready', async () => {
await startServer();
createWindow(); createWindow();
//Create Tray //Create Tray
tray = new Tray(assetPath("icon-taskbar.png")); tray = new Tray(assetPath("icon-taskbar.png"));
tray.on('double-click', () => win.show()); tray.on('double-click', () => restoreWindow());
tray.on('click', () => win.show()); tray.on('click', () => restoreWindow());
setTray(); setTray();
}); });
//Restore or create new window
function restoreWindow() {
if (win) return win.show();
createWindow();
}
//Update tray context menu //Update tray context menu
function setTray() { function setTray() {
const contextMenu = Menu.buildFromTemplate([ const contextMenu = Menu.buildFromTemplate([
{ {
label: 'Restore', label: 'Restore',
type: 'normal', type: 'normal',
click: () => win.show() click: () => restoreWindow()
}, },
playing ? playing ?
{ {
@ -125,6 +134,7 @@ function setTray() {
type: 'normal', type: 'normal',
click: () => { click: () => {
shouldExit = true; shouldExit = true;
if (!win) return app.quit();
win.close(); win.close();
} }
} }

View File

@ -7,6 +7,7 @@ import VueEsc from 'vue-esc';
import VueSocketIO from 'vue-socket.io'; import VueSocketIO from 'vue-socket.io';
//Globals //Globals
let ipcRenderer;
//Axios //Axios
let axiosInstance = axios.create({ let axiosInstance = axios.create({
baseURL: `${window.location.origin}`, baseURL: `${window.location.origin}`,
@ -226,7 +227,7 @@ new Vue({
this.position = this.audio.currentTime * 1000; this.position = this.audio.currentTime * 1000;
//Gapless playback //Gapless playback
if (this.position >= (this.duration() - 5000) && this.state == 2) { if (this.position >= (this.duration() - 7000) && this.state == 2) {
if (!this.shuffle && this.repeat != 2) if (!this.shuffle && this.repeat != 2)
this.loadGapless(); this.loadGapless();
} }
@ -364,7 +365,6 @@ new Vue({
//Update settings in electron //Update settings in electron
if (this.settings.electron) { if (this.settings.electron) {
const {ipcRenderer} = window.require('electron');
ipcRenderer.send('updateSettings', this.settings); ipcRenderer.send('updateSettings', this.settings);
} }
}, },
@ -422,7 +422,6 @@ new Vue({
//Update in electron //Update in electron
if (this.settings.electron) { if (this.settings.electron) {
const {ipcRenderer} = window.require('electron');
ipcRenderer.send('playing', this.state == 2); ipcRenderer.send('playing', this.state == 2);
} }
} }
@ -455,11 +454,11 @@ new Vue({
typeof navigator === 'object' && typeof navigator.userAgent === 'string' && typeof navigator === 'object' && typeof navigator.userAgent === 'string' &&
navigator.userAgent.indexOf('Electron') >= 0 navigator.userAgent.indexOf('Electron') >= 0
)); ));
if (this.settings.electron)
ipcRenderer = window.require('electron').ipcRenderer;
//Setup electron callbacks //Setup electron callbacks
if (this.settings.electron) { if (this.settings.electron) {
const {ipcRenderer} = window.require('electron');
//Save files on exit //Save files on exit
ipcRenderer.on('onExit', async () => { ipcRenderer.on('onExit', async () => {
this.pause(); this.pause();

View File

@ -101,7 +101,7 @@
:prepend-icon='$root.muted ? "mdi-volume-off" : "mdi-volume-high"' :prepend-icon='$root.muted ? "mdi-volume-off" : "mdi-volume-high"'
max='1.00' max='1.00'
step='0.01' step='0.01'
v-model='$root.audio.volume' v-model='$root.volume'
class='px-8' class='px-8'
style='padding-top: 2px;' style='padding-top: 2px;'
@change='updateVolume' @change='updateVolume'
@ -283,6 +283,7 @@ export default {
}, },
//Save volume //Save volume
updateVolume(v) { updateVolume(v) {
if (this.$root.audio) this.$root.audio.volume = v;
this.$root.volume = v; this.$root.volume = v;
}, },
//Repeat button click //Repeat button click
@ -305,7 +306,7 @@ export default {
}, },
'$root.position'() { '$root.position'() {
if (!this.seeking) this.position = this.$root.position / 1000; if (!this.seeking) this.position = this.$root.position / 1000;
} },
} }
}; };

View File

@ -1,7 +1,7 @@
{ {
"name": "freezer", "name": "freezer",
"private": true, "private": true,
"version": "1.0.7", "version": "1.0.8",
"description": "", "description": "",
"main": "background.js", "main": "background.js",
"scripts": { "scripts": {

View File

@ -248,11 +248,10 @@ class Download {
this.downloaded = start; this.downloaded = start;
//Get download info //Get download info
if (!this.url) { let streamInfo = Track.getUrlInfo(this.track.streamUrl);
let streamInfo = Track.getUrlInfo(this.track.streamUrl); this.url = DeezerAPI.getUrl(streamInfo.trackId, streamInfo.md5origin, streamInfo.mediaVersion, this.quality);
this.url = DeezerAPI.getUrl(streamInfo.trackId, streamInfo.md5origin, streamInfo.mediaVersion, this.quality);
}
this._request = https.get(this.url, {headers: {'Range': `bytes=${start}-`}}, (r) => { this._request = https.get(this.url, {headers: {'Range': `bytes=${start}-`}}, (r) => {
let outFile = fs.createWriteStream(tmp, {flags: 'a'});
let skip = false; let skip = false;
//Error //Error
if (r.statusCode >= 400) { if (r.statusCode >= 400) {
@ -274,11 +273,10 @@ class Download {
//Check if file exits //Check if file exits
fs.access(this.path, (err) => { fs.access(this.path, (err) => {
if (err) { if (err) {
//Pipe data to file
r.pipe(fs.createWriteStream(tmp, {flags: 'a'}));
} else { } else {
logger.warn('File already exists! Skipping...'); logger.warn('File already exists! Skipping...');
outFile.close();
skip = true; skip = true;
this._request.end(); this._request.end();
this.state = 3; this.state = 3;
@ -292,10 +290,14 @@ class Download {
r.on('end', () => { r.on('end', () => {
if (skip) return; if (skip) return;
if (this.downloaded != this.size) return; if (this.downloaded != this.size) return;
this._finished(tmp);
outFile.close(() => {
this._finished(tmp);
});
}); });
//Progress //Progress
r.on('data', (c) => { r.on('data', (c) => {
outFile.write(c);
this.downloaded += c.length; this.downloaded += c.length;
}); });
@ -335,7 +337,7 @@ class Download {
//Decrypt //Decrypt
//this.path += (this.quality == 9) ? '.flac' : '.mp3'; //this.path += (this.quality == 9) ? '.flac' : '.mp3';
decryptor.decryptFile(decryptor.getKey(this.track.id), tmp, `${tmp}.DEC`); decryptor.decryptFile(decryptor.getKey(this.track.id), tmp, `${tmp}.DEC`);
fs.promises.copyFile(`${tmp}.DEC`, this.path); await fs.promises.copyFile(`${tmp}.DEC`, this.path);
//Delete encrypted //Delete encrypted
await fs.promises.unlink(tmp); await fs.promises.unlink(tmp);
await fs.promises.unlink(`${tmp}.DEC`); await fs.promises.unlink(`${tmp}.DEC`);

View File

@ -351,6 +351,12 @@ app.get('/smarttracklist/:id', async (req, res) => {
let data = await deezer.callApi('smartTracklist.getSongs', { let data = await deezer.callApi('smartTracklist.getSongs', {
smartTracklist_id: id smartTracklist_id: id
}); });
//No more tracks
if (!data.results.data) {
logger.warn('No more STL tracks: ' + JSON.stringify(data.error));
return res.send([]);
}
let tracks = data.results.data.map((t) => new Track(t)); let tracks = data.results.data.map((t) => new Track(t));
return res.send(tracks); return res.send(tracks);
}); });

View File

@ -18,6 +18,6 @@ process.on('uncaughtException', (err) => {
}); });
process.on('unhandledRejection', (err) => { process.on('unhandledRejection', (err) => {
logger.error('Unhandled Rejection: ' + err + "\nStack: " + err.stack); logger.error('Unhandled Rejection: ' + err + "\nStack: " + err.stack);
}) });
module.exports = logger; module.exports = logger;

View File

@ -1,7 +1,7 @@
{ {
"name": "freezer", "name": "freezer",
"private": true, "private": true,
"version": "1.0.7", "version": "1.0.8",
"description": "", "description": "",
"scripts": { "scripts": {
"pack": "electron-builder --dir", "pack": "electron-builder --dir",