JFLib

ui/recent.rs#

Source: lib/ui/recent.rs

recent -- the app's list of recent files ("Zuletzt geöffnet") and the system's (plat::recent)

  recent_add(path)         a file the user opened or saved: first in the app's list (no
                           duplicates, at most RECENT_KEEP) and in the system's list
                           (plat::recent_add: Windows' recent files and jump list,
                           recently-used.xbel; needs the file readable under the app's
                           permissions)
  recent_files() -> [path] the app's list, newest first (a file may be gone meanwhile: the
                           app tells the user and calls recent_remove)
  recent_open(path) -> RecentOpen   a file of the list about to be opened (call it from the
                           user's click or key): Ready (read it now), Asking (the browser asks
                           for the permission again: App::command(UIC_RECENT, 1 readable /
                           0 refused or gone) follows, recent_reopened() names the file) or
                           Missing
  recent_reopened() -> Option<path>   the file UIC_RECENT answered for (once)
  recent_remove(path)      out of both lists
  recent_clear()           both lists emptied (the system's: this app's entries)

The app's list is config://recent.list (one path per line, newest first), read on first use
and kept in memory.  OS paths are kept absolute ("C:/x/a.png", "/home/u/a.png"; a folder
mount's file as its OS path), so another spelling of the same file is no new entry, and as
plat::persistent_name gives them (a Flatpak's file from the documents portal as its lasting
document: one of the portal's file dialog opens again after a restart without a new
dialog).  Headless runs (--shot, --script, agents) never touch the file and leave the
system's list alone (the list lives in memory there; jfgui_RECENT redirects the system's
list, plat/recent.rs).

The browser: the list is persisted in the origin's storage with every change (an emptied
list as an empty file: the storage keeps no deletions), so a reload starts with it.  A file
of the user's own (/handles/ID/NAME, Chromium's pickers) is read in at the start while the
browser still grants it; else recent_open asks through plat::web::reopen (the browser wants
the user's gesture).  Firefox and Safari have no such handles: the list stays, its files open
when the app kept them in the storage itself (plat::web::persist).
Android: the list is a file of the app's internal storage; the picker's grants are lasting
(takePersistableUriPermission), and a single document's grant is given up when its entry
leaves the list (pushed out, removed, cleared: Android keeps at most 128 / 512 of them); a
folder's grant stays, the app may use the folder for more.
/// how many files the app's list keeps
RECENT_KEEP: usize = 20
  • enum RecentOpen what recent_open found for a file of the list
    • Ready -- the file can be read now
    • Asking -- the browser asks the user for the permission again (a file of the user's own after a reload): App::command(UIC_RECENT, 1 readable now / 0 refused or gone) follows
    • Missing -- gone or out of reach: the app tells the user and may call recent_remove

impl Ui

  • fn recent_add(&mut self, path: &str) a file the user opened or saved: first in the app's recent files and in the system's
  • fn recent_open(&mut self, path: &str) -> RecentOpen a file of the recent list about to be opened (from the user's click or key): Ready, Asking (the browser asks for the permission; UIC_RECENT follows) or Missing
  • fn recent_reopened(&mut self) -> Option<String> the file UIC_RECENT answered for, once
  • fn recent_files(&self) -> Vec<String> the app's recent files, newest first
  • fn recent_remove(&mut self, path: &str) a file out of the app's and the system's recent files
  • fn recent_clear(&mut self) the app's recent files and its entries in the system's list forgotten

Source: docs/API.md in the JFLib repository.