(file *FileEntry)
| 252 | } |
| 253 | |
| 254 | func (a *App) loadFile(file *FileEntry) tea.Cmd { |
| 255 | a.currentFile = file |
| 256 | a.isLoading = true |
| 257 | |
| 258 | clearKittyImages() |
| 259 | |
| 260 | statusCmd := a.setStatus("Loading: "+file.Name, 3) |
| 261 | |
| 262 | loadCmd := func() tea.Msg { |
| 263 | result := make(chan tea.Msg, 1) |
| 264 | |
| 265 | go func() { |
| 266 | tagEditor := mp3.NewTagEditor() |
| 267 | tags, err := tagEditor.ReadTags(file.Path) |
| 268 | if err != nil { |
| 269 | result <- FileLoadErrorMsg{ |
| 270 | FilePath: file.Path, |
| 271 | Error: err, |
| 272 | } |
| 273 | return |
| 274 | } |
| 275 | |
| 276 | result <- FileLoadedMsg{ |
| 277 | FilePath: file.Path, |
| 278 | Tags: tags, |
| 279 | } |
| 280 | }() |
| 281 | |
| 282 | select { |
| 283 | case msg := <-result: |
| 284 | return msg |
| 285 | case <-time.After(5 * time.Second): |
| 286 | return FileLoadErrorMsg{ |
| 287 | FilePath: file.Path, |
| 288 | Error: fmt.Errorf("tag reading timed out"), |
| 289 | } |
| 290 | } |
| 291 | } |
| 292 | |
| 293 | return tea.Batch(statusCmd, loadCmd) |
| 294 | } |
| 295 | |
| 296 | func (a *App) saveTags() tea.Cmd { |
| 297 | if a.currentFile == nil { |
no test coverage detected