diff --git a/src/backend/app-management/electron/events/when-ready.js b/src/backend/app-management/electron/events/when-ready.js index e7873e59f..0d4e1a5b7 100644 --- a/src/backend/app-management/electron/events/when-ready.js +++ b/src/backend/app-management/electron/events/when-ready.js @@ -176,8 +176,8 @@ exports.whenReady = async () => { builtinGameLoader.loadGames(); windowManagement.updateSplashScreenStatus("Loading custom variables..."); - const {settings} = require("../../../common/settings-access"); - if (settings.getPersistCustomVariables()) { + const { SettingsManager } = require("../../../common/settings-manager"); + if (SettingsManager.getSetting("PersistCustomVariables")) { const customVariableManager = require("../../../common/custom-variable-manager"); customVariableManager.loadVariablesFromFile(); } diff --git a/src/backend/app-management/electron/events/windows-all-closed.js b/src/backend/app-management/electron/events/windows-all-closed.js index 154e7b96b..1a962024e 100644 --- a/src/backend/app-management/electron/events/windows-all-closed.js +++ b/src/backend/app-management/electron/events/windows-all-closed.js @@ -7,7 +7,7 @@ exports.windowsAllClosed = async () => { const logger = require("../../../logwrapper"); logger.debug("All windows closed triggered"); - const { settings } = require("../../../common/settings-access"); + const { SettingsManager } = require("../../../common/settings-manager"); const backupManager = require("../../../backup-manager"); // Stop all scheduled tasks @@ -27,7 +27,7 @@ exports.windowsAllClosed = async () => { chatModerationManager.stopService(); // Persist custom variables - if (settings.getPersistCustomVariables()) { + if (SettingsManager.getSetting("PersistCustomVariables")) { const customVariableManager = require("../../../common/custom-variable-manager"); customVariableManager.persistVariablesToFile(); } @@ -36,7 +36,7 @@ exports.windowsAllClosed = async () => { const viewerOnlineStatusManager = require("../../../viewers/viewer-online-status-manager"); await viewerOnlineStatusManager.setAllViewersOffline(); - if (settings.backupOnExit()) { + if (SettingsManager.getSetting("BackupOnExit")) { // Make a backup await backupManager.startBackup(false, app.quit); } else { diff --git a/src/backend/app-management/electron/tray-creation.js b/src/backend/app-management/electron/tray-creation.js index 2a2e4db62..f308351c8 100644 --- a/src/backend/app-management/electron/tray-creation.js +++ b/src/backend/app-management/electron/tray-creation.js @@ -6,7 +6,7 @@ const electron = require("electron"); const { Menu, Tray, app, nativeImage } = electron; const frontendCommunicator = require('../../common/frontend-communicator.js'); -const { settings } = require("../../common/settings-access"); +const { SettingsManager } = require("../../common/settings-manager"); let mainTray; let minimizedToTray = false; @@ -62,7 +62,7 @@ module.exports = function createTray(mainWindow) { }); mainWindow.on('minimize', () => { - if (settings.getMinimizeToTray() && minimizedToTray !== true) { + if (SettingsManager.getSetting("MinimizeToTray") && minimizedToTray !== true) { mainWindow.hide(); minimizedToTray = true; } diff --git a/src/backend/app-management/electron/window-management.js b/src/backend/app-management/electron/window-management.js index 76b4b2136..17df2f822 100644 --- a/src/backend/app-management/electron/window-management.js +++ b/src/backend/app-management/electron/window-management.js @@ -11,7 +11,7 @@ const logger = require("../../logwrapper"); const { setupTitlebar, attachTitlebarToWindow } = require("custom-electron-titlebar/main"); const screenHelpers = require("./screen-helpers"); const frontendCommunicator = require("../../common/frontend-communicator"); -const { settings } = require("../../common/settings-access"); +const { SettingsManager } = require("../../common/settings-manager"); const argv = require('../../common/argv-parser'); @@ -473,7 +473,7 @@ async function createMainWindow() { username: "Firebot" }); - if (settings.getOpenStreamPreviewOnLaunch() === true) { + if (SettingsManager.getSetting("OpenStreamPreviewOnLaunch") === true) { createStreamPreviewWindow(); } @@ -483,7 +483,7 @@ async function createMainWindow() { mainWindow.on("close", (event) => { const connectionManager = require("../../common/connection-manager"); - if (!settings.hasJustUpdated() && connectionManager.chatIsConnected() && connectionManager.streamerIsOnline()) { + if (!SettingsManager.getSetting("JustUpdated") && connectionManager.chatIsConnected() && connectionManager.streamerIsOnline()) { event.preventDefault(); dialog.showMessageBox(mainWindow, { message: "Are you sure you want to close Firebot while connected to Twitch?", diff --git a/src/backend/auth/auth-manager.ts b/src/backend/auth/auth-manager.ts index b2ff2be18..f9d9adb29 100644 --- a/src/backend/auth/auth-manager.ts +++ b/src/backend/auth/auth-manager.ts @@ -2,20 +2,20 @@ import { EventEmitter } from "events"; import ClientOAuth2 from "client-oauth2"; import logger from "../logwrapper"; import { AuthProvider, AuthProviderDefinition } from "./auth"; -import { settings } from "../common/settings-access"; +import { SettingsManager } from "../common/settings-manager"; import frontendCommunicator from "../common/frontend-communicator"; import { Notification, app } from "electron"; import windowManagement from "../app-management/electron/window-management"; class AuthManager extends EventEmitter { - private readonly _httpPort: string; + private readonly _httpPort: number; private _authProviders: AuthProvider[]; constructor() { super(); this._authProviders = []; - this._httpPort = settings.getWebServerPort(); + this._httpPort = SettingsManager.getSetting("WebServerPort"); } registerAuthProvider(provider: AuthProviderDefinition): void { diff --git a/src/backend/backup-manager.ts b/src/backend/backup-manager.ts index 96944f99f..0c664c6cd 100644 --- a/src/backend/backup-manager.ts +++ b/src/backend/backup-manager.ts @@ -6,7 +6,7 @@ import { glob } from "glob"; import { DeflateOptions, Zip, ZipDeflate, unzipSync } from "fflate"; import logger from "./logwrapper"; import utils from "./utility"; -import { settings } from "./common/settings-access"; +import { SettingsManager } from "./common/settings-manager"; import dataAccess from "./common/data-access.js"; import frontendCommunicator from "./common/frontend-communicator"; @@ -31,7 +31,7 @@ class BackupManager { } private async cleanUpOldBackups(callback: () => void) { - const maxBackups = settings.maxBackupCount(); + const maxBackups = SettingsManager.getSetting("MaxBackupCount"); if (maxBackups !== "All") { const fileNames = (await fsp.readdir(this._backupFolderPath)) @@ -78,7 +78,7 @@ class BackupManager { // listen for all archive data to be written output.on("close", async () => { - settings.setLastBackupDate(new Date()); + SettingsManager.saveSetting("LastBackupDate", new Date()); await this.cleanUpOldBackups(callback); }); @@ -107,7 +107,7 @@ class BackupManager { //archive.directory(folderPath, "profiles"); const varIgnoreInArchive = ['backups/**', 'clips/**', 'logs/**', 'overlay.html']; - const ignoreResources = settings.backupIgnoreResources(); + const ignoreResources = SettingsManager.getSetting("BackupIgnoreResources"); if (ignoreResources && !manualActivation) { logger.info("Ignoring overlay-resources folder"); @@ -147,8 +147,8 @@ class BackupManager { } async onceADayBackUpCheck() { - const shouldBackUp = settings.backupOnceADay(), - lastBackupDate = settings.lastBackupDate(), + const shouldBackUp = SettingsManager.getSetting("BackupOnceADay"), + lastBackupDate = SettingsManager.getSetting("LastBackupDate"), todayDate = new Date(); if (shouldBackUp) { diff --git a/src/backend/chat/chat-listeners/active-user-handler.js b/src/backend/chat/chat-listeners/active-user-handler.js index 1dbb40524..374e191d6 100644 --- a/src/backend/chat/chat-listeners/active-user-handler.js +++ b/src/backend/chat/chat-listeners/active-user-handler.js @@ -1,7 +1,7 @@ "use strict"; const chatHelpers = require("../chat-helpers"); -const { settings } = require("../../common/settings-access"); +const { SettingsManager } = require("../../common/settings-manager"); const frontendCommunicator = require("../../common/frontend-communicator"); const utils = require("../../utility"); const chatRolesManager = require("../../roles/chat-roles-manager"); @@ -235,7 +235,7 @@ exports.addActiveUser = async (chatUser, includeInOnline = false, forceActive = const viewerDatabase = require("../../viewers/viewer-database"); - const ttl = settings.getActiveChatUserListTimeout() * 60; + const ttl = SettingsManager.getSetting("ActiveChatUserListTimeout") * 60; let user = await viewerDatabase.getViewerById(chatUser.userId); diff --git a/src/backend/chat/commands/builtin/quotes.ts b/src/backend/chat/commands/builtin/quotes.ts index 65d0af3af..948f99bfd 100644 --- a/src/backend/chat/commands/builtin/quotes.ts +++ b/src/backend/chat/commands/builtin/quotes.ts @@ -277,23 +277,24 @@ export const QuotesManagementSystemCommand: SystemCommand<{ switch (triggeredArg) { case "add": { - const shouldInsertStreamerUsername = (commandOptions.defaultStreamerAttribution && args.length === 1) - || (commandOptions.defaultStreamerAttribution && !args[1].includes("@")); + const shouldInsertStreamerUsername = + (commandOptions.defaultStreamerAttribution && args.length === 1) || + (commandOptions.defaultStreamerAttribution && !args[1].includes("@")); const expectedArgs = shouldInsertStreamerUsername - ? 2 - : 3; - + ? 2 + : 3; + if (args.length < expectedArgs) { - await twitchChat.sendChatMessage(`Please provide some quote text!`); - return resolve(); + await twitchChat.sendChatMessage(`Please provide some quote text!`); + return resolve(); } // Once we've evaluated that the syntax is correct we make our API calls const channelData = await TwitchApi.channels.getChannelInformation(); const currentGameName = channelData && channelData.gameName ? channelData.gameName : "Unknown game"; - + // If shouldInsertStreamerUsername and no @ is included in the originator arg, set originator @streamerName and treat the rest as the quote if (shouldInsertStreamerUsername) { - args.splice(1,0,`@${channelData.displayName}`) + args.splice(1, 0, `@${channelData.displayName}`); } const newQuote = { @@ -404,8 +405,8 @@ export const QuotesManagementSystemCommand: SystemCommand<{ } case "searchdate": { const rawDay = parseInt(args[1]); - const rawMonth = parseInt(args[1]); - const rawYear = parseInt(args[1]); + const rawMonth = parseInt(args[2]); + const rawYear = parseInt(args[3]); const day = !isNaN(rawDay) ? rawDay : null; const month = !isNaN(rawMonth) ? rawMonth : null; diff --git a/src/backend/chat/commands/chat-command-handler.ts b/src/backend/chat/commands/chat-command-handler.ts index 2bb84bfa8..2fadbd997 100644 --- a/src/backend/chat/commands/chat-command-handler.ts +++ b/src/backend/chat/commands/chat-command-handler.ts @@ -11,7 +11,7 @@ import commandManager from "./command-manager"; import commandCooldownManager from "./command-cooldown-manager"; import twitchApi from "../../twitch-api/api"; import commandRunner from "./command-runner"; -import { settings } from "../../common/settings-access"; +import { SettingsManager } from "../../common/settings-manager"; const DEFAULT_COOLDOWN_MESSAGE = "This command is still on cooldown for: {timeLeft}"; const DEFAULT_RESTRICTION_MESSAGE = "Sorry, you cannot use this command because: {reason}"; @@ -130,7 +130,7 @@ class CommandHandler { } // 'inherit' or undefined = inherit app settings - if (command.allowTriggerBySharedChat !== true && !settings.getAllowCommandsInSharedChat()) { + if (command.allowTriggerBySharedChat !== true && !SettingsManager.getSetting("AllowCommandsInSharedChat")) { return false; } } diff --git a/src/backend/cloud-sync/profile-sync.js b/src/backend/cloud-sync/profile-sync.js index 1c110c1ab..e3d5b2c8d 100644 --- a/src/backend/cloud-sync/profile-sync.js +++ b/src/backend/cloud-sync/profile-sync.js @@ -6,7 +6,7 @@ const logger = require("../logwrapper"); const commandList = require("./sync-handlers/command-list"); const quoteList = require("./sync-handlers/quotes-list"); const frontendCommunicator = require("../common/frontend-communicator"); -const { settings } = require("../common/settings-access"); +const { SettingsManager } = require("../common/settings-manager"); const rankManager = require("../ranks/rank-manager"); async function syncProfileData(profileSyncData) { @@ -25,7 +25,7 @@ async function syncProfileData(profileSyncData) { 'variables': variableManager.getReplaceVariables().map(v => v.definition), 'ranks': rankManager.getAllItems(), 'quotes': quotes, - 'allowQuoteCSVDownloads': settings.getAllowQuoteCSVDownloads() + 'allowQuoteCSVDownloads': SettingsManager.getSetting("AllowQuoteCSVDownloads") }; const binId = await cloudSync.sync(completeSyncJSON); diff --git a/src/backend/common/common-listeners.js b/src/backend/common/common-listeners.js index e263cb43b..6b669a66c 100644 --- a/src/backend/common/common-listeners.js +++ b/src/backend/common/common-listeners.js @@ -11,7 +11,7 @@ exports.setupCommonListeners = () => { const frontendCommunicator = require("./frontend-communicator"); const dataAccess = require("./data-access"); const profileManager = require("./profile-manager"); - const { settings } = require("./settings-access"); + const { SettingsManager } = require("./settings-manager"); const backupManager = require("../backup-manager"); const webServer = require("../../server/http-server-manager"); @@ -198,7 +198,7 @@ exports.setupCommonListeners = () => { const GhReleases = require("electron-gh-releases"); //back up first - if (settings.backupBeforeUpdates()) { + if (SettingsManager.getSetting("BackupBeforeUpdates")) { await backupManager.startBackup(); } @@ -221,7 +221,7 @@ exports.setupCommonListeners = () => { renderWindow.webContents.send("updateDownloaded"); // Prepare for update install on next run - settings.setJustUpdated(true); + SettingsManager.saveSetting("JustUpdated", true); }); }); diff --git a/src/backend/common/connection-manager.js b/src/backend/common/connection-manager.js index aa1eaefe5..fc3a3a299 100644 --- a/src/backend/common/connection-manager.js +++ b/src/backend/common/connection-manager.js @@ -3,7 +3,7 @@ const { EventEmitter } = require("events"); const util = require("../utility"); const logger = require("../logwrapper"); const frontendCommunicator = require("./frontend-communicator"); -const { settings } = require("./settings-access"); +const { SettingsManager } = require("./settings-manager"); const twitchApi = require("../twitch-api/api"); const twitchChat = require("../chat/twitch-chat"); const twitchPubSubClient = require("../twitch-api/pubsub/pubsub-client"); @@ -224,7 +224,7 @@ manager.on("service-connection-update", (data) => { }); frontendCommunicator.onAsync("connect-sidebar-controlled-services", async () => { - const serviceIds = settings.getSidebarControlledServices(); + const serviceIds = SettingsManager.getSetting("SidebarControlledServices"); await manager.updateConnectionForServices(serviceIds.map(id => ({ id, @@ -233,7 +233,7 @@ frontendCommunicator.onAsync("connect-sidebar-controlled-services", async () => }); frontendCommunicator.on("disconnect-sidebar-controlled-services", () => { - const serviceIds = settings.getSidebarControlledServices(); + const serviceIds = SettingsManager.getSetting("SidebarControlledServices"); for (const id of serviceIds) { manager.updateServiceConnection(id, false); } diff --git a/src/backend/common/handlers/custom-scripts/custom-script-helpers.js b/src/backend/common/handlers/custom-scripts/custom-script-helpers.js index e73787444..15262cc1d 100644 --- a/src/backend/common/handlers/custom-scripts/custom-script-helpers.js +++ b/src/backend/common/handlers/custom-scripts/custom-script-helpers.js @@ -2,7 +2,7 @@ const twitchChat = require("../../../chat/twitch-chat"); const twitchApi = require("../../../twitch-api/api"); const profileManager = require("../../profile-manager"); -const settings = require('../../settings-access').settings; +const settings = require('../../settings-manager').SettingsManager; const path = require("path"); const logger = require("../../../logwrapper"); const { diff --git a/src/backend/common/handlers/custom-scripts/custom-script-runner.js b/src/backend/common/handlers/custom-scripts/custom-script-runner.js index dada6bbf7..7f621c1bf 100644 --- a/src/backend/common/handlers/custom-scripts/custom-script-runner.js +++ b/src/backend/common/handlers/custom-scripts/custom-script-runner.js @@ -2,11 +2,11 @@ const { ipcMain, shell } = require("electron"); const { v4: uuid } = require("uuid"); const logger = require("../../../logwrapper"); -const { settings } = require("../../settings-access"); const utils = require("../../../utility"); const profileManager = require("../../profile-manager"); const { getScriptPath, buildRunRequest, mapParameters, mapV4EffectToV5 } = require("./custom-script-helpers"); const effectRunner = require("../../effect-runner.js"); +import { SettingsManager } from "../../settings-manager"; /** * @typedef { import('./script-types').ScriptData } ScriptData @@ -36,7 +36,7 @@ async function executeScript(scriptData, trigger, isStartupScript = false) { let customScript; try { // Make sure we first remove the cached version, incase there was any changes - if (settings.getClearCustomScriptCache()) { + if (SettingsManager.getSetting("ClearCustomScriptCache")) { delete require.cache[require.resolve(scriptFilePath)]; } customScript = require(scriptFilePath); @@ -168,7 +168,7 @@ async function runStartUpScript(startUpScriptConfig) { const { scriptName } = startUpScriptConfig; logger.debug(`running startup script: ${scriptName}`); - if (!settings.isCustomScriptsEnabled()) { + if (SettingsManager.getSetting("RunCustomScripts") !== true) { logger.warn("Attempted to run startup script but custom scripts are disabled."); return; } @@ -229,7 +229,7 @@ function runScript(effect, trigger) { logger.debug(`running script: ${scriptName}`); - if (!settings.isCustomScriptsEnabled()) { + if (SettingsManager.getSetting("RunCustomScripts")) { renderWindow.webContents.send( "error", "Something attempted to run a custom script but this feature is disabled!" diff --git a/src/backend/common/handlers/mediaProcessor.js b/src/backend/common/handlers/mediaProcessor.js index ed1119cdd..6911e4534 100644 --- a/src/backend/common/handlers/mediaProcessor.js +++ b/src/backend/common/handlers/mediaProcessor.js @@ -1,7 +1,7 @@ "use strict"; const { ipcMain, dialog } = require("electron"); -const settings = require("../settings-access").settings; +const { SettingsManager } = require("../settings-manager"); const resourceTokenManager = require("../../resourceTokenManager.js"); const util = require("../../utility"); const logger = require("../../logwrapper"); @@ -73,7 +73,7 @@ function soundProcessor(effect) { selectedOutputDevice == null || selectedOutputDevice.label === "App Default" ) { - selectedOutputDevice = settings.getAudioOutputDevice(); + selectedOutputDevice = SettingsManager.getSetting("AudioOutputDevice"); } data.audioOutputDevice = selectedOutputDevice; @@ -82,9 +82,9 @@ function soundProcessor(effect) { data.resourceToken = resourceToken; } - if (settings.useOverlayInstances()) { + if (SettingsManager.getSetting("UseOverlayInstances")) { if (effect.overlayInstance != null) { - if (settings.getOverlayInstances().includes(effect.overlayInstance)) { + if (SettingsManager.getSetting("OverlayInstances").includes(effect.overlayInstance)) { data.overlayInstance = effect.overlayInstance; } } @@ -125,9 +125,9 @@ async function imageProcessor(effect, trigger) { "customCoords": effect.customCoords }; - if (settings.useOverlayInstances()) { + if (SettingsManager.getSetting("UseOverlayInstances")) { if (effect.overlayInstance != null) { - if (settings.getOverlayInstances().includes(effect.overlayInstance)) { + if (SettingsManager.getSetting("OverlayInstances").includes(effect.overlayInstance)) { data.overlayInstance = effect.overlayInstance; } } @@ -181,9 +181,9 @@ function videoProcessor(effect) { "loop": effect.loop === true }; - if (settings.useOverlayInstances()) { + if (SettingsManager.getSetting("UseOverlayInstances")) { if (effect.overlayInstance != null) { - if (settings.getOverlayInstances().includes(effect.overlayInstance)) { + if (SettingsManager.getSetting("OverlayInstances").includes(effect.overlayInstance)) { data.overlayInstance = effect.overlayInstance; } } @@ -230,10 +230,10 @@ async function showText(effect, trigger) { dto.position = getRandomPresetLocation(); } - if (settings.useOverlayInstances()) { + if (SettingsManager.getSetting("UseOverlayInstances")) { if (dto.overlayInstance != null) { //reset overlay if it doesnt exist - if (!settings.getOverlayInstances().includes(dto.overlayInstance)) { + if (!SettingsManager.getSetting("OverlayInstances").includes(dto.overlayInstance)) { dto.overlayInstance = null; } } diff --git a/src/backend/common/screenshot-helpers.ts b/src/backend/common/screenshot-helpers.ts index fdec15e75..f4031abb4 100644 --- a/src/backend/common/screenshot-helpers.ts +++ b/src/backend/common/screenshot-helpers.ts @@ -5,7 +5,7 @@ import logger from "../logwrapper"; import twitchApi from "../twitch-api/api"; import discordEmbedBuilder from "../integrations/builtin/discord/discord-embed-builder"; import discord from "../integrations/builtin/discord/discord-message-sender"; -import { settings } from "../common/settings-access"; +import { SettingsManager } from "../common/settings-manager"; import mediaProcessor from "../common/handlers/mediaProcessor"; import webServer from "../../server/http-server-manager"; import moment from "moment"; @@ -86,9 +86,9 @@ export function sendScreenshotToOverlay(screenshotDataUrl: string, effect: Scree } let overlayInstance = null; - if (settings.useOverlayInstances()) { + if (SettingsManager.getSetting("UseOverlayInstances")) { if (effect.overlayInstance != null) { - if (settings.getOverlayInstances().includes(effect.overlayInstance)) { + if (SettingsManager.getSetting("OverlayInstances").includes(effect.overlayInstance)) { overlayInstance = effect.overlayInstance; } } diff --git a/src/backend/common/settings-access.js b/src/backend/common/settings-access.js deleted file mode 100644 index 30efc5dec..000000000 --- a/src/backend/common/settings-access.js +++ /dev/null @@ -1,342 +0,0 @@ -"use strict"; - -const profileManager = require("./profile-manager"); -const logger = require("../logwrapper"); -const frontendCommunicator = require("./frontend-communicator"); -const fs = require("fs"); - -// This file centralizes access to the settings db -// We will need to refactor other files to use this. -const settings = {}; - -let settingsCache = {}; - -settings.flushSettingsCache = function () { - settingsCache = {}; - frontendCommunicator.send("flush-settings-cache"); -}; - -frontendCommunicator.on("settings-updated-renderer", (settingsUpdate) => { - if (settingsUpdate == null) { - return; - } - const { path, data } = settingsUpdate; - if (path == null || path === '') { - return; - } - settingsCache[path] = data; -}); - -frontendCommunicator.on("purge-settings-cache", () => { - settingsCache = {}; -}); - -function getSettingsFile() { - return profileManager.getJsonDbInProfile("/settings"); -} - -function pushDataToFile(path, data) { - try { - getSettingsFile().push(path, data); - settingsCache[path] = data; - frontendCommunicator.send("settings-updated-main", { path, data }); - } catch (err) { - logger.debug(err.message); - } -} - - -function handleCorruptSettingsFile() { - logger.warn("settings.json file appears to be corrupt. Resetting file..."); - - const settingsPath = profileManager.getPathInProfile("settings.json"); - fs.writeFileSync(settingsPath, JSON.stringify({ - settings: { - firstTimeUse: false - } - })); -} - -function getDataFromFile(path, forceCacheUpdate = false, defaultValue = undefined) { - try { - if (settingsCache[path] == null || forceCacheUpdate) { - const data = getSettingsFile().getData(path); - settingsCache[path] = data ?? defaultValue; - } - } catch (err) { - if (defaultValue !== undefined) { - settingsCache[path] = defaultValue; - } - if (err.name !== "DataError") { - logger.warn(err); - if ( - err.name === 'DatabaseError' && - err.inner instanceof SyntaxError && - err.inner.stack.includes('JSON.parse') - ) { - handleCorruptSettingsFile(); - } - } - } - return settingsCache[path]; -} - -settings.getAutoFlagBots = function () { - const autoFlagBots = getDataFromFile("/settings/autoFlagBots"); - return autoFlagBots != null ? autoFlagBots : true; -}; - -settings.getEventSettings = function () { - return getDataFromFile("/settings/eventSettings"); -}; - -settings.isCustomScriptsEnabled = function () { - return getDataFromFile("/settings/runCustomScripts") === true; -}; - -settings.setCustomScriptsEnabled = function (enabled) { - pushDataToFile("/settings/runCustomScripts", enabled === true); -}; - -settings.ignoreSubsequentSubEventsAfterCommunitySub = function () { - const ignoreSubEvents = getDataFromFile("/settings/ignoreSubsequentSubEventsAfterCommunitySub"); - return ignoreSubEvents != null ? ignoreSubEvents : true; -}; - -settings.hasJustUpdated = function () { - const updated = getDataFromFile("/settings/justUpdated"); - return updated != null ? updated : false; -}; - -settings.setJustUpdated = function (justUpdated) { - pushDataToFile("/settings/justUpdated", justUpdated === true); -}; - -settings.getOverlayVersion = function () { - const version = getDataFromFile("/settings/copiedOverlayVersion"); - return version != null ? version : ""; -}; - -settings.setOverlayVersion = function (newVersion) { - pushDataToFile("/settings/copiedOverlayVersion", newVersion.toString()); -}; - -settings.getClearCustomScriptCache = function () { - const clear = getDataFromFile("/settings/clearCustomScriptCache"); - return clear != null ? clear : false; -}; - -settings.setClearCustomScriptCache = function (clear) { - pushDataToFile("/settings/clearCustomScriptCache", clear === true); -}; - -settings.getCustomScriptsEnabled = function () { - return getDataFromFile("/settings/runCustomScripts") === true; -}; - -settings.setCustomScriptsEnabled = function (enabled) { - pushDataToFile("/settings/runCustomScripts", enabled === true); -}; - -settings.getPersistCustomVariables = function () { - return getDataFromFile("/settings/persistCustomVariables") === true; -}; - -settings.setPersistCustomVariables = function (enabled) { - pushDataToFile("/settings/persistCustomVariables", enabled === true); -}; - -settings.useOverlayInstances = function () { - const oi = getDataFromFile("/settings/useOverlayInstances"); - return oi != null ? oi : false; -}; - -settings.setUseOverlayInstances = function (oi) { - pushDataToFile("/settings/useOverlayInstances", oi === true); -}; - -settings.getOverlayInstances = function () { - const ois = getDataFromFile("/settings/overlayInstances"); - return ois != null ? ois : []; -}; - -settings.setOverlayInstances = function (ois) { - pushDataToFile("/settings/overlayInstances", ois); -}; - -settings.getForceOverlayEffectsToContinueOnRefresh = function () { - const forceOverlayEffectsToContinueOnRefresh = getDataFromFile("/settings/forceOverlayEffectsToContinueOnRefresh", false, true); - return forceOverlayEffectsToContinueOnRefresh === true; -}; - -settings.setForceOverlayEffectsToContinueOnRefresh = function (value) { - pushDataToFile("/settings/forceOverlayEffectsToContinueOnRefresh", value); -}; - -settings.backupKeepAll = function () { - const backupKeepAll = getDataFromFile("/settings/backupKeepAll"); - return backupKeepAll != null ? backupKeepAll : false; -}; - -settings.backupOnExit = function () { - const backupOnExit = getDataFromFile("/settings/backupOnExit"); - return backupOnExit != null ? backupOnExit : true; -}; - -settings.backupIgnoreResources = function () { - const save = getDataFromFile("/settings/backupIgnoreResources"); - return save != null ? save : true; -}; - -settings.setBackupIgnoreResources = function (backupIgnoreResources) { - pushDataToFile("/settings/backupIgnoreResources", backupIgnoreResources === false); -}; - -settings.backupBeforeUpdates = function () { - const backupBeforeUpdates = getDataFromFile("/settings/backupBeforeUpdates"); - return backupBeforeUpdates != null ? backupBeforeUpdates : true; -}; - -settings.backupOnceADay = function () { - const backupOnceADay = getDataFromFile("/settings/backupOnceADay"); - return backupOnceADay != null ? backupOnceADay : true; -}; - -settings.setBackupOnceADay = function (backupOnceADay) { - pushDataToFile("/settings/backupOnceADay", backupOnceADay === true); -}; - -settings.lastBackupDate = function () { - const lastBackup = getDataFromFile("/settings/lastBackupDate"); - return lastBackup != null ? new Date(lastBackup) : null; -}; - -settings.setLastBackupDate = function (lastBackup) { - pushDataToFile("/settings/lastBackupDate", lastBackup.toJSON()); -}; - -settings.maxBackupCount = function () { - const maxBackupCount = getDataFromFile("/settings/maxBackupCount"); - return maxBackupCount != null ? maxBackupCount : 25; -}; - -settings.setMaxBackupCount = function (maxBackupCount) { - pushDataToFile("/settings/maxBackupCount", maxBackupCount); -}; - -settings.getAllowQuoteCSVDownloads = function () { - return getDataFromFile("/settings/allowQuoteCSVDownloads") !== false; -}; - -settings.getActiveChatUserListTimeout = function () { - const inactiveTimer = getDataFromFile("/settings/activeChatUsers/inactiveTimer"); - return inactiveTimer != null ? parseInt(inactiveTimer) : 5; -}; - -settings.getWebSocketPort = function () { - const websocketPort = getDataFromFile("/settings/websocketPort"); - return websocketPort != null ? websocketPort : 8080; -}; - -settings.getWebServerPort = function () { - const serverPort = getDataFromFile("/settings/webServerPort"); - return serverPort != null ? serverPort : 7472; -}; - -settings.getViewerDbStatus = function () { - const status = getDataFromFile("/settings/viewerDB"); - return status != null ? status : true; -}; - -/* -* 0 = off, -* 1 = bugfix, -* 2 = feature, -* 3 = major release, -* 4 = betas -*/ -settings.getAutoUpdateLevel = function () { - const updateLevel = getDataFromFile("/settings/autoUpdateLevel"); - return updateLevel != null ? updateLevel : 2; -}; - -settings.getAudioOutputDevice = function () { - const device = getDataFromFile("/settings/audioOutputDevice"); - return device != null - ? device - : { label: "System Default", deviceId: "default" }; -}; - -settings.debugModeEnabled = function () { - const enabled = getDataFromFile("/settings/debugMode"); - return enabled != null ? enabled : false; -}; - -settings.getWhileLoopEnabled = function () { - const enabled = getDataFromFile('/settings/whileLoopEnabled'); - return enabled !== undefined ? enabled : false; -}; - -settings.setWhileLoopEnabled = function (enabled) { - pushDataToFile('/settings/whileLoopEnabled', enabled === true); -}; - -/**@returns {string[]} */ -settings.getSidebarControlledServices = function () { - const services = getDataFromFile("/settings/sidebarControlledServices"); - return services != null - ? services - : ["chat"]; -}; - -settings.getMinimizeToTray = function () { - const minimizeToTray = getDataFromFile('/settings/minimizeToTray'); - return minimizeToTray === true; -}; -settings.setMinimizeToTray = function (minimizeToTray) { - pushDataToFile('/settings/minimizeToTray', minimizeToTray === true); -}; - -settings.getOpenStreamPreviewOnLaunch = () => { - const openStreamPreviewOnLaunch = getDataFromFile("/settings/openStreamPreviewOnLaunch", false, false); - return openStreamPreviewOnLaunch === true; -}; -settings.setOpenStreamPreviewOnLaunch = (enabled) => { - pushDataToFile("/settings/openStreamPreviewOnLaunch", enabled === true); -}; - -settings.getQuickActionSettings = () => { - return getDataFromFile("/settings/quickActions"); -}; - -settings.setQuickActionSettings = (quickActions) => { - pushDataToFile("/settings/quickActions", quickActions); -}; - -settings.getWebOnlineCheckin = () => { - const webOnlineCheckin = getDataFromFile("/settings/webOnlineCheckin"); - return webOnlineCheckin === true; -}; - -settings.setWebOnlineCheckin = (value) => { - pushDataToFile("/settings/webOnlineCheckin", value); -}; - -settings.getTriggerUpcomingAdBreakMinutes = function () { - const value = getDataFromFile("/settings/triggerUpcomingAdBreakMinutes", false, 0); - return value ?? 0; -}; - -settings.setTriggerUpcomingAdBreakMinutes = function (value) { - pushDataToFile("/settings/triggerUpcomingAdBreakMinutes", value); -}; - -settings.getAllowCommandsInSharedChat = function () { - return getDataFromFile("/settings/allowCommandsInSharedChat", false, false); // default OFF -}; - -settings.setAllowCommandsInSharedChat = function (value) { - pushDataToFile("/settings/allowCommandsInSharedChat", value); -}; - -exports.settings = settings; diff --git a/src/backend/common/settings-manager.ts b/src/backend/common/settings-manager.ts new file mode 100644 index 000000000..fe6c6c68e --- /dev/null +++ b/src/backend/common/settings-manager.ts @@ -0,0 +1,332 @@ +import { EventEmitter } from "events"; +import { JsonDB } from "node-json-db"; +import fs from "fs"; +import logger from "../logwrapper"; +import profileManager from "./profile-manager"; +import dataAccess from "./data-access"; +import frontendCommunicator from "./frontend-communicator"; +import { + FirebotAutoUpdateLevel, + FirebotGlobalSettings, + FirebotSettingsDefaults, + FirebotSettingsPaths, + FirebotSettingsTypes +} from "../../types/settings"; + +class SettingsManager extends EventEmitter { + settingsCache = {}; + + private getSettingsFile(): JsonDB { + return profileManager.getJsonDbInProfile("/settings"); + } + + private getGlobalSettingsFile(): JsonDB { + return dataAccess.getJsonDbInUserData("./global-settings"); + } + + private handleCorruptSettingsFile() { + logger.warn("settings.json file appears to be corrupt. Resetting file..."); + + const settingsPath = profileManager.getPathInProfile("settings.json"); + fs.writeFileSync(settingsPath, JSON.stringify({ + settings: { + firstTimeUse: false + } + })); + } + + private getDataFromFile(settingPath: string, forceCacheUpdate = false, defaultValue = undefined) { + try { + if (this.settingsCache[settingPath] == null || forceCacheUpdate) { + const data = this.getSettingsFile().getData(settingPath); + this.settingsCache[settingPath] = data ?? defaultValue; + } + } catch (err) { + if (defaultValue !== undefined) { + this.settingsCache[settingPath] = defaultValue; + } + if (err.name !== "DataError") { + logger.warn(err); + if ( + err.name === "DatabaseError" && + err.inner instanceof SyntaxError && + err.inner.stack.includes("JSON.parse") + ) { + this.handleCorruptSettingsFile(); + } + } + } + return this.settingsCache[settingPath]; + } + + private getDataFromGlobalSettingsFile(settingPath: string, forceCacheUpdate = false, defaultValue = undefined) { + try { + if (this.settingsCache[settingPath] == null || forceCacheUpdate) { + const data = this.getGlobalSettingsFile().getData(settingPath); + this.settingsCache[settingPath] = data ?? defaultValue; + } + } catch (err) { + if (defaultValue !== undefined) { + this.settingsCache[settingPath] = defaultValue; + } + if (err.name !== "DataError") { + logger.warn(err); + } + } + return this.settingsCache[settingPath]; + } + + private pushDataToFile(settingPath: string, data: unknown) { + try { + this.getSettingsFile().push(settingPath, data); + this.settingsCache[settingPath] = data; + frontendCommunicator.send("settings:setting-updated", { settingPath, data }); + } catch (err) { + logger.debug(err.message); + } + } + + private pushDataToGlobalSettingsFile(settingPath: string, data: unknown) { + try { + this.getGlobalSettingsFile().push(settingPath, data); + this.settingsCache[settingPath] = data; + frontendCommunicator.send("settings:setting-updated", { settingPath, data }); + } catch (err) { + logger.debug(err.message); + } + } + + private deleteDataAtPath(settingPath: string) { + try { + this.getSettingsFile().delete(settingPath); + delete this.settingsCache[settingPath]; + frontendCommunicator.send("settings:setting-deleted", settingPath); + } catch { } + } + + /** + * Get the JSON data path for a specific Firebot setting in the settings file + * + * @param settingName Name of the setting + * @returns String representing the full JSON path of the setting data + */ + getSettingPath(settingName: string) { + return FirebotSettingsPaths[settingName] ?? `/settings/${settingName[0].toLowerCase()}${settingName.slice(1)}`; + } + + /** + * Get a Firebot setting value or its default + * + * @param settingName Name of the setting to get + * @param forceCacheUpdate Force an update to the settings cache. Defaults to `false`. + * @returns Setting value, or the default if one isn't explicitly set + */ + getSetting(settingName: SettingName, forceCacheUpdate = false): FirebotSettingsTypes[SettingName] { + let value: FirebotSettingsTypes[SettingName]; + + if (FirebotGlobalSettings[settingName] === true) { + value = this.getDataFromGlobalSettingsFile(this.getSettingPath(settingName), forceCacheUpdate, FirebotSettingsDefaults[settingName]); + } else { + value = this.getDataFromFile(this.getSettingPath(settingName), forceCacheUpdate, FirebotSettingsDefaults[settingName]); + } + + // Eventually, when we upgrade node-json-db, the library will handle this for us + if (typeof value === "string" && /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}/m.exec(value)) { + // This is a load-bearing cast + return new Date(value) as FirebotSettingsTypes[SettingName]; + } + + return value; + } + + /** + * Save a Firebot setting + * + * @param settingName Name of the setting to save + * @param data Setting data + */ + saveSetting(settingName: SettingName, data: FirebotSettingsTypes[SettingName]): void { + if (FirebotGlobalSettings[settingName] === true) { + this.pushDataToGlobalSettingsFile(this.getSettingPath(settingName), data); + } else { + this.pushDataToFile(this.getSettingPath(settingName), data); + } + this.emit(`settings:setting-saved:${settingName}`, data); + } + + /** + * Delete a Firebot setting + * + * @param settingName Name of the setting to delete + */ + deleteSetting(settingName: SettingName) { + this.deleteDataAtPath(this.getSettingPath(settingName)); + this.emit(`settings:setting-deleted:${settingName}`); + } + + /** + * Get a plugin setting or its default + * + * @param pluginName Name of the plugin + * @param settingName Name of the setting + * @param forceCacheUpdate Force an update to the settings cache. Defaults to `false`. + * @param defaultValue The default value to return if one isn't explicitly defined + * @returns The saved plugin setting value, or the default if it doesn't exist. + */ + getPluginSetting(pluginName: string, settingName: string, forceCacheUpdate = false, defaultValue: unknown = undefined) { + return this.getDataFromFile(`/plugins/${pluginName}/${settingName}`, forceCacheUpdate, defaultValue); + } + + /** + * Flushes the settings cache, forcing all settings to be retrieved from file on the next retrieval + */ + flushSettingsCache() { + this.settingsCache = {}; + frontendCommunicator.send("settings:settings-cache-flushed"); + } + + + // Everything below this is deprecated. Leaving them for back compat with scripts. + // You should use either getSetting or saveSetting with the relevant setting name. + + /** @deprecated Use `getSetting("EventSettings")` instead */ + getEventSettings = () => this.getSetting("EventSettings"); + + /** @deprecated Use `getSetting("IgnoreSubsequentSubEventsAfterCommunitySub")` instead */ + ignoreSubsequentSubEventsAfterCommunitySub = () => this.getSetting("IgnoreSubsequentSubEventsAfterCommunitySub"); + + /** @deprecated Use `getSetting("JustUpdated")` instead */ + hasJustUpdated = (): boolean => this.getSetting("JustUpdated"); + + /** @deprecated Use `saveSetting("JustUpdated", value)` instead */ + setJustUpdated = (value: boolean) => this.saveSetting("JustUpdated", value); + + /** @deprecated Use `getSetting("CopiedOverlayVersion")` instead */ + getOverlayVersion = () => this.getSetting("CopiedOverlayVersion"); + + /** @deprecated Use `saveSetting("CopiedOverlayVersion", value)` instead */ + setOverlayVersion = (value: string) => this.saveSetting("CopiedOverlayVersion", value); + + /** @deprecated Use `getSetting("ClearCustomScriptCache")` instead */ + getClearCustomScriptCache = () => this.getSetting("ClearCustomScriptCache"); + + /** @deprecated Use `saveSetting("ClearCustomScriptCache", value)` instead */ + setClearCustomScriptCache = (value: boolean) => this.saveSetting("ClearCustomScriptCache", value); + + /** @deprecated Use `getSetting("RunCustomScripts")` instead */ + isCustomScriptsEnabled = () => this.getSetting("RunCustomScripts"); + + /** @deprecated Use `getSetting("RunCustomScripts")` instead */ + getCustomScriptsEnabled = () => this.getSetting("RunCustomScripts"); + + /** @deprecated Use `saveSetting("RunCustomScripts", value)` instead */ + setCustomScriptsEnabled = (value: boolean) => this.saveSetting("RunCustomScripts", value); + + /** @deprecated Use `getSetting("PersistCustomVariables")` instead */ + getPersistCustomVariables = () => this.getSetting("PersistCustomVariables"); + + /** @deprecated Use `saveSetting("PersistCustomVariables", value)` instead */ + setPersistCustomVariables = (value: boolean) => this.saveSetting("PersistCustomVariables", value); + + /** @deprecated Use `getSetting("UseOverlayInstances")` instead */ + useOverlayInstances = (): boolean => this.getSetting("UseOverlayInstances"); + + /** @deprecated Use `saveSetting("UseOverlayInstances", value)` instead */ + setUseOverlayInstances = (value: boolean) => this.saveSetting("UseOverlayInstances", value); + + /** @deprecated Use `getSetting("OverlayInstances")` instead */ + getOverlayInstances = () => this.getSetting("OverlayInstances"); + + /** @deprecated Use `saveSetting("OverlayInstances", value)` instead */ + setOverlayInstances = (value: string[]) => this.saveSetting("OverlayInstances", value); + + /** @deprecated Use `getSetting("BackupKeepAll")` instead */ + backupKeepAll = () => this.getSetting("BackupKeepAll"); + + /** @deprecated Use `getSetting("BackupOnExit")` instead */ + backupOnExit = () => this.getSetting("BackupOnExit"); + + /** @deprecated Use `getSetting("BackupBeforeUpdates")` instead */ + backupBeforeUpdates = () => this.getSetting("BackupBeforeUpdates"); + + /** @deprecated Use `getSetting("BackupOnceADay")` instead */ + backupOnceADay = () => this.getSetting("BackupOnceADay"); + + /** @deprecated Use `saveSetting("BackupOnceADay", value)` instead */ + setBackupOnceADay = (value: boolean) => this.saveSetting("BackupOnceADay", value); + + /** @deprecated Use `getSetting("LastBackupDate")` instead */ + lastBackupDate = () => this.getSetting("LastBackupDate"); + + /** @deprecated Use `saveSetting("LastBackupDate", value)` instead */ + setLastBackupDate = (value: Date) => this.saveSetting("LastBackupDate", value); + + /** @deprecated Use `getSetting("MaxBackupCount")` instead */ + maxBackupCount = () => this.getSetting("MaxBackupCount"); + + /** @deprecated Use `getSetting("MaxBackupCount")` instead */ + setMaxBackupCount = (value: number) => this.saveSetting("MaxBackupCount", value); + + /** @deprecated Use `getSetting("AllowQuoteCSVDownloads")` instead */ + getAllowQuoteCSVDownloads = () => this.getSetting("AllowQuoteCSVDownloads"); + + /** @deprecated Use `getSetting("ActiveChatUserListTimeout")` instead */ + getActiveChatUserListTimeout = () => this.getSetting("ActiveChatUserListTimeout"); + + /** @deprecated Use `getSetting("WebServerPort")` instead */ + getWebSocketPort = () => this.getSetting("WebServerPort"); + + /** @deprecated Use `getSetting("WebServerPort")` instead */ + getWebServerPort = () => this.getSetting("WebServerPort"); + + /** @deprecated Use `getSetting("ViewerDB")` instead */ + getViewerDbStatus = () => this.getSetting("ViewerDB"); + + /** @deprecated Use `getSetting("AutoUpdateLevel")` instead */ + getAutoUpdateLevel = (): FirebotAutoUpdateLevel => this.getSetting("AutoUpdateLevel"); + + /** @deprecated Use `getSetting("AudioOutputDevice")` instead */ + getAudioOutputDevice = () => this.getSetting("AudioOutputDevice"); + + /** @deprecated Use `getSetting("DebugMode")` instead */ + debugModeEnabled = (): boolean => this.getSetting("DebugMode"); + + /** @deprecated Use `getSetting("WhileLoopEnabled")` instead */ + getWhileLoopEnabled = (): boolean => this.getSetting("WhileLoopEnabled"); + + /** @deprecated Use `saveSetting("WhileLoopEnabled", value)` instead */ + setWhileLoopEnabled = (value: boolean) => this.saveSetting("WhileLoopEnabled", value); + + /** @deprecated Use `getSetting("SidebarControlledServices")` instead */ + getSidebarControlledServices = (): string[] => this.getSetting("SidebarControlledServices"); + + /** @deprecated Use `getSetting("MinimizeToTray")` instead */ + getMinimizeToTray = () => this.getSetting("MinimizeToTray"); + + /** @deprecated Use `saveSetting("MinimizeToTray", value)` instead */ + setMinimizeToTray = (value: boolean) => this.saveSetting("MinimizeToTray", value); +} + +const settings = new SettingsManager(); + +frontendCommunicator.on("settings:get-setting-path", (settingName: keyof FirebotSettingsTypes) => { + return settings.getSettingPath(settingName); +}); + +frontendCommunicator.on("settings:get-setting", (settingName: keyof FirebotSettingsTypes) => { + return settings.getSetting(settingName); +}); + +frontendCommunicator.on("settings:save-setting", (request: { settingName: keyof FirebotSettingsTypes, data: FirebotSettingsTypes[keyof FirebotSettingsTypes] }) => { + settings.saveSetting(request.settingName, request.data); +}); + +frontendCommunicator.on("settings:delete-setting", (settingName: keyof FirebotSettingsTypes) => { + settings.deleteSetting(settingName); +}); + +frontendCommunicator.on("settings:flush-settings-cache", () => { + settings.flushSettingsCache(); +}); + +export { settings as SettingsManager }; diff --git a/src/backend/currency/currency-access.ts b/src/backend/currency/currency-access.ts index 233e1437f..feecee257 100644 --- a/src/backend/currency/currency-access.ts +++ b/src/backend/currency/currency-access.ts @@ -2,7 +2,7 @@ import { FirebotViewer } from "../../types/viewers"; import logger from "../logwrapper"; import frontendCommunicator from "../common/frontend-communicator"; -import { settings } from "../common/settings-access"; +import { SettingsManager } from "../common/settings-manager"; import profileManager from "../common/profile-manager"; export type Currency = { @@ -38,7 +38,7 @@ class CurrencyAccess { } isViewerDBOn(): boolean { - return settings.getViewerDbStatus(); + return SettingsManager.getSetting("ViewerDB"); } refreshCurrencyCache(): void { diff --git a/src/backend/effects/builtin/celebration.js b/src/backend/effects/builtin/celebration.js index ee4aa56f5..4f7ee578f 100644 --- a/src/backend/effects/builtin/celebration.js +++ b/src/backend/effects/builtin/celebration.js @@ -1,8 +1,8 @@ "use strict"; const webServer = require("../../../server/http-server-manager"); -const { EffectCategory, EffectDependency } = require('../../../shared/effect-constants'); -const { settings } = require("../../common/settings-access"); +const { EffectCategory } = require('../../../shared/effect-constants'); +const { SettingsManager } = require("../../common/settings-manager"); /** * The Celebration effect @@ -100,9 +100,9 @@ const celebration = { celebrationDuration: celebrationDuration }; - if (settings.useOverlayInstances()) { + if (SettingsManager.getSetting("UseOverlayInstances")) { if (effect.overlayInstance != null) { - if (settings.getOverlayInstances().includes(effect.overlayInstance)) { + if (SettingsManager.getSetting("OverlayInstances").includes(effect.overlayInstance)) { data.overlayInstance = effect.overlayInstance; } } diff --git a/src/backend/effects/builtin/clear-effects.js b/src/backend/effects/builtin/clear-effects.js index 58e05f825..e03b5fb8d 100644 --- a/src/backend/effects/builtin/clear-effects.js +++ b/src/backend/effects/builtin/clear-effects.js @@ -4,7 +4,7 @@ const webServer = require("../../../server/http-server-manager"); const frontendCommunicator = require("../../common/frontend-communicator"); const effectQueueRunner = require("../../effects/queues/effect-queue-runner"); const { EffectCategory } = require('../../../shared/effect-constants'); -const { settings } = require("../../common/settings-access"); +const { SettingsManager } = require("../../common/settings-manager"); const { abortAllEffectLists } = require("../../common/effect-abort-helpers"); /** @@ -39,7 +39,7 @@ const delay = { label="Overlay Effects" model="effect.overlay" /> -
+
- + - +
@@ -187,9 +187,9 @@ const showImage = { imageRotation: effect.rotation ? effect.rotation + effect.rotType : "0deg" }; - if (settings.useOverlayInstances()) { + if (SettingsManager.getSetting("UseOverlayInstances")) { if (effect.overlayInstance != null) { - if (settings.getOverlayInstances().includes(effect.overlayInstance)) { + if (SettingsManager.getSetting("OverlayInstances").includes(effect.overlayInstance)) { data.overlayInstance = effect.overlayInstance; } } diff --git a/src/backend/effects/builtin/show-text.js b/src/backend/effects/builtin/show-text.js index c4ccc3506..04a465b8d 100644 --- a/src/backend/effects/builtin/show-text.js +++ b/src/backend/effects/builtin/show-text.js @@ -1,6 +1,6 @@ "use strict"; -const { settings } = require("../../common/settings-access"); +const { SettingsManager } = require("../../common/settings-manager"); const webServer = require("../../../server/http-server-manager"); const logger = require("../../logwrapper"); const { EffectCategory } = require('../../../shared/effect-constants'); @@ -141,7 +141,7 @@ const showText = { $scope.editorClass = "text-editor-white-bg"; $scope.editorSettings = { - editorBackground: settingsService.getWysiwygBackground() + editorBackground: settingsService.getSetting("WysiwygBackground") }; function updateEditorClass() { @@ -154,7 +154,7 @@ const showText = { updateEditorClass(); $scope.editorBackgroundChanged = function() { - settingsService.setWysiwygBackground($scope.editorSettings.editorBackground); + settingsService.saveSetting("WysiwygBackground", $scope.editorSettings.editorBackground); updateEditorClass(); }; @@ -268,10 +268,10 @@ const showText = { dto.position = mediaProcessor.randomLocation(); //eslint-disable-line no-undef } - if (settings.useOverlayInstances()) { + if (SettingsManager.getSetting("UseOverlayInstances")) { if (dto.overlayInstance != null) { //reset overlay if it doesnt exist - if (!settings.getOverlayInstances().includes(dto.overlayInstance)) { + if (!SettingsManager.getSetting("OverlayInstances").includes(dto.overlayInstance)) { dto.overlayInstance = null; } } diff --git a/src/backend/events/twitch-events/gift-sub.ts b/src/backend/events/twitch-events/gift-sub.ts index d48aefb46..ef1db1933 100644 --- a/src/backend/events/twitch-events/gift-sub.ts +++ b/src/backend/events/twitch-events/gift-sub.ts @@ -1,6 +1,6 @@ import NodeCache from "node-cache"; import { DateTime } from "luxon"; -import { settings } from "../../common/settings-access"; +import { SettingsManager } from "../../common/settings-manager"; import eventManager from "../../events/EventManager"; import logger from "../../logwrapper"; @@ -36,7 +36,7 @@ export function triggerSubGift( giftSubMonths: number, streak: number ): void { - if (settings.ignoreSubsequentSubEventsAfterCommunitySub()) { + if (SettingsManager.getSetting("IgnoreSubsequentSubEventsAfterCommunitySub")) { logger.debug(`Attempting to process community gift sub from ${gifterDisplayName} at ${DateTime.now().toFormat("HH:mm:ss:SSS")}`); const cacheKey = `${gifterDisplayName}:${subPlan}`; diff --git a/src/backend/import/v4/areas/v4-overlay-instances-importer.js b/src/backend/import/v4/areas/v4-overlay-instances-importer.js index 35f90a537..ab34b1455 100644 --- a/src/backend/import/v4/areas/v4-overlay-instances-importer.js +++ b/src/backend/import/v4/areas/v4-overlay-instances-importer.js @@ -3,7 +3,7 @@ const path = require("path"); const logger = require("../../../logwrapper"); const importHelpers = require("../import-helpers"); -const { settings } = require("../../../common/settings-access"); +const { SettingsManager } = require("../../../common/settings-manager"); async function checkForV4SettingsFile() { @@ -29,12 +29,12 @@ exports.run = async () => { if (allV4Settings != null) { const useOverlayInstances = allV4Settings.settings.useOverlayInstances === true; - settings.setUseOverlayInstances(useOverlayInstances); + SettingsManager.saveSetting("UseOverlayInstances", useOverlayInstances); const overlayInstances = allV4Settings.settings.overlayInstances || []; - settings.setOverlayInstances(overlayInstances); + SettingsManager.saveSetting("OverlayInstances", overlayInstances); - settings.flushSettingsCache(); + SettingsManager.flushSettingsCache(); } } diff --git a/src/backend/import/v4/areas/v4-scripts-importer.js b/src/backend/import/v4/areas/v4-scripts-importer.js index cd7f98c94..bc72f788e 100644 --- a/src/backend/import/v4/areas/v4-scripts-importer.js +++ b/src/backend/import/v4/areas/v4-scripts-importer.js @@ -5,7 +5,7 @@ const logger = require("../../../logwrapper"); const importHelpers = require("../import-helpers"); const fse = require("fs-extra"); const profileManager = require("../../../common/profile-manager"); -const { settings } = require("../../../common/settings-access"); +const { SettingsManager } = require("../../../common/settings-manager"); const v4ScriptsPath = path.join(importHelpers.v4DataPath, "/scripts"); const v5ScriptsPath = profileManager.getPathInProfile("/scripts"); @@ -45,9 +45,9 @@ exports.run = async () => { if (allV4Settings != null) { const runCustomScripts = allV4Settings.settings.runCustomScripts === true; - settings.setCustomScriptsEnabled(runCustomScripts); + SettingsManager.saveSetting("RunCustomScripts", runCustomScripts); - settings.flushSettingsCache(); + SettingsManager.flushSettingsCache(); } } diff --git a/src/backend/integrations/builtin/aws/text-to-speech-polly-effect.js b/src/backend/integrations/builtin/aws/text-to-speech-polly-effect.js index d833ec871..d9eac842f 100644 --- a/src/backend/integrations/builtin/aws/text-to-speech-polly-effect.js +++ b/src/backend/integrations/builtin/aws/text-to-speech-polly-effect.js @@ -1,7 +1,7 @@ "use strict"; const { getPathInTmpDir } = require("../../../common/data-access"); -const { settings } = require("../../../common/settings-access"); +const { SettingsManager } = require("../../../common/settings-manager"); const resourceTokenManager = require("../../../resourceTokenManager"); const webServer = require("../../../../server/http-server-manager"); const { v4: uuid } = require("uuid"); @@ -359,7 +359,7 @@ const playSound = { }; $q.when(backendCommunicator.fireEventAsync("getAwsPollyVoices")) - .then(voices => { + .then((voices) => { $scope.isFetchingVoices = false; const voicesArray = voices.voices; @@ -455,7 +455,7 @@ const playSound = { }); $q.when(backendCommunicator.fireEventAsync("getAwsPollyLexicons")) - .then(lexicons => { + .then((lexicons) => { $scope.isFetchingLexicons = false; $scope.lexicons = lexicons.lexicons; @@ -471,7 +471,7 @@ const playSound = { /** * When the effect is saved */ - optionsValidator: effect => { + optionsValidator: (effect) => { const errors = []; if (effect.engine !== "standard" && effect.engine !== "neural") { @@ -491,7 +491,7 @@ const playSound = { /** * When the effect is triggered by something */ - onTriggerEvent: async event => { + onTriggerEvent: async (event) => { const effect = event.effect; const awsIntegration = integrationManager.getIntegrationDefinitionById("aws"); @@ -591,7 +591,7 @@ const playSound = { // Set output device. let selectedOutputDevice = effect.audioOutputDevice; if (selectedOutputDevice == null || selectedOutputDevice.label === "App Default") { - selectedOutputDevice = settings.getAudioOutputDevice(); + selectedOutputDevice = SettingsManager.getSetting("AudioOutputDevice"); } data.audioOutputDevice = selectedOutputDevice; diff --git a/src/backend/integrations/integration-manager.js b/src/backend/integrations/integration-manager.js index 22ad4b839..3d6918c29 100644 --- a/src/backend/integrations/integration-manager.js +++ b/src/backend/integrations/integration-manager.js @@ -5,7 +5,7 @@ const profileManager = require("../common/profile-manager"); const authManager = require("../auth/auth-manager"); const EventEmitter = require("events"); const { shell } = require('electron'); -const { settings } = require('../common/settings-access'); +const { SettingsManager } = require('../common/settings-manager'); const frontEndCommunicator = require('../common/frontend-communicator'); const { setValuesForFrontEnd, buildSaveDataFromSettingValues } = require("../common/firebot-setting-helpers"); @@ -63,7 +63,7 @@ class IntegrationManager extends EventEmitter { global.renderWindow.webContents.send("integrationsUpdated"); } - integration.integration.on("connected", id => { + integration.integration.on("connected", (id) => { renderWindow.webContents.send("integrationConnectionUpdate", { id: id, connected: true @@ -72,7 +72,7 @@ class IntegrationManager extends EventEmitter { logger.info(`Successfully connected to ${id}`); }); - integration.integration.on("disconnected", id => { + integration.integration.on("disconnected", (id) => { renderWindow.webContents.send("integrationConnectionUpdate", { id: id, connected: false @@ -81,7 +81,7 @@ class IntegrationManager extends EventEmitter { logger.info(`Disconnected from ${id}`); }); - integration.integration.on("reconnect", id => { + integration.integration.on("reconnect", (id) => { logger.debug(`Reconnecting to ${id}...`); this.connectIntegration(id); }); @@ -158,7 +158,7 @@ class IntegrationManager extends EventEmitter { getAllIntegrationDefinitions() { return this._integrations .map(i => i.definition) - .map(i => { + .map((i) => { return { id: i.id, name: i.name, @@ -210,7 +210,7 @@ class IntegrationManager extends EventEmitter { } if (int.definition.linkType === "auth") { - shell.openExternal(`http://localhost:${settings.getWebServerPort()}/api/v1/auth?providerId=${encodeURIComponent(int.definition.authProviderDetails.id)}`); + shell.openExternal(`http://localhost:${SettingsManager.getSetting("WebServerPort")}/api/v1/auth?providerId=${encodeURIComponent(int.definition.authProviderDetails.id)}`); } else if (int.definition.linkType === "id") { frontEndCommunicator.send("requestIntegrationAccountId", { integrationId: int.definition.id, @@ -419,7 +419,7 @@ ipcMain.on("disconnectIntegration", (event, integrationId) => { manager.disconnectIntegration(integrationId); }); -ipcMain.on("getAllIntegrationDefinitions", event => { +ipcMain.on("getAllIntegrationDefinitions", (event) => { logger.info("got 'get all integrations' request"); event.returnValue = manager.getAllIntegrationDefinitions(); }); diff --git a/src/backend/quick-actions/quick-action-manager.js b/src/backend/quick-actions/quick-action-manager.js index fd8c93827..f6cf25f5e 100644 --- a/src/backend/quick-actions/quick-action-manager.js +++ b/src/backend/quick-actions/quick-action-manager.js @@ -6,7 +6,7 @@ const effectRunner = require("../common/effect-runner"); const presetEffectListManager = require("../effects/preset-lists/preset-effect-list-manager"); const { EffectTrigger } = require("../../shared/effect-constants"); const accountAccess = require("../common/account-access"); -const { settings } = require("../common/settings-access"); +const { SettingsManager } = require("../common/settings-manager"); /** @typedef {import("../../shared/types").QuickActionDefinition} QuickActionDefinition */ @@ -55,10 +55,10 @@ class QuickActionManager extends JsonDbManager { if (!savedQuickAction) { return; } - const quickActionSettings = settings.getQuickActionSettings(); + const quickActionSettings = SettingsManager.getSetting("QuickActions"); if (!Object.keys(quickActionSettings).includes(quickAction.id)) { quickActionSettings[quickAction.id] = { enabled: true, position: Object.keys(quickActionSettings).length }; - settings.setQuickActionSettings(quickActionSettings); + SettingsManager.saveSetting("QuickActions", quickActionSettings); } if (notify) { this.triggerUiRefresh(); @@ -68,9 +68,9 @@ class QuickActionManager extends JsonDbManager { deleteQuickAction(customQuickActionId) { if (super.deleteItem(customQuickActionId)) { - const quickActionSettings = settings.getQuickActionSettings(); + const quickActionSettings = SettingsManager.getSetting("QuickActions"); delete quickActionSettings[customQuickActionId]; - settings.setQuickActionSettings(quickActionSettings); + SettingsManager.saveSetting("QuickActions", quickActionSettings); } } diff --git a/src/backend/twitch-api/ad-manager.ts b/src/backend/twitch-api/ad-manager.ts index 837c4544d..a25efb34c 100644 --- a/src/backend/twitch-api/ad-manager.ts +++ b/src/backend/twitch-api/ad-manager.ts @@ -4,7 +4,7 @@ import logger from "../logwrapper"; import accountAccess from "../common/account-access"; import twitchApi from "./api"; import frontendCommunicator from "../common/frontend-communicator"; -import { settings } from "../common/settings-access"; +import { SettingsManager } from "../common/settings-manager"; import eventManager from "../events/EventManager"; class AdManager { @@ -59,7 +59,7 @@ class AdManager { duration: adSchedule.duration }); - const upcomingTriggerMinutes = Number(settings.getTriggerUpcomingAdBreakMinutes()); + const upcomingTriggerMinutes = Number(SettingsManager.getSetting("TriggerUpcomingAdBreakMinutes")); const minutesUntilNextAdBreak = this.secondsUntilNextAdBreak / 60; if (upcomingTriggerMinutes > 0 diff --git a/src/backend/twitch-api/stream-info-manager.ts b/src/backend/twitch-api/stream-info-manager.ts index 99b96f5ac..3a801bd7d 100644 --- a/src/backend/twitch-api/stream-info-manager.ts +++ b/src/backend/twitch-api/stream-info-manager.ts @@ -2,7 +2,7 @@ import { DateTime } from "luxon"; import axios from "axios"; import logger from "../logwrapper"; import accountAccess from "../common/account-access"; -import { settings } from "../common/settings-access"; +import { SettingsManager } from "../common/settings-manager"; import frontendCommunicator from "../common/frontend-communicator"; import TwitchApi from "./api"; import { @@ -93,7 +93,7 @@ class TwitchStreamInfoManager { this.streamInfo.viewers = stream.viewers; this.streamInfo.startedAt = stream.startDate; - if (settings.getWebOnlineCheckin() === true) { + if (SettingsManager.getSetting("WebOnlineCheckin") === true) { await this.doWebCheckin(); } diff --git a/src/backend/variables/builtin/twitch/chat/message/chat-message-text-only.ts b/src/backend/variables/builtin/twitch/chat/message/chat-message-text-only.ts index 019c1fffe..fc366b6a1 100644 --- a/src/backend/variables/builtin/twitch/chat/message/chat-message-text-only.ts +++ b/src/backend/variables/builtin/twitch/chat/message/chat-message-text-only.ts @@ -52,10 +52,10 @@ const model: ReplaceVariable = { .filter(tp => tp !== ""); // Trim the command trigger if this was a command, unless an optional argument of false was provided. - if (trigger?.type === EffectTrigger.COMMAND && trigger?.metadata?.command?.trigger !== null && + if (trigger?.type === EffectTrigger.COMMAND && trigger?.metadata?.userCommand?.trigger !== null && (args.length < 1 || !(args[0] === false || `${args[0]}`.toLowerCase() === "false"))) { - const triggerRegex = new RegExp(trigger.metadata.command.trigger, "i"); + const triggerRegex = new RegExp(trigger.metadata.userCommand.trigger, "i"); const triggerIndex = textParts.findIndex(tp => triggerRegex.test(tp)); if (triggerIndex >= 0) { diff --git a/src/backend/viewers/viewer-database.ts b/src/backend/viewers/viewer-database.ts index 927b83df5..819da270a 100644 --- a/src/backend/viewers/viewer-database.ts +++ b/src/backend/viewers/viewer-database.ts @@ -3,7 +3,7 @@ import Datastore from "@seald-io/nedb"; import { DateTime } from "luxon"; import { BasicViewer, FirebotViewer } from "../../types/viewers"; -import { settings } from "../common/settings-access"; +import { SettingsManager } from "../common/settings-manager"; import logger from "../logwrapper"; import profileManager from "../common/profile-manager"; import accountAccess from "../common/account-access"; @@ -138,7 +138,7 @@ class ViewerDatabase extends EventEmitter { * @returns `true` if the viewer database is enabled, or `false` otherwise */ isViewerDBOn(): boolean { - return settings.getViewerDbStatus(); + return SettingsManager.getSetting("ViewerDB"); } async connectViewerDatabase(): Promise { diff --git a/src/backend/viewers/viewer-online-status-manager.ts b/src/backend/viewers/viewer-online-status-manager.ts index fcb0e79f5..13235f7c1 100644 --- a/src/backend/viewers/viewer-online-status-manager.ts +++ b/src/backend/viewers/viewer-online-status-manager.ts @@ -1,7 +1,7 @@ import { BasicViewer, FirebotViewer } from "../../types/viewers"; import logger from "../logwrapper"; -import { settings } from "../common/settings-access"; +import { SettingsManager } from "../common/settings-manager"; import viewerDatabase from "./viewer-database"; import chatRolesManager from "../roles/chat-roles-manager"; import connectionManager from "../common/connection-manager"; @@ -100,7 +100,7 @@ class ViewerOnlineStatusManager { lastSeen: now }; - if (await chatRolesManager.userIsKnownBot(viewer.id) === true && settings.getAutoFlagBots()) { + if (await chatRolesManager.userIsKnownBot(viewer.id) === true && SettingsManager.getSetting("AutoFlagBots")) { dbData.disableAutoStatAccrual = true; dbData.disableActiveUserList = true; } diff --git a/src/gui/app/app-main.js b/src/gui/app/app-main.js index 5c32fb97c..7c9bbcd24 100644 --- a/src/gui/app/app-main.js +++ b/src/gui/app/app-main.js @@ -194,8 +194,8 @@ connectionService.validateAccounts(); ttsService.obtainVoices().then(() => { - if (settingsService.getDefaultTtsVoiceId() == null) { - settingsService.setDefaultTtsVoiceId(ttsService.getOsDefaultVoiceId()); + if (settingsService.getSetting("DefaultTtsVoiceId") == null) { + settingsService.saveSetting("DefaultTtsVoiceId", ttsService.getOsDefaultVoiceId()); } }); @@ -390,12 +390,12 @@ //$scope.accounts = connectionService.accounts; //$scope.profiles = connectionService.profiles; - if (settingsService.hasJustUpdated()) { + if (settingsService.getSetting("JustUpdated")) { utilityService.showUpdatedModal(); - settingsService.setJustUpdated(false); - } else if (settingsService.isFirstTimeUse()) { + settingsService.saveSetting("JustUpdated", false); + } else if (settingsService.getSetting("FirstTimeUse")) { utilityService.showSetupWizard(); - settingsService.setFirstTimeUse(false); + settingsService.saveSetting("FirstTimeUse", false); } /** @@ -415,7 +415,7 @@ // Apply Theme $scope.appTheme = function() { - return settingsService.getTheme(); + return settingsService.getSetting("Theme"); }; $rootScope.showSpinner = false; @@ -516,7 +516,7 @@ app.filter("hideBotMessages", function(settingsService, accountAccess) { return function(elements) { - const shouldHide = settingsService.chatHideBotAccountMessages(); + const shouldHide = settingsService.getSetting("ChatHideBotAccountMessages"); if (!shouldHide) { return elements; } @@ -533,7 +533,7 @@ app.filter("hideWhispers", function(settingsService) { return function(elements) { - const shouldHide = settingsService.getChatHideWhispers(); + const shouldHide = settingsService.getSetting("ChatHideWhispers"); if (!shouldHide) { return elements; } diff --git a/src/gui/app/controllers/chat-messages.controller.js b/src/gui/app/controllers/chat-messages.controller.js index f7d934157..acfde9dbb 100644 --- a/src/gui/app/controllers/chat-messages.controller.js +++ b/src/gui/app/controllers/chat-messages.controller.js @@ -44,7 +44,7 @@ }; $scope.updateLayoutSettings = (updatedSettings) => { - let settings = settingsService.getDashboardLayoutSettings(); + let settings = settingsService.getSetting("DashboardLayout"); if (settings == null) { settings = { @@ -53,7 +53,7 @@ dashboardActivityFeed: "275px" }; - settingsService.setDashboardLayoutSettings(settings); + settingsService.saveSetting("DashboardLayout", settings); } if (updatedSettings) { @@ -61,7 +61,7 @@ settings[key] = value; }); - settingsService.setDashboardLayoutSettings(settings); + settingsService.saveSetting("DashboardLayout", settings); } $scope.layout = settings; @@ -72,17 +72,17 @@ function getUpdatedChatSettings() { $scope.updateLayoutSettings(); - $scope.compactDisplay = settingsService.isChatCompactMode(); - $scope.alternateBackgrounds = settingsService.chatAlternateBackgrounds(); - $scope.hideDeletedMessages = settingsService.chatHideDeletedMessages(); - $scope.showAvatars = settingsService.getShowAvatars(); - $scope.showTimestamps = settingsService.getShowTimestamps(); - $scope.showBttvEmotes = settingsService.getShowBttvEmotes(); - $scope.showFfzEmotes = settingsService.getShowFfzEmotes(); - $scope.showSevenTvEmotes = settingsService.getShowSevenTvEmotes(); - $scope.showPronouns = settingsService.getShowPronouns(); - $scope.customFontSizeEnabled = settingsService.getChatCustomFontSizeEnabled(); - $scope.customFontSize = settingsService.getChatCustomFontSize(); + $scope.compactDisplay = settingsService.getSetting("ChatCompactMode"); + $scope.alternateBackgrounds = settingsService.getSetting("ChatAlternateBackgrounds"); + $scope.hideDeletedMessages = settingsService.getSetting("ChatHideDeletedMessages"); + $scope.showAvatars = settingsService.getSetting("ChatAvatars"); + $scope.showTimestamps = settingsService.getSetting("ChatTimestamps"); + $scope.showBttvEmotes = settingsService.getSetting("ChatShowBttvEmotes"); + $scope.showFfzEmotes = settingsService.getSetting("ChatShowFfzEmotes"); + $scope.showSevenTvEmotes = settingsService.getSetting("ChatShowSevenTvEmotes"); + $scope.showPronouns = settingsService.getSetting("ChatPronouns"); + $scope.customFontSizeEnabled = settingsService.getSetting("ChatCustomFontSizeEnabled"); + $scope.customFontSize = settingsService.getSetting("ChatCustomFontSize"); $scope.customFontSizeStyle = $scope.customFontSizeEnabled ? `font-size: ${$scope.customFontSize}px !important;` : ""; } diff --git a/src/gui/app/controllers/settings.controller.js b/src/gui/app/controllers/settings.controller.js index 92299caef..10f8991ae 100644 --- a/src/gui/app/controllers/settings.controller.js +++ b/src/gui/app/controllers/settings.controller.js @@ -96,7 +96,7 @@ }; $scope.getSelectedVoiceName = () => { - const selectedVoiceId = settingsService.getDefaultTtsVoiceId(); + const selectedVoiceId = settingsService.getSetting("DefaultTtsVoiceId"); const voice = ttsService.getVoiceById(selectedVoiceId); return voice ? voice.name : "Unknown Voice"; }; @@ -107,7 +107,7 @@ }, {}); $scope.ttsVolumeSlider = { - value: settingsService.getTtsVoiceVolume(), + value: settingsService.getSetting("TtsVoiceVolume"), options: { floor: 0, ceil: 1, @@ -117,20 +117,20 @@ return Math.floor(value * 10); }, onChange: (_, value) => { - settingsService.setTtsVoiceVolume(value); + settingsService.saveSetting("TtsVoiceVolume", value); } } }; $scope.ttsRateSlider = { - value: settingsService.getTtsVoiceRate(), + value: settingsService.getSetting("TtsVoiceRate"), options: { floor: 0.1, ceil: 10, step: 0.1, precision: 1, onChange: (_, value) => { - settingsService.setTtsVoiceRate(value); + settingsService.saveSetting("TtsVoiceRate", value); } } }; @@ -183,10 +183,10 @@ backupService.startBackup(); }; - $scope.currentMaxBackups = settingsService.maxBackupCount(); + $scope.currentMaxBackups = settingsService.getSetting("MaxBackupCount"); $scope.updateMaxBackups = function(option) { - settingsService.setMaxBackupCount(option); + settingsService.saveSetting("MaxBackupCount", option); }; $scope.openDevTools = () => { @@ -209,10 +209,10 @@ }; $scope.toggleWhileLoops = () => { - const whileLoopsEnabled = settingsService.getWhileLoopEnabled(); + const whileLoopsEnabled = settingsService.getSetting("WhileLoopEnabled"); if (whileLoopsEnabled) { - settingsService.setWhileLoopEnabled(false); + settingsService.saveSetting("WhileLoopEnabled", false); } else { utilityService .showConfirmationModal({ @@ -223,26 +223,12 @@ }) .then((confirmed) => { if (confirmed) { - settingsService.setWhileLoopEnabled(true); + settingsService.saveSetting("WhileLoopEnabled", true); } }); } }; - $scope.setActiveChatUsers = (value) => { - value = value === true; - settingsService.setActiveChatUsers(value); - ipcRenderer.send("setActiveChatUsers", value); - }; - - $scope.setActiveChatUserTimeout = (value) => { - if (value == null) { - value = "10"; - } - settingsService.setActiveChatUserListTimeout(value); - ipcRenderer.send('setActiveChatUserTimeout', value); - }; - $scope.audioOutputDevices = [{ label: "System Default", deviceId: "default" @@ -281,12 +267,12 @@ } ); - if (settingsService.getAutoUpdateLevel() > 3) { - settingsService.setAutoUpdateLevel(3); + if (settingsService.getSetting("AutoUpdateLevel") > 3) { + settingsService.saveSetting("AutoUpdateLevel", 3); } $scope.autoUpdateSlider = { - value: settingsService.getAutoUpdateLevel(), + value: settingsService.getSetting("AutoUpdateLevel"), options: { showSelectionBar: true, showTicks: true, @@ -312,7 +298,7 @@ return "orange"; }, onChange: function() { - settingsService.setAutoUpdateLevel($scope.autoUpdateSlider.value); + settingsService.saveSetting("AutoUpdateLevel", $scope.autoUpdateSlider.value); } } }; @@ -332,7 +318,7 @@ } }; - $scope.currentPort = settingsService.getWebSocketPort(); + $scope.currentPort = settingsService.getSetting("WebServerPort"); /** * Modals @@ -476,47 +462,5 @@ }; utilityService.showModal(showBackupListModalContext); }; - - $scope.showChangePortModal = function() { - const showChangePortModalContext = { - templateUrl: "changePortModal.html", - size: "sm", - controllerFunc: ($scope, settingsService, $uibModalInstance) => { - $scope.newPort = settingsService.getWebSocketPort(); - - $scope.newPortError = false; - - // When the user clicks a call to action that will close the modal, such as "Save" - $scope.changePort = function() { - // validate port number - const newPort = $scope.newPort; - if ( - newPort == null || - newPort === "" || - newPort <= 1024 || - newPort >= 49151 - ) { - $scope.newPortError = true; - return; - } - - // Save port. This will save to both firebot and the overlay. - settingsService.setWebSocketPort(newPort); - - $uibModalInstance.close(newPort); - }; - - // When they hit cancel, click the little x, or click outside the modal, we don't want to do anything. - $scope.dismiss = function() { - $uibModalInstance.dismiss("cancel"); - }; - }, - closeCallback: (port) => { - // Update the local port scope var so setting input updates - $scope.currentPort = port; - } - }; - utilityService.showModal(showChangePortModalContext); - }; }); }()); diff --git a/src/gui/app/controllers/viewers.controller.js b/src/gui/app/controllers/viewers.controller.js index 41efdc2bf..5037770f5 100644 --- a/src/gui/app/controllers/viewers.controller.js +++ b/src/gui/app/controllers/viewers.controller.js @@ -7,7 +7,7 @@ .controller("viewersController", function($route, $scope, viewersService, currencyService, utilityService, settingsService) { - $scope.viewerTablePageSize = settingsService.getViewerListPageSize(); + $scope.viewerTablePageSize = settingsService.getSetting("ViewerListPageSize"); $scope.showUserDetailsModal = (userId) => { const closeFunc = () => { diff --git a/src/gui/app/directives/chat/quick-actions/quick-actions.js b/src/gui/app/directives/chat/quick-actions/quick-actions.js index 060825087..51604674e 100644 --- a/src/gui/app/directives/chat/quick-actions/quick-actions.js +++ b/src/gui/app/directives/chat/quick-actions/quick-actions.js @@ -64,10 +64,10 @@ $scope.quickActionsService = quickActionsService; $scope.logger = logger; - $ctrl.settings = settingsService.getQuickActionSettings(); + $ctrl.settings = settingsService.getSetting("QuickActions"); backendCommunicator.on("all-quick-actions", () => { - $ctrl.settings = settingsService.getQuickActionSettings(); + $ctrl.settings = settingsService.getSetting("QuickActions"); }); $ctrl.triggerQuickAction = (quickActionId) => { @@ -90,7 +90,7 @@ }; }); - settingsService.setQuickActionSettings($ctrl.settings); + settingsService.saveSetting("QuickActions", $ctrl.settings); } else { let highestPosition = Math.max(...Object.values($ctrl.settings).map(s => s.position)); quickActionsService.quickActions.forEach((qa) => { @@ -149,7 +149,7 @@ settings: () => $ctrl.settings }, dismissCallback: () => { - settingsService.setQuickActionSettings($ctrl.settings); + settingsService.saveSetting("QuickActions", $ctrl.settings); } }); }; diff --git a/src/gui/app/directives/effect-option-settings/eosAudioOutputDevice.js b/src/gui/app/directives/effect-option-settings/eosAudioOutputDevice.js index e7f44d04c..1b2609e86 100644 --- a/src/gui/app/directives/effect-option-settings/eosAudioOutputDevice.js +++ b/src/gui/app/directives/effect-option-settings/eosAudioOutputDevice.js @@ -49,7 +49,7 @@ }; } - $q.when(navigator.mediaDevices.enumerateDevices()).then(deviceList => { + $q.when(navigator.mediaDevices.enumerateDevices()).then((deviceList) => { deviceList = deviceList .filter( d => @@ -57,7 +57,7 @@ d.deviceId !== "communications" && d.deviceId !== "default" ) - .map(d => { + .map((d) => { return { label: d.label, deviceId: d.deviceId }; }); @@ -68,7 +68,7 @@ if (ctrl.effect.overlayInstance != null) { if ( !settingsService - .getOverlayInstances() + .getSetting("OverlayInstances") .includes(ctrl.effect.overlayInstance) ) { ctrl.effect.overlayInstance = null; diff --git a/src/gui/app/directives/effect-option-settings/eosOverlayInstance.js b/src/gui/app/directives/effect-option-settings/eosOverlayInstance.js index a0026ef13..4c769b654 100644 --- a/src/gui/app/directives/effect-option-settings/eosOverlayInstance.js +++ b/src/gui/app/directives/effect-option-settings/eosOverlayInstance.js @@ -10,14 +10,14 @@ padTop: "<" }, template: ` - +
@@ -34,7 +34,7 @@ if (ctrl.effect.overlayInstance != null) { if ( !settingsService - .getOverlayInstances() + .getSetting("OverlayInstances") .includes(ctrl.effect.overlayInstance) ) { ctrl.effect.overlayInstance = null; diff --git a/src/gui/app/directives/misc/stream-info.component.js b/src/gui/app/directives/misc/stream-info.component.js index 8d62a062e..cf8548ff6 100644 --- a/src/gui/app/directives/misc/stream-info.component.js +++ b/src/gui/app/directives/misc/stream-info.component.js @@ -9,19 +9,19 @@ bindings: {}, template: `
-
+
{{sessionTimeDisplay}}
-
+
{{sis.streamInfo.viewers}}
- + - +
`, controller: function($scope, streamInfoService, settingsService, hypeTrainService, adBreakService, $interval) { diff --git a/src/gui/app/directives/modals/chat/chat-settings-modal.js b/src/gui/app/directives/modals/chat/chat-settings-modal.js index 9f0981b93..5af48c1ea 100644 --- a/src/gui/app/directives/modals/chat/chat-settings-modal.js +++ b/src/gui/app/directives/modals/chat/chat-settings-modal.js @@ -13,17 +13,17 @@
Main Settings
@@ -78,42 +78,42 @@
-
+
@@ -122,7 +122,7 @@
Emote Settings
@@ -201,25 +201,25 @@ onlyStreamer: "Only when I /clear", always: "When I or mods /clear" }; - $scope.chatFeedMode = settingsService.getClearChatFeedMode(); - $scope.setChatFeedMode = mode => settingsService.setClearChatFeedMode(mode); + $scope.chatFeedMode = settingsService.getSetting("ClearChatFeedMode"); + $scope.setChatFeedMode = mode => settingsService.saveSetting("ClearChatFeedMode", mode); - $scope.compactMode = settingsService.isChatCompactMode(); + $scope.compactMode = settingsService.getSetting("ChatCompactMode"); $scope.toggleCompactMode = function() { $scope.compactMode = !$scope.compactMode; - settingsService.setChatCompactMode($scope.compactMode); + settingsService.saveSetting("ChatCompactMode", $scope.compactMode); }; $scope.playNotification = function() { soundService.playChatNotification(); }; - $scope.selectedNotificationSound = settingsService.getTaggedNotificationSound(); + $scope.selectedNotificationSound = settingsService.getSetting("ChatTaggedNotificationSound"); - $scope.notificationVolume = settingsService.getTaggedNotificationVolume(); + $scope.notificationVolume = settingsService.getSetting("ChatTaggedNotificationVolume"); $scope.volumeUpdated = function() { - settingsService.setTaggedNotificationVolume($scope.notificationVolume); + settingsService.saveSetting("ChatTaggedNotificationVolume", $scope.notificationVolume); }; $scope.sliderOptions = { @@ -248,7 +248,7 @@ $rootScope.$broadcast("rzSliderForceRender"); }, 50); - settingsService.setTaggedNotificationSound({ + settingsService.saveSetting("ChatTaggedNotificationSound", { name: sound.name, path: sound.name === "Custom" ? sound.path : undefined }); @@ -257,28 +257,28 @@ $scope.setShowThirdPartyEmotes = (party) => { switch (party) { case "bttv": - settingsService.setShowBttvEmotes(!settingsService.getShowBttvEmotes()); + settingsService.saveSetting("ChatShowBttvEmotes", !settingsService.getSetting("ChatShowBttvEmotes")); break; case "ffz": - settingsService.setShowFfzEmotes(!settingsService.getShowFfzEmotes()); + settingsService.saveSetting("ChatShowFfzEmotes", !settingsService.getSetting("ChatShowFfzEmotes")); break; case "7tv": - settingsService.setShowSevenTvEmotes(!settingsService.getShowSevenTvEmotes()); + settingsService.saveSetting("ChatShowSevenTvEmotes", !settingsService.getSetting("ChatShowSevenTvEmotes")); } chatMessagesService.refreshEmotes(); }; $scope.toggleCustomFontEnabled = () => { - settingsService.setChatCustomFontSizeEnabled(!settingsService.getChatCustomFontSizeEnabled()); + settingsService.saveSetting("ChatCustomFontSizeEnabled", !settingsService.getSetting("ChatCustomFontSizeEnabled")); $timeout(() => { $rootScope.$broadcast("rzSliderForceRender"); }, 50); }; - $scope.customFontSize = settingsService.getChatCustomFontSize(); + $scope.customFontSize = settingsService.getSetting("ChatCustomFontSize"); $scope.fontSizeUpdated = function() { - settingsService.setChatCustomFontSize($scope.customFontSize); + settingsService.saveSetting("ChatCustomFontSize", $scope.customFontSize); }; $scope.fontSliderOptions = { floor: 10, diff --git a/src/gui/app/directives/modals/chat/edit-activity-events-modal.js b/src/gui/app/directives/modals/chat/edit-activity-events-modal.js index 11c4537ce..3dbefbb98 100644 --- a/src/gui/app/directives/modals/chat/edit-activity-events-modal.js +++ b/src/gui/app/directives/modals/chat/edit-activity-events-modal.js @@ -18,21 +18,21 @@ Select All -
+
{{event.eventName}} ({{event.sourceName}}) -
+
@@ -52,11 +52,11 @@ $ctrl.events = []; - $ctrl.allowedEvents = settingsService.getAllowedActivityEvents(); + $ctrl.allowedEvents = settingsService.getSetting("AllowedActivityEvents"); $q.when(backendCommunicator .fireEventAsync("get-activity-feed-supported-events")) - .then(supportedEvents => { + .then((supportedEvents) => { if (supportedEvents != null) { $ctrl.events = supportedEvents; } @@ -90,7 +90,7 @@ $ctrl.save = () => { console.log($ctrl.allowedEvents); - settingsService.setAllowedActivityEvents($ctrl.allowedEvents); + settingsService.saveSetting("AllowedActivityEvents", $ctrl.allowedEvents); $ctrl.close(); }; diff --git a/src/gui/app/directives/modals/commands/addOrEditCustomCommand/addOrEditCustomCommandModal.js b/src/gui/app/directives/modals/commands/addOrEditCustomCommand/addOrEditCustomCommandModal.js index ceebce9dc..bc3d7db95 100644 --- a/src/gui/app/directives/modals/commands/addOrEditCustomCommand/addOrEditCustomCommandModal.js +++ b/src/gui/app/directives/modals/commands/addOrEditCustomCommand/addOrEditCustomCommandModal.js @@ -19,7 +19,7 @@ $ctrl.command = { active: true, - simple: !settingsService.getDefaultToAdvancedCommandMode(), + simple: !settingsService.getSetting("DefaultToAdvancedCommandMode"), sendCooldownMessage: true, cooldownMessage: "This command is still on cooldown for: {timeLeft}", cooldown: {}, @@ -96,9 +96,9 @@ $ctrl.command.simple = !$ctrl.command.simple; if ($ctrl.isNewCommand && - !settingsService.getDefaultToAdvancedCommandMode() && - !settingsService.getSeenAdvancedCommandModePopup()) { - settingsService.setSeenAdvancedCommandModePopup(true); + !settingsService.getSetting("DefaultToAdvancedCommandMode") && + !settingsService.getSetting("SeenAdvancedCommandModePopup")) { + settingsService.saveSetting("SeenAdvancedCommandModePopup", true); utilityService.showConfirmationModal({ title: "Default Mode", question: `Do you want to always use Advanced Mode for new Commands?`, @@ -109,7 +109,7 @@ cancelBtnType: "btn-default" }).then((confirmed) => { if (confirmed) { - settingsService.setDefaultToAdvancedCommandMode(true); + settingsService.saveSetting("DefaultToAdvancedCommandMode", true); ngToast.create({ className: 'success', content: "New commands will now default to Advanced Mode.", diff --git a/src/gui/app/directives/modals/misc/connectionPanelModal.js b/src/gui/app/directives/modals/misc/connectionPanelModal.js index 9c791b576..0cd961d96 100644 --- a/src/gui/app/directives/modals/misc/connectionPanelModal.js +++ b/src/gui/app/directives/modals/misc/connectionPanelModal.js @@ -91,7 +91,7 @@ $ctrl.toggledServiceIsChecked = function(service) { - let sidebarControlledServices = settingsService.getSidebarControlledServices(); + let sidebarControlledServices = settingsService.getSetting("SidebarControlledServices"); if (sidebarControlledServices.includes(service)) { sidebarControlledServices = sidebarControlledServices.filter( s => s !== service @@ -99,11 +99,11 @@ } else { sidebarControlledServices.push(service); } - settingsService.setSidebarControlledServices(sidebarControlledServices); + settingsService.saveSetting("SidebarControlledServices", sidebarControlledServices); }; $ctrl.serviceIsChecked = function(service) { - const sidebarControlledServices = settingsService.getSidebarControlledServices(); + const sidebarControlledServices = settingsService.getSetting("SidebarControlledServices"); return sidebarControlledServices.includes(service); }; diff --git a/src/gui/app/directives/modals/misc/create-overlay-instances.modal.js b/src/gui/app/directives/modals/misc/create-overlay-instances.modal.js index d536528d6..6c738d56f 100644 --- a/src/gui/app/directives/modals/misc/create-overlay-instances.modal.js +++ b/src/gui/app/directives/modals/misc/create-overlay-instances.modal.js @@ -37,7 +37,7 @@ $ctrl.create = () => { if ( settingsService - .getOverlayInstances() + .getSetting("OverlayInstances") .includes($ctrl.name) || $ctrl.name === "" ) { $ctrl.createError = true; diff --git a/src/gui/app/directives/modals/misc/edit-overlay-instances-modal.js b/src/gui/app/directives/modals/misc/edit-overlay-instances-modal.js index 451571997..30e43d645 100644 --- a/src/gui/app/directives/modals/misc/edit-overlay-instances-modal.js +++ b/src/gui/app/directives/modals/misc/edit-overlay-instances-modal.js @@ -45,25 +45,23 @@ const $ctrl = this; $ctrl.getOverlayInstances = () => { - return settingsService.getOverlayInstances(); + return settingsService.getSetting("OverlayInstances"); }; - $ctrl.usingObs = settingsService.getOverlayCompatibility() === "OBS"; - $ctrl.deleteOverlayInstanceAtIndex = (index) => { - const instances = settingsService.getOverlayInstances(); + const instances = settingsService.getSetting("OverlayInstances"); instances.splice(index, 1); - settingsService.setOverlayInstances(instances); + settingsService.saveSetting("OverlayInstances", instances); }; const addOverlayInstance = (overlayInstance) => { - const instances = settingsService.getOverlayInstances(); + const instances = settingsService.getSetting("OverlayInstances"); instances.push(overlayInstance); - settingsService.setOverlayInstances(instances); + settingsService.saveSetting("OverlayInstances", instances); }; $ctrl.showViewUrlModal = (instanceName) => { @@ -73,7 +71,7 @@ $ctrl.showCreateInstanceModal = () => { utilityService.showModal({ component: "createOverlayInstancesModal", - closeCallback: response => { + closeCallback: (response) => { addOverlayInstance(response.instanceName); } }); diff --git a/src/gui/app/directives/modals/misc/setupWizardModal.js b/src/gui/app/directives/modals/misc/setupWizardModal.js index 5aab0156b..ea119614d 100644 --- a/src/gui/app/directives/modals/misc/setupWizardModal.js +++ b/src/gui/app/directives/modals/misc/setupWizardModal.js @@ -222,7 +222,7 @@

Would you like to be featured on our website during your live streams?

@@ -373,7 +373,7 @@ $ctrl.v4DataDetected = false; backendCommunicator.fireEventAsync("v4-data-check") - .then(detected => { + .then((detected) => { $ctrl.v4DataDetected = detected; }); @@ -406,11 +406,11 @@ $ctrl.importStarted = true; }); - backendCommunicator.on("v4-import-update", data => { + backendCommunicator.on("v4-import-update", (data) => { $ctrl.currentlyImporting = data.importing; }); - backendCommunicator.on("v4-import-complete", data => { + backendCommunicator.on("v4-import-complete", (data) => { $ctrl.importCompleted = true; $ctrl.importStarted = false; $ctrl.importSuccess = data.success; @@ -492,7 +492,7 @@ $ctrl.startBackupRestoreProcess = () => { backupService.openBackupZipFilePicker() - .then(backupFilePath => { + .then((backupFilePath) => { if (backupFilePath != null) { backupService.initiateBackupRestore(backupFilePath); } diff --git a/src/gui/app/directives/modals/viewers/viewerDetailsModal.js b/src/gui/app/directives/modals/viewers/viewerDetailsModal.js index 274627707..f8a5305cd 100644 --- a/src/gui/app/directives/modals/viewers/viewerDetailsModal.js +++ b/src/gui/app/directives/modals/viewers/viewerDetailsModal.js @@ -191,7 +191,7 @@ $ctrl.hasFirebotData = false; - $ctrl.viewerDbEnabled = settingsService.getViewerDB(); + $ctrl.viewerDbEnabled = settingsService.getSetting("ViewerDB"); $ctrl.accountAccess = accountAccess; diff --git a/src/gui/app/directives/settings/categories/advanced-settings.js b/src/gui/app/directives/settings/categories/advanced-settings.js index 057de40a9..f2871d642 100644 --- a/src/gui/app/directives/settings/categories/advanced-settings.js +++ b/src/gui/app/directives/settings/categories/advanced-settings.js @@ -8,69 +8,69 @@ template: `
- Firebot must be restarted for changes to this setting to take effect. - - If you aren't careful, you can cause an infinite loop and freeze Firebot. - - We recommend that you make a backup first, just in case. - - - - - @@ -86,10 +86,10 @@ $scope.settings = settingsService; $scope.toggleWhileLoops = () => { - const whileLoopsEnabled = settingsService.getWhileLoopEnabled(); + const whileLoopsEnabled = settingsService.getSetting("WhileLoopEnabled"); if (whileLoopsEnabled) { - settingsService.setWhileLoopEnabled(false); + settingsService.saveSetting("WhileLoopEnabled", false); } else { utilityService .showConfirmationModal({ @@ -98,9 +98,9 @@ confirmLabel: "I understand, enable.", confirmBtnType: "btn-primary" }) - .then(confirmed => { + .then((confirmed) => { if (confirmed) { - settingsService.setWhileLoopEnabled(true); + settingsService.saveSetting("WhileLoopEnabled", true); } }); } @@ -114,7 +114,7 @@ confirmLabel: "Recalculate", confirmBtnType: "btn-danger" }) - .then(confirmed => { + .then((confirmed) => { if (confirmed) { backendCommunicator.fireEvent("recalc-quote-ids"); } diff --git a/src/gui/app/directives/settings/categories/backups-settings.js b/src/gui/app/directives/settings/categories/backups-settings.js index b8b243660..0a9efa513 100644 --- a/src/gui/app/directives/settings/categories/backups-settings.js +++ b/src/gui/app/directives/settings/categories/backups-settings.js @@ -17,10 +17,10 @@ description="The maximum number of backups to keep. When Firebot makes a new backup, it will delete the oldest if this number has been reached." > @@ -38,8 +38,8 @@ >
@@ -56,8 +56,8 @@ >When Firebot closes
@@ -66,8 +66,8 @@ >Once a day
diff --git a/src/gui/app/directives/settings/categories/database-settings.js b/src/gui/app/directives/settings/categories/database-settings.js index 0de2c8a77..477aff9be 100644 --- a/src/gui/app/directives/settings/categories/database-settings.js +++ b/src/gui/app/directives/settings/categories/database-settings.js @@ -14,9 +14,9 @@ > @@ -28,9 +28,9 @@ > @@ -42,9 +42,9 @@ > diff --git a/src/gui/app/directives/settings/categories/general-settings.js b/src/gui/app/directives/settings/categories/general-settings.js index d1cf82ae9..a48aaf3c0 100644 --- a/src/gui/app/directives/settings/categories/general-settings.js +++ b/src/gui/app/directives/settings/categories/general-settings.js @@ -11,9 +11,9 @@
@@ -23,11 +23,11 @@ description="When minimized, Firebot will minimize to tray instead of task bar" > @@ -36,11 +36,11 @@ description="Get audible alerts when Firebot connects or disconnects." > @@ -56,22 +56,22 @@ data-toggle="dropdown" aria-haspopup="true" aria-expanded="true" - aria-label="Choose your audio output device {{settings.getAudioOutputDevice().label}}" + aria-label="Choose your audio output device {{settings.getSetting('AudioOutputDevice').label}}" > - {{settings.getAudioOutputDevice().label}} + {{settings.getSetting('AudioOutputDevice').label}}
@@ -208,7 +208,7 @@ $q.when(navigator.mediaDevices.enumerateDevices()).then((deviceList) => { deviceList = deviceList .filter( - (d) => d.kind === "audiooutput" && d.deviceId !== "communications" && d.deviceId !== "default" + d => d.kind === "audiooutput" && d.deviceId !== "communications" && d.deviceId !== "default" ) .map((d) => { return { label: d.label, deviceId: d.deviceId }; @@ -221,8 +221,7 @@ if (value == null) { value = "10"; } - settingsService.setActiveChatUserListTimeout(value); - ipcRenderer.send("setActiveChatUserTimeout", value); + settingsService.saveSetting("ActiveChatUserListTimeout", value); }; } }); diff --git a/src/gui/app/directives/settings/categories/overlay-settings.js b/src/gui/app/directives/settings/categories/overlay-settings.js index efc9b760a..9d68c4bd7 100644 --- a/src/gui/app/directives/settings/categories/overlay-settings.js +++ b/src/gui/app/directives/settings/categories/overlay-settings.js @@ -14,7 +14,7 @@ > @@ -24,15 +24,15 @@ > Edit Instances @@ -45,10 +45,10 @@ even if they're set to wait." > @@ -69,11 +69,8 @@ controller: function($scope, settingsService, utilityService) { $scope.settings = settingsService; - $scope.showFontManagementModal = function() { - utilityService.showModal({ - component: "fontManagementModal", - size: "sm" - }); + $scope.showOverlayInfoModal = function(overlayInstance) { + utilityService.showOverlayInfoModal(overlayInstance); }; $scope.showEditOverlayInstancesModal = function() { @@ -81,6 +78,13 @@ component: "editOverlayInstancesModal" }); }; + + $scope.showFontManagementModal = function() { + utilityService.showModal({ + component: "fontManagementModal", + size: "sm" + }); + }; } }); }()); diff --git a/src/gui/app/directives/settings/categories/scripts-settings.js b/src/gui/app/directives/settings/categories/scripts-settings.js index 0bc79ef9f..1e3467724 100644 --- a/src/gui/app/directives/settings/categories/scripts-settings.js +++ b/src/gui/app/directives/settings/categories/scripts-settings.js @@ -21,9 +21,9 @@ @@ -35,7 +35,7 @@ > @@ -46,10 +46,10 @@ > diff --git a/src/gui/app/directives/settings/categories/trigger-settings.js b/src/gui/app/directives/settings/categories/trigger-settings.js index 2eafd8fa6..d7adf4f33 100644 --- a/src/gui/app/directives/settings/categories/trigger-settings.js +++ b/src/gui/app/directives/settings/categories/trigger-settings.js @@ -16,9 +16,9 @@ > @@ -30,9 +30,9 @@ > @@ -48,9 +48,9 @@ > @@ -62,9 +62,9 @@ > diff --git a/src/gui/app/directives/settings/categories/tts-settings.js b/src/gui/app/directives/settings/categories/tts-settings.js index da43f807f..19a50e1b3 100644 --- a/src/gui/app/directives/settings/categories/tts-settings.js +++ b/src/gui/app/directives/settings/categories/tts-settings.js @@ -16,7 +16,7 @@ options="ttsVoiceOptions" ng-init="ttsVoice = getSelectedVoiceName()" selected="ttsVoice" - on-update="settings.setDefaultTtsVoiceId(option)" + on-update="settings.saveSetting('DefaultTtsVoiceId', option)" right-justify="true" aria-label="Choose your Text to Speech voice" /> @@ -67,7 +67,7 @@ $scope.settings = settingsService; $scope.getSelectedVoiceName = () => { - const selectedVoiceId = settingsService.getDefaultTtsVoiceId(); + const selectedVoiceId = settingsService.getSetting("DefaultTtsVoiceId"); const voice = ttsService.getVoiceById(selectedVoiceId); return voice ? voice.name : "Unknown Voice"; }; @@ -75,7 +75,7 @@ $scope.ttsVoices = ttsService.getVoices(); $scope.getSelectedVoiceName = () => { - const selectedVoiceId = settingsService.getDefaultTtsVoiceId(); + const selectedVoiceId = settingsService.getSetting("DefaultTtsVoiceId"); const voice = ttsService.getVoiceById(selectedVoiceId); return voice ? voice.name : "Unknown Voice"; }; @@ -86,7 +86,7 @@ }, {}); $scope.ttsVolumeSlider = { - value: settingsService.getTtsVoiceVolume(), + value: settingsService.getSetting("TtsVoiceVolume"), options: { floor: 0, ceil: 1, @@ -97,13 +97,13 @@ return Math.floor(value * 10); }, onChange: (_, value) => { - settingsService.setTtsVoiceVolume(value); + settingsService.saveSetting("TtsVoiceVolume", value); } } }; $scope.ttsRateSlider = { - value: settingsService.getTtsVoiceRate(), + value: settingsService.getSetting("TtsVoiceRate"), options: { floor: 0.1, ceil: 10, @@ -111,7 +111,7 @@ precision: 1, ariaLabel: "Text to speech rate ", onChange: (_, value) => { - settingsService.setTtsVoiceRate(value); + settingsService.saveSetting("TtsVoiceRate", value); } } }; diff --git a/src/gui/app/directives/sidebar/sidebar.js b/src/gui/app/directives/sidebar/sidebar.js index 48477f0ec..fcf0d82cd 100644 --- a/src/gui/app/directives/sidebar/sidebar.js +++ b/src/gui/app/directives/sidebar/sidebar.js @@ -125,7 +125,7 @@ ctrl.is = integrationService; - ctrl.isViewerDBOn = settingsService.getViewerDB; + ctrl.isViewerDBOn = () => settingsService.getSetting("ViewerDB"); ctrl.extensionPages = () => uiExtensionsService.extensions.map(e => e.pages.map((p) => { p.extensionId = e.id; diff --git a/src/gui/app/services/activity-feed.service.js b/src/gui/app/services/activity-feed.service.js index 97cc0ccda..d2b28953c 100644 --- a/src/gui/app/services/activity-feed.service.js +++ b/src/gui/app/services/activity-feed.service.js @@ -23,7 +23,7 @@ service.allActivities.length = 500; } - const allowedEvents = settingsService.getAllowedActivityEvents(); + const allowedEvents = settingsService.getSetting("AllowedActivityEvents"); if (!activity.event.forceAllow && !allowedEvents.includes(`${activity.source.id}:${activity.event.id}`)) { return; } @@ -83,7 +83,7 @@ component: "editActivityEventsModal", size: "sm", closeCallback: () => { - const allowedEvents = settingsService.getAllowedActivityEvents(); + const allowedEvents = settingsService.getSetting("AllowedActivityEvents"); service.activities = service.allActivities .filter(a => allowedEvents.includes(`${a.source.id}:${a.event.id}`)); } diff --git a/src/gui/app/services/chat-messages.service.js b/src/gui/app/services/chat-messages.service.js index 35075e778..8a84fa128 100644 --- a/src/gui/app/services/chat-messages.service.js +++ b/src/gui/app/services/chat-messages.service.js @@ -28,11 +28,6 @@ // The message/thread currently being replied to service.threadDetails = null; - // Tells us if we should process in app chat or not. - service.getChatFeed = function() { - return settingsService.getRealChatFeed(); - }; - // Return the chat queue. service.getChatQueue = function() { return service.chatQueue; @@ -242,18 +237,9 @@ }); }; - // Gets view count setting for ui. - service.getChatViewCountSetting = function() { - const viewCount = settingsService.getChatViewCount(); - if (viewCount === "On") { - return true; - } - return false; - }; - // Gets view count setting for ui. service.getChatViewerListSetting = function() { - return settingsService.getShowChatViewerList(); + return settingsService.getSetting("ShowChatViewerList"); }; function markMessageAsDeleted(messageId) { @@ -307,29 +293,26 @@ // }, 250); backendCommunicator.on("twitch:chat:rewardredemption", (redemption) => { - if (settingsService.getRealChatFeed()) { - - const redemptionItem = { - id: uuid(), - type: "redemption", - data: redemption - }; + const redemptionItem = { + id: uuid(), + type: "redemption", + data: redemption + }; - if (service.chatQueue && service.chatQueue.length > 0) { - const lastQueueItem = service.chatQueue[service.chatQueue.length - 1]; - if (!lastQueueItem.rewardMatched && + if (service.chatQueue && service.chatQueue.length > 0) { + const lastQueueItem = service.chatQueue[service.chatQueue.length - 1]; + if (!lastQueueItem.rewardMatched && lastQueueItem.type === "message" && lastQueueItem.data.customRewardId != null && lastQueueItem.data.customRewardId === redemption.reward.id && lastQueueItem.data.userId === redemption.user.id) { - lastQueueItem.rewardMatched = true; - service.chatQueue.splice(-1, 0, redemptionItem); - return; - } + lastQueueItem.rewardMatched = true; + service.chatQueue.splice(-1, 0, redemptionItem); + return; } - - service.chatQueue.push(redemptionItem); } + + service.chatQueue.push(redemptionItem); }); backendCommunicator.on("twitch:chat:user-joined", (user) => { @@ -376,7 +359,7 @@ }); backendCommunicator.on("twitch:chat:clear-feed", (modUsername) => { - const clearMode = settingsService.getClearChatFeedMode(); + const clearMode = settingsService.getSetting("ClearChatFeedMode"); const isStreamer = accountAccess.accounts.streamer.username.toLowerCase() === modUsername.toLowerCase(); @@ -428,37 +411,35 @@ service.chatUserUpdated(user); } - if (settingsService.getRealChatFeed()) { - // Push new message to queue. - const messageItem = { - id: uuid(), - type: "message", - data: chatMessage - }; + // Push new message to queue. + const messageItem = { + id: uuid(), + type: "message", + data: chatMessage + }; - if (chatMessage.customRewardId != null && + if (chatMessage.customRewardId != null && service.chatQueue && service.chatQueue.length > 0) { - const lastQueueItem = service.chatQueue[service.chatQueue.length - 1]; - if (lastQueueItem.type === "redemption" && + const lastQueueItem = service.chatQueue[service.chatQueue.length - 1]; + if (lastQueueItem.type === "redemption" && lastQueueItem.data.reward.id === chatMessage.customRewardId && lastQueueItem.data.user.id === chatMessage.userId) { - messageItem.rewardMatched = true; - } + messageItem.rewardMatched = true; } + } - service.chatQueue.push(messageItem); + service.chatQueue.push(messageItem); - service.pruneChatQueue(); - } + service.pruneChatQueue(); }); service.allEmotes = []; service.filteredEmotes = []; service.refreshEmotes = () => { - const showBttvEmotes = settingsService.getShowBttvEmotes(); - const showFfzEmotes = settingsService.getShowFfzEmotes(); - const showSevenTvEmotes = settingsService.getShowSevenTvEmotes(); + const showBttvEmotes = settingsService.getSetting("ChatShowBttvEmotes"); + const showFfzEmotes = settingsService.getSetting("ChatShowFfzEmotes"); + const showSevenTvEmotes = settingsService.getSetting("ChatShowSevenTvEmotes"); service.filteredEmotes = service.allEmotes.filter((e) => { if (showBttvEmotes !== true && e.origin === "BTTV") { @@ -487,9 +468,7 @@ listenerService.registerListener( { type: listenerService.ListenerType.CHAT_UPDATE }, (data) => { - if (settingsService.getRealChatFeed() === true) { - service.chatUpdateHandler(data); - } + service.chatUpdateHandler(data); } ); diff --git a/src/gui/app/services/connection-manager.service.js b/src/gui/app/services/connection-manager.service.js index 304980a50..94a4ca728 100644 --- a/src/gui/app/services/connection-manager.service.js +++ b/src/gui/app/services/connection-manager.service.js @@ -18,7 +18,7 @@ let overlayStatus = listenerService.fireEventSync("getOverlayStatus"); function delay(time) { - return new Promise(resolve => { + return new Promise((resolve) => { setTimeout(() => { resolve(); }, time || 100); @@ -31,7 +31,7 @@ { type: listenerService.ListenerType.OVERLAY_CONNECTION_STATUS }, - overlayStatusData => { + (overlayStatusData) => { overlayStatus = overlayStatusData; } ); @@ -45,13 +45,13 @@ }; service.setConnectionToChat = function(shouldConnect) { - return new Promise(resolve => { + return new Promise((resolve) => { listenerService.registerListener( { type: listenerService.ListenerType.CHAT_CONNECTION_STATUS, runOnce: true }, - isChatConnected => { + (isChatConnected) => { resolve(isChatConnected); } ); @@ -66,12 +66,12 @@ service.connectedServiceCount = function(services) { if (services == null) { - services = settingsService.getSidebarControlledServices(); + services = settingsService.getSetting("SidebarControlledServices"); } let count = 0; - services.forEach(s => { + services.forEach((s) => { switch (s) { case "chat": if (connectionService.connectedToChat) { @@ -92,21 +92,21 @@ }; service.partialServicesConnected = function() { - const services = settingsService.getSidebarControlledServices(); + const services = settingsService.getSetting("SidebarControlledServices"); const connectedCount = service.connectedServiceCount(); return connectedCount > 0 && services.length > connectedCount; }; service.allServicesConnected = function() { - const services = settingsService.getSidebarControlledServices(); + const services = settingsService.getSetting("SidebarControlledServices"); const connectedCount = service.connectedServiceCount(); return services.length === connectedCount; }; service.toggleSidebarServices = function() { - const services = settingsService.getSidebarControlledServices(); + const services = settingsService.getSetting("SidebarControlledServices"); // we only want to connect if none of the connections are currently connected // otherwise we will attempt to disconnect everything. @@ -190,12 +190,12 @@ } case "integrations": { const sidebarControlledIntegrations = settingsService - .getSidebarControlledServices() + .getSetting("SidebarControlledServices") .filter(s => s.startsWith("integration.")) .map(s => s.replace("integration.", "")); let connectedCount = 0; - sidebarControlledIntegrations.forEach(i => { + sidebarControlledIntegrations.forEach((i) => { if (integrationService.integrationIsConnected(i)) { connectedCount++; } diff --git a/src/gui/app/services/connection.service.js b/src/gui/app/services/connection.service.js index e39f13202..236634b28 100644 --- a/src/gui/app/services/connection.service.js +++ b/src/gui/app/services/connection.service.js @@ -201,7 +201,7 @@ function updateSidebarServicesOverallStatus() { let oneDisconnected = false; let oneConnected = false; - const serviceIds = settingsService.getSidebarControlledServices(); + const serviceIds = settingsService.getSetting("SidebarControlledServices"); for (const serviceId of serviceIds) { if (serviceId == null || (serviceId !== "chat" && !serviceId.startsWith("integration."))) { diff --git a/src/gui/app/services/integration.service.js b/src/gui/app/services/integration.service.js index 8ae7346e2..a8c241631 100644 --- a/src/gui/app/services/integration.service.js +++ b/src/gui/app/services/integration.service.js @@ -82,12 +82,12 @@ integrationId, shouldConnect ) { - return new Promise(resolve => { + return new Promise((resolve) => { const listenerId = listenerService.registerListener( { type: listenerService.ListenerType.INTEGRATION_CONNECTION_UPDATE }, - data => { + (data) => { if (data.id === integrationId) { listenerService.unregisterListener( listenerService.ListenerType.INTEGRATION_CONNECTION_UPDATE, @@ -156,7 +156,7 @@ resolveObj: { integration: () => integration }, - closeCallback: resp => { + closeCallback: (resp) => { const action = resp.action; if (action === 'save') { @@ -190,28 +190,28 @@ if (integration == null || !integration.connectionToggle) { return; } - const sidebarControlledServices = settingsService.getSidebarControlledServices(); + const sidebarControlledServices = settingsService.getSetting("SidebarControlledServices"); const service = `integration.${integration.id}`; if (!sidebarControlledServices.includes(service)) { sidebarControlledServices.push(service); } - settingsService.setSidebarControlledServices(sidebarControlledServices); + settingsService.saveSetting("SidebarControlledServices", sidebarControlledServices); }); backendCommunicator.on("integrationUnlinked", (intId) => { - let sidebarControlledServices = settingsService.getSidebarControlledServices(); + let sidebarControlledServices = settingsService.getSetting("SidebarControlledServices"); const service = `integration.${intId}`; if (sidebarControlledServices.includes(service)) { sidebarControlledServices = sidebarControlledServices.filter(s => s !== service); } - settingsService.setSidebarControlledServices(sidebarControlledServices); + settingsService.saveSetting("SidebarControlledServices", sidebarControlledServices); }); listenerService.registerListener( { type: listenerService.ListenerType.INTEGRATION_CONNECTION_UPDATE }, - data => { + (data) => { const integration = integrations.find(i => i.id === data.id); if (integration != null) { integration.connected = data.connected; diff --git a/src/gui/app/services/overlay-url-helper.service.js b/src/gui/app/services/overlay-url-helper.service.js index aaa99e739..06644b95f 100644 --- a/src/gui/app/services/overlay-url-helper.service.js +++ b/src/gui/app/services/overlay-url-helper.service.js @@ -12,11 +12,11 @@ service.getOverlayPath = function(instanceName) { let overlayPath = dataAccess.getPathInUserData("overlay.html"); - const port = settingsService.getWebServerPort(); + const port = settingsService.getSetting("WebServerPort"); const params = {}; if (port !== 7472 && !isNaN(port)) { - params["port"] = settingsService.getWebServerPort(); + params["port"] = settingsService.getSetting("WebServerPort"); } if (instanceName != null && instanceName !== "") { @@ -24,7 +24,7 @@ } let paramCount = 0; - Object.entries(params).forEach(p => { + Object.entries(params).forEach((p) => { const key = p[0], value = p[1]; diff --git a/src/gui/app/services/settings.service.js b/src/gui/app/services/settings.service.js index c59067233..8c6937953 100644 --- a/src/gui/app/services/settings.service.js +++ b/src/gui/app/services/settings.service.js @@ -2,850 +2,69 @@ (function () { //This handles settings access for frontend - const fs = require("fs"); - const { ipcRenderer } = require("electron"); - angular .module("firebotApp") - .factory("settingsService", function (utilityService, logger, profileManager, dataAccess, backendCommunicator) { + .factory("settingsService", function (utilityService, backendCommunicator) { const service = {}; + let settingPathCache = {}; let settingsCache = {}; - backendCommunicator.on("flush-settings-cache", () => { - settingsCache = {}; - }); - - backendCommunicator.on("settings-updated-main", (settingsUpdate) => { - if (settingsUpdate == null) { - return; + /** @param {string} settingName */ + function getSettingPath(settingName) { + if (settingPathCache[settingName] == null) { + settingPathCache[settingName] = backendCommunicator.fireEventSync("settings:get-setting-path", settingName); } - const { path, data } = settingsUpdate; - if (path == null || path === '') { - return; - } - settingsCache[path] = data; - }); - function getSettingsFile() { - return profileManager.getJsonDbInProfile("/settings"); + return settingPathCache[settingName]; } - function pushDataToFile(path, data) { - try { - getSettingsFile().push(path, data); - settingsCache[path] = data; - backendCommunicator.fireEvent("settings-updated-renderer", { path, data }); - } catch (err) { } //eslint-disable-line no-empty - } - - function getDataFromFile(path, forceCacheUpdate, defaultValue) { - try { - if (settingsCache[path] == null || forceCacheUpdate) { - const data = getSettingsFile().getData(path); - settingsCache[path] = data ?? defaultValue; - } - } catch (err) { - if (defaultValue !== undefined) { - settingsCache[path] = defaultValue; - } - if (err.name !== "DataError") { - logger.warn(err); - } - } - return settingsCache[path]; - } - - function deleteDataAtPath(path) { - try { - getSettingsFile().delete(path); - delete settingsCache[path]; - backendCommunicator.fireEvent("settings-updated-renderer", { path, data: null }); - } catch (err) { } //eslint-disable-line no-empty - } - - service.purgeSettingsCache = function () { - settingsCache = {}; - backendCommunicator.fireEvent("purge-settings-cache"); - }; - - service.getCustomScriptsEnabled = function () { - return getDataFromFile("/settings/runCustomScripts", false, false) === true; - }; - - service.setCustomScriptsEnabled = function (enabled) { - pushDataToFile("/settings/runCustomScripts", enabled === true); - }; - - service.getSidebarExpanded = function () { - const expanded = getDataFromFile("/settings/sidebarExpanded", false, true); - return expanded != null ? expanded : true; - }; - - service.setSidebarExpanded = function (expanded) { - pushDataToFile("/settings/sidebarExpanded", expanded === true); - }; - - service.getDefaultToAdvancedCommandMode = function () { - return getDataFromFile("/settings/defaultToAdvancedCommandMode", false, false) === true; - }; - - service.setDefaultToAdvancedCommandMode = function (defaultToAdvanced) { - pushDataToFile("/settings/defaultToAdvancedCommandMode", defaultToAdvanced === true); - }; - - service.getSeenAdvancedCommandModePopup = function () { - return getDataFromFile("/settings/seenAdvancedCommandModePopup", false, false) === true; - }; - - service.setSeenAdvancedCommandModePopup = function (seen) { - pushDataToFile("/settings/seenAdvancedCommandModePopup", seen === true); - }; - - service.getPersistCustomVariables = function () { - return getDataFromFile("/settings/persistCustomVariables", false, false) === true; - }; - - service.setPersistCustomVariables = function (enabled) { - pushDataToFile("/settings/persistCustomVariables", enabled === true); - }; - - service.getAllowQuoteCSVDownloads = function () { - return getDataFromFile("/settings/allowQuoteCSVDownloads", false, true) !== false; - }; - - service.setAllowQuoteCSVDownloads = function (enabled) { - pushDataToFile("/settings/allowQuoteCSVDownloads", enabled === true); - }; - - service.legacySortTagsImported = function () { - return getDataFromFile("/settings/legacySortTagsImported", false, false) === true; - }; - - service.setLegacySortTagsImported = function (enabled) { - pushDataToFile("/settings/legacySortTagsImported", enabled === true); - }; - - service.getViewerListPageSize = function () { - const viewerListPageSize = getDataFromFile("/settings/viewerListDatabase/pageSize", false, 10); - return viewerListPageSize != null ? viewerListPageSize : 10; - }; - - service.setViewerListPageSize = function (viewerListPageSize = 10) { - pushDataToFile("/settings/viewerListDatabase/pageSize", viewerListPageSize); - }; - - service.isBetaTester = function () { - const betaTester = getDataFromFile("/settings/beta", false, "No"); - return betaTester != null ? betaTester : "No"; - }; - - service.setBetaTester = function (isTester) { - pushDataToFile("/settings/beta", isTester); - }; - - service.getEmulator = function () { - const emulator = getDataFromFile("/settings/emulation", false, "nut-js"); - return emulator != null ? emulator : "nut-js"; - }; - - service.setEmulator = function (emulator) { - pushDataToFile("/settings/emulation", emulator); - }; - - service.getViewerDB = function () { - let viewerDB = getDataFromFile("/settings/viewerDB"); - - // If viewerDB setting is not set, default to true to avoid future "cant find datapath" errors. - if (viewerDB == null) { - logger.debug('Viewer DB setting not found. Defaulting to true.'); - service.setViewerDB(true); - viewerDB = getDataFromFile("/settings/viewerDB"); - } - return viewerDB != null ? viewerDB : true; - }; - - service.setViewerDB = function (status) { - pushDataToFile("/settings/viewerDB", status); - - if (status === true) { - ipcRenderer.send("connect-viewer-db"); - } else { - ipcRenderer.send("disconnect-viewer-db"); - } - }; - - service.getAutoFlagBots = function () { - let autoFlagBots = getDataFromFile("/settings/autoFlagBots"); - - // If viewerDB setting is not set, default to true to avoid future "cant find datapath" errors. - if (autoFlagBots == null) { - logger.debug('Auto Flag Bots setting not found. Defaulting to true.'); - service.setAutoFlagBots(true); - autoFlagBots = getDataFromFile("/settings/viewerDB"); - } - return autoFlagBots != null ? autoFlagBots : true; - }; - - service.setAutoFlagBots = function (status) { - pushDataToFile("/settings/autoFlagBots", status); - }; - - // Used for settings menu. - service.getChatFeed = function () { - const chatFeed = getDataFromFile("/settings/chatFeed", false, false); - if (chatFeed === true) { - return "On"; - } - return "Off"; - }; - - // Used for the app itself. - service.getRealChatFeed = function () { - return true; - }; - - service.chatFeedEnabled = function () { - return true; - }; - - service.setChatFeed = function () { }; - - // Used for settings menu. - service.getChatViewCount = function () { - const chatViewCount = getDataFromFile("/settings/chatViewCount", false, "Off"); - if (chatViewCount === true) { - return "On"; - } - return "Off"; - }; - - service.setChatViewCount = function (chatViewCount) { - pushDataToFile("/settings/chatViewCount", chatViewCount === true); - }; - - service.getViewerCount = function () { - return getDataFromFile("/settings/chatViewCount"); - }; - - service.getQuickActionSettings = () => { - return getDataFromFile("/settings/quickActions"); - }; - - service.setQuickActionSettings = (quickActions) => { - pushDataToFile("/settings/quickActions", quickActions); - }; - - service.setDashboardLayoutSettings = (layoutSettings) => { - pushDataToFile("/settings/dashboard/layout", layoutSettings); - }; - - service.getDashboardLayoutSettings = () => { - return getDataFromFile("/settings/dashboard/layout"); - }; - - service.getShowChatViewerList = function () { - const value = getDataFromFile("/settings/chatUsersList", false, true); - return value == null ? true : value; - }; - - service.setShowChatViewerList = function (chatViewerList) { - pushDataToFile("/settings/chatUsersList", chatViewerList === true); - }; - - service.showActivityFeed = function () { - const show = getDataFromFile("/settings/activityFeed", false, true); - return show == null ? true : show; - }; - - service.setShowActivityFeed = function (showActivityFeed) { - pushDataToFile("/settings/activityFeed", showActivityFeed === true); - }; - - service.getAllowedActivityEvents = function () { - const events = getDataFromFile("/settings/allowedActivityEvents"); - return events == null ? [ - "twitch:raid", - "twitch:raid-sent-off", - "twitch:follow", - "twitch:sub", - "twitch:subs-gifted", - "twitch:community-subs-gifted", - "twitch:cheer", - "streamlabs:donation", - "streamlabs:eldonation", - 'extralife:donation', - "tipeeestream:donation", - "streamelements:donation", - "twitch:channel-reward-redemption" - ] : events; - }; - - service.setAllowedActivityEvents = function (events) { - if (events == null || !Array.isArray(events)) { + backendCommunicator.on("settings:setting-updated", ({ settingPath, data }) => { + if (settingPath == null || settingPath === "") { return; } - pushDataToFile("/settings/allowedActivityEvents", events); - }; - - service.ignoreSubsequentSubEventsAfterCommunitySub = function () { - const ignoreSubEvents = getDataFromFile("/settings/ignoreSubsequentSubEventsAfterCommunitySub", false, true); - return ignoreSubEvents != null ? ignoreSubEvents : true; - }; - - service.setIgnoreSubsequentSubEventsAfterCommunitySub = function (ignoreSubEvents) { - pushDataToFile("/settings/ignoreSubsequentSubEventsAfterCommunitySub", ignoreSubEvents === true); - }; - - service.getWysiwygBackground = function () { - const bg = getDataFromFile("/settings/wysiwygBackground", false, 'white'); - return bg != null ? bg : 'white'; - }; - - service.setWysiwygBackground = function (bg) { - pushDataToFile("/settings/wysiwygBackground", bg); - }; - - service.getClearChatFeedMode = function () { - const mode = getDataFromFile("/settings/clearChatFeedMode", false, 'onlyStreamer'); - return mode != null ? mode : 'onlyStreamer'; - }; - - service.setClearChatFeedMode = function (mode) { - pushDataToFile("/settings/clearChatFeedMode", mode); - }; - - service.isChatCompactMode = function () { - const compact = getDataFromFile("/settings/chatCompactMode", false, false); - return compact != null ? compact : false; - }; - - service.setChatCompactMode = function (compact) { - pushDataToFile("/settings/chatCompactMode", compact === true); - }; - - service.getShowAvatars = function () { - const value = getDataFromFile("/settings/chatAvatars", false, true); - return value != null ? value : true; - }; - service.setShowAvatars = function (value) { - pushDataToFile("/settings/chatAvatars", value === true); - }; - - service.getShowTimestamps = function () { - const value = getDataFromFile("/settings/chatTimestamps", false, true); - return value != null ? value : true; - }; - service.setShowTimestamps = function (value) { - pushDataToFile("/settings/chatTimestamps", value === true); - }; - - service.getShowThirdPartyEmotes = function () { - const value = getDataFromFile("/settings/chatThirdPartyEmotes", false, true); - return value != null ? value : true; - }; - - service.getShowBttvEmotes = function () { - const value = getDataFromFile("/settings/chat/emotes/bttv", false, service.getShowThirdPartyEmotes()); - return value != null ? value : service.getShowThirdPartyEmotes(); - }; - service.setShowBttvEmotes = function (value) { - pushDataToFile("/settings/chat/emotes/bttv", value === true); - }; - - service.getShowFfzEmotes = function () { - const value = getDataFromFile("/settings/chat/emotes/ffz", false, service.getShowThirdPartyEmotes()); - return value != null ? value : service.getShowThirdPartyEmotes(); - }; - service.setShowFfzEmotes = function (value) { - pushDataToFile("/settings/chat/emotes/ffz", value === true); - }; - - service.getShowSevenTvEmotes = function () { - const value = getDataFromFile("/settings/chat/emotes/seventv", false, service.getShowThirdPartyEmotes()); - return value != null ? value : service.getShowThirdPartyEmotes(); - }; - service.setShowSevenTvEmotes = function (value) { - pushDataToFile("/settings/chat/emotes/seventv", value === true); - }; - - service.getShowPronouns = function () { - const value = getDataFromFile("/settings/chatPronouns", false, true); - return value != null ? value : true; - }; - service.setShowPronouns = function (value) { - pushDataToFile("/settings/chatPronouns", value === true); - }; - - service.getChatCustomFontSizeEnabled = function () { - const value = getDataFromFile("/settings/chatCustomFontSizeEnabled", false, false); - return value != null ? value : false; - }; - service.setChatCustomFontSizeEnabled = function (value) { - pushDataToFile("/settings/chatCustomFontSizeEnabled", value === true); - }; - - service.getChatCustomFontSize = function () { - const value = getDataFromFile("/settings/chatCustomFontSize", false, 17); - return value != null ? value : 17; - }; - service.setChatCustomFontSize = function (value) { - pushDataToFile("/settings/chatCustomFontSize", value); - }; - - service.chatAlternateBackgrounds = function () { - const alternate = getDataFromFile('/settings/chatAlternateBackgrounds', false, true); - return alternate != null ? alternate : true; - }; - - service.setChatAlternateBackgrounds = function (alternate) { - pushDataToFile('/settings/chatAlternateBackgrounds', alternate === true); - }; - - service.chatHideBotAccountMessages = function () { - const shouldHide = getDataFromFile('/settings/chatHideBotAccountMessages', false, false); - return shouldHide != null ? shouldHide : false; - }; - - service.setChatHideBotAccountMessages = function (shouldHide) { - pushDataToFile('/settings/chatHideBotAccountMessages', shouldHide === true); - }; - - service.getChatHideWhispers = function () { - const shouldHide = getDataFromFile('/settings/chatHideWhispers', false, false); - return shouldHide === true; - }; - - service.setChatHideWhispers = function (shouldHide) { - pushDataToFile('/settings/chatHideWhispers', shouldHide === true); - }; - - service.getShowUptimeStat = function () { - const value = getDataFromFile("/settings/showUptimeStat", false, true); - return value != null ? value : true; - }; - service.setShowUptimeStat = function (value) { - pushDataToFile("/settings/showUptimeStat", value === true); - }; - service.getShowViewerCountStat = function () { - const value = getDataFromFile("/settings/showViewerCountStat", false, true); - return value != null ? value : true; - }; - service.setShowViewerCountStat = function (value) { - pushDataToFile("/settings/showViewerCountStat", value === true); - }; - service.getShowHypeTrainIndicator = function () { - const value = getDataFromFile("/settings/showHypeTrainIndicator", false, true); - return value != null ? value : true; - }; - service.setShowHypeTrainIndicator = function (value) { - pushDataToFile("/settings/showHypeTrainIndicator", value === true); - }; - - service.getShowAdBreakIndicator = function () { - const value = getDataFromFile("/settings/showAdBreakIndicator", false, true); - return value != null ? value : true; - }; - - service.setShowAdBreakIndicator = function (value) { - pushDataToFile("/settings/showAdBreakIndicator", value === true); - }; - - service.getTriggerUpcomingAdBreakMinutes = function () { - const value = getDataFromFile("/settings/triggerUpcomingAdBreakMinutes", false, 0); - return value ?? 0; - }; - - service.setTriggerUpcomingAdBreakMinutes = function (value) { - pushDataToFile("/settings/triggerUpcomingAdBreakMinutes", value); - }; - - service.chatHideDeletedMessages = function () { - const hide = getDataFromFile('/settings/chatHideDeletedMessages', false, false); - return hide != null ? hide : false; - }; - - service.setChatHideDeletedMessages = function (hide) { - pushDataToFile('/settings/chatHideDeletedMessages', hide === true); - }; - - service.getOverlayCompatibility = function () { - const overlay = getDataFromFile("/settings/overlayImages", false, "Other"); - return overlay != null ? overlay : "Other"; - }; - - service.setOverlayCompatibility = function (overlay) { - const overlaySetting = overlay === "OBS" ? overlay : "Other"; - pushDataToFile("/settings/overlayImages", overlaySetting); - }; - - service.getTheme = function () { - const theme = getDataFromFile("/settings/theme", false, "Obsidian"); - return theme != null ? theme : "Obsidian"; - }; - - service.setTheme = function (theme) { - pushDataToFile("/settings/theme", theme); - }; - - service.soundsEnabled = function () { - const sounds = getDataFromFile("/settings/sounds", false, "On"); - return sounds != null ? sounds : "On"; - }; - - service.setSoundsEnabled = function (enabled) { - pushDataToFile("/settings/sounds", enabled); - }; - - service.getOpenStreamPreviewOnLaunch = () => { - const openStreamPreviewOnLaunch = getDataFromFile("/settings/openStreamPreviewOnLaunch", false, false); - return openStreamPreviewOnLaunch === true; - }; - - service.setOpenStreamPreviewOnLaunch = (enabled) => { - pushDataToFile("/settings/openStreamPreviewOnLaunch", enabled === true); - }; - - service.getActiveChatUserListTimeout = function () { - const inactiveTimer = getDataFromFile("/settings/activeChatUsers/inactiveTimer", false, 5); - return inactiveTimer != null ? parseInt(inactiveTimer) : 5; - }; - - service.setActiveChatUserListTimeout = function (inactiveTimer) { - pushDataToFile("/settings/activeChatUsers/inactiveTimer", inactiveTimer); - }; - - /* - * 0 = off, - * 1 = bugfix, - * 2 = feature, - * 3 = major release, - * 4 = betas - */ - service.getAutoUpdateLevel = function () { - const updateLevel = getDataFromFile("/settings/autoUpdateLevel", false, 2); - return updateLevel != null ? updateLevel : 2; - }; - - service.setAutoUpdateLevel = function (updateLevel) { - pushDataToFile("/settings/autoUpdateLevel", updateLevel); - }; - - service.notifyOnBeta = function () { - const beta = getDataFromFile("/settings/notifyOnBeta", false, false); - return beta != null ? beta : false; - }; - - service.setNotifyOnBeta = function (beta) { - pushDataToFile("/settings/notifyOnBeta", beta === true); - }; - service.isFirstTimeUse = function () { - const ftu = getDataFromFile("/settings/firstTimeUse", false, true); - return ftu != null ? ftu : true; - }; - - service.setFirstTimeUse = function (ftu) { - pushDataToFile("/settings/firstTimeUse", ftu === true); - }; - - service.hasJustUpdated = function () { - const updated = getDataFromFile("/settings/justUpdated", false, false); - return updated != null ? updated : false; - }; - - service.setJustUpdated = function (justUpdated) { - pushDataToFile("/settings/justUpdated", justUpdated === true); - }; + settingsCache[settingPath] = data; + }); - service.getOverlayVersion = function () { - const version = getDataFromFile("/settings/copiedOverlayVersion", false, ""); - return version != null ? version : ""; - }; + backendCommunicator.on("settings:setting-deleted", (settingPath) => { + delete settingsCache[settingPath]; + }); - service.setOverlayVersion = function (newVersion) { - pushDataToFile("/settings/copiedOverlayVersion", newVersion.toString()); - }; + backendCommunicator.on("settings:settings-cache-flushed", () => { + settingPathCache = {}; + settingsCache = {}; + }); - service.getWebServerPort = function () { - const serverPort = getDataFromFile("/settings/webServerPort", false, 7472); - return serverPort != null ? serverPort : 7472; - }; + service.getSetting = function (settingName, forceCacheUpdate = false) { + const settingPath = getSettingPath(settingName); - service.setWebServerPort = function (port) { - // Ensure port is a number. - if (!Number.isInteger(port)) { - return; + if (settingsCache[settingPath] == null || forceCacheUpdate === true) { + settingsCache[settingPath] = backendCommunicator.fireEventSync("settings:get-setting", settingName); } - // Save to settings file for app front end - pushDataToFile("/settings/webServerPort", port); - - const path = dataAccess.getPathInWorkingDir( - "/resources/overlay/js/port.js" - ); - - // Overwrite the 'port.js' file in the overlay settings folder with the new port - fs.writeFile(path, `window.WEBSERVER_PORT = ${port}`, { encoding: "utf8" }, () => { - logger.info(`Set overlay port to: ${port}`); - }); + return settingsCache[settingPath]; }; - service.getWebSocketPort = function () { - return service.getWebServerPort(); + service.saveSetting = function (settingName, data) { + backendCommunicator.fireEvent("settings:save-setting", { + settingName, + data + }); }; - service.setWebSocketPort = function (port) { - return service.setWebServerPort(port); + service.deleteSetting = function (settingName) { + backendCommunicator.fireEventAsync("settings:delete-setting", settingName); }; - service.setInactiveTimer = function (inactiveTimer) { - console.log(inactiveTimer); + service.flushSettingsCache = function () { + backendCommunicator.fireEvent("settings:flush-settings-cache"); }; service.showOverlayInfoModal = function (instanceName) { utilityService.showOverlayInfoModal(instanceName); }; - service.showOverlayEventsModal = function () { - utilityService.showOverlayEventsModal(); - }; - - service.getOverlayEventsSettings = function () { - const settings = getDataFromFile("/settings/eventSettings", false, {}); - return settings != null ? settings : {}; - }; - - service.saveOverlayEventsSettings = function (eventSettings) { - pushDataToFile("/settings/eventSettings", eventSettings); - }; - - service.getClearCustomScriptCache = function () { - const clear = getDataFromFile("/settings/clearCustomScriptCache", false, false); - return clear != null ? clear : false; - }; - - service.setClearCustomScriptCache = function (clear) { - pushDataToFile("/settings/clearCustomScriptCache", clear === true); - }; - - service.useOverlayInstances = function () { - const oi = getDataFromFile("/settings/useOverlayInstances", false, false); - return oi != null ? oi : false; - }; - - service.setUseOverlayInstances = function (oi) { - pushDataToFile("/settings/useOverlayInstances", oi === true); - }; - - service.getOverlayInstances = function () { - const ois = getDataFromFile("/settings/overlayInstances", false, []); - return ois != null ? ois : []; - }; - - service.setOverlayInstances = function (ois) { - pushDataToFile("/settings/overlayInstances", ois); - }; - - service.getForceOverlayEffectsToContinueOnRefresh = function () { - const forceOverlayEffectsToContinueOnRefresh = getDataFromFile("/settings/forceOverlayEffectsToContinueOnRefresh", false, true); - return forceOverlayEffectsToContinueOnRefresh === true; - }; - - service.setForceOverlayEffectsToContinueOnRefresh = function (value) { - pushDataToFile("/settings/forceOverlayEffectsToContinueOnRefresh", value); - }; - - service.backupKeepAll = function () { - const backupKeepAll = getDataFromFile("/settings/backupKeepAll", false, false); - return backupKeepAll != null ? backupKeepAll : false; - }; - - service.setBackupKeepAll = function (backupKeepAll) { - pushDataToFile("/settings/backupKeepAll", backupKeepAll === true); - }; - - service.backupOnExit = function () { - const save = getDataFromFile("/settings/backupOnExit", false, true); - return save != null ? save : true; - }; - - service.setBackupOnExit = function (backupOnExit) { - pushDataToFile("/settings/backupOnExit", backupOnExit === true); - }; - - service.backupIgnoreResources = function () { - const save = getDataFromFile("/settings/backupIgnoreResources", false, true); - return save != null ? save : true; - }; - - service.setBackupIgnoreResources = function (backupIgnoreResources) { - pushDataToFile("/settings/backupIgnoreResources", backupIgnoreResources === true); - }; - - service.backupBeforeUpdates = function () { - const backupBeforeUpdates = getDataFromFile( - "/settings/backupBeforeUpdates", false, true - ); - return backupBeforeUpdates != null ? backupBeforeUpdates : true; - }; - - service.setBackupBeforeUpdates = function (backupBeforeUpdates) { - pushDataToFile( - "/settings/backupBeforeUpdates", - backupBeforeUpdates === true - ); - }; - - service.backupOnceADay = function () { - const backupOnceADay = getDataFromFile("/settings/backupOnceADay", false, true); - return backupOnceADay != null ? backupOnceADay : true; - }; - - service.setBackupOnceADay = function (backupOnceADay) { - pushDataToFile("/settings/backupOnceADay", backupOnceADay === true); - }; - - service.maxBackupCount = function () { - const maxBackupCount = getDataFromFile("/settings/maxBackupCount", false, 25); - return maxBackupCount != null ? maxBackupCount : 25; - }; - - service.setMaxBackupCount = function (maxBackupCount) { - pushDataToFile("/settings/maxBackupCount", maxBackupCount); - }; - - service.getAudioOutputDevice = function () { - const defaultVal = { label: "System Default", deviceId: "default" }; - const device = getDataFromFile("/settings/audioOutputDevice", false, defaultVal); - return device != null - ? device - : defaultVal; - }; - - service.setAudioOutputDevice = function (device) { - pushDataToFile("/settings/audioOutputDevice", device); - }; - - service.getSidebarControlledServices = function () { - const services = getDataFromFile("/settings/sidebarControlledServices", false, ["chat"]); - return services != null - ? services - : ["chat"]; - }; - - service.setSidebarControlledServices = function (services) { - pushDataToFile("/settings/sidebarControlledServices", services); - }; - - service.getTaggedNotificationSound = function () { - const sound = getDataFromFile("/settings/chat/tagged/sound"); - return sound != null ? sound : { name: "None" }; - }; - - service.setTaggedNotificationSound = function (sound) { - pushDataToFile("/settings/chat/tagged/sound", sound); - }; - - service.getTaggedNotificationVolume = function () { - const volume = getDataFromFile("/settings/chat/tagged/volume"); - return volume != null ? volume : 5; - }; - - service.setTaggedNotificationVolume = function (volume) { - pushDataToFile("/settings/chat/tagged/volume", volume); - }; - - service.debugModeEnabled = function () { - const globalSettings = dataAccess.getJsonDbInUserData("/global-settings"); - let enabled; - try { - enabled = globalSettings.getData("/settings/debugMode"); - } catch (err) { } //eslint-disable-line no-empty - return enabled != null ? enabled : false; - }; - - service.setDebugModeEnabled = function (enabled) { - const globalSettings = dataAccess.getJsonDbInUserData("/global-settings"); - try { - globalSettings.push("/settings/debugMode", enabled === true); - } catch (err) { } //eslint-disable-line no-empty - }; - - service.getViewerColumnPreferences = function () { - const prefs = getDataFromFile("/settings/viewerColumnPreferences", false, { lastSeen: true }); - return prefs != null ? prefs : { lastSeen: true }; - }; - - service.setViewerColumnPreferences = function (prefs) { - pushDataToFile("/settings/viewerColumnPreferences", prefs); - }; - - service.deleteFromViewerColumnPreferences = function (columnName) { - deleteDataAtPath(`/settings/viewerColumnPreferences/${columnName}`); - }; - - service.getDefaultTtsVoiceId = function () { - const id = getDataFromFile('/settings/defaultTtsVoiceId'); - return id; - }; - - service.setDefaultTtsVoiceId = function (id) { - pushDataToFile('/settings/defaultTtsVoiceId', id); - }; - - service.getTtsVoiceVolume = function () { - const volume = getDataFromFile('/settings/ttsVoiceVolume', false, 0.5); - return volume !== undefined ? volume : 0.5; - }; - - service.setTtsVoiceVolume = function (volume) { - pushDataToFile('/settings/ttsVoiceVolume', volume); - }; - - service.getTtsVoiceRate = function () { - const rate = getDataFromFile('/settings/ttsVoiceRate', false, 1); - return rate !== undefined ? rate : 1; - }; - - service.setTtsVoiceRate = function (rate) { - pushDataToFile('/settings/ttsVoiceRate', rate); - }; - - - service.getWhileLoopEnabled = function () { - const enabled = getDataFromFile('/settings/whileLoopEnabled', false, false); - return enabled !== undefined ? enabled : false; - }; - - service.setWhileLoopEnabled = function (enabled) { - pushDataToFile('/settings/whileLoopEnabled', enabled === true); - }; - - service.getMinimizeToTray = function () { - return getDataFromFile('/settings/minimizeToTray', false, false) === true; - }; - service.setMinimizeToTray = function (minimizeToTray) { - pushDataToFile('/settings/minimizeToTray', minimizeToTray === true); - }; - - service.getWebOnlineCheckin = () => { - const webOnlineCheckin = getDataFromFile("/settings/webOnlineCheckin"); - return webOnlineCheckin === true; - }; - - service.setWebOnlineCheckin = (value) => { - pushDataToFile("/settings/webOnlineCheckin", value); - }; - - service.getAllowCommandsInSharedChat = function () { - return getDataFromFile("/settings/allowCommandsInSharedChat", false, false); // default OFF - }; - - service.setAllowCommandsInSharedChat = function (value) { - pushDataToFile("/settings/allowCommandsInSharedChat", value); - }; - return service; }); -}()); +}()); \ No newline at end of file diff --git a/src/gui/app/services/sidebar-manager.service.js b/src/gui/app/services/sidebar-manager.service.js index a62fa358c..51a61127a 100644 --- a/src/gui/app/services/sidebar-manager.service.js +++ b/src/gui/app/services/sidebar-manager.service.js @@ -6,12 +6,12 @@ .factory("sidebarManager", function($timeout, $rootScope, $location, $translate, settingsService, uiExtensionsService, backendCommunicator) { const service = {}; - service.navExpanded = settingsService.getSidebarExpanded(); + service.navExpanded = settingsService.getSetting("SidebarExpanded"); service.toggleNav = function() { service.navExpanded = !service.navExpanded; $rootScope.$broadcast("navToggled"); - settingsService.setSidebarExpanded(service.navExpanded); + settingsService.saveSetting("SidebarExpanded", service.navExpanded); }; service.currentTab = "chat feed"; diff --git a/src/gui/app/services/sort-tags.service.js b/src/gui/app/services/sort-tags.service.js index 197b045e6..1f1c9f664 100644 --- a/src/gui/app/services/sort-tags.service.js +++ b/src/gui/app/services/sort-tags.service.js @@ -96,7 +96,7 @@ resolveObj: { tags: () => sortTagsForContext }, - closeCallback: tags => { + closeCallback: (tags) => { sortTags[context] = tags; saveAllSortTags(); } @@ -105,11 +105,11 @@ }; /** @param {SortTag} context */ - service.getSelectedSortTag = (context) => selectedSortTags[context]; + service.getSelectedSortTag = context => selectedSortTags[context]; /** @param {string} context */ // eslint-disable-next-line no-confusing-arrow - service.getSelectedSortTagDisplay = (context) => (selectedSortTags[context] != null ? selectedSortTags[context].name : `All ${context}`); + service.getSelectedSortTagDisplay = context => (selectedSortTags[context] != null ? selectedSortTags[context].name : `All ${context}`); /** * @param {string} context @@ -125,9 +125,9 @@ */ service.getLegacyEventAndCommandTags = () => { - if (!settingsService.legacySortTagsImported()) { + if (!settingsService.getSetting("LegacySortTagsImported")) { - settingsService.setLegacySortTagsImported(true); + settingsService.saveSetting("LegacySortTagsImported", true); /**@type {Object.} */ const legacySortTags = { @@ -155,7 +155,7 @@ // silently fail } - Object.keys(legacySortTags).forEach(context => { + Object.keys(legacySortTags).forEach((context) => { if (sortTags[context] == null) { sortTags[context] = []; diff --git a/src/gui/app/services/sound.service.js b/src/gui/app/services/sound.service.js index 2796c0bd1..d129b9619 100644 --- a/src/gui/app/services/sound.service.js +++ b/src/gui/app/services/sound.service.js @@ -13,8 +13,8 @@ // Connection Sounds service.connectSound = function(type) { - if (settingsService.soundsEnabled() === "On") { - const outputDevice = settingsService.getAudioOutputDevice(); + if (settingsService.getSetting("SoundsEnabled") === "On") { + const outputDevice = settingsService.getSetting("AudioOutputDevice"); if (type === "Online") { service.playSound("../sounds/connect_new_b.mp3", 0.2, outputDevice); } else { @@ -25,8 +25,8 @@ let popCounter = 0; service.popSound = function() { - if (settingsService.soundsEnabled() === "On") { - const outputDevice = settingsService.getAudioOutputDevice(); + if (settingsService.getSetting("SoundsEnabled") === "On") { + const outputDevice = settingsService.getSetting("AudioOutputDevice"); popCounter++; if (popCounter > 4) { popCounter = 1; @@ -79,7 +79,7 @@ ]; service.playChatNotification = function() { - let selectedSound = settingsService.getTaggedNotificationSound(); + let selectedSound = settingsService.getSetting("ChatTaggedNotificationSound"); if (selectedSound.name === "None") { return; @@ -91,7 +91,7 @@ ); } - const volume = settingsService.getTaggedNotificationVolume() / 100 * 10; + const volume = settingsService.getSetting("ChatTaggedNotificationVolume") / 100 * 10; if (selectedSound.path != null && selectedSound.path !== "") { service.playSound(selectedSound.path, volume); } @@ -101,11 +101,11 @@ service.playSound = function(path, volume, outputDevice, fileType = null, maxSoundLength = null) { if (outputDevice == null) { - outputDevice = settingsService.getAudioOutputDevice(); + outputDevice = settingsService.getSetting("AudioOutputDevice"); } $q.when(service.getHowlSound(path, volume, outputDevice, fileType)) - .then(sound => { + .then((sound) => { let maxSoundLengthTimeout; // Clear listener after first call. @@ -131,9 +131,9 @@ }); }; - service.getHowlSound = function(path, volume, outputDevice = settingsService.getAudioOutputDevice(), fileType = null) { + service.getHowlSound = function(path, volume, outputDevice = settingsService.getSetting("AudioOutputDevice"), fileType = null) { return navigator.mediaDevices.enumerateDevices() - .then(deviceList => { + .then((deviceList) => { const filteredDevice = deviceList.filter(d => d.label === outputDevice.label || d.deviceId === outputDevice.deviceId); @@ -153,7 +153,7 @@ }; service.getSoundDuration = function(path, format = undefined) { - return new Promise(resolve => { + return new Promise((resolve) => { console.log("duration for", path, format); @@ -178,7 +178,7 @@ // Watches for an event from main process listenerService.registerListener( { type: listenerService.ListenerType.PLAY_SOUND }, - data => { + (data) => { const filepath = data.filepath; const volume = data.volume / 100 * 10; @@ -187,7 +187,7 @@ selectedOutputDevice == null || selectedOutputDevice.label === "App Default" ) { - selectedOutputDevice = settingsService.getAudioOutputDevice(); + selectedOutputDevice = settingsService.getSetting("AudioOutputDevice"); } if (selectedOutputDevice.deviceId === 'overlay') { diff --git a/src/gui/app/services/tts.service.js b/src/gui/app/services/tts.service.js index db4c9b11a..e829c7962 100644 --- a/src/gui/app/services/tts.service.js +++ b/src/gui/app/services/tts.service.js @@ -26,8 +26,8 @@ }); }; service.obtainVoices = () => { - return new Promise(resolve => { - $q.when(obtainVoices()).then(foundVoices => { + return new Promise((resolve) => { + $q.when(obtainVoices()).then((foundVoices) => { voices = foundVoices; resolve(); }); @@ -35,7 +35,7 @@ }; service.getVoices = () => { - return voices.map(v => { + return voices.map((v) => { return { id: v.voiceURI, name: v.name @@ -52,7 +52,7 @@ }; service.getFirebotDefaultVoiceId = () => { - const savedDefaultVoiceId = settingsService.getDefaultTtsVoiceId(); + const savedDefaultVoiceId = settingsService.getSetting("DefaultTtsVoiceId"); if (savedDefaultVoiceId) { return savedDefaultVoiceId; } @@ -86,8 +86,8 @@ const msg = new SpeechSynthesisUtterance(); msg.voice = speechSynthesisVoice; - msg.volume = settingsService.getTtsVoiceVolume(); - msg.rate = settingsService.getTtsVoiceRate(); + msg.volume = settingsService.getSetting("TtsVoiceVolume"); + msg.rate = settingsService.getSetting("TtsVoiceRate"); msg.text = text; msg.lang = 'en-US'; diff --git a/src/gui/app/services/updates.service.js b/src/gui/app/services/updates.service.js index 2a491be68..31dbcfec3 100644 --- a/src/gui/app/services/updates.service.js +++ b/src/gui/app/services/updates.service.js @@ -84,7 +84,7 @@ if (!foundMajorRelease && (updateType === UpdateType.MAJOR || updateType === UpdateType.MAJOR_PRERELEASE)) { foundMajorRelease = true; - if (settingsService.notifyOnBeta()) { + if (settingsService.getSetting("NotifyOnBeta")) { service.majorUpdate = { gitName: release.name, gitVersion: release.tag_name, @@ -95,7 +95,7 @@ updateType === UpdateType.PATCH || updateType === UpdateType.MINOR || updateType === UpdateType.NONE || - (updateType === UpdateType.PRERELEASE && settingsService.notifyOnBeta())) { + (updateType === UpdateType.PRERELEASE && settingsService.getSetting("NotifyOnBeta"))) { latestRelease = release; latestUpdateType = updateType; break; @@ -117,7 +117,7 @@ let updateIsAvailable = false; if (latestUpdateType !== UpdateType.NONE) { updateIsAvailable = true; - const autoUpdateLevel = settingsService.getAutoUpdateLevel(); + const autoUpdateLevel = settingsService.getSetting("AutoUpdateLevel"); // Check if we should auto update based on the users setting if (shouldAutoUpdate(autoUpdateLevel, latestUpdateType)) { diff --git a/src/gui/app/services/utility.service.js b/src/gui/app/services/utility.service.js index 5c69578ed..8380d5365 100644 --- a/src/gui/app/services/utility.service.js +++ b/src/gui/app/services/utility.service.js @@ -321,7 +321,7 @@ instanceName ) => { - $scope.usingOverlayInstances = settingsService.useOverlayInstances(); + $scope.usingOverlayInstances = settingsService.getSetting("UseOverlayInstances"); $scope.broadcastingSoftwares = [ "Local", "Direct Link/2 PC Setup" @@ -338,7 +338,7 @@ $scope.buildOverlayPath = () => { let overlayPath = dataAccess.getPathInUserData("overlay.html"); - const port = settingsService.getWebServerPort(); + const port = settingsService.getSetting("WebServerPort"); const params = {}; if ($scope.selectedBroadcastingSoftware === "Direct Link/2 PC Setup") { @@ -346,7 +346,7 @@ } else { if (port !== 7472 && !isNaN(port)) { - params["port"] = settingsService.getWebServerPort(); + params["port"] = settingsService.getSetting("WebServerPort"); } overlayPath = `file:///${overlayPath.replace(/^\//g, "")}`; } @@ -408,10 +408,10 @@ $uibModalInstance, settingsService ) => { - $scope.textSettings = settingsService.getOverlayEventsSettings(); + $scope.textSettings = settingsService.getSetting("EventSettings"); $scope.save = function() { - settingsService.saveOverlayEventsSettings($scope.textSettings); + settingsService.saveSetting("EventsSettings", $scope.textSettings); $uibModalInstance.dismiss(); }; diff --git a/src/gui/app/services/viewers.service.js b/src/gui/app/services/viewers.service.js index e20d6af4e..905ad9809 100644 --- a/src/gui/app/services/viewers.service.js +++ b/src/gui/app/services/viewers.service.js @@ -9,7 +9,7 @@ // Check to see if the DB is turned on or not. service.isViewerDbOn = function() { - return settingsService.getViewerDB(); + return settingsService.getSetting("ViewerDB"); }; service.viewers = []; diff --git a/src/gui/app/templates/chat/_chat-messages.html b/src/gui/app/templates/chat/_chat-messages.html index d48667bf0..8d71a9109 100644 --- a/src/gui/app/templates/chat/_chat-messages.html +++ b/src/gui/app/templates/chat/_chat-messages.html @@ -172,13 +172,13 @@

diff --git a/src/server/http-server-manager.ts b/src/server/http-server-manager.ts index bd40b2a22..c72bf5fc2 100644 --- a/src/server/http-server-manager.ts +++ b/src/server/http-server-manager.ts @@ -6,7 +6,7 @@ import bodyParser from "body-parser"; import cors from 'cors'; import path from 'path'; import logger from "../backend/logwrapper"; -import { settings } from "../backend/common/settings-access"; +import { SettingsManager } from "../backend/common/settings-manager"; import effectManager from "../backend/effects/effectManager"; import resourceTokenManager from "../backend/resourceTokenManager"; import websocketServerManager from "./websocket-server-manager"; @@ -200,7 +200,7 @@ class HttpServerManager extends EventEmitter { } startDefaultHttpServer() { - const port: number = settings.getWebServerPort(); + const port: number = SettingsManager.getSetting("WebServerPort"); websocketServerManager.createServer(this.defaultHttpServer); diff --git a/src/types/settings.d.ts b/src/types/settings.d.ts new file mode 100644 index 000000000..cb098aff3 --- /dev/null +++ b/src/types/settings.d.ts @@ -0,0 +1,193 @@ +export enum FirebotAutoUpdateLevel { + Off = 0, + Bugfix = 1, + Feature = 2, + MajorRelease = 3, + Betas = 4, +} + +export type FirebotAudioDevice = { + label: string; + deviceId: string; +} + +export type FirebotSettingsTypes = { + ActiveChatUserListTimeout: number; + AllowCommandsInSharedChat: boolean; + AllowQuoteCSVDownloads: boolean; + AllowedActivityEvents: string[]; + AudioOutputDevice: FirebotAudioDevice; + AutoFlagBots: boolean; + AutoUpdateLevel: FirebotAutoUpdateLevel; + BackupBeforeUpdates: boolean; + BackupIgnoreResources: boolean; + BackupKeepAll: boolean; + BackupLocation: string; + BackupOnceADay: boolean; + BackupOnExit: boolean; + ChatAlternateBackgrounds: boolean; + ChatAvatars: boolean; + ChatCompactMode: boolean; + ChatCustomFontSize: number; + ChatCustomFontSizeEnabled: boolean; + ChatHideBotAccountMessages: boolean; + ChatHideDeletedMessages: boolean; + ChatHideWhispers: boolean; + ChatPronouns: boolean; + ChatShowBttvEmotes: boolean; + ChatShowFfzEmotes: boolean; + ChatShowSevenTvEmotes: boolean; + ChatTaggedNotificationSound: { name: string, path?: string | undefined }; + ChatTaggedNotificationVolume: number; + ChatTimestamps: boolean; + ClearChatFeedMode: "never" | "onlyStreamer" | "always"; + ClearCustomScriptCache: boolean; + CopiedOverlayVersion: string; + DashboardLayout: object; //TODO + DebugMode: boolean; + DefaultToAdvancedCommandMode: boolean; + DefaultTtsVoiceId: string; + EventSettings: object; //TODO + FirstTimeUse: boolean; + ForceOverlayEffectsToContinueOnRefresh: boolean; + IgnoreSubsequentSubEventsAfterCommunitySub: boolean; + JustUpdated: boolean; + LastBackupDate: Date; + LegacySortTagsImported: boolean; + MaxBackupCount: number | "All"; + MinimizeToTray: boolean; + NotifyOnBeta: boolean; + OpenStreamPreviewOnLaunch: boolean; + OverlayInstances: string[]; + PersistCustomVariables: boolean; + QuickActions: object; //TODO + RunCustomScripts: boolean; + SeenAdvancedCommandModePopup: boolean; + ShowAdBreakIndicator: boolean; + ShowActivityFeed: boolean; + ShowChatViewerList: boolean; + ShowHypeTrainIndicator: boolean; + ShowUptimeStat: boolean; + ShowViewerCountStat: boolean; + SidebarControlledServices: string[]; + SidebarExpanded: boolean; + SoundsEnabled: "On" | "Off"; + Theme: string; + TriggerUpcomingAdBreakMinutes: number; + TtsVoiceRate: number; + TtsVoiceVolume: number; + UseOverlayInstances: boolean; + ViewerDB: boolean; + ViewerListPageSize: number; + WebOnlineCheckin: boolean; + WebServerPort: number; + WhileLoopEnabled: boolean; + WysiwygBackground: "black" | "white"; +} + +export const FirebotGlobalSettings: Partial> = { + DebugMode: true +}; + +export const FirebotSettingsDefaults: FirebotSettingsTypes = { + ActiveChatUserListTimeout: 5, + AllowCommandsInSharedChat: false, + AllowQuoteCSVDownloads: true, + AllowedActivityEvents: [ + "twitch:raid", + "twitch:raid-sent-off", + "twitch:follow", + "twitch:sub", + "twitch:subs-gifted", + "twitch:community-subs-gifted", + "twitch:cheer", + "streamlabs:donation", + "streamlabs:eldonation", + 'extralife:donation', + "tipeeestream:donation", + "streamelements:donation", + "twitch:channel-reward-redemption" + ], + AudioOutputDevice: { label: "System Default", deviceId: "default" }, + AutoFlagBots: true, + AutoUpdateLevel: FirebotAutoUpdateLevel.Feature, + BackupBeforeUpdates: true, + BackupIgnoreResources: true, + BackupKeepAll: false, + BackupLocation: undefined, + BackupOnceADay: true, + BackupOnExit: true, + ChatAlternateBackgrounds: true, + ChatAvatars: true, + ChatCompactMode: false, + ChatCustomFontSize: 17, + ChatCustomFontSizeEnabled: false, + ChatHideBotAccountMessages: false, + ChatHideDeletedMessages: false, + ChatHideWhispers: false, + ChatPronouns: true, + ChatShowBttvEmotes: true, + ChatShowFfzEmotes: true, + ChatShowSevenTvEmotes: true, + ChatTaggedNotificationSound: { name: "None" }, + ChatTaggedNotificationVolume: 5, + ChatTimestamps: true, + ClearChatFeedMode: "onlyStreamer", + ClearCustomScriptCache: false, + CopiedOverlayVersion: "", + DashboardLayout: {}, + DebugMode: false, + DefaultToAdvancedCommandMode: false, + DefaultTtsVoiceId: undefined, + EventSettings: {}, + FirstTimeUse: true, + ForceOverlayEffectsToContinueOnRefresh: true, + IgnoreSubsequentSubEventsAfterCommunitySub: true, + JustUpdated: false, + LegacySortTagsImported: false, + LastBackupDate: null, + MaxBackupCount: 25, + MinimizeToTray: false, + NotifyOnBeta: false, + OpenStreamPreviewOnLaunch: false, + OverlayInstances: [], + PersistCustomVariables: false, + QuickActions: {}, + RunCustomScripts: false, + SeenAdvancedCommandModePopup: false, + ShowActivityFeed: true, + ShowAdBreakIndicator: true, + ShowChatViewerList: true, + ShowHypeTrainIndicator: true, + ShowUptimeStat: true, + ShowViewerCountStat: true, + SidebarControlledServices: ["chat"], + SidebarExpanded: true, + SoundsEnabled: "On", + Theme: "Obsidian", + TriggerUpcomingAdBreakMinutes: 0, + TtsVoiceRate: 1, + TtsVoiceVolume: 0.5, + UseOverlayInstances: false, + ViewerDB: true, + ViewerListPageSize: 10, + WebOnlineCheckin: false, + WebServerPort: 7472, + WhileLoopEnabled: false, + WysiwygBackground: "white" +}; + +/** Anything in `SettingsTypes` not listed here will resolve to "/settings/settingName" (e.g. "/settings/autoFlagBots") */ +export const FirebotSettingsPaths: Partial> = { + ActiveChatUserListTimeout: "/settings/activeChatUsers/inactiveTimer", + ChatShowBttvEmotes: "/settings/chat/emotes/bttv", + ChatShowFfzEmotes: "/settings/chat/emotes/ffz", + ChatShowSevenTvEmotes: "/settings/chat/emotes/seventv", + ChatTaggedNotificationSound: "/settings/chat/tagged/sound", + ChatTaggedNotificationVolume: "/settings/chat/tagged/volume", + DashboardLayout: "/settings/dashboard/layout", + ShowActivityFeed: "/settings/activityFeed", + ShowChatViewerList: "/settings/chatUsersList", + SoundsEnabled: "/settings/sounds", + ViewerListPageSize: "/settings/viewerListDatabase/pageSize" +}; \ No newline at end of file