plat/assoc.rs#
Source: lib/plat/assoc.rs
assoc -- the app's file types and URL schemes (apps/NAME/PACKAGE filetypes= / schemes=)
registered for the running program without a setup: developer and portable builds. The
setup (apps/installer), the .deb, MSIX and Flatpak declare them themselves (docs/PACKAGING.md).
package() -> Package what build_rs.py built in (JFGUI_PACKAGE: display,
app_id, categories, filetypes, schemes; ui::main! hands
it over with package_set); without it: the app's name,
no types
Package::parse(text) that text ("key=value" lines)
parse_types(text) -> [FileType] "ext[,ext..]|mime|description[|own]; ..." -- every
extension gets the app under "Open with"; "own" types
also open with it by default
parse_schemes(text) -> [scheme] "scheme scheme ..." (';', ',' or blanks)
reg_entries(app, display, exe, types, schemes, app_id) -> [RegValue] the values below
HKCU\Software\Classes the setup and assoc_register write
(app_id: the program's AppUserModelID in its ProgIDs,
"" = none)
package_entries(&Package, exe) -> [RegValue] all of a package's values: reg_entries and,
with browser=1, the web browser's registration (below)
app_id_boot() -> Option<id> (ui::main!, Windows) PACKAGE's app id as the process's
explicit AppUserModelID (taskbar.rs) once the setup
installed this program (install.ini beside it names the
id) or --register registered it (the record names it);
jfgui_AUMID=ID gives one, jfgui_AUMID=off none. Every
other program keeps the id Windows derives from its path
assoc_conflicts(&Package) -> Result<[Conflict], AssocError> the defaults of other
programs a registration would replace
assoc_register(&Package, take) -> Result<Registered, AssocError> register this program;
take(&Conflict) decides each default of another program
(false: it stays, the app is only offered under "Open
with"); a registration of before is undone first
assoc_unregister() -> Result<bool, AssocError> undo exactly what the record lists (false:
nothing was registered)
assoc_registered() -> Option<String> the program the record names
default_browser_status() -> BrowserStatus (PACKAGE browser=1) is this app the system's web
browser: Default, NotDefault, Unknown (browser_status(pkg))
default_browser_request() -> Result<(), AssocError> let the user make it the default: the
system's own page or question (browser_request(pkg))
file_uri_path(arg) -> Option<String> a local file:// URI as a path (Linux desktops hand
files over as URIs for Exec=... %U)
console_print(text) stdout, else the console the program was started from
(Windows programs of the GUI subsystem: --register)
The record (config://assoc.list) lists every key, value and file the registration added and
what it replaced; unregistering removes those (a value only while it still holds what was
written) and puts back what was there. Windows (win_assoc.rs): the setup's entries below
HKCU\Software\Classes -- the ProgID <app>.<ext> (description, DefaultIcon, shell\open\command
= "<exe>" "%1", AppUserModelID = the app id: what Windows asks of a handler with an explicit
id for the recent files of the type), .<ext>\OpenWithProgids, for own types the default and
Content Type of .<ext>, a scheme's key (URL:<display>, URL Protocol, shell\open\command =
"<exe>" -- "%1": the URL after "--" is one argument, never options) -- then SHChangeNotify.
A default of another program is the extension's default value (HKCU or HKLM) or a key of the
same name with another command; the user's own choice in Windows' dialog (UserChoice, hashed) is never
changed (Conflict::fixed). Linux (linux_assoc.rs): $XDG_DATA_HOME/applications/<app_id>.desktop
(Exec with %U for schemes, else %F; MimeType=), own types as shared-mime-info XML in
$XDG_DATA_HOME/mime/packages/<app_id>.xml, the defaults of own types and schemes in
$XDG_CONFIG_HOME/mimeapps.list [Default Applications] (written directly, no xdg-mime); the
caches are refreshed by update-mime-database / update-desktop-database when they are there
(without update-mime-database the own types are known after the next system update of the
MIME database; the .desktop file needs no cache). A default of another program is an entry
in a mimeapps.list or, without one, another installed .desktop file with that MIME type.
In an MSIX package or a Flatpak the package declares everything: Unavailable. Web and
Android: Unavailable.
Not a permission of the manifest: only what PACKAGE declares is written, in the user's own
part of the system (HKCU, $XDG_*_HOME).
A web browser (PACKAGE browser=1, schemes= with http and https). Windows: http and https get no
keys of their own (HKCU\Software\Classes\http would stand in for the system's handler); the
ProgID <app>URL opens web addresses (URL Protocol, the open command, Application with the
name and icon), Software\Clients\StartMenuInternet\<app> is the browser of Default Programs
(name, icon, the command, Capabilities: ApplicationName / Description / Icon, StartMenu,
URLAssociations http / https -> <app>URL, FileAssociations .<ext> -> the file types' ProgIDs)
and Software\RegisteredApplications\<app> names its Capabilities. Windows 10 and later never
let a program take the default itself: browser_request opens Settings at the app's page of the
default apps (ms-settings:defaultapps?registeredAppUser=<app>), the user decides there;
browser_status reads the user's choice of http and https (UserChoiceLatest, else UserChoice).
Linux: the .desktop file says Network;WebBrowser; besides the MIME types; browser_status reads
the defaults of x-scheme-handler/http and https from the mimeapps.list files (as xdg-mime and
xdg-settings do), browser_request writes the app as the user's default of those and of
text/html (and KDE's BrowserApplication in kdeglobals): the user asked for it with the call, and
the desktops offer no question of their own. macOS: browser_status asks Launch Services for
http's handler, browser_request sets it for http and https -- macOS asks the user itself ("Do you
want to change your default web browser?"). In a Flatpak, an MSIX package, the browser and on
Android / iOS: Unknown and Unavailable.
struct FileTypeone file type of PACKAGE filetypes=exts: Vec<String>-- lower case, without the dotmime: Stringdesc: Stringown: bool-- the app is the default program of these extensions
struct Packagewhat the app registers (apps/NAME/PACKAGE, built in by build_rs.py)app: String-- the app's name (vfs::app_id): Windows ProgIDs <app>.<ext>display: String-- PACKAGE display=: menus, "URL:<display>"app_id: String-- the reverse-DNS id (PACKAGE app_id=, else org.jflib.<App>): the Linux .desktop idcategories: String-- PACKAGE categories= (the .desktop file)types: Vec<FileType>schemes: Vec<String>browser: bool-- PACKAGE browser=1: the app is a web browser (registered as one; default_browser_status, default_browser_request)
struct Conflicta default of another program that a registration would replacewhat: String-- ".ext" (an own file type), "scheme:" (a URL scheme), a ProgID or a file that is in the wayholder: String-- who has it now: a ProgID or command (Windows), a .desktop id or file (Linux)fixed: bool-- the user chose that program in the system's dialog (Windows UserChoice): it stays, take is not asked
struct Registeredwhat assoc_register didexe: String-- the program the entries starttypes: usize-- file types and schemes registeredschemes: usizekept: Vec<Conflict>-- the defaults of other programs that stayed (take said no, or fixed)notes: Vec<String>-- hints (a missing cache tool ...)
enum AssocErrorwhy a registration failedUnavailable-- not here: web, Android, an MSIX package or a Flatpak (the package declares the types)Empty-- PACKAGE has no filetypes= and no schemes=Declined(Conflict)-- a file of another program is in the way and take said no (Linux: the .desktop file)Failed(String)-- the system refused or failed: what it saidNotRegistered-- (default_browser_request) the app is not registered as a web browser here: PACKAGE without browser=1, or neither the package nor --register registered this program
fn package_set(text: Option<&str>)(ui::main!) keep the built-in PACKAGE text (JFGUI_PACKAGE)fn package() -> Packagewhat the app registers: the built-in PACKAGE, else the app's name without types
impl Package
fn parse(text: &str) -> Package"key=value" lines: display, app_id, categories, filetypes, schemes, browser (the app is vfs::app_id; missing values get the defaults of tools/pkgmeta.py)fn mime_of(&self, path: &str) -> Option<String>the MIME type of a file name by its extension (own file types first), None when unknownfn parse_types(text: &str) -> Vec<FileType>"ext[,ext..]|mime|description[|own]; ..." -> the valid entriesfn parse_schemes(text: &str) -> Vec<String>"scheme scheme; ..." -> the valid schemes (lower case)struct RegValuea value below HKCU (reg_entries): key, name ("" = the default value), REG_SZ valuekey: Stringname: Stringvalue: Stringroot: String-- RV_TREE: the app's own key it lies in (a ProgID, a scheme), removed as a wholekind: u8
/// a value in a key of the app's own (RegValue::root)
RV_TREE: u8 = 0
/// a value in a shared key (.ext\OpenWithProgids): only the value is the app's
RV_SHARED: u8 = 1
/// the default (and Content Type) of an extension: the app becomes its default program
RV_DEFAULT: u8 = 2
fn reg_entries(app: &str, display: &str, exe: &str, types: &[FileType], schemes: &[String], app_id: &str) -> Vec<RegValue>the HKCU values of the file types and schemes for the program exe (backslashes): the setup's and assoc_register's. app_id: the AppUserModelID the program runs under ("" = none, Windows derives one): each ProgID names it (AppUserModelID), as Windows wants for the recent files of an explicit idfn package_entries(pkg: &Package, exe: &str) -> Vec<RegValue>every HKCU value of pkg for the program exe: reg_entries of its file types and schemes and, with browser=1, the web browser's registration in place of http's and https's own keys (the ProgID <app>URL, Software\Clients\StartMenuInternet\<app> with its Capabilities, the value <app> in Software\RegisteredApplications) -- what the setup and assoc_register writeenum BrowserStatus(default_browser_status) is the app the system's web browserDefault-- web addresses (http and https) open with this appNotDefault-- with another program (or the app is no browser: PACKAGE without browser=1)Unknown-- the system does not say: no default set (Linux), or not to be found out here (a Flatpak, the browser, Android, iOS)
fn default_browser_status() -> BrowserStatus(PACKAGE browser=1) is this app the system's web browser (the built-in PACKAGE: browser_status(&package())). Ask again when the app's window is active again (UIC_ACTIVE): the user may have changed it in the system's settings meanwhilefn browser_status(pkg: &Package) -> BrowserStatusis the app of pkg the system's web browser: Windows -- the user's choice of http and https (UserChoiceLatest, else UserChoice) is its ProgID <app>URL; Linux -- the mimeapps.list files' defaults of x-scheme-handler/http and https name one of its .desktop files (none named: Unknown); macOS -- Launch Services' handler of http and https is its bundlefn default_browser_request() -> Result<(), AssocError>(PACKAGE browser=1) let the user make this app the system's web browser (the built-in PACKAGE: browser_request(&package())); call it from the user's clickfn browser_request(pkg: &Package) -> Result<(), AssocError>let the user make the app of pkg the web browser: Windows 10 and later -- Settings opens at the app's page of the default apps (ms-settings:defaultapps?registeredAppUser=<app>; Windows lets no program take the default itself), the user picks there; Linux -- the app's installed .desktop file becomes the user's default of x-scheme-handler/http, https and text/html in mimeapps.list (and KDE's BrowserApplication), as xdg-settings set default-web-browser does; macOS -- Launch Services' handler of http and https, macOS asks the user. Ok: asked or set (read browser_status again later); NotRegistered: no browser=1, or this program is not registered as a browser (install the package or run --register first); Unavailable: a Flatpak, an MSIX package, the browser, Android, iOS. jfgui_OPEN_DRYRUN=1 (Windows): the page is printed, not openedfn assoc_conflicts(pkg: &Package) -> Result<Vec<Conflict>, AssocError>the defaults of other programs a registration of pkg would replace (nothing is written)fn assoc_register(pkg: &Package, take: &mut dyn FnMut(&Conflict) -> bool) -> Result<Registered, AssocError>register this program for pkg's file types and schemes; take(conflict) -> replace that default of another programfn assoc_unregister() -> Result<bool, AssocError>undo the registration of the record -> Ok(false) when there was nonefn assoc_registered() -> Option<String>the program a registration of this app starts (the record), None without onefn app_id_boot() -> Option<String>(ui::main!) Windows: PACKAGE's app id as the process's explicit AppUserModelID when this program was installed by the setup (install.ini beside it names the id) or registered with --register (the record names this program); jfgui_AUMID=ID gives one, =off none -> the id set. Other programs (and other systems) keep the id the system derivesfn file_uri_path(arg: &str) -> Option<String>a local file:// URI as a path ("file:///home/a%20b.txt" -> "/home/a b.txt", Windows "file:///C:/a.txt" -> "C:/a.txt"); None for anything else (another host, no URI)fn console_print(text: &str)text on stdout, else (Windows, a GUI program started from a console) on the console of the parent processfn hkcu_get(sub: &str, name: Option<&str>) -> Option<String>(Windows) (tests, Windows) HKCU\sub: name Some(n) its string value ("" = the default value), None: Some("") when the key exists