[READ-ONLY] Mirror of https://github.com/probablykasper/ferrum. Music library app for Mac, Linux and Windows ferrum.kasper.space
electron linux macos music music-library music-player napi windows
0

Configure Feed

Select the types of activity you want to include in your feed.

Fix sorting

Kasper (Sep 26, 2024, 3:20 AM +0200) af3a1045 fa6b6487

+38 -6
+1
ferrum-addon/addon.d.ts
··· 21 21 } 22 22 export declare function copyFile(from: string, to: string): void 23 23 export declare function atomicFileSave(filePath: string, content: string): void 24 + export declare function get_default_sort_desc(field: string): boolean 24 25 export interface Track { 25 26 size: number 26 27 duration: number
+14
src-native/library.rs
··· 96 96 Bool, 97 97 } 98 98 99 + #[napi(js_name = "get_default_sort_desc")] 100 + #[allow(dead_code)] 101 + pub fn get_default_sort_desc(field: String) -> bool { 102 + if field == "index" { 103 + return true; 104 + } 105 + let field = get_track_field_type(&field); 106 + let desc = match field { 107 + Some(TrackField::String) => false, 108 + _ => true, 109 + }; 110 + return desc; 111 + } 112 + 99 113 pub fn get_track_field_type(field: &str) -> Option<TrackField> { 100 114 let field = match field { 101 115 "size" => TrackField::I64,
+5 -3
src-native/sort.rs
··· 93 93 let mut track_ids = get_tracklist_item_ids(library, &options.playlist_id)?; 94 94 95 95 if options.sort_key == "index" { 96 - // No need to sort for index. Note: Indexes descend from "first to last", 97 - // unlike other numbers which ascend from "high to low" 96 + // Note: Indexes descend from "first to last", unlike 97 + // other numbers which ascend from "high to low" 98 + if !options.sort_desc { 99 + track_ids.reverse(); 100 + } 98 101 println!("Sort: {}ms", now.elapsed().as_millis()); 99 - track_ids.reverse(); 100 102 return Ok(track_ids); 101 103 } 102 104
+14 -3
src/components/TrackList.svelte
··· 5 5 current_playlist_id.subscribe((id) => { 6 6 if (id === 'root') { 7 7 sort_key.set('dateAdded') 8 - sort_desc.set(true) 8 + sort_desc.set(get_default_sort_desc('dateAdded')) 9 9 } else { 10 10 sort_key.set('index') 11 - sort_desc.set(true) 11 + sort_desc.set(get_default_sort_desc('index')) 12 12 } 13 13 }) 14 14 export const group_album_tracks = writable(true) ··· 23 23 move_tracks, 24 24 remove_from_playlist, 25 25 playlist_items_updated, 26 + get_default_sort_desc, 26 27 } from '../lib/data' 27 28 import { new_playback_instance, playing_id } from '../lib/player' 28 29 import { ··· 441 442 style:width={column.width} 442 443 role="button" 443 444 on:click={() => { 444 - sort_key.set(column.key) 445 + if (tracks_page.playlistKind === 'special' && column.key === 'index') { 446 + return 447 + } else if (column.key === 'image') { 448 + return 449 + } 450 + if ($sort_key === column.key) { 451 + sort_desc.set(!$sort_desc) 452 + } else { 453 + sort_key.set(column.key) 454 + sort_desc.set(get_default_sort_desc(column.key)) 455 + } 445 456 }} 446 457 draggable="true" 447 458 on:dragstart={(e) => on_col_drag_start(e, i)}
+4
src/lib/data.ts
··· 184 184 // methods.save() 185 185 } 186 186 187 + export function get_default_sort_desc(field: string) { 188 + return call((addon) => addon.get_default_sort_desc(field)) 189 + } 190 + 187 191 export const methods = { 188 192 importTrack: (path: string, now: MsSinceUnixEpoch) => { 189 193 call((data) => data.import_file(path, now))