Skip to content

Commit

Permalink
WIP more profile manager refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
zunderscore committed Dec 28, 2024
1 parent c161769 commit 20db1b9
Show file tree
Hide file tree
Showing 27 changed files with 95 additions and 109 deletions.
4 changes: 2 additions & 2 deletions src/backend/app-management/electron/events/when-ready.js
Original file line number Diff line number Diff line change
Expand Up @@ -225,8 +225,8 @@ exports.whenReady = async () => {
// change anything until we are ready as changing this will break most scripts
const Effect = require("../../../common/EffectType");
global.EffectType = Effect.EffectTypeV5Map;
const profileManager = require("../../../common/profile-manager");
global.SCRIPTS_DIR = profileManager.getPathInProfile("/scripts/");
const { ProfileManager } = require("../../../common/profile-manager");
global.SCRIPTS_DIR = ProfileManager.getPathInProfile("/scripts/");

windowManagement.updateSplashScreenStatus("Running daily backup...");
const { BackupManager } = require("../../../backup-manager");
Expand Down
4 changes: 2 additions & 2 deletions src/backend/app-management/electron/window-management.js
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ async function createMainWindow() {
exports.mainWindow = mainWindow;
global.renderWindow = mainWindow;

const profileManager = require("../../common/profile-manager");
const { ProfileManager } = require("../../common/profile-manager");
const dataAccess = require("../../common/data-access");
const menuTemplate = [
{
Expand All @@ -231,7 +231,7 @@ async function createMainWindow() {
sublabel: "Open the folder where Firebot data is stored",
click: () => {
const rootFolder = path.resolve(
profileManager.getPathInProfile("/")
ProfileManager.getPathInProfile("/")
);
shell.openPath(rootFolder);
},
Expand Down
9 changes: 0 additions & 9 deletions src/backend/app-management/profile-tasks.js

This file was deleted.

9 changes: 4 additions & 5 deletions src/backend/channel-rewards/channel-reward-manager.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { JsonDB } from "node-json-db";
import logger from "../logwrapper";
import accountAccess from "../common/account-access";
import profileManager from "../common/profile-manager";
import { ProfileManager } from "../common/profile-manager";
import frontendCommunicator from "../common/frontend-communicator";
import twitchApi from "../twitch-api/api";
import activeUserHandler from "../chat/chat-listeners/active-user-handler"
import activeUserHandler from "../chat/chat-listeners/active-user-handler";
import { CustomReward, RewardRedemption, RewardRedemptionsApprovalRequest } from "../twitch-api/resource/channel-rewards";
import { EffectTrigger } from "../../shared/effect-constants";
import { RewardRedemptionMetadata, SavedChannelReward } from "../../types/channel-rewards";
Expand Down Expand Up @@ -74,8 +74,7 @@ class ChannelRewardManager {
}

getChannelRewardsDb(): JsonDB {
return profileManager
.getJsonDbInProfile("channel-rewards");
return ProfileManager.getJsonDbInProfile("channel-rewards");
}

async loadChannelRewards() {
Expand Down Expand Up @@ -293,7 +292,7 @@ class ChannelRewardManager {
If all user data is present mark user as active
handles use from src/backend/events/twitch-events/reward-redemption.ts
the two other uses of triggerChannel reward do not have this data and are initiated by the streamer
retrigger-event and manually-trigger-reward and as such should not set a user as active
retrigger-event and manually-trigger-reward and as such should not set a user as active
*/
await activeUserHandler.addActiveUser({userName: metadata.username, userId: metadata.userId, displayName: metadata.userDisplayName}, true);
}
Expand Down
4 changes: 2 additions & 2 deletions src/backend/chat/commands/command-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { DateTime } from "luxon";
import { CommandDefinition, SystemCommand, SystemCommandDefinition } from "../../../types/commands";
import logger from "../../logwrapper";
import util from "../../utility";
import profileManager from "../../common/profile-manager";
import { ProfileManager } from "../../common/profile-manager";
import frontendCommunicator from "../../common/frontend-communicator";
import accountAccess from "../../common/account-access";

Expand Down Expand Up @@ -43,7 +43,7 @@ class CommandManager extends TypedEmitter<Events> {
}

private getCommandsDb(): JsonDB {
return profileManager.getJsonDbInProfile("/chat/commands");
return ProfileManager.getJsonDbInProfile("/chat/commands");
}

/**
Expand Down
10 changes: 5 additions & 5 deletions src/backend/chat/moderation/chat-moderation-manager.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
"use strict";
const logger = require("../../logwrapper");
const profileManager = require("../../common/profile-manager");
const { ProfileManager } = require("../../common/profile-manager");
const { Worker } = require("worker_threads");
const frontendCommunicator = require("../../common/frontend-communicator");
const rolesManager = require("../../roles/custom-roles-manager");
const permitCommand = require("./url-permit-command");
const utils = require("../../utility");

const getChatModerationSettingsDb = () => profileManager.getJsonDbInProfile("/chat/moderation/chat-moderation-settings");
const getBannedWordsDb = () => profileManager.getJsonDbInProfile("/chat/moderation/banned-words", false);
const getBannedRegularExpressionsDb = () => profileManager.getJsonDbInProfile("/chat/moderation/banned-regular-expressions", false);
const getUrlAllowlistDb = () => profileManager.getJsonDbInProfile("/chat/moderation/url-allowlist", false);
const getChatModerationSettingsDb = () => ProfileManager.getJsonDbInProfile("/chat/moderation/chat-moderation-settings");
const getBannedWordsDb = () => ProfileManager.getJsonDbInProfile("/chat/moderation/banned-words", false);
const getBannedRegularExpressionsDb = () => ProfileManager.getJsonDbInProfile("/chat/moderation/banned-regular-expressions", false);
const getUrlAllowlistDb = () => ProfileManager.getJsonDbInProfile("/chat/moderation/url-allowlist", false);

// default settings
let chatModerationSettings = {
Expand Down
8 changes: 4 additions & 4 deletions src/backend/common/account-access.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"use strict";

const profileManager = require("./profile-manager");
const { ProfileManager } = require("./profile-manager");
const logger = require("../logwrapper");
const frontendCommunicator = require("./frontend-communicator");
const EventEmitter = require("events");
Expand Down Expand Up @@ -64,7 +64,7 @@ async function updateStreamerAccountSettings(streamerAccount) {
}

function saveAccountDataToFile(accountType) {
const authDb = profileManager.getJsonDbInProfile("/auth-twitch");
const authDb = ProfileManager.getJsonDbInProfile("/auth-twitch");
const account = cache[accountType];
try {
authDb.push(`/${accountType}`, account);
Expand All @@ -80,7 +80,7 @@ function saveAccountDataToFile(accountType) {
* @param {boolean} [emitUpdate=true] - If an account update event should be emitted
*/
async function loadAccountData(emitUpdate = true) {
const authDb = profileManager.getJsonDbInProfile("/auth-twitch");
const authDb = ProfileManager.getJsonDbInProfile("/auth-twitch");
try {
const dbData = authDb.getData("/"),
streamer = dbData.streamer,
Expand Down Expand Up @@ -195,7 +195,7 @@ function removeAccount(accountType) {
return;
}

const authDb = profileManager.getJsonDbInProfile("/auth-twitch");
const authDb = ProfileManager.getJsonDbInProfile("/auth-twitch");
try {
authDb.delete(`/${accountType}`);
} catch (error) {
Expand Down
5 changes: 2 additions & 3 deletions src/backend/common/custom-variable-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,8 @@ cache.on("set", function(key, value) {
cache.on("del", onCustomVariableDelete);

function getVariableCacheDb() {
const profileManager = require("../common/profile-manager");
return profileManager
.getJsonDbInProfile("custom-variable-cache");
const { ProfileManager } = require("../common/profile-manager");
return ProfileManager.getJsonDbInProfile("custom-variable-cache");
}

exports.getInitialInspectorVariables = () =>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"use strict";
const twitchChat = require("../../../chat/twitch-chat");
const twitchApi = require("../../../twitch-api/api");
const profileManager = require("../../profile-manager");
const { ProfileManager } = require("../../profile-manager");
const settings = require('../../settings-manager').SettingsManager;
const path = require("path");
const logger = require("../../../logwrapper");
Expand Down Expand Up @@ -146,7 +146,7 @@ function buildRunRequest(scriptManifest, params, trigger) {
}

function getScriptPath(scriptName) {
const scriptsFolder = profileManager.getPathInProfile("/scripts");
const scriptsFolder = ProfileManager.getPathInProfile("/scripts");
return path.resolve(scriptsFolder, scriptName);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const { ipcMain, shell } = require("electron");
const { v4: uuid } = require("uuid");
const logger = require("../../../logwrapper");
const utils = require("../../../utility");
const profileManager = require("../../profile-manager");
const { ProfileManager } = require("../../profile-manager");
const { getScriptPath, buildRunRequest, mapParameters } = require("./custom-script-helpers");
const effectRunner = require("../../effect-runner.js");
import { SettingsManager } from "../../settings-manager";
Expand Down Expand Up @@ -254,7 +254,7 @@ async function stopAllScripts() {
}

ipcMain.on("openScriptsFolder", function () {
shell.openPath(profileManager.getPathInProfile("/scripts"));
shell.openPath(ProfileManager.getPathInProfile("/scripts"));
});

exports.runScript = runScript;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"use strict";

const logger = require("../../../logwrapper");
const profileManager = require("../../../common/profile-manager");
const { ProfileManager } = require("../../../common/profile-manager");
const frontendCommunicator = require("../../../common/frontend-communicator");
const { runStartUpScript, startUpScriptSaved, startUpScriptDeleted } = require("./custom-script-runner");

Expand All @@ -19,8 +19,7 @@ const { runStartUpScript, startUpScriptSaved, startUpScriptDeleted } = require("
let startupScripts = {};

function getStartupScriptsConfig() {
return profileManager
.getJsonDbInProfile("startup-scripts-config");
return ProfileManager.getJsonDbInProfile("startup-scripts-config");
}

function loadStartupConfig() {
Expand Down
4 changes: 2 additions & 2 deletions src/backend/counters/counter-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import JsonDbManager from "../database/json-db-manager";
import frontendCommunicator from "../common/frontend-communicator";
import accountAccess from "../common/account-access";
import effectRunner from "../common/effect-runner";
import profileManager from "../common/profile-manager";
import { ProfileManager } from "../common/profile-manager";
import { TriggerType } from "../common/EffectType";
import { Counter } from "../../types/counters";
import { EffectList } from "../../types/effects";
Expand Down Expand Up @@ -90,7 +90,7 @@ class CounterManager extends JsonDbManager<Counter> {
}

getCounterTxtFilePath(counterName: string): string {
const folder = profileManager.getPathInProfile("/counters/");
const folder = ProfileManager.getPathInProfile("/counters/");
const sanitizedCounterName = sanitizeFileName(counterName);

return path.join(folder, `${sanitizedCounterName}.txt`) || "";
Expand Down
4 changes: 2 additions & 2 deletions src/backend/currency/currency-access.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { FirebotViewer } from "../../types/viewers";
import logger from "../logwrapper";
import frontendCommunicator from "../common/frontend-communicator";
import { SettingsManager } from "../common/settings-manager";
import profileManager from "../common/profile-manager";
import { ProfileManager } from "../common/profile-manager";

export type Currency = {
id: string;
Expand Down Expand Up @@ -47,7 +47,7 @@ class CurrencyAccess {
}

logger.debug("Refreshing currency cache");
const db = profileManager.getJsonDbInProfile("/currency/currency");
const db = ProfileManager.getJsonDbInProfile("/currency/currency");

let issue2801 = false;
const cache = db.getData("/");
Expand Down
6 changes: 2 additions & 4 deletions src/backend/database/json-db-manager.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
"use strict";

import profileManager from "../common/profile-manager";
import { ProfileManager } from "../common/profile-manager";
import logger from "../logwrapper";
import { v4 as uuid } from "uuid";
import { TypedEmitter, type ListenerSignature } from "tiny-typed-emitter";
Expand Down Expand Up @@ -45,7 +43,7 @@ class JsonDbManager<T extends Item, E extends ListenerSignature<E> = DefaultEven
this.items = {};

/** @protected */
this.db = profileManager.getJsonDbInProfile(path);
this.db = ProfileManager.getJsonDbInProfile(path);
}

loadItems(): void {
Expand Down
8 changes: 4 additions & 4 deletions src/backend/database/statsDatabase.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
"use strict";
const Datastore = require("nedb");
const profileManager = require("../common/profile-manager");
const { ProfileManager } = require("../common/profile-manager");
const logger = require("../logwrapper");
const { app } = require("electron");

let db;

function connectStatsDatabase() {
const path = profileManager.getPathInProfile("db/stats.db");
const path = ProfileManager.getPathInProfile("db/stats.db");
db = new Datastore({ filename: path });
db.loadDatabase(err => {
db.loadDatabase((err) => {
if (err) {
logger.error("Error Loading Database: ", err.message);
logger.debug("Failed Database Path: ", path);
Expand Down Expand Up @@ -46,7 +46,7 @@ function insertStatRecord(eventType, userId, meta) {
};

// Insert this record into the stats database.
db.insert(ins, err => {
db.insert(ins, (err) => {
if (err) {
logger.error("Error adding user: ", err.message);
}
Expand Down
8 changes: 4 additions & 4 deletions src/backend/events/events-access.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

const { ipcMain } = require("electron");
const logger = require("../logwrapper");
const profileManager = require("../common/profile-manager");
const { ProfileManager } = require("../common/profile-manager");

const frontendCommunicator = require("../common/frontend-communicator");

Expand All @@ -13,7 +13,7 @@ let groups = {};
let sortTags = [];

function getEventsDb() {
return profileManager.getJsonDbInProfile(`${EVENTS_FOLDER}events`);
return ProfileManager.getJsonDbInProfile(`${EVENTS_FOLDER}events`);
}

function saveGroup(group) {
Expand Down Expand Up @@ -195,7 +195,7 @@ function getEvent(eventId) {
return event;
}

ipcMain.on("getAllEventData", event => {
ipcMain.on("getAllEventData", (event) => {
logger.debug("got 'get all event data' request");
event.returnValue = {
mainEvents: Array.isArray(mainEvents) ? mainEvents : Object.values(mainEvents),
Expand Down Expand Up @@ -225,7 +225,7 @@ ipcMain.on("eventUpdate", (_, data) => {
}
});

frontendCommunicator.on("event-sort-tags-update", tags => {
frontendCommunicator.on("event-sort-tags-update", (tags) => {
sortTags = tags;
saveSortTags();
});
Expand Down
4 changes: 2 additions & 2 deletions src/backend/font-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import fsp from "fs/promises";
import path from "path";
import logger from "./logwrapper";
import frontendCommunicator from "./common/frontend-communicator";
import profileManager from "./common/profile-manager";
import { ProfileManager } from "./common/profile-manager";
import webServer from "../server/http-server-manager";

export enum FontFormat {
Expand Down Expand Up @@ -72,7 +72,7 @@ class FontManager {
}

get fontsFolder() {
return profileManager.getPathInProfile("/fonts");
return ProfileManager.getPathInProfile("/fonts");
}

get fontCssPath() {
Expand Down
6 changes: 3 additions & 3 deletions src/backend/games/game-manager.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
"use strict";

const profileManager = require("../common/profile-manager");
const { ProfileManager } = require("../common/profile-manager");
const frontendCommunicator = require("../common/frontend-communicator");

const getGameDb = () => profileManager.getJsonDbInProfile("/games");
const getGameDb = () => ProfileManager.getJsonDbInProfile("/games");

/**
* @typedef {"string" | "number" | "boolean" | "enum" | "filepath" | "currency-select" | "chatter-select" | "editable-list" | "role-percentages" | "role-numbers"} SettingType
Expand Down Expand Up @@ -178,7 +178,7 @@ function saveAllGameSettings() {
}

function getGames() {
return registeredGames.map(g => {
return registeredGames.map((g) => {
return {
id: g.id,
name: g.name,
Expand Down
6 changes: 3 additions & 3 deletions src/backend/hotkeys/hotkey-manager.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"use strict";

const { ipcMain, globalShortcut } = require("electron");
const profileManager = require("../../backend/common/profile-manager.js");
const { ProfileManager } = require("../../backend/common/profile-manager.js");
const { TriggerType } = require("../common/EffectType");
const effectRunner = require("../common/effect-runner.js");

Expand Down Expand Up @@ -55,14 +55,14 @@ function registerAllHotkeys() {
if (hotkeysCache == null) {
return;
}
hotkeysCache.filter(hk => hk.active).forEach(k => {
hotkeysCache.filter(hk => hk.active).forEach((k) => {
registerHotkey(k.code);
});
}

function refreshHotkeyCache(retry = 1) {
// Setup events db.
const dbEvents = profileManager.getJsonDbInProfile("/hotkeys");
const dbEvents = ProfileManager.getJsonDbInProfile("/hotkeys");

try {
if (retry <= 3) {
Expand Down
Loading

0 comments on commit 20db1b9

Please sign in to comment.