Settings > Apps: choose the default browser, email, files, terminal, editor, viewers and players
CI / test (push) Failing after 45s
CI / test (push) Failing after 45s
- A sixth Settings tab, Apps (key 6, SettingsTab::Apps; the popup is 390 px wide for it): Web
browser, Email, File manager, Terminal, Text editor, Image viewer, Video player, Music player,
PDF and documents, Archive manager. Each row shows the current default with its real icon (the
icon-theme lookup the task manager uses; a letter tile when there is none). Click a row to list
the installed apps that can take it, click one to make it the default. A chosen app that has
been uninstalled since is named in red under its row ("gthumb is not installed any more").
- Installed apps come from the .desktop files in the XDG data dirs (and flatpak's exports), with
MimeType= and Categories= (desktop_entry_keys, now shared with the launcher's parse_desktop).
A kind lists the shown apps that handle one of its MIME types; the terminal lists
TerminalEmulator apps; browsers are only offered as browsers.
- Reading follows the mimeapps.list spec: $XDG_CONFIG_HOME/[chandra-]mimeapps.list, then
$XDG_CONFIG_DIRS (/etc/xdg), then $XDG_DATA_HOME and $XDG_DATA_DIRS applications/; the first
installed [Default Applications] entry wins, else [Added Associations], else mimeinfo.cache
(minus [Removed Associations]), else the first installed app that handles the type. A hidden
(NoDisplay) default still counts and its name is shown.
- Setting writes [Default Applications] in ~/.config/mimeapps.list for each of the kind's MIME
types the app handles (always the main one: http/https/text/html for browsers, mailto,
inode/directory, text/plain, image/png..., video/mp4..., audio/mpeg..., application/pdf...,
application/zip...), as xdg-mime default / xdg-settings do, without running them. Every other
section, entry, comment and blank line is kept; the app leaves those types' [Removed
Associations]; a chandra-mimeapps.list that already names one of those types is updated too.
- The terminal has no MIME type: state.edn :terminal "kitty" (desktop id), also written first in
~/.config/xdg-terminals.list (xdg-terminal-exec). Terminal=true apps from the launcher (and
session restore) now start in it (foot -e, kgx/gnome-terminal/ptyxis --, kitty <cmd>, wezterm
start --) instead of always foot; with no choice: xdg-terminals.list, then foot, then any
installed terminal. Terminal apps are listed when any terminal emulator is installed, not only
foot.
- New `default-apps` capability (categories, apps, set-default, refresh): host tables 11 (sss:
name current missing) and 12 (issii: category id name icon current), request 19 (category *
1000 + app, -1 rescans) in the wasmer/wasmtime stub, host-wasm and the MoonBit wasmhost
(chandra:host/plasmoids default-app(s32)). Nothing is scanned until the tab opens (refresh).
- Tests with a temporary XDG tree: categories and current defaults (user file, system file,
Added Associations, mimeinfo.cache, missing apps, hidden defaults), writing that keeps other
entries, desktop-specific files, the terminal list and commands, the Apps tab end to end, and
the :terminal round trip through state.edn.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DPL5hgywj7RPmFdFhpzGZj
This commit is contained in:
26 files changed
+1605
-73
No files matched your search
+36
-54
@@ -12,6 +12,10 @@ priv struct DesktopApp {
|
||||
wm_class : String
|
||||
/// Icon=: an icon theme name ("firefox") or an absolute path.
|
||||
icon : String
|
||||
/// Terminal=true: runs inside a terminal.
|
||||
terminal : Bool
|
||||
/// Categories= has TerminalEmulator.
|
||||
terminal_emulator : Bool
|
||||
}
|
||||
|
||||
///| Directories scanned, lowest priority first (later ones override by file name).
|
||||
@@ -56,80 +60,51 @@ fn clean_exec(exec : String) -> String {
|
||||
sb.to_string().trim(chars=" ").to_string()
|
||||
}
|
||||
|
||||
///| Parse one .desktop file; None when it should not be listed.
|
||||
///| Parse one .desktop file; None when it should not be listed. A Terminal=true app keeps its
|
||||
/// own command (`terminal`): it is started inside the chosen terminal (`DesktopShell::command_for`).
|
||||
fn parse_desktop(id : String, text : String, have_terminal : Bool) -> DesktopApp? {
|
||||
let mut in_entry = false
|
||||
let mut name = ""
|
||||
let mut generic = ""
|
||||
let mut comment = ""
|
||||
let mut exec = ""
|
||||
let mut cats = ""
|
||||
let mut hidden = false
|
||||
let mut terminal = false
|
||||
let mut kind = "Application"
|
||||
let mut wm_class = ""
|
||||
let mut icon = ""
|
||||
for raw in text.split("\n") {
|
||||
let line = raw.trim(chars=" \r\t").to_string()
|
||||
if line.length() == 0 || line.has_prefix("#") {
|
||||
continue
|
||||
}
|
||||
if line.has_prefix("[") {
|
||||
in_entry = line == "[Desktop Entry]"
|
||||
continue
|
||||
}
|
||||
if !in_entry {
|
||||
continue
|
||||
}
|
||||
match line.find("=") {
|
||||
None => ()
|
||||
Some(eq) => {
|
||||
let key = line[:eq].trim(chars=" ").to_string()
|
||||
let val = line[eq + 1:].trim(chars=" ").to_string()
|
||||
match key {
|
||||
"Name" => name = val
|
||||
"GenericName" => generic = val
|
||||
"Comment" => comment = val
|
||||
"Exec" => exec = val
|
||||
"Categories" => cats = val
|
||||
"Type" => kind = val
|
||||
"NoDisplay" | "Hidden" => if val == "true" { hidden = true }
|
||||
"Terminal" => terminal = val == "true"
|
||||
"StartupWMClass" => wm_class = val
|
||||
"Icon" => icon = val
|
||||
_ => ()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
let k = desktop_entry_keys(text)
|
||||
let get = fn(key : String) { k.get(key).unwrap_or("") }
|
||||
let name = get("Name")
|
||||
let exec = get("Exec")
|
||||
let hidden = get("NoDisplay") == "true" || get("Hidden") == "true"
|
||||
let terminal = get("Terminal") == "true"
|
||||
let kind = k.get("Type").unwrap_or("Application")
|
||||
if hidden || kind != "Application" || name.length() == 0 || exec.length() == 0 {
|
||||
return None
|
||||
}
|
||||
if terminal && !have_terminal {
|
||||
return None
|
||||
}
|
||||
let mut command = clean_exec(exec)
|
||||
if terminal {
|
||||
command = "foot -e " + command
|
||||
}
|
||||
let cats = get("Categories")
|
||||
let category = match cats.split(";").next() {
|
||||
Some(c) if c.length() > 0 => c.to_string()
|
||||
_ => "Other"
|
||||
}
|
||||
let comment = if comment.length() > 0 { comment } else { generic }
|
||||
Some({ id, name, comment, category, command, wm_class, icon })
|
||||
let comment = get("Comment")
|
||||
let comment = if comment.length() > 0 { comment } else { get("GenericName") }
|
||||
Some({
|
||||
id,
|
||||
name,
|
||||
comment,
|
||||
category,
|
||||
command: clean_exec(exec),
|
||||
wm_class: get("StartupWMClass"),
|
||||
icon: get("Icon"),
|
||||
terminal,
|
||||
terminal_emulator: semi_list(cats).contains("TerminalEmulator"),
|
||||
})
|
||||
}
|
||||
|
||||
///| Scan every applications dir; later dirs override earlier ones, result sorted by name.
|
||||
fn scan_desktop_apps() -> Array[DesktopApp] {
|
||||
let have_terminal = @sys.has_exe("foot")
|
||||
let by_id : Map[String, DesktopApp] = {}
|
||||
let removed : Map[String, Bool] = {}
|
||||
for dir in app_dirs() {
|
||||
for file in @sys.list_desktop_files(dir) {
|
||||
let bytes = @sys.read_file_bytes(dir + "/" + file)
|
||||
let id = file[:file.length() - 8].to_string()
|
||||
match parse_desktop(id, @utf8.decode_lossy(bytes), have_terminal) {
|
||||
match parse_desktop(id, @utf8.decode_lossy(bytes), true) {
|
||||
Some(app) => {
|
||||
by_id.set(id, app)
|
||||
removed.remove(id)
|
||||
@@ -140,9 +115,16 @@ fn scan_desktop_apps() -> Array[DesktopApp] {
|
||||
}
|
||||
}
|
||||
}
|
||||
// Terminal apps are only listed when there is a terminal to run them in.
|
||||
let mut have_terminal = @sys.has_exe("foot")
|
||||
for _, a in by_id {
|
||||
have_terminal = have_terminal || a.terminal_emulator
|
||||
}
|
||||
let apps : Array[DesktopApp] = []
|
||||
for _, a in by_id {
|
||||
apps.push(a)
|
||||
if have_terminal || !a.terminal {
|
||||
apps.push(a)
|
||||
}
|
||||
}
|
||||
apps.sort_by(fn(a, b) {
|
||||
let x = a.name.to_lower()
|
||||
|
||||
Reference in new issue
Block a user