Skip to content

Commit 984399d

Browse files
committed
renamed to filerix. Added Drive and File listeners
1 parent 4e6f501 commit 984399d

File tree

6 files changed

+195
-82
lines changed

6 files changed

+195
-82
lines changed

package-lock.json

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
{
2-
"name": "@kingmaj0r/libfm",
2+
"name": "@kingmaj0r/filerix",
33
"version": "1.0.2",
4-
"main": "dist/libfm.cjs.js",
5-
"module": "dist/libfm.es.js",
4+
"main": "dist/filerix.cjs.js",
5+
"module": "dist/filerix.es.js",
66
"exports": {
77
".": {
88
"types": "./dist/types/index.d.ts",
9-
"import": "./dist/libfm.es.js",
10-
"require": "./dist/libfm.cjs.js"
9+
"import": "./dist/filerix.es.js",
10+
"require": "./dist/filerix.cjs.js"
1111
},
1212
"./lib": {
1313
"types": "./dist/types/lib/index.d.ts",
@@ -27,7 +27,7 @@
2727
"keywords": [],
2828
"author": "KingMaj0r",
2929
"license": "MIT",
30-
"description": "Electron & nodejs bindings for libfm.",
30+
"description": "Electron & nodejs bindings for filerix.",
3131
"dependencies": {
3232
"typescript": "^5.7.3",
3333
"vite": "^6.0.11"

src/electron/index.ts

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { ipcMain, IpcMainEvent } from "electron";
2-
import libfm, {
2+
import {
33
copyFile,
44
getFiles,
55
searchFiles,
@@ -8,16 +8,22 @@ import libfm, {
88
getDeviceLabelOrUUID,
99
getDriveUsage,
1010
mountDrive,
11-
unmountDrive
11+
unmountDrive,
12+
startDriveListener,
13+
stopDriveListener,
14+
startFileListener,
15+
stopFileListener,
1216
} from "../lib/index.js";
1317

14-
export default function initFM({ debug = "none" }: { debug?: "debug" | "info" | "warning" | "error" | "none" } = { }) {
15-
libfm.initLogger(debug);
16-
18+
export default function initFM() {
1719
ipcMain.on("copyFile", (event: IpcMainEvent, path: string, destination: string) => {
1820
event.returnValue = copyFile(path, destination);
1921
});
2022

23+
ipcMain.on("cutFile", (event: IpcMainEvent, path: string, destination: string) => {
24+
event.returnValue = copyFile(path, destination);
25+
});
26+
2127
ipcMain.on("getFiles", (event: IpcMainEvent, directoryPath: string) => {
2228
event.returnValue = getFiles(directoryPath);
2329
});
@@ -49,4 +55,28 @@ export default function initFM({ debug = "none" }: { debug?: "debug" | "info" |
4955
ipcMain.on("unmountDrive", (event: IpcMainEvent, disk: string) => {
5056
event.returnValue = unmountDrive(disk);
5157
});
58+
59+
ipcMain.on("startDriveListener", (event: IpcMainEvent) => {
60+
startDriveListener((action: string, device: string) => {
61+
event.sender.send("startDriveListener-event", { action, device });
62+
});
63+
event.returnValue = true;
64+
});
65+
66+
ipcMain.on("stopDriveListener", (event: IpcMainEvent) => {
67+
stopDriveListener();
68+
event.returnValue = true;
69+
});
70+
71+
ipcMain.on("startFileListener", (event: IpcMainEvent, path: string) => {
72+
startFileListener(path, (action: string, device: string) => {
73+
event.sender.send("startFileListener-event", { action, device });
74+
});
75+
event.returnValue = true;
76+
});
77+
78+
ipcMain.on("stopFileListener", (event: IpcMainEvent) => {
79+
stopFileListener();
80+
event.returnValue = true;
81+
});
5282
}

src/index.ts

Lines changed: 37 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -8,82 +8,65 @@ interface FileEntry {
88
type FileList = FileEntry[];
99

1010
export function getUserName(): string {
11-
try {
12-
return window.ipcRenderer.sendSync("getUserName");
13-
} catch (error) {
14-
console.error("Failed to get username:", error);
15-
throw error;
16-
}
11+
return window.ipcRenderer.sendSync("getUserName");
1712
}
1813

1914
export function getFiles(path: string): FileList {
20-
try {
21-
return window.ipcRenderer.sendSync("getFiles", path);
22-
} catch (error) {
23-
console.error("Failed to fetch files:", error);
24-
throw error;
25-
}
15+
return window.ipcRenderer.sendSync("getFiles", path);
2616
}
2717

2818
export function searchFiles(currentPath: string, searchQuery: string): FileList {
29-
try {
30-
return window.ipcRenderer.sendSync("searchFiles", currentPath, searchQuery);
31-
} catch (error) {
32-
console.error("Error during file search:", error);
33-
throw error;
34-
}
19+
return window.ipcRenderer.sendSync("searchFiles", currentPath, searchQuery);
3520
}
3621

3722
export function getDrives(): FileList {
38-
try {
39-
return window.ipcRenderer.sendSync("getDrives");
40-
} catch (error) {
41-
console.error("Error during file search:", error);
42-
throw error;
43-
}
23+
return window.ipcRenderer.sendSync("getDrives");
4424
}
4525

4626
export function getDriveUsage(disk: string) {
47-
try {
48-
return window.ipcRenderer.sendSync("getDriveUsage", disk);
49-
} catch (error) {
50-
console.error("Error during file search:", error);
51-
throw error;
52-
}
27+
return window.ipcRenderer.sendSync("getDriveUsage", disk);
5328
}
5429

5530
export function getDeviceLabelOrUUID(disk: string) {
56-
try {
57-
return window.ipcRenderer.sendSync("getDeviceLabelOrUUID", disk);
58-
} catch (error) {
59-
console.error("Error during file search:", error);
60-
throw error;
61-
}
31+
return window.ipcRenderer.sendSync("getDeviceLabelOrUUID", disk);
6232
}
6333

6434
export function mountDrive(disk: string) {
65-
try {
66-
return window.ipcRenderer.sendSync("mountDrive", disk);
67-
} catch (error) {
68-
console.error("Error during file search:", error);
69-
throw error;
70-
}
35+
return window.ipcRenderer.sendSync("mountDrive", disk);
7136
}
7237

7338
export function unmountDrive(disk: string) {
74-
try {
75-
return window.ipcRenderer.sendSync("unmountDrive", disk);
76-
} catch (error) {
77-
console.error("Error during file search:", error);
78-
throw error;
79-
}
39+
return window.ipcRenderer.sendSync("unmountDrive", disk);
8040
}
8141

8242
export function copyFile(path: string, destination: string) {
83-
try {
84-
return window.ipcRenderer.sendSync("copyFile", path, destination);
85-
} catch (error) {
86-
console.error("Error during file search:", error);
87-
throw error;
88-
}
43+
return window.ipcRenderer.sendSync("copyFile", path, destination);
8944
}
45+
46+
export function cutFile(path: string, destination: string) {
47+
return window.ipcRenderer.sendSync("cutFile", path, destination);
48+
}
49+
50+
export function startDriveListener(callback: (action: string, device: string) => void) {
51+
window.ipcRenderer.sendSync("startDriveListener");
52+
53+
window.ipcRenderer.on("startDriveListener-event", (_, { action, device }) => {
54+
callback(action, device);
55+
});
56+
}
57+
58+
export function stopDriveListener() {
59+
return window.ipcRenderer.sendSync("stopDriveListener");
60+
}
61+
62+
export function startFileListener(path: string, callback: (eventType: string, filePath: string) => void) {
63+
window.ipcRenderer.sendSync("startFileListener", path);
64+
65+
window.ipcRenderer.on("stopDriveListener-event", (_, { eventType, filePath }) => {
66+
callback(eventType, filePath);
67+
});
68+
}
69+
70+
export function stopFileListener() {
71+
return window.ipcRenderer.sendSync("stopFileListener");
72+
}

0 commit comments

Comments
 (0)