jukebox
All repositories: gitoria
3.3 KB
// lib/remember.hl — WHAT THE LISTENER LAST CHOSE, kept in storage/ui.json: the sort of the Songs screen (artist, title, album, plays), and the player's Shuffle (on / off)// and Repeat (off / all / one), and where each list was scrolled to (per list key, never a row, in pixels from the top: scroll = { 'songs:artist' = 5600, ... }). The screen and the player open the way they were left. Its own file, apart from settings.json (that one holds the library paths and is// written whole by the settings call). Every write keeps the other keys of the file.import { readFile, writeFile, exists, mkDir } from 'hl:fs'import { floor } from 'hl:math'import { storageRoot, storageDir } from './util.hl'static uiFile = storageRoot + '/ui.json'static sorts = ['artist', 'title', 'album', 'plays']static repeats = ['off', 'all', 'one']static rowHeight = 56// everything the file holds ({} when there is no file or it says something else)static readUi = () => {if (!exists(uiFile)) { return {} }text = readFile(uiFile)if (text == null || !text.trim().startsWith('{')) { return {} }j = JSON.parse(text)if (j == null) { return {} }return j}// the whole file again, with the one key changedstatic writeUi = (key, value) => {j = readUi()j[key] = valuemkDir(storageRoot)writeFile(uiFile, JSON.stringify(j), 420)}// the sort the Songs screen was left with ('artist' when nothing was saved or the file says something else)static lastSort = () => {j = readUi()if (j.sort == null || !sorts.includes(j.sort)) { return 'artist' }return j.sort}// the listener chose a sort: keep it for the next visit; a name that is no sort is ignoredstatic rememberSort = (sort) => {if (sort == null || !sorts.includes(sort)) { return null }writeUi('sort', sort)return sort}// Shuffle as the player was left: 'on' or 'off' (off when nothing was saved)static lastShuffle = () => {j = readUi()return j.shuffle == 'on' ? 'on' : 'off'}// Repeat as the player was left: 'off', 'all' or 'one' (off when nothing was saved)static lastRepeat = () => {j = readUi()if (j.repeat == null || !repeats.includes(j.repeat)) { return 'off' }return j.repeat}// the listener pressed Shuffle or Repeat: keep both for the next visit; a value that is none of the names is ignoredstatic rememberPlayer = (shuffle, repeat) => {if (shuffle == 'on' || shuffle == 'off') { writeUi('shuffle', shuffle) }if (repeat != null && repeats.includes(repeat)) { writeUi('repeat', repeat) }return { shuffle = lastShuffle() repeat = lastRepeat() }}// where the list `key` was scrolled to (pixels from its top); 0 when nothing was savedstatic lastScroll = (key) => {j = readUi()if (j.scroll == null || j.scroll[key] == null) { return 0 }top = j.scroll[key]return top > 0 ? top : 0}// the listener scrolled the list `key`: keep the offset for the next visit; no key or no number is ignoredstatic rememberScroll = (key, top) => {if (key == null || key == '' || top == null || top < 0) { return null }j = readUi()scroll = j.scroll == null ? {} : j.scrollif (scroll[key] == top) { return top }scroll[key] = topwriteUi('scroll', scroll)return top}// the first row to load so that the rows around a saved offset are in the first chunk (the list asks for more when it needs them)static startRowFor = (top) => {start = floor(top / rowHeight) - 20return start < 0 ? 0 : start}
Branches
Latest commits
- 10f8a8c8Merge branch 'code-order' into mainJukebox
- 204fc828Merge branch 'day72' into mainJukebox
- 95f5faae|||PR jukebox#7 Drop needless let declarationsmre
- 33072bb5|||PR Record day72 gates and Chrome proofmre
- 95f2cd73|||PR Use typed parent methods for screen playback and local server facesmre
- 6422a020Sync media-player at 51c3818mre
- b582ba1cVendor complete Hybriel day72 plugin setmre
- 02dccbc9Merge branch 'records-1119' into mainJukebox
- a39e1c23|||PR Records: missions 013-015, reconnect fix livemre
- fc7db075Merge branch 'reconnect-retry' into mainJukebox
- ac6f4c6fL2: plain declaration for a in pickedNextmre
- 2f335086Review round 2: only an explicit queue pick drops pend (not the automatic advance); jb23 records every source changemre
- 3eb6695fReview fixes: action generation, queue pick clears pend, Previous/Next retry the decided request, typed handlersmre
- 7a53c0c2|||PR A tap lost to a dead socket plays after reconnect (mission 015)mre
- 1f0cd77bMerge branch 'records-day41' into mainJukebox
- 67be229f|||PR Records: day41 live (PR #4), mission 012, statusmre
- 0bb027daconductor: caramboleyo is the user, not owner/creatorApollo
- 04f5d9d5Merge branch 'day41' into mainJukebox
- 8ed6da45|||PR README: media-player pin df9e7dfmre
- d5d45fc3|||PR media-player df9e7df (repeat-one fix), sync pin and SOURCEmre