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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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