@@ -16,6 +16,7 @@ export const useFileUpload = () => {
1616 const lastUpdatedFromNow = ref ( '' ) ;
1717 const lastUpdated = useState ( LAST_UPDATED , ( ) => dayjs ( ) ) ;
1818 const watchingFiles = useState ( 'watching-files' , ( ) => ( [ ] ) ) ;
19+ const notifications = useNotifications ( ) ;
1920 // const { addLog } = useLogs();
2021
2122 const startFileWatchingProcess = async ( ) => {
@@ -103,48 +104,52 @@ export const useFileUpload = () => {
103104
104105 const handleUpload = async ( force = false ) => {
105106 const lastStartedDate = await getStorageItem < string > ( LAST_STARTED_DATE ) ;
106- if ( ! force && lastStartedDate && dayjs ( ) . diff ( dayjs ( lastStartedDate ) , 'seconds' ) < 15 ) {
107+ if ( ! force && lastStartedDate && dayjs ( ) . diff ( dayjs ( lastStartedDate ) , 'seconds' ) < 15 ) {
107108 return ;
108109 }
109110 isProcessing . value = true ;
110- await saveStorageItem < string > ( LAST_STARTED_DATE , dayjs ( ) . format ( ) )
111+ await saveStorageItem < string > ( LAST_STARTED_DATE , dayjs ( ) . format ( ) ) ;
111112 const files = await getAllFiles ( ) ;
112113 const dedupedFiles = removeDuplicateFiles ( files ) ;
113- const apiKey = await getStorageItem < string > ( API_KEY )
114+
114115 for ( const file of dedupedFiles ) {
115116 // addLog({
116117 // date: new Date(),
117118 // title: 'Attempting to upload...',
118119 // note: `File path: ${file.path}`
119- // })
120+ // });
120121 const contents = await readBigFile ( file , { baseDir : BaseDirectory . Home } ) ;
121122
122123 try {
123- const message = await invoke ( 'submit_addon_data' , { contents} )
124+ const message = await invoke ( 'submit_addon_data' , { contents } ) ;
124125
125126 // addLog({
126127 // date: new Date(),
127128 // title: 'Uploaded file!',
128129 // note: `File path: ${file.path}; Return: ${message}`
129- // })
130+ // });
130131 console . log ( `File: ${ file } ; Return: ${ message } ` ) ;
131132 } catch ( error ) {
132133 // addLog({
133134 // date: new Date(),
134135 // title: 'File failed to upload!',
135136 // note: `File path: ${file.path}; Return: ${error}`
136- // })
137+ // });
137138 console . log ( `File: ${ file } ; Return: ${ error } ` ) ;
139+ await notifications . send ( { title : 'Wowthing Sync' , body : 'An error occurred while uploading. Please try again later.' } ) ;
140+ isProcessing . value = false ;
141+ return ; // Stop the rest of the loop from working
138142 }
139143 }
140144
141145 await handleLastUpdated ( ) ;
146+ await notifications . send ( { title : 'Wowthing Sync' , body : 'Upload was completed successfully' } ) ;
142147 isProcessing . value = false ;
143- }
148+ } ;
144149
145150 const removeDuplicateFiles = ( arr ) => {
146151 var unique = arr . reduce ( function ( files , file ) {
147- if ( ! files . find ( m => m . path == file . path ) ) {
152+ if ( ! files . find ( m => m == file ) ) {
148153 files . push ( file ) ;
149154 }
150155 return files ;
0 commit comments