@@ -8,82 +8,65 @@ interface FileEntry {
88type FileList = FileEntry [ ] ;
99
1010export 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
1914export 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
2818export 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
3722export 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
4626export 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
5530export 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
6434export 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
7338export 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
8242export 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