feat: you can now set updateFrequency in the settings window

This commit is contained in:
Rick van Lieshout 2023-04-27 11:35:00 +02:00
parent 3d2a9c3992
commit 4498e8a73e
5 changed files with 110 additions and 75 deletions

View File

@ -9,34 +9,35 @@
* windowBounds: { width: 800, height: 600 }, * windowBounds: { width: 800, height: 600 },
*/ */
const settings = { const settings = {
notifications: "notifications",
api: "api",
menuBar: "menuBar",
playBackControl: "playBackControl",
skipArtists: "skipArtists",
skippedArtists: "skippedArtists",
adBlock: "adBlock", adBlock: "adBlock",
disableBackgroundThrottle: "disableBackgroundThrottle", api: "api",
apiSettings: { apiSettings: {
root: "apiSettings", root: "apiSettings",
port: "apiSettings.port", port: "apiSettings.port",
}, },
singleInstance: "singleInstance", disableBackgroundThrottle: "disableBackgroundThrottle",
disableHardwareMediaKeys: "disableHardwareMediaKeys", disableHardwareMediaKeys: "disableHardwareMediaKeys",
enableCustomHotkeys: "enableCustomHotkeys",
enableDiscord: "enableDiscord",
flags: { flags: {
disableHardwareMediaKeys: "flags.disableHardwareMediaKeys", disableHardwareMediaKeys: "flags.disableHardwareMediaKeys",
gpuRasterization: "flags.gpuRasterization", gpuRasterization: "flags.gpuRasterization",
}, },
menuBar: "menuBar",
minimizeOnClose: "minimizeOnClose",
mpris: "mpris", mpris: "mpris",
enableCustomHotkeys: "enableCustomHotkeys", notifications: "notifications",
playBackControl: "playBackControl",
singleInstance: "singleInstance",
skipArtists: "skipArtists",
skippedArtists: "skippedArtists",
trayIcon: "trayIcon", trayIcon: "trayIcon",
enableDiscord: "enableDiscord", updateFrequency: "updateFrequency",
windowBounds: { windowBounds: {
root: "windowBounds", root: "windowBounds",
width: "windowBounds.width", width: "windowBounds.width",
height: "windowBounds.height", height: "windowBounds.height",
}, },
minimizeOnClose: "minimizeOnClose",
}; };
module.exports = settings; module.exports = settings;

View File

