Skip to content

Commit

Permalink
Merge branch 'v5' into feat/reveal-correct-trivia-answer
Browse files Browse the repository at this point in the history
  • Loading branch information
zunderscore authored Jan 1, 2025
2 parents fc5c023 + a466bbd commit fa31924
Show file tree
Hide file tree
Showing 53 changed files with 957 additions and 820 deletions.
21 changes: 11 additions & 10 deletions src/backend/app-management/electron/events/when-ready.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,6 @@ exports.whenReady = async () => {
windowManagement.updateSplashScreenStatus("Refreshing Twitch account data...");
await accountAccess.refreshTwitchData();

const twitchFrontendListeners = require("../../../twitch-api/frontend-twitch-listeners");
twitchFrontendListeners.setupListeners();

windowManagement.updateSplashScreenStatus("Starting stream status poll...");
connectionManager.startOnlineCheckInterval();

Expand All @@ -72,7 +69,7 @@ exports.whenReady = async () => {

windowManagement.updateSplashScreenStatus("Loading currencies...");
const currencyAccess = require("../../../currency/currency-access").default;
currencyAccess.refreshCurrencyCache();
currencyAccess.loadCurrencies();

windowManagement.updateSplashScreenStatus("Loading ranks...");
const viewerRanksManager = require("../../../ranks/rank-manager");
Expand Down Expand Up @@ -166,8 +163,8 @@ exports.whenReady = async () => {
chatModerationManager.load();

windowManagement.updateSplashScreenStatus("Loading counters...");
const countersManager = require("../../../counters/counter-manager");
countersManager.loadItems();
const { CounterManager } = require("../../../counters/counter-manager");
CounterManager.loadItems();

windowManagement.updateSplashScreenStatus("Loading games...");
const gamesManager = require("../../../games/game-manager");
Expand All @@ -183,6 +180,10 @@ exports.whenReady = async () => {
customVariableManager.loadVariablesFromFile();
}

windowManagement.updateSplashScreenStatus("Loading sort tags...");
const { SortTagManager } = require("../../../sort-tags/sort-tag-manager");
SortTagManager.loadSortTags();

// get importer in memory
windowManagement.updateSplashScreenStatus("Loading importers...");

Expand All @@ -196,8 +197,8 @@ exports.whenReady = async () => {
setupCommonListeners();

windowManagement.updateSplashScreenStatus("Loading hotkeys...");
const hotkeyManager = require("../../../hotkeys/hotkey-manager");
hotkeyManager.refreshHotkeyCache();
const { HotkeyManager } = require("../../../hotkeys/hotkey-manager");
HotkeyManager.loadHotkeys();

windowManagement.updateSplashScreenStatus("Starting currency timer...");
const currencyManager = require("../../../currency/currency-manager");
Expand Down Expand Up @@ -251,8 +252,8 @@ exports.whenReady = async () => {
// load activity feed manager
require("../../../events/activity-feed-manager");

const iconManager = require("../../../common/icon-manager");
iconManager.loadFontAwesomeIcons();
const { IconManager } = require("../../../common/icon-manager");
await IconManager.loadFontAwesomeIcons();

windowManagement.updateSplashScreenStatus("Starting stream info poll...");
const streamInfoPoll = require("../../../twitch-api/stream-info-manager");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ exports.windowsAllClosed = async () => {
await customScriptRunner.stopAllScripts();

// Unregister all shortcuts.
const hotkeyManager = require("../../../hotkeys/hotkey-manager");
hotkeyManager.unregisterAllHotkeys();
const { HotkeyManager } = require("../../../hotkeys/hotkey-manager");
HotkeyManager.unregisterAllHotkeys();

// Stop the chat moderation service
const chatModerationManager = require("../../../chat/moderation/chat-moderation-manager");
Expand Down
4 changes: 4 additions & 0 deletions src/backend/auth/twitch-auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,11 @@ class TwitchAuthProviders {
'moderator:manage:shield_mode',
'moderator:manage:shoutouts',
'moderator:manage:unban_requests',
'moderator:manage:warnings',
'moderator:read:automod_settings',
'moderator:read:banned_users',
'moderator:read:blocked_terms',
'moderator:read:chat_messages',
'moderator:read:chat_settings',
'moderator:read:chatters',
'moderator:read:followers',
Expand All @@ -77,6 +80,7 @@ class TwitchAuthProviders {
'moderator:read:shoutouts',
'moderator:read:unban_requests',
'moderator:read:vips',
'moderator:read:warnings',
'user:edit:broadcast',
'user:manage:blocked_users',
'user:manage:whispers',
Expand Down
31 changes: 13 additions & 18 deletions src/backend/backup-manager.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { app } from "electron";
import path from "path";
import fs from "fs";
import fsp from "fs/promises";
import { glob } from "glob";
import { DeflateOptions, Zip, ZipDeflate, unzipSync } from "fflate";
Expand Down Expand Up @@ -144,23 +143,23 @@ class BackupManager {
const maxBackups = SettingsManager.getSetting("MaxBackupCount");

if (maxBackups !== "All") {
const fileNames = (await fsp.readdir(this._backupFolderPath))
.map((v) => {
const fileNames = (await Promise.all((await fsp.readdir(this._backupFolderPath))
.map(async (v) => {
return {
name: v,
time: (fs.statSync(path.join(this._backupFolderPath, v))).birthtime.getTime()
time: (await fsp.stat(path.join(this._backupFolderPath, v))).birthtime.getTime()
};
})
})))
.sort((a, b) => b.time - a.time)
.map(v => v.name)
.filter(n => !n.includes("NODELETE") && n.endsWith(".zip"));

fileNames.splice(0, maxBackups);

fileNames.forEach((f) => {
for (const f of fileNames) {
logger.info(`Deleting old backup: ${f}`);
fs.unlinkSync(path.join(this._backupFolderPath, f));
});
await fsp.unlink(path.join(this._backupFolderPath, f));
}

if (callback instanceof Function) {
callback();
Expand All @@ -184,15 +183,9 @@ class BackupManager {
}.${fileExtension}`;

await fsp.mkdir(this._backupFolderPath, { recursive: true });
const output = fs.createWriteStream(path.join(this._backupFolderPath, filename));

// listen for all archive data to be written
output.on("close", async () => {
SettingsManager.saveSetting("LastBackupDate", new Date());
await this.cleanUpOldBackups(callback);
});
const output = await fsp.open(path.join(this._backupFolderPath, filename), "w");

const archive = new Zip((err, data, final) => {
const archive = new Zip(async (err, data, final) => {
if (err) {
// throw error
if (manualActivation) {
Expand All @@ -204,10 +197,12 @@ class BackupManager {
globalThis.renderWindow.webContents.send("error", err);
throw err;
} else {
output.write(data);
await output.write(data);

if (final) {
output.close();
await output.close();
SettingsManager.saveSetting("LastBackupDate", new Date());
await this.cleanUpOldBackups(callback);
}
}
});
Expand Down
42 changes: 21 additions & 21 deletions src/backend/common/data-access.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ const isDev = !app.isPackaged;

// This is the path to folder the app is currently living in. IE: C:\Users\<user>\AppData\Local\Firebot\app-4.0.0\
// This will change after every update.
const workingDirectoryRoot = process.platform === 'darwin' ? process.resourcesPath : process.cwd();
const workingDirectoryRoot = process.platform === 'darwin' ? process.resourcesPath : path.dirname(process.execPath);
const workingDirectoryPath = isDev ? path.join(app.getAppPath(), "build") : workingDirectoryRoot;

const getWorkingDirectoryPath = function() {
const getWorkingDirectoryPath = function () {
return workingDirectoryPath;
};

Expand All @@ -38,29 +38,29 @@ if (Object.hasOwn(argv, 'fbuser-data-directory') && argv['fbuser-data-directory'
tmpDirectoryPath = path.join(rootUserDataPath, "tmp");
}

const getPathInUserData = function(filePath) {
const getPathInUserData = function (filePath) {
return path.join(userDataPath, filePath);
};

const getPathInWorkingDir = function(filePath) {
const getPathInWorkingDir = function (filePath) {
return path.join(workingDirectoryPath, filePath);
};

const getPathInTmpDir = function(filePath) {
const getPathInTmpDir = function (filePath) {
return path.join(tmpDirectoryPath, filePath);
};

const deletePathInTmpDir = function(filePath) {
const deletePathInTmpDir = function (filePath) {
fs.unlinkSync(path.join(tmpDirectoryPath, filePath));
};

const deletePathInUserData = function(filePath) {
const deletePathInUserData = function (filePath) {
fs.unlinkSync(path.join(userDataPath, filePath));
};

const deleteFolderRecursive = function(pathname) {
const deleteFolderRecursive = function (pathname) {
if (fs.existsSync(pathname)) {
fs.readdirSync(pathname).forEach(function(file) {
fs.readdirSync(pathname).forEach(function (file) {
const curPath = path.join(pathname, file);
if (fs.statSync(curPath).isDirectory()) {
// recurse
Expand All @@ -74,7 +74,7 @@ const deleteFolderRecursive = function(pathname) {
}
};

const getUserDataPath = function() {
const getUserDataPath = function () {
return userDataPath;
};

Expand All @@ -98,20 +98,20 @@ function pathExists(path) {
});
}

const createFirebotDataDir = function() {
const createFirebotDataDir = function () {
if (!pathExists(userDataPath)) {
const logger = require("../logwrapper");
logger.info("Creating firebot-data folder...");
fs.mkdirSync(userDataPath);
}
};

const getJsonDbInUserData = function(filePath) {
const getJsonDbInUserData = function (filePath) {
const jsonDbPath = path.join(userDataPath, filePath);
return new JsonDB(jsonDbPath, true, true);
};

const makeDirInUserData = async function(filePath) {
const makeDirInUserData = async function (filePath) {
new Promise((resolve) => {
const joinedPath = path.join(userDataPath, filePath);
fs.mkdir(joinedPath, () => {
Expand All @@ -120,7 +120,7 @@ const makeDirInUserData = async function(filePath) {
});
};

const makeDirInUserDataSync = function(filePath) {
const makeDirInUserDataSync = function (filePath) {
try {
const joinedPath = path.join(userDataPath, filePath);
fs.mkdirSync(joinedPath);
Expand All @@ -132,17 +132,17 @@ const makeDirInUserDataSync = function(filePath) {
}
};

const writeFileInWorkingDir = function(filePath, data, callback) {
const writeFileInWorkingDir = function (filePath, data, callback) {
const joinedPath = path.join(workingDirectoryPath, filePath);
fs.writeFile(joinedPath, data, { encoding: "utf8" }, callback);
};

const writeFileInUserData = function(filePath, data, callback) {
const writeFileInUserData = function (filePath, data, callback) {
const joinedPath = path.join(userDataPath, filePath);
fs.writeFile(joinedPath, data, { encoding: "utf8" }, callback);
};

const copyDefaultConfigToUserData = function(
const copyDefaultConfigToUserData = function (
configFileName,
userDataDestination
) {
Expand All @@ -155,7 +155,7 @@ const copyDefaultConfigToUserData = function(
fs.writeFileSync(destination, fs.readFileSync(source));
};

const copyResourceToUserData = function(
const copyResourceToUserData = function (
resourcePath = "",
resourceName,
userDataDestination = ""
Expand All @@ -177,12 +177,12 @@ const copyResourceToUserData = function(
}
};

const workingDirPathExists = function(filePath) {
const workingDirPathExists = function (filePath) {
const joinedPath = path.join(workingDirectoryPath, filePath);
return pathExists(joinedPath);
};

const userDataPathExists = function(filePath) {
const userDataPathExists = function (filePath) {
const joinedPath = path.join(userDataPath, filePath);
return pathExists(joinedPath);
};
Expand All @@ -191,7 +191,7 @@ function pathExistsSync(path) {
return fs.existsSync(path);
}

const userDataPathExistsSync = function(filePath) {
const userDataPathExistsSync = function (filePath) {
const joinedPath = path.join(userDataPath, filePath);
return pathExistsSync(joinedPath);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,9 @@ function buildModules(scriptManifest) {

quotesManager: require("../../../quotes/quotes-manager"),
frontendCommunicator: require("../../frontend-communicator"),
counterManager: require("../../../counters/counter-manager"),
counterManager: require("../../../counters/counter-manager").CounterManager,
utils: require("../../../utility"),
resourceTokenManager: require("../../../resourceTokenManager"),
resourceTokenManager: require("../../../resource-token-manager").ResourceTokenManager,

notificationManager: {
addNotification: (notificationBase, permanentlySave = true) => {
Expand Down
8 changes: 4 additions & 4 deletions src/backend/common/handlers/mediaProcessor.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"use strict";

const { SettingsManager } = require("../settings-manager");
const resourceTokenManager = require("../../resourceTokenManager.js");
const { ResourceTokenManager } = require("../../resource-token-manager");
const util = require("../../utility");
const logger = require("../../logwrapper");
const webServer = require("../../../server/http-server-manager");
Expand Down Expand Up @@ -47,7 +47,7 @@ function soundProcessor(effect) {
data.audioOutputDevice = selectedOutputDevice;

if (selectedOutputDevice.deviceId === "overlay") {
const resourceToken = resourceTokenManager.storeResourcePath(effect.file, 30);
const resourceToken = ResourceTokenManager.storeResourcePath(effect.file, 30);
data.resourceToken = resourceToken;
}

Expand Down Expand Up @@ -107,7 +107,7 @@ async function imageProcessor(effect, trigger) {
}

if (effect.imageType === "local") {
const resourceToken = resourceTokenManager.storeResourcePath(
const resourceToken = ResourceTokenManager.storeResourcePath(
effect.file,
effect.length
);
Expand Down Expand Up @@ -158,7 +158,7 @@ function videoProcessor(effect) {
}
}

const resourceToken = resourceTokenManager.storeResourcePath(
const resourceToken = ResourceTokenManager.storeResourcePath(
effect.file,
effect.length
);
Expand Down
Loading

0 comments on commit fa31924

Please sign in to comment.