Skip to content

Commit 0a1f709

Browse files
authored
Move callbacks to connectSyncRoot (#161)
* Move callbacks to connectSyncRoot * Fix tsc
1 parent 87ed0a8 commit 0a1f709

5 files changed

Lines changed: 9 additions & 25 deletions

File tree

examples/register.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ const queueManager = new QueueManager({ handlers, persistPath: settings.queuePer
2727
drive.registerSyncRoot({
2828
providerName: settings.driveName,
2929
providerVersion: settings.driveVersion,
30-
callbacks,
3130
logoPath: settings.iconPath,
3231
});
33-
drive.connectSyncRoot();
32+
33+
drive.connectSyncRoot({ callbacks });
3434

3535
try {
3636
initInfoItems();

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@internxt/node-win",
3-
"version": "1.0.11",
3+
"version": "1.0.12",
44
"description": "Drive desktop node addon",
55
"main": "dist/index.ts",
66
"types": "dist/index.d.ts",

src/types/callbacks.type.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,4 @@ export type InputSyncCallbacks = {
3030
noneCallback?: NapiCallbackFunction;
3131
};
3232

33-
export type ExtraCallbacks = {
34-
notifyFileAddedCallback?: NapiCallbackFunction;
35-
notifyMessageCallback?: NapiCallbackFunction;
36-
};
37-
38-
export type Callbacks = InputSyncCallbacks & ExtraCallbacks;
33+
export type Callbacks = InputSyncCallbacks;

src/virtual-drive.ts

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import fs from "fs";
2-
import path, { join, win32 } from "path";
2+
import path, { join, posix, win32 } from "path";
33

44
import { Addon, DependencyInjectionAddonProvider } from "./addon-wrapper";
55
import { TLogger } from "./logger";
@@ -51,7 +51,7 @@ class VirtualDrive {
5151
}
5252

5353
convertToWindowsPath({ path }: { path: string }) {
54-
return path.replaceAll("/", win32.sep);
54+
return path.replaceAll(posix.sep, win32.sep);
5555
}
5656

5757
fixPath(path: string) {
@@ -89,12 +89,8 @@ class VirtualDrive {
8989
return this.addon.deleteFileSyncRoot({ path: this.fixPath(path) });
9090
}
9191

92-
connectSyncRoot() {
93-
if (this.callbacks === undefined) {
94-
throw new Error("Callbacks are not defined");
95-
}
96-
97-
const connectionKey = this.addon.connectSyncRoot({ callbacks: this.callbacks });
92+
connectSyncRoot({ callbacks }: { callbacks: Callbacks }) {
93+
const connectionKey = this.addon.connectSyncRoot({ callbacks });
9894

9995
this.logger.debug({ msg: "connectSyncRoot", connectionKey });
10096
return connectionKey;
@@ -180,15 +176,12 @@ class VirtualDrive {
180176
async registerSyncRoot({
181177
providerName,
182178
providerVersion,
183-
callbacks,
184179
logoPath,
185180
}: {
186181
providerName: string;
187182
providerVersion: string;
188-
callbacks: Callbacks;
189183
logoPath: string;
190184
}): Promise<any> {
191-
this.callbacks = callbacks;
192185
this.logger.debug({ msg: "Registering sync root", syncRootPath: this.syncRootPath });
193186
return this.addon.registerSyncRoot({
194187
providerName,

src/virtual-drive.unit.test.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import { mockDeep } from "vitest-mock-extended";
66
import { addon } from "@/addon";
77

88
import { TLogger } from "./logger";
9-
import { Callbacks } from "./types/callbacks.type";
109
import VirtualDrive from "./virtual-drive";
1110

1211
vi.mock(import("fs"));
@@ -160,14 +159,11 @@ describe("VirtualDrive", () => {
160159
const providerName = "MyProvider";
161160
const providerVersion = "1.0.0";
162161
const logoPath = "C:\\iconPath";
163-
const callbacks = mockDeep<Callbacks>();
164162

165163
// Act
166-
expect(drive.callbacks).toBe(undefined);
167-
await drive.registerSyncRoot({ providerName, providerVersion, callbacks, logoPath });
164+
await drive.registerSyncRoot({ providerName, providerVersion, logoPath });
168165

169166
// Assert
170-
expect(drive.callbacks).not.toBe(undefined);
171167
expect(addon.registerSyncRoot).toHaveBeenCalledWith(
172168
syncRootPath,
173169
providerName,

0 commit comments

Comments
 (0)