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
- 5838d6c7|||PR STATUS: #22 pending decision, PR-only rulemre
- 29d2029cRecords: PR-only rule (Kunibert)mre
- adacb0abRecords: neutral ticket rule, #22 decision recordedmre
- b2d6f121Records: #308 hold liftedmre
- 7ab67533Records: day39 on hold (hybriel#308)mre
- 22f21739Records: note rebase before mergemre
- f7368ea3Records: mission 011 day39, waits for lisbethmre
- 9515d2cdRecords: jb20 livemre
- 019f6601ui gate: comment names the open bug components#27 (workaround, not fixed)mre
- 277a2722README: provenance linemre
- 4169ca6aREADME: sync pinmre
- a01f3aa8ui gate: back to the top before the sort checks (the screen reopens where it was left)mre
- f7936c20Lists keep their scroll position across a reload (jukebox#20): per-list offsets in storage/ui.json, gate jb20mre
- d67906devirtual-list and icons from components.hybriel e5b98ec (centerId, scrollTop, onScroll)mre
- df7920ceRecords: R3 startedmre
- 0549f038Mission 010: jb20 livemre
- 273494e2STATUS rewrittenmre
- 227c9b96Records: jb19 livemre
- 9f365376README: the bar's controls (jb19)mre
- d18851fdjb19: pressed switches look different (whole selector), queue column cannot widen past the panel, gates follow the new bar (jb3, jb11, jb15)mre