diff --git a/src/electron/frontend/core/globals.js b/src/electron/frontend/core/globals.js index 941a1e26c6..51af1f821d 100644 --- a/src/electron/frontend/core/globals.js +++ b/src/electron/frontend/core/globals.js @@ -21,7 +21,7 @@ export const reloadPageToHome = () => { // Filesystem Management const root = isTestEnvironment ? joinPath(paths.root, ".test") : paths.root; -export const homeDirectory = os.homedir(); +export const homeDirectory = os ? os.homedir() : "/"; export const appDirectory = joinPath(homeDirectory, root); @@ -35,9 +35,9 @@ export const testDataFolderPath = joinPath(appDirectory, ...paths.subfolders.tes // Encryption const IV_LENGTH = 16; const KEY_LENGTH = 32; -export const ENCRYPTION_KEY = Buffer.concat([Buffer.from(appDirectory), Buffer.alloc(KEY_LENGTH)], KEY_LENGTH); +export const ENCRYPTION_KEY = isElectron ? Buffer.concat([Buffer.from(appDirectory), Buffer.alloc(KEY_LENGTH)], KEY_LENGTH) : "" -export const ENCRYPTION_IV = crypto.randomBytes(IV_LENGTH); +export const ENCRYPTION_IV = isElectron ? crypto.randomBytes(IV_LENGTH) : ""; // Storybook export const isStorybook = window.location.href.includes("iframe.html"); diff --git a/src/electron/frontend/utils/electron.js b/src/electron/frontend/utils/electron.js index 315402501f..b057112b9f 100644 --- a/src/electron/frontend/utils/electron.js +++ b/src/electron/frontend/utils/electron.js @@ -6,18 +6,18 @@ export const isElectron = userAgent.indexOf(" electron/") > -1; export const electron = globalThis.electron ?? {}; // ipcRenderer, remote, shell, etc. // Node Modules -export const fs = require("fs-extra"); // File System -export const os = require("os"); -export const crypto = require("crypto"); -export const path = require("path"); +export const fs = isElectron && require("fs-extra"); // File System +export const os = isElectron && require("os"); +export const crypto = isElectron && require("crypto"); +export const path = isElectron && require("path"); // Remote Electron Modules export const remote = isElectron ? require("@electron/remote") : {}; export const app = remote.app; // Electron Information -export const port = electron.ipcRenderer ? electron.ipcRenderer.sendSync("get-port") : 4242; -export const SERVER_FILE_PATH = electron.ipcRenderer ? electron.ipcRenderer.sendSync("get-server-file-path") : ""; +export const port = isElectron ? electron.ipcRenderer.sendSync("get-port") : 4242; +export const SERVER_FILE_PATH = isElectron ? electron.ipcRenderer.sendSync("get-server-file-path") : ""; // Link the renderer to the main process if (isElectron) {