-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8a2761b
commit 3bcf7dd
Showing
20 changed files
with
255 additions
and
101 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,3 +4,4 @@ node_modules | |
package-lock.json | ||
.env | ||
coverage | ||
desktop/resources/transfers |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { defineConfig } from "vite"; | ||
import { resolve } from "node:path"; | ||
import fs from "node:fs"; | ||
|
||
// Define an array of worker entry points | ||
const workerEntries = fs | ||
.readdirSync(resolve(__dirname, "src/main/fileProcessing/workers")) | ||
.filter((file) => file.endsWith(".ts")) | ||
.reduce( | ||
(entries, file) => { | ||
const name = file.replace(".ts", ""); | ||
entries[name] = resolve(__dirname, `src/main/fileProcessing/workers/${file}`); | ||
return entries; | ||
}, | ||
{} as Record<string, string>, | ||
); | ||
|
||
/** | ||
* Config used to build commonjs worker files in the out/cjs-workers directory. | ||
* These files are added to the executable's program files when configured in the package.json build. | ||
*/ | ||
|
||
export default defineConfig({ | ||
build: { | ||
lib: { | ||
entry: workerEntries, // Multiple entry points | ||
formats: ["cjs"], // Build as CommonJS | ||
fileName: (format, entryName) => `${entryName}.js`, // Use entry name for output | ||
}, | ||
outDir: "out/cjs-workers", // Output directory | ||
rollupOptions: { | ||
external: ["worker_threads", "fs", "path", "p-limit"], // Externalize Node.js modules | ||
}, | ||
target: "node22", | ||
ssr: true, | ||
minify: false, // Disable minification to help with debugging | ||
}, | ||
optimizeDeps: { | ||
exclude: ["fs", "path"], // Exclude Node.js modules from optimization | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { defineConfig } from "vite"; | ||
import { resolve } from "node:path"; | ||
import fs from "node:fs"; | ||
|
||
// Define an array of worker entry points | ||
const workerEntries = fs | ||
.readdirSync(resolve(__dirname, "src/main/fileProcessing/workers")) | ||
.filter((file) => file.endsWith(".ts")) | ||
.reduce( | ||
(entries, file) => { | ||
const name = file.replace(".ts", ""); | ||
entries[name] = resolve(__dirname, `src/main/fileProcessing/workers/${file}`); | ||
return entries; | ||
}, | ||
{} as Record<string, string>, | ||
); | ||
|
||
/** | ||
* Config used to build esmodule worker files in the out/es-workers directory. | ||
* These files are used when in development mode using 'npm run dev'. | ||
*/ | ||
|
||
export default defineConfig({ | ||
build: { | ||
lib: { | ||
entry: workerEntries, // Multiple entry points | ||
formats: ["es"], // Build as ESModule | ||
fileName: (format, entryName) => `${entryName}.js`, // Use entry name for output | ||
}, | ||
outDir: "out/es-workers", // Output directory | ||
rollupOptions: { | ||
external: ["worker_threads", "fs", "path", "p-limit"], // Externalize Node.js modules | ||
}, | ||
target: "node22", | ||
ssr: true, | ||
minify: false, // Disable minification to help with debugging | ||
}, | ||
optimizeDeps: { | ||
exclude: ["fs", "path"], // Exclude Node.js modules from optimization | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# IMPORTANT | ||
|
||
Workers must be compiled to JavaScript before they can be used. | ||
|
||
Follow these steps every time changes are made to an existing worker, OR a new worker is added. | ||
|
||
## Adding a New Worker | ||
|
||
1. Add the worker to the `build > extraFiles` in `desktop\package.json`. This will tell the build process to include it in the executable's program files. | ||
|
||
2. Rebuild the app using `npm run build`. | ||
|
||
3. Restart the development build using `npm run dev`. | ||
|
||
<br /> | ||
|
||
## Updating an Existing Worker | ||
|
||
1. Rebuild the app using `npm run build`. | ||
|
||
2. Restart the development build using `npm run dev`. |
1 change: 0 additions & 1 deletion
1
...top/src/preload/api/workers/WorkerPool.ts → ...top/src/main/fileProcessing/WorkerPool.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,6 @@ | ||
import { Worker } from "node:worker_threads"; | ||
|
||
type WorkerData<T = unknown> = { | ||
payload: T; | ||
[key: string]: T; | ||
}; | ||
|
||
|
File renamed without changes.
1 change: 0 additions & 1 deletion
1
desktop/src/preload/api/workers/index.ts → desktop/src/main/fileProcessing/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
export * from "./WorkerPool"; | ||
export * from "./copyWorker"; | ||
export * from "./createWorkerPool"; | ||
export * from "./processFolder"; |
27 changes: 16 additions & 11 deletions
27
.../src/preload/api/workers/processFolder.ts → .../src/main/fileProcessing/processFolder.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,39 @@ | ||
import path from "node:path"; | ||
import type { WorkerPool } from "./WorkerPool"; | ||
import { app } from "electron"; | ||
|
||
/** | ||
* Processes a folder by running the workers using the WorkerPool. | ||
* | ||
* @param workerPool - The WorkerPool instance to manage worker threads. | ||
* @param filePath - The source folder path to be processed. | ||
* @param destination - The destination folder path for the copied files. | ||
* @param isDev - Is running in the development build (npm run dev). | ||
* @returns A Promise that resolves when the worker processes complete. | ||
*/ | ||
export const processFolder = async ( | ||
workerPool: WorkerPool, | ||
pool: WorkerPool, | ||
filePath: string, | ||
destination: string, | ||
isDev = false, | ||
): Promise<void> => { | ||
// Worker script path | ||
const workerScript = path.resolve(__dirname, "copyWorker.js"); | ||
const workerScript = isDev | ||
? path.resolve(__dirname, "../es-workers/copyWorker.js") | ||
: path.join(app.getAppPath(), "../../resources/copyWorker.cjs"); | ||
|
||
const destinationPath = isDev | ||
? path.resolve(__dirname, "../../resources/transfers/TR_0000_0000") | ||
: path.join(app.getAppPath(), "../../resources/transfers/TR_0000_0000"); | ||
|
||
const workerData = { | ||
payload: { | ||
source: filePath, | ||
destination, | ||
}, | ||
source: filePath, | ||
destination: destinationPath, | ||
}; | ||
|
||
try { | ||
// Run the copyWorker task using the WorkerPool | ||
await workerPool.runTask(workerScript, workerData); | ||
console.log(`Successfully copied folder from ${filePath} to ${destination}`); | ||
await pool.runTask(workerScript, workerData); | ||
console.log(`Successfully copied folder from ${filePath} to ${destinationPath}`); | ||
} catch (error) { | ||
console.error(`Failed to copy folder from ${filePath} to ${destination}:`, error); | ||
console.error(`Failed to copy folder from ${filePath} to ${destinationPath}:`, error); | ||
} | ||
}; |
Oops, something went wrong.