tidal-hifi/src/pages/settings/preload.js

93 lines
2.3 KiB
JavaScript
Raw Normal View History

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);
trayIcon.checked = store.get(settings.trayIcon);
// mpris.checked = store.get(settings.mpris);
2019-11-03 18:52:15 +01:00
}
/**
* Open an url in the default browsers
*/
2020-10-04 11:52:08 +02:00
window.openExternal = function (url) {
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) => {
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");
trayIcon = get("trayIcon");
// 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);
addInputListener(trayIcon, settings.trayIcon);
// addInputListener(mpris, settings.mpris);
2019-11-03 18:52:15 +01:00
});