Files
2026-10-11 07:55:36 -07:00

109 lines
3.8 KiB
JavaScript
Executable File

const fs = require('fs');
const path = require('path');
const { app } = require('electron');
const settingsPath = path.join(app.getPath('userData'), 'settings.json');
const defaults = {
notificationsEnabled: true,
macNotificationsAsked: false,
notificationTypes: {
nowPlaying: true,
paused: true,
liked: true,
unliked: true,
verificationRequired: true,
torStarted: true,
torStopped: true,
torCrashed: true,
},
torEnabled: false,
hotkeys: {
playpause: 'MediaPlayPause',
next: 'MediaNextTrack',
previous: 'MediaPreviousTrack',
like: 'F23',
},
discordRpc: {
enabled: false,
},
lastfm: {
enabled: false,
apiKey: '',
apiSecret: '',
sessionKey: '',
username: '',
},
tuneshine: {
enabled: false,
devices: [], // [{ url, name, enabled }]
},
streamDeck: {
autoInstall: true, // copy the plugin into Elgato's folder on launch
},
// Radio / autoplay "vibe" tuning — how tightly stations stay on the seed's vibe.
// Weights read by the renderer's vibeScore/filterByVibe; edited in Settings → Radio.
radioVibe: {
genreExact: 3, // points when the candidate's genre == the seed's
genrePartial: 2, // points when one genre string contains the other
tag: 1, // points per shared tag
title: 1, // points per shared meaningful title word
artist: 1, // bonus when same artist AND already on-vibe
keepThreshold: 1, // minimum score for a track to be kept
minTracks: 16, // floor before the dominant-genre fallback tops up
},
};
let current = JSON.parse(JSON.stringify(defaults));
function loadSettings() {
try {
if (fs.existsSync(settingsPath)) {
const data = JSON.parse(fs.readFileSync(settingsPath, 'utf8'));
current = {
...defaults,
...data,
hotkeys: { ...defaults.hotkeys, ...(data.hotkeys || {}) },
discordRpc: { ...defaults.discordRpc, ...(data.discordRpc || {}) },
lastfm: { ...defaults.lastfm, ...(data.lastfm || {}) },
tuneshine: { ...defaults.tuneshine, ...(data.tuneshine || {}) },
radioVibe: { ...defaults.radioVibe, ...(data.radioVibe || {}) },
notificationTypes: { ...defaults.notificationTypes, ...(data.notificationTypes || {}) },
};
console.log('[settings] Loaded from disk:', settingsPath);
console.log('[settings] Active settings:', JSON.stringify(current, null, 2));
} else {
console.log('[settings] No settings file found, using defaults.');
}
} catch (err) {
console.error('[settings] Error loading settings:', err);
}
return current;
}
function saveSettings(updates) {
console.log('[settings] Saving updates:', JSON.stringify(updates));
current = {
...current,
...updates,
hotkeys: { ...current.hotkeys, ...(updates.hotkeys || {}) },
discordRpc: { ...current.discordRpc, ...(updates.discordRpc || {}) },
lastfm: { ...current.lastfm, ...(updates.lastfm || {}) },
tuneshine: { ...current.tuneshine, ...(updates.tuneshine || {}) },
radioVibe: { ...current.radioVibe, ...(updates.radioVibe || {}) },
notificationTypes: { ...current.notificationTypes, ...(updates.notificationTypes || {}) },
};
try {
fs.writeFileSync(settingsPath, JSON.stringify(current, null, 2), 'utf8');
console.log('[settings] Saved to disk successfully.');
} catch (err) {
console.error('[settings] Error saving settings:', err);
}
return current;
}
function getSettings() {
return current;
}
module.exports = { loadSettings, saveSettings, getSettings };