@@ -59,14 +59,20 @@ export default function Main() {
59
59
} ) ;
60
60
const [ importState , setImportState ] = useState ( {
61
61
songsImported : 0 ,
62
- totalSongs : 0 ,
62
+ totalSongs : 1 ,
63
63
estimatedTimeRemainingString : '' ,
64
64
} ) ;
65
65
const [ showAlbumArtMenu , setShowAlbumArtMenu ] = useState < AlbumArtMenuState > ( ) ;
66
66
67
67
const importNewLibrary = async ( rescan = false ) => {
68
68
setDialogState ( ( prev ) => ( { ...prev , showImportingProgress : true } ) ) ;
69
69
70
+ setImportState ( ( prev ) => ( {
71
+ ...prev ,
72
+ songsImported : 0 ,
73
+ totalSongs : 1 ,
74
+ } ) ) ;
75
+
70
76
window . electron . ipcRenderer . sendMessage ( 'select-library' , {
71
77
rescan,
72
78
} ) ;
@@ -78,18 +84,29 @@ export default function Main() {
78
84
totalSongs : args . totalSongs ,
79
85
} ) ) ;
80
86
81
- // Calculate estimated time remaining
82
- const timePerSong = 0.1 ; // seconds per song (approximate)
83
- const remainingSongs = args . totalSongs - args . songsImported ;
84
- const estimatedSeconds = remainingSongs * timePerSong ;
85
- const minutes = Math . floor ( estimatedSeconds / 60 ) ;
86
- const seconds = Math . floor ( estimatedSeconds % 60 ) ;
87
+ // Average time per song based on testing:
88
+ // - ~3ms for metadata parsing
89
+ // - ~6ms for file copy (if needed)
90
+ // - ~1ms overhead
91
+ const avgTimePerSong = 10 ; // milliseconds
92
+ const estimatedTimeRemaining = Math . floor (
93
+ ( args . totalSongs - args . songsImported ) * avgTimePerSong ,
94
+ ) ;
95
+
96
+ const minutes = Math . floor ( estimatedTimeRemaining / 60000 ) ;
97
+ const seconds = Math . floor ( ( estimatedTimeRemaining % 60000 ) / 1000 ) ;
98
+
99
+ const timeRemainingString =
100
+ // eslint-disable-next-line no-nested-ternary
101
+ minutes < 1
102
+ ? seconds === 0
103
+ ? 'Processing Metadata...'
104
+ : `${ seconds } s left`
105
+ : `${ minutes } m ${ seconds } s left` ;
87
106
88
107
setImportState ( ( prev ) => ( {
89
108
...prev ,
90
- estimatedTimeRemainingString : `${ minutes } :${ seconds
91
- . toString ( )
92
- . padStart ( 2 , '0' ) } `,
109
+ estimatedTimeRemainingString : timeRemainingString ,
93
110
} ) ) ;
94
111
} ) ;
95
112
0 commit comments