@ -1,20 +1,21 @@
let trayIcon, let adBlock,
minimizeOnClose, api,
mpris, disableBackgroundThrottle,
disableHardwareMediaKeys,
enableCustomHotkeys, enableCustomHotkeys,
enableDiscord, enableDiscord,
skipArtists, gpuRasterization,
menuBar,
minimizeOnClose,
mpris,
notifications, notifications,
playBackControl, playBackControl,
api,
port, port,
menuBar,
skippedArtists,
adBlock,
disableBackgroundThrottle,
singleInstance, singleInstance,
disableHardwareMediaKeys, skipArtists,
gpuRasterization; skippedArtists,
trayIcon,
updateFrequency;
const { store, settings } = require("./../../scripts/settings"); const { store, settings } = require("./../../scripts/settings");
const { ipcRenderer } = require("electron"); const { ipcRenderer } = require("electron");
@ -25,23 +26,24 @@ const { app } = remote;
* Sync the UI forms with the current settings * Sync the UI forms with the current settings
*/ */
function refreshSettings() { function refreshSettings() {
notifications.checked = store.get(settings.notifications); adBlock.checked = store.get(settings.adBlock);
playBackControl.checked = store.get(settings.playBackControl);
api.checked = store.get(settings.api); api.checked = store.get(settings.api);
port.value = store.get(settings.apiSettings.port); disableBackgroundThrottle.checked = store.get("disableBackgroundThrottle");
menuBar.checked = store.get(settings.menuBar); disableHardwareMediaKeys.checked = store.get(settings.flags.disableHardwareMediaKeys);
trayIcon.checked = store.get(settings.trayIcon);
mpris.checked = store.get(settings.mpris);
enableCustomHotkeys.checked = store.get(settings.enableCustomHotkeys); enableCustomHotkeys.checked = store.get(settings.enableCustomHotkeys);
enableDiscord.checked = store.get(settings.enableDiscord); enableDiscord.checked = store.get(settings.enableDiscord);
gpuRasterization.checked = store.get(settings.flags.gpuRasterization);
menuBar.checked = store.get(settings.menuBar);
minimizeOnClose.checked = store.get(settings.minimizeOnClose); minimizeOnClose.checked = store.get(settings.minimizeOnClose);
mpris.checked = store.get(settings.mpris);
notifications.checked = store.get(settings.notifications);
playBackControl.checked = store.get(settings.playBackControl);
port.value = store.get(settings.apiSettings.port);
singleInstance.checked = store.get(settings.singleInstance);
skipArtists.checked = store.get(settings.skipArtists); skipArtists.checked = store.get(settings.skipArtists);
skippedArtists.value = store.get(settings.skippedArtists).join("\n"); skippedArtists.value = store.get(settings.skippedArtists).join("\n");
adBlock.checked = store.get(settings.adBlock); trayIcon.checked = store.get(settings.trayIcon);
singleInstance.checked = store.get(settings.singleInstance); updateFrequency.value = store.get(settings.updateFrequency);
disableHardwareMediaKeys.checked = store.get(settings.flags.disableHardwareMediaKeys);
gpuRasterization.checked = store.get(settings.flags.gpuRasterization);
disableBackgroundThrottle.checked = store.get("disableBackgroundThrottle");
} }
/** /**
@ -109,41 +111,43 @@ window.addEventListener("DOMContentLoaded", () => {
document.getElementById(tab).click(); document.getElementById(tab).click();
}); });
notifications = get("notifications"); adBlock = get("adBlock");
playBackControl = get("playBackControl");
api = get("apiCheckbox"); api = get("apiCheckbox");
port = get("port"); disableBackgroundThrottle = get("disableBackgroundThrottle");
menuBar = get("menuBar"); disableHardwareMediaKeys = get("disableHardwareMediaKeys");
trayIcon = get("trayIcon");
minimizeOnClose = get("minimizeOnClose");
mpris = get("mprisCheckbox");
enableCustomHotkeys = get("enableCustomHotkeys"); enableCustomHotkeys = get("enableCustomHotkeys");
enableDiscord = get("enableDiscord"); enableDiscord = get("enableDiscord");
gpuRasterization = get("gpuRasterization");
menuBar = get("menuBar");
minimizeOnClose = get("minimizeOnClose");
mpris = get("mprisCheckbox");
notifications = get("notifications");
playBackControl = get("playBackControl");
port = get("port");
trayIcon = get("trayIcon");
skipArtists = get("skipArtists"); skipArtists = get("skipArtists");
skippedArtists = get("skippedArtists"); skippedArtists = get("skippedArtists");
adBlock = get("adBlock");
disableBackgroundThrottle = get("disableBackgroundThrottle");
singleInstance = get("singleInstance"); singleInstance = get("singleInstance");
disableHardwareMediaKeys = get("disableHardwareMediaKeys"); updateFrequency = get("updateFrequency");
gpuRasterization = get("gpuRasterization");
refreshSettings(); refreshSettings();
addInputListener(notifications, settings.notifications); addInputListener(adBlock, settings.adBlock);
addInputListener(playBackControl, settings.playBackControl);
addInputListener(api, settings.api); addInputListener(api, settings.api);
addInputListener(port, settings.apiSettings.port); addInputListener(disableBackgroundThrottle, settings.disableBackgroundThrottle);
addInputListener(menuBar, settings.menuBar); addInputListener(disableHardwareMediaKeys, settings.flags.disableHardwareMediaKeys);
addInputListener(trayIcon, settings.trayIcon);
addInputListener(mpris, settings.mpris);
addInputListener(enableCustomHotkeys, settings.enableCustomHotkeys); addInputListener(enableCustomHotkeys, settings.enableCustomHotkeys);
addInputListener(enableDiscord, settings.enableDiscord); addInputListener(enableDiscord, settings.enableDiscord);
addInputListener(gpuRasterization, settings.flags.gpuRasterization);
addInputListener(menuBar, settings.menuBar);
addInputListener(minimizeOnClose, settings.minimizeOnClose); addInputListener(minimizeOnClose, settings.minimizeOnClose);
addInputListener(mpris, settings.mpris);
addInputListener(notifications, settings.notifications);
addInputListener(playBackControl, settings.playBackControl);
addInputListener(port, settings.apiSettings.port);
addInputListener(skipArtists, settings.skipArtists); addInputListener(skipArtists, settings.skipArtists);
addTextAreaListener(skippedArtists, settings.skippedArtists); addTextAreaListener(skippedArtists, settings.skippedArtists);
addInputListener(adBlock, settings.adBlock);
addInputListener(disableBackgroundThrottle, settings.disableBackgroundThrottle);
addInputListener(singleInstance, settings.singleInstance); addInputListener(singleInstance, settings.singleInstance);
addInputListener(disableHardwareMediaKeys, settings.flags.disableHardwareMediaKeys); addInputListener(trayIcon, settings.trayIcon);
addInputListener(gpuRasterization, settings.flags.gpuRasterization); addInputListener(updateFrequency, settings.updateFrequency);
}); });

View File

@ -160,7 +160,7 @@
<div class="group__option"> <div class="group__option">
<div class="group__description"> <div class="group__description">
<label for="port">API port</label> <label for="port">API port</label>
<input id="port" type="text" class="text-input" name="port" /> <input id="port" type="number" class="text-input" name="port" />
</div> </div>
</div> </div>
<div class="group__option"> <div class="group__option">
@ -212,6 +212,22 @@
</section> </section>
<section id="advanced-section" class="tabs__section"> <section id="advanced-section" class="tabs__section">
<div class="group">
<p class="group__title">Settings</p>
<div class="group__option">
<div class="group__description">
<h4>Update frequency</h4>
<p>
The amount of time, in milliseconds, that tidal-hifi will refresh its playback info by scraping the
website.
The default of 500 seems to work in more cases but if you are fine with a bit more resource usage you
can decrease it as well.
</p>
<input id="updateFrequency" type="number" class="text-input" name="updateFrequency" />
</div>
</div>
</div>
<div class="group"> <div class="group">
<p class="group__title">Flags</p> <p class="group__title">Flags</p>
<div class="group__option"> <div class="group__option">

View File

@ -7,7 +7,7 @@ const { downloadFile } = require("./scripts/download");
const statuses = require("./constants/statuses"); const statuses = require("./constants/statuses");
const hotkeys = require("./scripts/hotkeys"); const hotkeys = require("./scripts/hotkeys");
const globalEvents = require("./constants/globalEvents"); const globalEvents = require("./constants/globalEvents");
const { skipArtists } = require("./constants/settings"); const { skipArtists, updateFrequency } = require("./constants/settings");
const notificationPath = `${app.getPath("userData")}/notification.jpg`; const notificationPath = `${app.getPath("userData")}/notification.jpg`;
const appName = "Tidal Hifi"; const appName = "Tidal Hifi";
let currentSong = ""; let currentSong = "";
@ -68,14 +68,13 @@ const elements = {
/** /**
* returns an array of all artists in the current song * returns an array of all artists in the current song
* @returns {Array} artists * @returns {Array} artists
*/ */
getArtistsArray: function () { getArtistsArray: function () {
const footer = this.get("footer"); const footer = this.get("footer");
if (footer) { if (footer) {
const artists = footer.querySelectorAll(this.artists); const artists = footer.querySelectorAll(this.artists);
if (artists) if (artists) return Array.from(artists).map((artist) => artist.textContent);
return Array.from(artists).map((artist) => artist.textContent);
} }
return []; return [];
}, },
@ -84,10 +83,9 @@ const elements = {
* unify the artists array into a string separated by commas * unify the artists array into a string separated by commas
* @param {Array} artistsArray * @param {Array} artistsArray
* @returns {String} artists * @returns {String} artists
*/ */
getArtistsString: function (artistsArray) { getArtistsString: function (artistsArray) {
if (artistsArray.length > 0) if (artistsArray.length > 0) return artistsArray.join(", ");
return artistsArray.join(", ");
return "unknown artist(s)"; return "unknown artist(s)";
}, },
@ -145,6 +143,21 @@ const elements = {
}, },
}; };
/**
* Get the update frequency from the store
* make sure it returns a number, if not use the default
*/
function getUpdateFrequency() {
const storeValue = store.get(updateFrequency);
const defaultValue = 500;
if (!isNaN(storeValue)) {
return storeValue;
} else {
return defaultValue;
}
}
/** /**
* Play or pause the current song * Play or pause the current song
*/ */
@ -416,7 +429,7 @@ setInterval(function () {
} }
} }
} }
}, 100); }, getUpdateFrequency());
if (process.platform === "linux" && store.get(settings.mpris)) { if (process.platform === "linux" && store.get(settings.mpris)) {
try { try {

View File

@ -7,29 +7,30 @@ let settingsWindow;
const store = new Store({ const store = new Store({
defaults: { defaults: {
notifications: true,
api: true,
playBackControl: true,
skipArtists: false,
skippedArtists: [""],
adBlock: false, adBlock: false,
disableBackgroundThrottle: true, api: true,
menuBar: true,
apiSettings: { apiSettings: {
port: 47836, port: 47836,
}, },
singleInstance: true, disableBackgroundThrottle: true,
disableHardwareMediaKeys: false, disableHardwareMediaKeys: false,
trayIcon: true,
minimizeOnClose: false,
mpris: false,
enableCustomHotkeys: false, enableCustomHotkeys: false,
enableDiscord: false, enableDiscord: false,
windowBounds: { width: 800, height: 600 },
flags: { flags: {
gpuRasterization: true, gpuRasterization: true,
disableHardwareMediaKeys: false, disableHardwareMediaKeys: false,
}, },
menuBar: true,
minimizeOnClose: false,
mpris: false,
notifications: true,
playBackControl: true,
singleInstance: true,
skipArtists: false,
skippedArtists: [""],
trayIcon: true,
updateFrequency: 500,
windowBounds: { width: 800, height: 600 },
}, },
migrations: { migrations: {
"3.1.0": (migrationStore) => { "3.1.0": (migrationStore) => {