tidal-hifi/src/scripts/settings.js

71 lines
1.6 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: {
notifications: true,
api: true,
2019-11-03 18:52:15 +01:00
playBackControl: true,
menuBar: true,
apiSettings: {
port: 47836,
},
2020-10-04 11:52:08 +02:00
mpris: false,
windowBounds: { width: 800, height: 600 },
},
});
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: 500,
height: 600,
show: false,
frame: false,
title: "Tidal-hifi - settings",
webPreferences: {
affinity: "window",
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;