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
- d7b5e780|||PR Records 2026-11-24 (2): live day72, PR #19 merge, #10 newsmre
- 43b564dbMerge branch 'records-1124b' into mainJukebox
- fa86b08c|||PR Records 2026-11-24: LOG, STATUS, missions 020-023mre
- 0a2ae3daMerge remote-tracking branch 'origin/records-1123' into records-1124mre
- 9a48cfcaMerge branch 'vendor-theme' into mainJukebox
- 170d3735Merge branch 'code-order-2' into mainJukebox
- 3f1918a7|||PR Re-sync layouts theme 4099e64 with Segoe UI firstmre
- 2e7f6a43Vendor virtual-list 489afcf from components.hybrielmre
- 0ba85799Merge branch 'reset-classes' into mainJukebox
- 502eeed5jukebox#20: vendor virtual-list initial resetKey baseline fixmre
- 6d5ce287|||PR jukebox#9 Centralize songs table reads and writes in db.hlmre
- dcca21abjukebox#8 Move copies and queue logic into their topicsmre
- 3b76651cjukebox#20: update virtual-list README pin and resetKey optionsmre
- bc09e1e8|||PR jukebox#20: reset virtual lists through resetKey (partial validation)mre
- a3796dc5Records: live step waits for idlemre
- 3b158e16Records: merges of #9 and #11mre
- 27204167Merge main into records-1123mre
- 10f8a8c8Merge branch 'code-order' into mainJukebox
- 204fc828Merge branch 'day72' into mainJukebox
- 8e8d0e2b|||PR Records: PROCEDURES.md, missions 016-019, GO 2026-11-23mre