[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.

Re-add most track actions

Kasper (Sep 26, 2024, 3:20 AM +0200) b0edd28d e6ead9d1

+61 -50
+33 -23
src/components/TrackList.svelte
··· 6 6 </script> 7 7 8 8 <script lang="ts"> 9 - import { filter, paths, methods, track_lists_details_map, move_tracks } from '../lib/data' 9 + import { 10 + filter, 11 + paths, 12 + methods, 13 + track_lists_details_map, 14 + move_tracks, 15 + remove_from_playlist, 16 + } from '../lib/data' 10 17 import { new_playback_instance, playing_id } from '../lib/player' 11 18 import { 12 19 get_duration, ··· 62 69 selection.update_all_items(track_indexes) 63 70 } 64 71 72 + function get_selected_track_ids() { 73 + return Array.from(selection.items).map((track_index) => tracks_page.trackIds[track_index]) 74 + } 75 + 65 76 const track_action_unlisten = ipc_listen('selectedTracksAction', (_, action) => { 66 - // let first_index = selection.findFirst() 67 - // if (first_index === null || !tracklist_element.contains(document.activeElement)) { 68 - // return 69 - // } 70 - // if (action === 'Play Next') { 71 - // const ids = selection.getSelectedIndexes().map((i) => page.get_track_id(i)) 72 - // prepend_to_user_queue(ids) 73 - // } else if (action === 'Add to Queue') { 74 - // const ids = selection.getSelectedIndexes().map((i) => page.get_track_id(i)) 75 - // append_to_user_queue(ids) 76 - // } else if (action === 'Get Info') { 77 - // open_track_info(page.get_track_ids(), first_index) 78 - // } else if (action === 'revealTrackFile') { 79 - // const track = page.get_track(first_index) 80 - // ipc_renderer.invoke('revealTrackFile', paths.tracksDir, track.file) 81 - // } else if (action === 'Remove from Playlist') { 82 - // remove_from_open_playlist(selection.getSelectedIndexes()) 83 - // } else if (action === 'Delete from Library') { 84 - // delete_indexes(selection.getSelectedIndexes()) 85 - // } else { 86 - // assert_unreachable(action) 87 - // } 77 + let first_index = selection.find_first_index() 78 + if (first_index === null || !tracklist_element.contains(document.activeElement)) { 79 + return 80 + } 81 + if (action === 'Play Next') { 82 + prepend_to_user_queue(get_selected_track_ids()) 83 + } else if (action === 'Add to Queue') { 84 + append_to_user_queue(get_selected_track_ids()) 85 + } else if (action === 'Get Info') { 86 + open_track_info(tracks_page.trackIds, first_index) 87 + } else if (action === 'revealTrackFile') { 88 + const track_id = tracks_page.trackIds[first_index] 89 + const track = methods.getTrack(track_id) 90 + ipc_renderer.invoke('revealTrackFile', paths.tracksDir, track.file) 91 + } else if (action === 'Remove from Playlist') { 92 + // remove_from_playlist(params.playlist_id, item_ids) 93 + } else if (action === 'Delete from Library') { 94 + delete_indexes(selection.items) 95 + } else { 96 + assert_unreachable(action) 97 + } 88 98 }) 89 99 onDestroy(track_action_unlisten) 90 100
+28 -27
src/lib/selection-new.ts
··· 294 294 } 295 295 296 296 export class SvelteSelection<T> { 297 - readonly selection: Selection<T> 298 - readonly store: Writable<Set<T>> 299 - readonly subscribe: typeof this.store.subscribe 297 + readonly #selection: Selection<T> 298 + readonly #store: Writable<Set<T>> 299 + readonly subscribe: Writable<Set<T>>['subscribe'] 300 + readonly items: Set<T> 300 301 constructor(all_items: T[], options: SelectionOptions<T>) { 301 - this.selection = new Selection(all_items, options) 302 - this.store = writable(this.selection.items) 303 - this.subscribe = this.store.subscribe 302 + this.#selection = new Selection(all_items, options) 303 + this.#store = writable(this.#selection.items) 304 + this.subscribe = this.#store.subscribe 305 + this.items = this.#selection.items 306 + } 307 + 308 + find_first_index() { 309 + return this.#selection.find_first_index() 304 310 } 305 311 306 312 clear() { 307 - this.selection.clear() 308 - this.store.set(this.selection.items) 313 + this.#selection.clear() 314 + this.#store.set(this.#selection.items) 309 315 } 310 316 311 317 update_all_items(all: T[]) { 312 - this.selection.update_all_items(all) 313 - this.store.set(this.selection.items) 318 + this.#selection.update_all_items(all) 319 + this.#store.set(this.#selection.items) 314 320 } 315 321 316 322 shift_select_to(to_index: number) { 317 - this.selection.shift_select_to(to_index) 318 - this.store.set(this.selection.items) 319 - } 320 - 321 - find_first_index() { 322 - this.selection.find_first_index() 323 - this.store.set(this.selection.items) 323 + this.#selection.shift_select_to(to_index) 324 + this.#store.set(this.#selection.items) 324 325 } 325 326 326 327 mouse_down_select(e: MouseEvent, index: number) { 327 - this.selection.mouse_down_select(e, index) 328 - this.store.set(this.selection.items) 328 + this.#selection.mouse_down_select(e, index) 329 + this.#store.set(this.#selection.items) 329 330 } 330 331 handle_mouse_down(e: MouseEvent, index: number) { 331 - this.selection.handle_mouse_down(e, index) 332 - this.store.set(this.selection.items) 332 + this.#selection.handle_mouse_down(e, index) 333 + this.#store.set(this.#selection.items) 333 334 } 334 335 handle_contextmenu(e: MouseEvent, index: number) { 335 - this.selection.handle_contextmenu(e, index) 336 - this.store.set(this.selection.items) 336 + this.#selection.handle_contextmenu(e, index) 337 + this.#store.set(this.#selection.items) 337 338 } 338 339 handle_click(e: MouseEvent, index: number) { 339 - this.selection.handle_click(e, index) 340 - this.store.set(this.selection.items) 340 + this.#selection.handle_click(e, index) 341 + this.#store.set(this.#selection.items) 341 342 } 342 343 handle_keydown(e: KeyboardEvent) { 343 - this.selection.handle_keydown(e) 344 - this.store.set(this.selection.items) 344 + this.#selection.handle_keydown(e) 345 + this.#store.set(this.#selection.items) 345 346 } 346 347 }