11import { audio } from '../api/audio.js' ;
22import { lastfm } from '../api/lastfm.js' ;
33import { settings } from '../api/settings.js' ;
4+ import { tauriConfirm , tauriInvoke } from '../api/shared.js' ;
45import { modLabel , SHORTCUT_DEFINITIONS } from '../shortcuts.js' ;
56
67export function createSettingsView ( Alpine ) {
@@ -238,8 +239,7 @@ export function createSettingsView(Alpine) {
238239 }
239240
240241 try {
241- const { invoke } = window . __TAURI__ . core ;
242- const info = await invoke ( 'app_get_info' ) ;
242+ const info = await tauriInvoke ( 'app_get_info' ) ;
243243 this . appInfo = {
244244 version : info . version || '—' ,
245245 build : info . build || '—' ,
@@ -292,8 +292,7 @@ export function createSettingsView(Alpine) {
292292
293293 this . watchedFoldersLoading = true ;
294294 try {
295- const { invoke } = window . __TAURI__ . core ;
296- this . watchedFolders = await invoke ( 'watched_folders_list' ) ;
295+ this . watchedFolders = await tauriInvoke ( 'watched_folders_list' ) ;
297296 } catch ( error ) {
298297 console . error ( '[settings] Failed to load watched folders:' , error ) ;
299298 Alpine . store ( 'ui' ) . toast ( 'Failed to load watched folders' , 'error' ) ;
@@ -313,8 +312,7 @@ export function createSettingsView(Alpine) {
313312 const path = await open ( { directory : true , multiple : false } ) ;
314313 if ( ! path ) return ;
315314
316- const { invoke } = window . __TAURI__ . core ;
317- const folder = await invoke ( 'watched_folders_add' , {
315+ const folder = await tauriInvoke ( 'watched_folders_add' , {
318316 request : { path, mode : 'continuous' , cadence_minutes : 10 , enabled : true } ,
319317 } ) ;
320318 this . watchedFolders . push ( folder ) ;
@@ -329,8 +327,7 @@ export function createSettingsView(Alpine) {
329327 if ( ! window . __TAURI__ ) return ;
330328
331329 try {
332- const { invoke } = window . __TAURI__ . core ;
333- await invoke ( 'watched_folders_remove' , { id } ) ;
330+ await tauriInvoke ( 'watched_folders_remove' , { id } ) ;
334331 } catch ( error ) {
335332 // If the folder was already removed (e.g. by delete-all), just clean up the UI
336333 if ( ! error ?. toString ( ) . includes ( 'not found' ) ) {
@@ -347,8 +344,7 @@ export function createSettingsView(Alpine) {
347344 if ( ! window . __TAURI__ ) return ;
348345
349346 try {
350- const { invoke } = window . __TAURI__ . core ;
351- const updated = await invoke ( 'watched_folders_update' , { id, request : updates } ) ;
347+ const updated = await tauriInvoke ( 'watched_folders_update' , { id, request : updates } ) ;
352348 const index = this . watchedFolders . findIndex ( ( f ) => f . id === id ) ;
353349 if ( index !== - 1 ) {
354350 this . watchedFolders [ index ] = updated ;
@@ -364,8 +360,7 @@ export function createSettingsView(Alpine) {
364360
365361 this . scanningFolders . add ( id ) ;
366362 try {
367- const { invoke } = window . __TAURI__ . core ;
368- await invoke ( 'watched_folders_rescan' , { id } ) ;
363+ await tauriInvoke ( 'watched_folders_rescan' , { id } ) ;
369364 Alpine . store ( 'ui' ) . toast ( 'Rescan started' , 'success' ) ;
370365 } catch ( error ) {
371366 console . error ( '[settings] Failed to rescan folder:' , error ) ;
@@ -387,18 +382,10 @@ export function createSettingsView(Alpine) {
387382 } ,
388383
389384 async resetSettings ( ) {
390- let confirmed = false ;
391-
392- if ( window . __TAURI__ ?. dialog ?. confirm ) {
393- confirmed = await window . __TAURI__ . dialog . confirm (
394- 'This will reset all settings to their defaults. Your library and playlists will not be affected.' ,
395- { title : 'Reset Settings' , kind : 'warning' } ,
396- ) ;
397- } else {
398- confirmed = confirm (
399- 'This will reset all settings to their defaults. Your library and playlists will not be affected.' ,
400- ) ;
401- }
385+ const confirmed = await tauriConfirm (
386+ 'This will reset all settings to their defaults. Your library and playlists will not be affected.' ,
387+ { title : 'Reset Settings' , kind : 'warning' } ,
388+ ) ;
402389
403390 if ( ! confirmed ) return ;
404391
@@ -421,7 +408,6 @@ export function createSettingsView(Alpine) {
421408
422409 this . isExportingLogs = true ;
423410 try {
424- const { invoke } = window . __TAURI__ . core ;
425411 const { save } = window . __TAURI__ . dialog ;
426412
427413 const path = await save ( {
@@ -434,7 +420,7 @@ export function createSettingsView(Alpine) {
434420 return ;
435421 }
436422
437- await invoke ( 'export_diagnostics' , { path } ) ;
423+ await tauriInvoke ( 'export_diagnostics' , { path } ) ;
438424 Alpine . store ( 'ui' ) . toast ( 'Diagnostics exported successfully' , 'success' ) ;
439425 } catch ( error ) {
440426 console . error ( '[settings] Failed to export logs:' , error ) ;
@@ -452,8 +438,7 @@ export function createSettingsView(Alpine) {
452438 if ( ! window . __TAURI__ ) return ;
453439
454440 try {
455- const { invoke } = window . __TAURI__ . core ;
456- const status = await invoke ( 'network_cache_status' ) ;
441+ const status = await tauriInvoke ( 'network_cache_status' ) ;
457442 this . networkCache . enabled = status . enabled ;
458443 this . networkCache . persistent = status . persistent ;
459444 this . networkCache . maxGb = status . max_bytes / 1_073_741_824 ;
@@ -519,8 +504,7 @@ export function createSettingsView(Alpine) {
519504
520505 this . networkCache . isPurging = true ;
521506 try {
522- const { invoke } = window . __TAURI__ . core ;
523- await invoke ( 'network_cache_purge' ) ;
507+ await tauriInvoke ( 'network_cache_purge' ) ;
524508 this . networkCache . usedBytes = 0 ;
525509 this . networkCache . fileCount = 0 ;
526510 Alpine . store ( 'ui' ) . toast ( 'Network cache cleared' , 'success' ) ;
@@ -792,18 +776,10 @@ export function createSettingsView(Alpine) {
792776 } ,
793777
794778 async resetLovedCache ( ) {
795- let confirmed = false ;
796-
797- if ( window . __TAURI__ ?. dialog ?. confirm ) {
798- confirmed = await window . __TAURI__ . dialog . confirm (
799- 'This will clear the loved tracks cache and remove auto-favorited tracks (synced from Last.fm). Manually favorited tracks are kept.\n\nYou can re-sync from Last.fm afterward to rebuild the cache.' ,
800- { title : 'Reset Loved Tracks Cache' , kind : 'warning' } ,
801- ) ;
802- } else {
803- confirmed = confirm (
804- 'This will clear the loved tracks cache and remove auto-favorited tracks (synced from Last.fm). Manually favorited tracks are kept.\n\nYou can re-sync from Last.fm afterward to rebuild the cache.' ,
805- ) ;
806- }
779+ const confirmed = await tauriConfirm (
780+ 'This will clear the loved tracks cache and remove auto-favorited tracks (synced from Last.fm). Manually favorited tracks are kept.\n\nYou can re-sync from Last.fm afterward to rebuild the cache.' ,
781+ { title : 'Reset Loved Tracks Cache' , kind : 'warning' } ,
782+ ) ;
807783
808784 if ( ! confirmed ) return ;
809785
@@ -850,14 +826,13 @@ export function createSettingsView(Alpine) {
850826
851827 let unlisten = null ;
852828 try {
853- const { invoke } = window . __TAURI__ . core ;
854829 const { listen } = window . __TAURI__ . event ;
855830
856831 unlisten = await listen ( 'reconcile:progress' , ( e ) => {
857832 this . reconcileScan . progress = e . payload ;
858833 } ) ;
859834
860- const result = await invoke ( 'library_reconcile_scan' ) ;
835+ const result = await tauriInvoke ( 'library_reconcile_scan' ) ;
861836 this . reconcileScan . lastResult = result ;
862837
863838 const total = result . backfilled + result . duplicates_merged ;
@@ -980,16 +955,10 @@ export function createSettingsView(Alpine) {
980955 if ( this . columnSettings . resetSort ) parts . push ( 'sort settings' ) ;
981956
982957 const message = `Reset column ${ parts . join ( ', ' ) } ?` ;
983-
984- let confirmed = false ;
985- if ( window . __TAURI__ ?. dialog ?. confirm ) {
986- confirmed = await window . __TAURI__ . dialog . confirm ( message , {
987- title : 'Reset Column Settings' ,
988- kind : 'warning' ,
989- } ) ;
990- } else {
991- confirmed = confirm ( message ) ;
992- }
958+ const confirmed = await tauriConfirm ( message , {
959+ title : 'Reset Column Settings' ,
960+ kind : 'warning' ,
961+ } ) ;
993962
994963 if ( ! confirmed ) return ;
995964 }
0 commit comments