From a27d4dbeafdc3ab09af382c4f872b41c55970ebd Mon Sep 17 00:00:00 2001 From: Dwynr Date: Tue, 28 May 2024 09:00:33 +0200 Subject: [PATCH] fix: only start workers in a node env --- package.json | 2 +- src/fuse/worker.ts | 103 ++++++++++++++++++++++--------------------- src/sync/worker.ts | 3 +- src/webdav/worker.ts | 3 +- 4 files changed, 58 insertions(+), 53 deletions(-) diff --git a/package.json b/package.json index 97cc091..48a8cc3 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@filen/desktop", - "version": "0.1.5", + "version": "0.1.6", "description": "Filen Desktop Client", "main": "dist/index.js", "types": "dist/types/index.d.ts", diff --git a/src/fuse/worker.ts b/src/fuse/worker.ts index d63668c..7d3b49c 100644 --- a/src/fuse/worker.ts +++ b/src/fuse/worker.ts @@ -5,6 +5,7 @@ import os from "os" import pathModule from "path" import fs from "fs-extra" import { waitForSDKConfig } from "../config" +import { IS_NODE } from "../constants" const FUSE = Fuse.default @@ -154,59 +155,61 @@ export class FUSEWorker { } } -// TODO: Remove - -const baseTmpPath = pathModule.join(os.tmpdir(), "filen-desktop") -const fullDownloadsTmpPath = pathModule.join(baseTmpPath, "fullDownloads") -const uploadsTmpPath = pathModule.join(baseTmpPath, "uploads") -const encryptedChunksTmpPath = pathModule.join(baseTmpPath, "encryptedChunks") -const decryptedChunksTmpPath = pathModule.join(baseTmpPath, "decryptedChunks") -const xattrPath = pathModule.join(baseTmpPath, "xattr") -const writeTmpPath = pathModule.join(baseTmpPath, "write") - -fs.ensureDirSync(baseTmpPath) -fs.ensureDirSync(fullDownloadsTmpPath) -fs.ensureDirSync(uploadsTmpPath) -fs.ensureDirSync(encryptedChunksTmpPath) -fs.ensureDirSync(decryptedChunksTmpPath) -fs.ensureDirSync(xattrPath) -fs.ensureDirSync(writeTmpPath) - -process.stdout.write( - JSON.stringify({ - type: "ready" - }) -) - -waitForSDKConfig() - .then(sdkConfig => { - const fuseWorker = new FUSEWorker({ - mountPoint: "M:", - baseTmpPath, - fullDownloadsTmpPath, - uploadsTmpPath, - encryptedChunksTmpPath, - decryptedChunksTmpPath, - xattrPath, - writeTmpPath, - sdkConfig +if (IS_NODE) { + // TODO: Remove + + const baseTmpPath = pathModule.join(os.tmpdir(), "filen-desktop") + const fullDownloadsTmpPath = pathModule.join(baseTmpPath, "fullDownloads") + const uploadsTmpPath = pathModule.join(baseTmpPath, "uploads") + const encryptedChunksTmpPath = pathModule.join(baseTmpPath, "encryptedChunks") + const decryptedChunksTmpPath = pathModule.join(baseTmpPath, "decryptedChunks") + const xattrPath = pathModule.join(baseTmpPath, "xattr") + const writeTmpPath = pathModule.join(baseTmpPath, "write") + + fs.ensureDirSync(baseTmpPath) + fs.ensureDirSync(fullDownloadsTmpPath) + fs.ensureDirSync(uploadsTmpPath) + fs.ensureDirSync(encryptedChunksTmpPath) + fs.ensureDirSync(decryptedChunksTmpPath) + fs.ensureDirSync(xattrPath) + fs.ensureDirSync(writeTmpPath) + + process.stdout.write( + JSON.stringify({ + type: "ready" }) - - fuseWorker - .initialize() - .then(() => { - // + ) + + waitForSDKConfig() + .then(sdkConfig => { + const fuseWorker = new FUSEWorker({ + mountPoint: "M:", + baseTmpPath, + fullDownloadsTmpPath, + uploadsTmpPath, + encryptedChunksTmpPath, + decryptedChunksTmpPath, + xattrPath, + writeTmpPath, + sdkConfig }) - .catch(err => { - console.error(err) - process.exit(1) - }) - }) - .catch(err => { - console.error(err) + fuseWorker + .initialize() + .then(() => { + // + }) + .catch(err => { + console.error(err) + + process.exit(1) + }) + }) + .catch(err => { + console.error(err) - process.exit(1) - }) + process.exit(1) + }) +} export default FUSEWorker diff --git a/src/sync/worker.ts b/src/sync/worker.ts index 2498595..91807ee 100644 --- a/src/sync/worker.ts +++ b/src/sync/worker.ts @@ -1,6 +1,7 @@ import type { SyncPair } from "./types" import Sync from "./lib/sync" import { type FilenSDKConfig } from "@filen/sdk" +import { IS_NODE } from "../constants" /** * SyncWorker @@ -60,7 +61,7 @@ export class SyncWorker { } // Only start the worker if it is actually invoked. -if (process.argv.slice(2).includes("--worker")) { +if (process.argv.slice(2).includes("--worker") && IS_NODE) { // TODO: Proper init const syncWorker = new SyncWorker({ dbPath: "", diff --git a/src/webdav/worker.ts b/src/webdav/worker.ts index 83b3c30..e30e370 100644 --- a/src/webdav/worker.ts +++ b/src/webdav/worker.ts @@ -1,6 +1,7 @@ import SDK, { type FilenSDKConfig } from "@filen/sdk" import * as WebDAV from "@filen/webdav-server" import FileSystem from "./filesystem" +import { IS_NODE } from "../constants" export type WebDAVUser = { name: string @@ -101,7 +102,7 @@ export class WebDAVWorker { } // Only start the worker if it is actually invoked. -if (process.argv.slice(2).includes("--worker")) { +if (process.argv.slice(2).includes("--worker") && IS_NODE) { const webdavWorker = new WebDAVWorker({ users: [ {