tidal-hifi/src/scripts/settings.js

97 lines
2.2 KiB
JavaScript
Raw Normal View History

const Store = require("electron-store");
const settings = require("./../constants/settings");
2019-11-03 18:52:15 +01:00
const path = require("path");
const { BrowserWindow } = require("electron");
let settingsWindow;
const store = new Store({
defaults: {
adBlock: false,
api: true,
apiSettings: {
port: 47836,
},
customCSS: "",
disableBackgroundThrottle: true,
disableHardwareMediaKeys: false,
enableCustomHotkeys: false,
enableDiscord: false,
flags: {
gpuRasterization: true,
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: {
"3.1.0": (migrationStore) => {
console.log("running migrations for 3.1.0");
migrationStore.set(
settings.flags.disableHardwareMediaKeys,
migrationStore.get("disableHardwareMediaKeys") ?? false
);
},
},
});
const settingsModule = {
store,
settings,
2019-11-03 18:52:15 +01:00
settingsWindow,
};
2020-10-04 11:52:08 +02:00
settingsModule.createSettingsWindow = function () {
2019-11-03 18:52:15 +01:00
settingsWindow = new BrowserWindow({
width: 700,
2019-11-03 18:52:15 +01:00
height: 600,
resizable: false,
2019-11-03 18:52:15 +01:00
show: false,
transparent: true,
2019-11-03 18:52:15 +01:00
frame: false,
title: "TIDAL Hi-Fi settings",
2019-11-03 18:52:15 +01:00
webPreferences: {
preload: path.join(__dirname, "../pages/settings/preload.js"),
plugins: true,
nodeIntegration: true,
},
});
settingsWindow.on("close", (event) => {
if (settingsWindow != null) {
event.preventDefault();
settingsWindow.hide();
}
});
settingsWindow.loadURL(`file://${__dirname}/../pages/settings/settings.html`);
settingsModule.settingsWindow = settingsWindow;
};
2020-10-04 11:52:08 +02:00
settingsModule.showSettingsWindow = function (tab = "general") {
settingsWindow.webContents.send("goToTab", tab);
2019-11-03 18:52:15 +01:00
// refresh data just before showing the window
settingsWindow.webContents.send("refreshData");
settingsWindow.show();
};
2020-10-04 11:52:08 +02:00
settingsModule.hideSettingsWindow = function () {
2019-11-03 18:52:15 +01:00
settingsWindow.hide();
};
2020-10-04 11:52:08 +02:00
settingsModule.closeSettingsWindow = function () {
2019-11-03 18:52:15 +01:00
settingsWindow = null;
};
module.exports = settingsModule;