Skip to content

Commit

Permalink
Merge pull request #2946 from dennisrijsdijk/fix/linux-pwd-requirement
Browse files Browse the repository at this point in the history
fix: linux overlay not working when pwd not firebot dir
  • Loading branch information
zunderscore authored Dec 26, 2024
2 parents 9fcf79d + 190d2fb commit 8b13242
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 24 deletions.
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

0 comments on commit 8b13242

Please sign in to comment.