154
154
</template >
155
155
156
156
<script >
157
- /* eslint no-unused-vars: "error"*/
158
157
import { ref , computed } from " vue" ;
159
158
import { useStore } from " vuex" ;
160
159
import { apiInstance } from " ../api" ;
@@ -180,6 +179,7 @@ import {
180
179
IonInfiniteScrollContent ,
181
180
IonFab ,
182
181
IonFabButton ,
182
+ modalController ,
183
183
} from " @ionic/vue" ;
184
184
import {
185
185
arrowUp ,
@@ -201,7 +201,7 @@ import {
201
201
} from " ../enums" ;
202
202
203
203
export default {
204
- props: [" modalController " , " action" ],
204
+ props: [" action" ],
205
205
setup (props ) {
206
206
const store = useStore ();
207
207
const serverConfig = computed (
@@ -243,47 +243,55 @@ export default {
243
243
});
244
244
245
245
const loadFilebrowserSettings = async () => {
246
- // Get paths or drives
247
- if (store .state .simpleapi .MPVInfo .mpvremoteConfig .unsafefilebrowsing ) {
248
- await apiInstance .get (" /drives" ).then ((response ) => {
249
- drives .value = response .data ;
250
- });
251
- } else {
252
- await apiInstance
253
- .get (" filebrowser/paths" )
254
- .then ((response ) => (drives .value = response .data ));
255
- }
246
+ try {
247
+ // Get paths or drives
248
+ if (serverConfig .value .unsafefilebrowsing ) {
249
+ await apiInstance
250
+ .get (" /drives" )
251
+ .then ((response ) => {
252
+ drives .value = response .data ;
253
+ })
254
+ .catch (async () => {
255
+ // If got error fetching driver fallback to filebrowser paths
256
+ await apiInstance
257
+ .get (" filebrowser/paths" )
258
+ .then ((response ) => (drives .value = response .data ));
259
+ });
260
+ } else {
261
+ await apiInstance
262
+ .get (" filebrowser/paths" )
263
+ .then ((response ) => (drives .value = response .data ));
264
+ }
256
265
257
- // Get collections.
258
- if (store .state .simpleapi .MPVInfo .mpvremoteConfig .uselocaldb ) {
259
- await apiInstance
260
- .get (" /collections" )
261
- .then ((response ) => (collections .value = response .data ));
266
+ // Get collections.
267
+ if (serverConfig .value .uselocaldb ) {
268
+ await apiInstance
269
+ .get (" /collections" )
270
+ .then ((response ) => (collections .value = response .data ));
271
+ }
272
+ } catch (err) {
273
+ console .log (err);
274
+ store .dispatch (" app/showToast" , {
275
+ message: ` Failed to load settings: ${ err} ` ,
276
+ duration: 5000 ,
277
+ });
262
278
}
263
279
};
264
280
265
281
const loadFileBrowser = async () => {
266
282
await loadFilebrowserSettings ();
267
283
if (filemanLastPath) {
268
- console .log (" Fileman last path exists " );
269
284
if (filemanLastPath .type == " collection" ) {
270
- console .log (" Collection should be loaded" );
271
- getDirectoryContents (null , filemanLastPath .collection_id ).catch (
272
- () => {
273
- console .log (" Got error, loading basic" );
274
- getDirectoryContents ();
285
+ await getDirectoryContents (null , filemanLastPath .collection_id ).catch (
286
+ async () => {
287
+ await getDirectoryContents ();
275
288
}
276
289
);
277
290
} else if (filemanLastPath .type == " directory" ) {
278
- getDirectoryContents (filemanLastPath .cwd ).catch (() => {
279
- getDirectoryContents ();
291
+ await getDirectoryContents (filemanLastPath .cwd ).catch (async () => {
292
+ await getDirectoryContents ();
280
293
});
281
- } else {
282
- // No valid directory content detected
283
- loading .value = false ;
284
294
}
285
- } else {
286
- loading .value = false ;
287
295
}
288
296
};
289
297
@@ -353,7 +361,7 @@ export default {
353
361
};
354
362
355
363
const onCancelClicked = () => {
356
- saveLastPath ().then (() => props . modalController .dismiss ());
364
+ saveLastPath ().then (() => modalController .dismiss ());
357
365
};
358
366
359
367
const handlePlayAction = async (entry ) => {
@@ -382,23 +390,22 @@ export default {
382
390
383
391
if (role === " continue" ) {
384
392
saveLastPath ().then (() => {
385
- props . modalController .dismiss ({
393
+ modalController .dismiss ({
386
394
filename: entry .fullPath ,
387
395
seekTo: entry .mediaStatus .current_time ,
388
396
});
389
397
});
390
398
} else if (role === " play" ) {
391
399
saveLastPath ().then (() => {
392
- props . modalController .dismiss ({
400
+ modalController .dismiss ({
393
401
filename: entry .fullPath ,
394
402
appendToPlaylist: true ,
395
403
});
396
- console .log (" Play from start" );
397
404
});
398
405
}
399
406
} else {
400
407
saveLastPath ().then (() => {
401
- props . modalController .dismiss ({
408
+ modalController .dismiss ({
402
409
filename: entry .fullPath ,
403
410
appendToPlaylist: true ,
404
411
});
@@ -421,7 +428,7 @@ export default {
421
428
props .action == FileBrowserActions .OPENSUB &&
422
429
entry .type == FileBrowserEntryTypes .SUBTITLE
423
430
) {
424
- props . modalController .dismiss ({ filename: entry .fullPath });
431
+ modalController .dismiss ({ filename: entry .fullPath });
425
432
}
426
433
};
427
434
@@ -497,7 +504,7 @@ export default {
497
504
browsableFiles .value = files .value .content .slice (0 , INFINITE_SCROLL_STEP );
498
505
};
499
506
const onOpenDirectoryClicked = () => {
500
- saveLastPath ().then (() => props . modalController .dismiss (files .value .cwd ));
507
+ saveLastPath ().then (() => modalController .dismiss (files .value .cwd ));
501
508
};
502
509
503
510
const doSort = () => {
@@ -590,7 +597,7 @@ export default {
590
597
browserContent .value .$el .scrollToPoint (0 , 0 , 500 );
591
598
};
592
599
593
- loadFileBrowser ();
600
+ loadFileBrowser (). finally (() => ( loading . value = false )) ;
594
601
return {
595
602
logScroll,
596
603
onCancelClicked,
0 commit comments