2019-11-03 18:52:15 +01:00
|
|
|
let notifications;
|
|
|
|
let playBackControl;
|
|
|
|
let api;
|
|
|
|
let port;
|
|
|
|
let menuBar;
|
|
|
|
|
|
|
|
const { store, settings } = require("./../../scripts/settings");
|
|
|
|
const { ipcRenderer } = require("electron");
|
|
|
|
const globalEvents = require("./../../constants/globalEvents");
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sync the UI forms with the current settings
|
|
|
|
*/
|
|
|
|
function refreshSettings() {
|
|
|
|
notifications.checked = store.get(settings.notifications);
|
|
|
|
playBackControl.checked = store.get(settings.playBackControl);
|
|
|
|
api.checked = store.get(settings.api);
|
|
|
|
port.value = store.get(settings.apiSettings.port);
|
|
|
|
menuBar.checked = store.get(settings.menuBar);
|
2020-10-07 20:10:31 +02:00
|
|
|
trayIcon.checked = store.get(settings.trayIcon);
|
2020-11-29 10:55:01 +01:00
|
|
|
mpris.checked = store.get(settings.mpris);
|
2019-11-03 18:52:15 +01:00
|
|
|
}
|
|
|
|
|
2019-11-03 20:22:59 +01:00
|
|
|
/**
|
|
|
|
* Open an url in the default browsers
|
|
|
|
*/
|
2020-10-04 11:52:08 +02:00
|
|
|
window.openExternal = function (url) {
|
2019-11-03 20:22:59 +01:00
|
|
|
const { shell } = require("electron");
|
|
|
|
shell.openExternal(url);
|
|
|
|
};
|
|
|
|
|
2019-11-03 18:52:15 +01:00
|
|
|
/**
|
|
|
|
* hide the settings window
|
|
|
|
*/
|
2020-10-04 11:52:08 +02:00
|
|
|
window.hide = function () {
|
2019-11-03 18:52:15 +01:00
|
|
|
ipcRenderer.send(globalEvents.hideSettings);
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Restart tidal-hifi after changes
|
|
|
|
*/
|
2020-10-04 11:52:08 +02:00
|
|
|
window.restart = function () {
|
2019-11-03 18:52:15 +01:00
|
|
|
const remote = require("electron").remote;
|
|
|
|
remote.app.relaunch();
|
|
|
|
remote.app.exit(0);
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Bind UI components to functions after DOMContentLoaded
|
|
|
|
*/
|
|
|
|
window.addEventListener("DOMContentLoaded", () => {
|
|
|
|
function get(id) {
|
|
|
|
return document.getElementById(id);
|
|
|
|
}
|
|
|
|
|
|
|
|
function addInputListener(source, key) {
|
2020-10-04 11:52:08 +02:00
|
|
|
source.addEventListener("input", function (event, data) {
|
2019-11-03 18:52:15 +01:00
|
|
|
if (this.value === "on") {
|
|
|
|
store.set(key, source.checked);
|
|
|
|
} else {
|
|
|
|
store.set(key, this.value);
|
|
|
|
}
|
|
|
|
ipcRenderer.send(globalEvents.storeChanged);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
ipcRenderer.on("refreshData", () => {
|
|
|
|
refreshSettings();
|
|
|
|
});
|
|
|
|
|
2020-10-04 11:52:08 +02:00
|
|
|
ipcRenderer.on("goToTab", (_, tab) => {
|
2019-11-03 20:22:59 +01:00
|
|
|
document.getElementById(tab).click();
|
|
|
|
});
|
|
|
|
|
2019-11-03 18:52:15 +01:00
|
|
|
notifications = get("notifications");
|
|
|
|
playBackControl = get("playBackControl");
|
|
|
|
api = get("apiCheckbox");
|
|
|
|
port = get("port");
|
|
|
|
menuBar = get("menuBar");
|
2020-10-07 20:10:31 +02:00
|
|
|
trayIcon = get("trayIcon");
|
2020-11-29 10:55:01 +01:00
|
|
|
mpris = get("mprisCheckbox");
|
2019-11-03 18:52:15 +01:00
|
|
|
|
|
|
|
refreshSettings();
|
|
|
|
|
|
|
|
addInputListener(notifications, settings.notifications);
|
|
|
|
addInputListener(playBackControl, settings.playBackControl);
|
|
|
|
addInputListener(api, settings.api);
|
|
|
|
addInputListener(port, settings.apiSettings.port);
|
|
|
|
addInputListener(menuBar, settings.menuBar);
|
2020-10-07 20:10:31 +02:00
|
|
|
addInputListener(trayIcon, settings.trayIcon);
|
2020-11-29 10:55:01 +01:00
|
|
|
addInputListener(mpris, settings.mpris);
|
2019-11-03 18:52:15 +01:00
|
|
|
});
|