Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: linux overlay not working when pwd not firebot dir #2946

Merged
merged 2 commits into from
Dec 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
4 changes: 1 addition & 3 deletions src/server/http-server-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ import { CustomWebSocketHandler } from "../types/websocket";

import dataAccess from "../backend/common/data-access";

import electron from 'electron';
const workingDirectoryRoot = process.platform === 'darwin' ? process.resourcesPath : process.cwd();
const cwd = !electron.app.isPackaged ? path.join(electron.app.getAppPath(), "build") : workingDirectoryRoot;
const cwd = dataAccess.getWorkingDirectoryPath();

interface ServerInstance {
name: string;
Expand Down
Loading