gitoria

jukebox

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit64bc782364bc7823Records: #21 causemre64bc7823/lib/remember.hl

1.1 KB

  1. // lib/remember.hl — WHAT THE LISTENER LAST CHOSE, kept in storage/ui.json: the sort of the Songs screen (artist, title, album, plays).
  2. // The screen opens the way it was left. Its own file, apart from settings.json (that one holds the library paths and is written whole by the settings call).
  3. import { readFile, writeFile, exists, mkDir } from 'hl:fs'
  4. import { storageRoot, storageDir } from './util.hl'
  5. static uiFile = storageRoot + '/ui.json'
  6. static sorts = ['artist', 'title', 'album', 'plays']
  7. // the sort the Songs screen was left with ('artist' when nothing was saved or the file says something else)
  8. static lastSort = () => {
  9. if (!exists(uiFile)) { return 'artist' }
  10. text = readFile(uiFile)
  11. if (text == null || !text.trim().startsWith('{')) { return 'artist' }
  12. j = JSON.parse(text)
  13. if (j == null || j.sort == null || !sorts.includes(j.sort)) { return 'artist' }
  14. return j.sort
  15. }
  16. // the listener chose a sort: keep it for the next visit; a name that is no sort is ignored
  17. static rememberSort = (sort) => {
  18. if (sort == null || !sorts.includes(sort)) { return null }
  19. mkDir(storageRoot)
  20. writeFile(uiFile, JSON.stringify({ sort = sort }), 420)
  21. return sort
  22. }

Branches

Latest commits

  • 64bc7823Records: #21 causemre
  • 76639655Records: B1 questionmre
  • d7906b36Records: mission 005 startedmre
  • d3df773cMission 005: doc linemre
  • 6a5d840aMission 005: jukebox#22mre
  • 13e5e748Records: mission 004 startedmre
  • a8098271Mission 004: jukebox#21mre
  • df8f5205Records: jukebox#19-21, #11 closedmre
  • b7a4e692Records: hybriel#298mre
  • 9bcbb017Records: day38b waits for day39 fixmre
  • f80504e1Records: day38b repro sentmre
  • 8048258bRecords: day38b jb3 regression, L1 Chromes stoppedmre
  • 68aace7fRecords: mission 003 day38bmre
  • d105d8a9Records: mpackdb integrity check cleanmre
  • 6e980c53Records: mpackdb rule refinementmre
  • 6d335ac4Records: storage copy rulingmre
  • 7eb2898dRecords: mpackdb second-opener rule until day38mre
  • b011f98eRecords: style form live on day35mre
  • 60d90cb2Records: L1 woken for the restartmre
  • 75ae544fRecords: restart waits for the connection to closemre