now using electron-store to save settings between launches

This commit is contained in:
Rick van Lieshout 2019-11-03 11:18:01 +01:00
parent 3d334cd19e
commit 6ef4a0854d
8 changed files with 195 additions and 31 deletions

View File

@ -1,17 +1,21 @@
<img src = "./build/icon.png" height="50" style="float:right; margin-top: 29px;" /> <h1>
# Tidal-hifi Tidal-hifi
<img src = "./build/icon.png" height="30" align="right" />
</h1>
The web version of [listen.tidal.com](listen.tidal.com) running in electron with hifi support thanks to widevine. The web version of [listen.tidal.com](listen.tidal.com) running in electron with hifi support thanks to widevine.
![tidal-hifi preview](./docs/preview.png) ![tidal-hifi preview](./docs/preview.png)
## Table of contents
<!-- toc --> <!-- toc -->
- [Installation](#installation) - [Installation](#installation)
- [Using releases](#using-releases) - [Using releases](#using-releases)
- [Using source](#using-source) - [Using source](#using-source)
- [Why](#why)
- [Integrations](#integrations) - [Integrations](#integrations)
- [Why](#why)
- [Why not extend existing projects?](#why-not-extend-existing-projects) - [Why not extend existing projects?](#why-not-extend-existing-projects)
- [Special thanks to..](#special-thanks-to) - [Special thanks to..](#special-thanks-to)
@ -32,16 +36,16 @@ To install and work with the code on this project follow these steps:
- npm install - npm install
- npm start - npm start
## Integrations
- [i3 blocks config](https://github.com/Mastermindzh/dotfiles/commit/9714b2fa1d670108ce811d5511fd3b7a43180647) - My dotfiles where I use this app to fetch currently playing music (direct commit)
## Why ## Why
I moved from Spotify over to Tidal and found Linux support to be lacking. I moved from Spotify over to Tidal and found Linux support to be lacking.
When I started this project there weren't any Linux apps that offered Tidal's "hifi" options nor any scripts to control it. When I started this project there weren't any Linux apps that offered Tidal's "hifi" options nor any scripts to control it.
## Integrations
- [i3 blocks config](https://github.com/Mastermindzh/dotfiles/commit/9714b2fa1d670108ce811d5511fd3b7a43180647) - My dotfiles where I use this app to fetch currently playing music (direct commit)
## Why not extend existing projects? ## Why not extend existing projects?
Whilst there are a handful of projects attempting to run Tidal on Electron they are all unappealing to me because of various reasons: Whilst there are a handful of projects attempting to run Tidal on Electron they are all unappealing to me because of various reasons:
@ -49,7 +53,7 @@ Whilst there are a handful of projects attempting to run Tidal on Electron they
- Lack of a maintainers/developers. (no hotfixes, no issues being handled etc) - Lack of a maintainers/developers. (no hotfixes, no issues being handled etc)
- Most are simple web wrappers, not my cup of tea. - Most are simple web wrappers, not my cup of tea.
- Some are DE oriented. I want this to work on WM's too. - Some are DE oriented. I want this to work on WM's too.
- None have widevine working at the moment and that is really the hardest part.. - None have widevine working at the moment
Sometimes it's just easier to start over, cover my own needs and then making it available to the public :) Sometimes it's just easier to start over, cover my own needs and then making it available to the public :)

144
package-lock.json generated
View File

@ -732,6 +732,67 @@
} }
} }
}, },
"conf": {
"version": "6.2.0",
"resolved": "https://registry.npmjs.org/conf/-/conf-6.2.0.tgz",
"integrity": "sha512-fvl40R6YemHrFsNiyP7TD0tzOe3pQD2dfT2s20WvCaq57A1oV+RImbhn2Y4sQGDz1lB0wNSb7dPcPIvQB69YNA==",
"requires": {
"ajv": "^6.10.2",
"debounce-fn": "^3.0.1",
"dot-prop": "^5.0.0",
"env-paths": "^2.2.0",
"json-schema-typed": "^7.0.1",
"make-dir": "^3.0.0",
"onetime": "^5.1.0",
"pkg-up": "^3.0.1",
"semver": "^6.2.0",
"write-file-atomic": "^3.0.0"
},
"dependencies": {
"dot-prop": {
"version": "5.2.0",
"resolved": "https://registry.npmjs.org/dot-prop/-/dot-prop-5.2.0.tgz",
"integrity": "sha512-uEUyaDKoSQ1M4Oq8l45hSE26SnTxL6snNnqvK/VWx5wJhmff5z0FUVJDKDanor/6w3kzE3i7XZOk+7wC0EXr1A==",
"requires": {
"is-obj": "^2.0.0"
}
},
"env-paths": {
"version": "2.2.0",
"resolved": "https://registry.npmjs.org/env-paths/-/env-paths-2.2.0.tgz",
"integrity": "sha512-6u0VYSCo/OW6IoD5WCLLy9JUGARbamfSavcNXry/eu8aHVFei6CD3Sw+VGX5alea1i9pgPHW0mbu6Xj0uBh7gA=="
},
"is-obj": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/is-obj/-/is-obj-2.0.0.tgz",
"integrity": "sha512-drqDG3cbczxxEJRoOXcOjtdp1J/lyp1mNn0xaznRs8+muBhgQcrnbspox5X5fOw0HnMnbfDzvnEMEtqDEJEo8w=="
},
"make-dir": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/make-dir/-/make-dir-3.0.0.tgz",
"integrity": "sha512-grNJDhb8b1Jm1qeqW5R/O63wUo4UXo2v2HMic6YT9i/HBlF93S8jkMgH7yugvY9ABDShH4VZMn8I+U8+fCNegw==",
"requires": {
"semver": "^6.0.0"
}
},
"semver": {
"version": "6.3.0",
"resolved": "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz",
"integrity": "sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw=="
},
"write-file-atomic": {
"version": "3.0.1",
"resolved": "https://registry.npmjs.org/write-file-atomic/-/write-file-atomic-3.0.1.tgz",
"integrity": "sha512-JPStrIyyVJ6oCSz/691fAjFtefZ6q+fP6tm+OS4Qw6o+TGQxNp1ziY2PgS+X/m0V8OWhZiO/m4xSj+Pr4RrZvw==",
"requires": {
"imurmurhash": "^0.1.4",
"is-typedarray": "^1.0.0",
"signal-exit": "^3.0.2",
"typedarray-to-buffer": "^3.1.5"
}
}
}
},
"configstore": { "configstore": {
"version": "4.0.0", "version": "4.0.0",
"resolved": "https://registry.npmjs.org/configstore/-/configstore-4.0.0.tgz", "resolved": "https://registry.npmjs.org/configstore/-/configstore-4.0.0.tgz",
@ -815,6 +876,14 @@
"assert-plus": "^1.0.0" "assert-plus": "^1.0.0"
} }
}, },
"debounce-fn": {
"version": "3.0.1",
"resolved": "https://registry.npmjs.org/debounce-fn/-/debounce-fn-3.0.1.tgz",
"integrity": "sha512-aBoJh5AhpqlRoHZjHmOzZlRx+wz2xVwGL9rjs+Kj0EWUrL4/h4K7OD176thl2Tdoqui/AaA4xhHrNArGLAaI3Q==",
"requires": {
"mimic-fn": "^2.1.0"
}
},
"debug": { "debug": {
"version": "3.2.6", "version": "3.2.6",
"resolved": "https://registry.npmjs.org/debug/-/debug-3.2.6.tgz", "resolved": "https://registry.npmjs.org/debug/-/debug-3.2.6.tgz",
@ -1039,6 +1108,22 @@
"chokidar": "^3.0.2" "chokidar": "^3.0.2"
} }
}, },
"electron-store": {
"version": "5.1.0",
"resolved": "https://registry.npmjs.org/electron-store/-/electron-store-5.1.0.tgz",
"integrity": "sha512-uhAF/4+zDb+y0hWqlBirEPEAR4ciCZDp4fRWGFNV62bG+ArdQPpXk7jS0MEVj3CfcG5V7hx7Dpq5oD+1j6GD8Q==",
"requires": {
"conf": "^6.2.0",
"type-fest": "^0.7.1"
},
"dependencies": {
"type-fest": {
"version": "0.7.1",
"resolved": "https://registry.npmjs.org/type-fest/-/type-fest-0.7.1.tgz",
"integrity": "sha512-Ne2YiiGN8bmrmJJEuTWTLJR32nh/JdL1+PSicowtNb0WFpn59GK8/lfD61bVtzguz7b3PBt74nxpv/Pw5po5Rg=="
}
}
},
"emoji-regex": { "emoji-regex": {
"version": "7.0.3", "version": "7.0.3",
"resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-7.0.3.tgz", "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-7.0.3.tgz",
@ -1508,8 +1593,7 @@
"imurmurhash": { "imurmurhash": {
"version": "0.1.4", "version": "0.1.4",
"resolved": "https://registry.npmjs.org/imurmurhash/-/imurmurhash-0.1.4.tgz", "resolved": "https://registry.npmjs.org/imurmurhash/-/imurmurhash-0.1.4.tgz",
"integrity": "sha1-khi5srkoojixPcT7a21XbyMUU+o=", "integrity": "sha1-khi5srkoojixPcT7a21XbyMUU+o="
"dev": true
}, },
"indent-string": { "indent-string": {
"version": "2.1.0", "version": "2.1.0",
@ -1712,6 +1796,11 @@
"resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-0.4.1.tgz", "resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-0.4.1.tgz",
"integrity": "sha512-xbbCH5dCYU5T8LcEhhuh7HJ88HXuW3qsI3Y0zOZFKfZEHcpWiHU/Jxzk629Brsab/mMiHQti9wMP+845RPe3Vg==" "integrity": "sha512-xbbCH5dCYU5T8LcEhhuh7HJ88HXuW3qsI3Y0zOZFKfZEHcpWiHU/Jxzk629Brsab/mMiHQti9wMP+845RPe3Vg=="
}, },
"json-schema-typed": {
"version": "7.0.2",
"resolved": "https://registry.npmjs.org/json-schema-typed/-/json-schema-typed-7.0.2.tgz",
"integrity": "sha512-40FRIcBSz4y0Ego3gMpbkhtIgebpxKRgW/7i1FfDNL4/xEPQKBM12tKSiCZFNQvad5K4IS3I5Sc8cxza/KSwog=="
},
"json-stringify-safe": { "json-stringify-safe": {
"version": "5.0.1", "version": "5.0.1",
"resolved": "https://registry.npmjs.org/json-stringify-safe/-/json-stringify-safe-5.0.1.tgz", "resolved": "https://registry.npmjs.org/json-stringify-safe/-/json-stringify-safe-5.0.1.tgz",
@ -1787,7 +1876,6 @@
"version": "3.0.0", "version": "3.0.0",
"resolved": "https://registry.npmjs.org/locate-path/-/locate-path-3.0.0.tgz", "resolved": "https://registry.npmjs.org/locate-path/-/locate-path-3.0.0.tgz",
"integrity": "sha512-7AO748wWnIhNqAuaty2ZWHkQHRSNfPVIsPIfwEOWO22AmaoVrWavlOcMR5nzTLNYvp36X220/maaRsrec1G65A==", "integrity": "sha512-7AO748wWnIhNqAuaty2ZWHkQHRSNfPVIsPIfwEOWO22AmaoVrWavlOcMR5nzTLNYvp36X220/maaRsrec1G65A==",
"dev": true,
"requires": { "requires": {
"p-locate": "^3.0.0", "p-locate": "^3.0.0",
"path-exists": "^3.0.0" "path-exists": "^3.0.0"
@ -1894,6 +1982,11 @@
"mime-db": "1.40.0" "mime-db": "1.40.0"
} }
}, },
"mimic-fn": {
"version": "2.1.0",
"resolved": "https://registry.npmjs.org/mimic-fn/-/mimic-fn-2.1.0.tgz",
"integrity": "sha512-OqbOk5oEQeAZ8WXWydlu9HJjz9WVdEIvamMCcXmuqUYjTknH/sqsWvhQ3vgwKFRR1HpjvNBKQ37nbJgYzGqGcg=="
},
"mimic-response": { "mimic-response": {
"version": "1.0.1", "version": "1.0.1",
"resolved": "https://registry.npmjs.org/mimic-response/-/mimic-response-1.0.1.tgz", "resolved": "https://registry.npmjs.org/mimic-response/-/mimic-response-1.0.1.tgz",
@ -2067,6 +2160,14 @@
"wrappy": "1" "wrappy": "1"
} }
}, },
"onetime": {
"version": "5.1.0",
"resolved": "https://registry.npmjs.org/onetime/-/onetime-5.1.0.tgz",
"integrity": "sha512-5NcSkPHhwTVFIQN+TUqXoS5+dlElHXdpAWu9I0HP20YOtIi+aZ0Ct82jdlILDxjLEAWwvm+qj1m6aEtsDVmm6Q==",
"requires": {
"mimic-fn": "^2.1.0"
}
},
"p-cancelable": { "p-cancelable": {
"version": "1.1.0", "version": "1.1.0",
"resolved": "https://registry.npmjs.org/p-cancelable/-/p-cancelable-1.1.0.tgz", "resolved": "https://registry.npmjs.org/p-cancelable/-/p-cancelable-1.1.0.tgz",
@ -2083,7 +2184,6 @@
"version": "2.2.1", "version": "2.2.1",
"resolved": "https://registry.npmjs.org/p-limit/-/p-limit-2.2.1.tgz", "resolved": "https://registry.npmjs.org/p-limit/-/p-limit-2.2.1.tgz",
"integrity": "sha512-85Tk+90UCVWvbDavCLKPOLC9vvY8OwEX/RtKF+/1OADJMVlFfEHOiMTPVyxg7mk/dKa+ipdHm0OUkTvCpMTuwg==", "integrity": "sha512-85Tk+90UCVWvbDavCLKPOLC9vvY8OwEX/RtKF+/1OADJMVlFfEHOiMTPVyxg7mk/dKa+ipdHm0OUkTvCpMTuwg==",
"dev": true,
"requires": { "requires": {
"p-try": "^2.0.0" "p-try": "^2.0.0"
} }
@ -2092,7 +2192,6 @@
"version": "3.0.0", "version": "3.0.0",
"resolved": "https://registry.npmjs.org/p-locate/-/p-locate-3.0.0.tgz", "resolved": "https://registry.npmjs.org/p-locate/-/p-locate-3.0.0.tgz",
"integrity": "sha512-x+12w/To+4GFfgJhBEpiDcLozRJGegY+Ei7/z0tSLkMmxGZNybVMSfWj9aJn8Z5Fc7dBUNJOOVgPv2H7IwulSQ==", "integrity": "sha512-x+12w/To+4GFfgJhBEpiDcLozRJGegY+Ei7/z0tSLkMmxGZNybVMSfWj9aJn8Z5Fc7dBUNJOOVgPv2H7IwulSQ==",
"dev": true,
"requires": { "requires": {
"p-limit": "^2.0.0" "p-limit": "^2.0.0"
} }
@ -2100,8 +2199,7 @@
"p-try": { "p-try": {
"version": "2.2.0", "version": "2.2.0",
"resolved": "https://registry.npmjs.org/p-try/-/p-try-2.2.0.tgz", "resolved": "https://registry.npmjs.org/p-try/-/p-try-2.2.0.tgz",
"integrity": "sha512-R4nPAVTAU0B9D35/Gk3uJf/7XYbQcyohSKdvAxIRSNghFl4e71hVoGnBNQz9cWaXxO2I10KTC+3jMdvvoKw6dQ==", "integrity": "sha512-R4nPAVTAU0B9D35/Gk3uJf/7XYbQcyohSKdvAxIRSNghFl4e71hVoGnBNQz9cWaXxO2I10KTC+3jMdvvoKw6dQ=="
"dev": true
}, },
"package-json": { "package-json": {
"version": "6.5.0", "version": "6.5.0",
@ -2140,8 +2238,7 @@
"path-exists": { "path-exists": {
"version": "3.0.0", "version": "3.0.0",
"resolved": "https://registry.npmjs.org/path-exists/-/path-exists-3.0.0.tgz", "resolved": "https://registry.npmjs.org/path-exists/-/path-exists-3.0.0.tgz",
"integrity": "sha1-zg6+ql94yxiSXqfYENe1mwEP1RU=", "integrity": "sha1-zg6+ql94yxiSXqfYENe1mwEP1RU="
"dev": true
}, },
"path-is-inside": { "path-is-inside": {
"version": "1.0.2", "version": "1.0.2",
@ -2215,6 +2312,24 @@
"pinkie": "^2.0.0" "pinkie": "^2.0.0"
} }
}, },
"pkg-up": {
"version": "3.1.0",
"resolved": "https://registry.npmjs.org/pkg-up/-/pkg-up-3.1.0.tgz",
"integrity": "sha512-nDywThFk1i4BQK4twPQ6TA4RT8bDY96yeuCVBWL3ePARCiEKDRSrNGbFIgUJpLp+XeIR65v8ra7WuJOFUBtkMA==",
"requires": {
"find-up": "^3.0.0"
},
"dependencies": {
"find-up": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/find-up/-/find-up-3.0.0.tgz",
"integrity": "sha512-1yD6RmLI1XBfxugvORwlck6f75tYL+iR0jqwsOrOxMZyGYqUuDhJ0l4AXdO1iX/FTs9cBAMEk1gWSEx1kSbylg==",
"requires": {
"locate-path": "^3.0.0"
}
}
}
},
"prepend-http": { "prepend-http": {
"version": "2.0.0", "version": "2.0.0",
"resolved": "https://registry.npmjs.org/prepend-http/-/prepend-http-2.0.0.tgz", "resolved": "https://registry.npmjs.org/prepend-http/-/prepend-http-2.0.0.tgz",
@ -2627,8 +2742,7 @@
"signal-exit": { "signal-exit": {
"version": "3.0.2", "version": "3.0.2",
"resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-3.0.2.tgz", "resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-3.0.2.tgz",
"integrity": "sha1-tf3AjxKH6hF4Yo5BXiUTK3NkbG0=", "integrity": "sha1-tf3AjxKH6hF4Yo5BXiUTK3NkbG0="
"dev": true
}, },
"single-line-log": { "single-line-log": {
"version": "1.1.2", "version": "1.1.2",
@ -2950,6 +3064,14 @@
"integrity": "sha1-hnrHTjhkGHsdPUfZlqeOxciDB3c=", "integrity": "sha1-hnrHTjhkGHsdPUfZlqeOxciDB3c=",
"dev": true "dev": true
}, },
"typedarray-to-buffer": {
"version": "3.1.5",
"resolved": "https://registry.npmjs.org/typedarray-to-buffer/-/typedarray-to-buffer-3.1.5.tgz",
"integrity": "sha512-zdu8XMNEDepKKR+XYOXAVPtWui0ly0NtohUscw+UmaHiAWT8hrV1rr//H6V+0DvJ3OQ19S979M0laLfX8rm82Q==",
"requires": {
"is-typedarray": "^1.0.0"
}
},
"unique-string": { "unique-string": {
"version": "1.0.0", "version": "1.0.0",
"resolved": "https://registry.npmjs.org/unique-string/-/unique-string-1.0.0.tgz", "resolved": "https://registry.npmjs.org/unique-string/-/unique-string-1.0.0.tgz",

View File

@ -18,6 +18,7 @@
"author": "Rick van Lieshout <info@rickvanlieshout.com> (http://rickvanlieshout.com)", "author": "Rick van Lieshout <info@rickvanlieshout.com> (http://rickvanlieshout.com)",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"electron-store": "^5.1.0",
"express": "^4.17.1", "express": "^4.17.1",
"hotkeys-js": "^3.7.1", "hotkeys-js": "^3.7.1",
"node-notifier": "^6.0.0", "node-notifier": "^6.0.0",

25
src/constants/settings.js Normal file
View File

@ -0,0 +1,25 @@
/**
* Object to type my settings file:
*
* notifications: true,
* api: true,
* apiSettings: {
* port: 47836,
* },
* windowBounds: { width: 800, height: 600 },
*/
const settings = {
notifications: "notifications",
api: "api",
apiSettings: {
root: "apiSettings",
port: "apiSettings.port",
},
windowBounds: {
root: "windowBounds",
width: "windowBounds.width",
height: "windowBounds.height",
},
};
module.exports = settings;

View File

@ -1,5 +1,5 @@
const { app, BrowserWindow, globalShortcut, ipcMain } = require("electron"); const { app, BrowserWindow, globalShortcut, ipcMain } = require("electron");
const { settings } = require("./scripts/settings"); const { settings, store } = require("./scripts/settings");
const { addTray, refreshTray } = require("./scripts/tray"); const { addTray, refreshTray } = require("./scripts/tray");
const path = require("path"); const path = require("path");
@ -49,6 +49,11 @@ function createWindow(options = {}) {
mainWindow.on("closed", function() { mainWindow.on("closed", function() {
mainWindow = null; mainWindow = null;
}); });
mainWindow.on("resize", () => {
let { width, height } = mainWindow.getBounds();
store.set(settings.windowBounds.root, { width, height });
});
} }
function addGlobalShortcuts() { function addGlobalShortcuts() {
@ -67,7 +72,7 @@ app.on("ready", () => {
addGlobalShortcuts(); addGlobalShortcuts();
addTray({ icon }); addTray({ icon });
refreshTray(); refreshTray();
settings.api && expressModule.run(mainWindow); store.get(settings.api) && expressModule.run(mainWindow);
}); });
app.on("activate", function() { app.on("activate", function() {

View File

@ -1,6 +1,6 @@
const { setTitle, getTitle } = require("./scripts/window-functions"); const { setTitle, getTitle } = require("./scripts/window-functions");
const { dialog } = require("electron").remote; const { dialog } = require("electron").remote;
const { settings } = require("./scripts/settings"); const { store, settings } = require("./scripts/settings");
const { ipcRenderer } = require("electron"); const { ipcRenderer } = require("electron");
const { app } = require("electron").remote; const { app } = require("electron").remote;
const { downloadFile } = require("./scripts/download"); const { downloadFile } = require("./scripts/download");
@ -260,7 +260,7 @@ setInterval(function() {
}).then( }).then(
() => { () => {
ipcRenderer.send("update-info", options); ipcRenderer.send("update-info", options);
settings.notifications && notifier.notify(options); store.get(settings.notifications) && notifier.notify(options);
}, },
() => {} () => {}
); );

View File

@ -1,6 +1,6 @@
const express = require("express"); const express = require("express");
const { mediaInfo } = require("./mediaInfo"); const { mediaInfo } = require("./mediaInfo");
const settingsModule = require("./settings"); const { store, settings } = require("./settings");
const globalEvents = require("./../constants/globalEvents"); const globalEvents = require("./../constants/globalEvents");
const statuses = require("./../constants/statuses"); const statuses = require("./../constants/statuses");
@ -47,7 +47,7 @@ expressModule.run = function(mainWindow) {
}); });
}); });
expressApp.listen(settingsModule.settings.apiSettings.port, () => {}); expressApp.listen(store.get(settings.apiSettings.port), () => {});
}; };
module.exports = expressModule; module.exports = expressModule;

View File

@ -1,12 +1,19 @@
const settings = { const Store = require("electron-store");
notifications: true, const settings = require("./../constants/settings");
api: true,
apiSettings: { const store = new Store({
port: 47836, defaults: {
notifications: true,
api: true,
apiSettings: {
port: 47836,
},
windowBounds: { width: 800, height: 600 },
}, },
}; });
const settingsModule = { const settingsModule = {
store,
settings, settings,
}; };