Launcher: pick up web apps as they are installed, categories, scrolling
CI / test (push) Failing after 49s

- Read the app catalog again when the Applications menu opens if .desktop files were added or removed (and on Reload); it was only read at login, so a PWA installed during the session was missing from the menu and its search
- List a Chromium browser's web apps in their own category ("Chrome Apps", "Chromium Apps", ...), as Plasma does; don't take one for the default browser
- Category column and a scrollable list (wheel, scrollbar) when the catalog doesn't fit the menu
- Show menu-spec main category names instead of the first Categories= entry; sort apps A-Z (they were sorted shortest name first)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
nandiandClaude Opus 5.5 committed 2026-11-28 23:42:10 -08:00
1 parent aa92aaac6f
commit 68baf1a467
11 files changed
+578 -109

No files matched your search

+138 -36
View File
@@ -18,29 +18,6 @@ priv struct DesktopApp {
terminal_emulator : Bool
}
///| Directories scanned, lowest priority first (later ones override by file name).
fn app_dirs() -> Array[String] {
let home = @sys.getenv("HOME")
let data_home = {
let x = @sys.getenv("XDG_DATA_HOME")
if x.length() > 0 { x } else { home + "/.local/share" }
}
let dirs : Array[String] = []
let xdg = @sys.getenv("XDG_DATA_DIRS")
let list = if xdg.length() > 0 { xdg } else { "/usr/local/share:/usr/share" }
let parts : Array[String] = list.split(":").map(x => x.to_string()).collect()
// XDG_DATA_DIRS is highest priority first; we want lowest first.
for i = parts.length() - 1; i >= 0; i = i - 1 {
if parts[i].length() > 0 {
dirs.push(parts[i] + "/applications")
}
}
dirs.push("/var/lib/flatpak/exports/share/applications")
dirs.push(home + "/.local/share/flatpak/exports/share/applications")
dirs.push(data_home + "/applications")
dirs
}
///| Drop Exec field codes (%f %U ...), keep a literal %%.
fn clean_exec(exec : String) -> String {
let sb = StringBuilder::new()
@@ -60,6 +37,57 @@ fn clean_exec(exec : String) -> String {
sb.to_string().trim(chars=" ").to_string()
}
///| The menu category of a web app a Chromium browser installed (its Exec starts the browser with
/// --app-id), named the way the browser names its own menu folder ("Chrome Apps"); None for any
/// other command. These files carry no Categories=: the browsers sort them into their folder with
/// a desktop menu file instead.
fn web_app_category(command : String) -> String? {
match command.find("--app-id=") {
None => None
Some(i) => {
// Only the browser's part: an app id may spell anything in a-p.
let browser = command[:i].to_string().to_lower()
for
it in [
("brave", "Brave Apps"),
("microsoft", "Edge Apps"),
("msedge", "Edge Apps"),
("vivaldi", "Vivaldi Apps"),
("opera", "Opera Apps"),
("chromium", "Chromium Apps"),
("chrome", "Chrome Apps"),
] {
if browser.contains(it.0) {
return Some(it.1)
}
}
Some("Web Apps")
}
}
}
///| The menu category for a Categories= value: the first of the menu spec's main categories in
/// it, by the name menus show, else "Other" (toolkit names such as Qt and GTK are no category).
fn menu_category(categories : String) -> String {
for c in semi_list(categories) {
match c {
"AudioVideo" | "Audio" | "Video" => return "Multimedia"
"Development" => return "Development"
"Education" => return "Education"
"Game" => return "Games"
"Graphics" => return "Graphics"
"Network" => return "Internet"
"Office" => return "Office"
"Science" => return "Science"
"Settings" => return "Settings"
"System" => return "System"
"Utility" => return "Utilities"
_ => ()
}
}
"Other"
}
///| 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? {
@@ -77,10 +105,7 @@ fn parse_desktop(id : String, text : String, have_terminal : Bool) -> DesktopApp
return None
}
let cats = get("Categories")
let category = match cats.split(";").next() {
Some(c) if c.length() > 0 => c.to_string()
_ => "Other"
}
let category = web_app_category(exec).unwrap_or(menu_category(cats))
let comment = get("Comment")
let comment = if comment.length() > 0 { comment } else { get("GenericName") }
Some({
@@ -96,11 +121,65 @@ fn parse_desktop(id : String, text : String, have_terminal : Bool) -> DesktopApp
})
}
///| Scan every applications dir; later dirs override earlier ones, result sorted by name.
fn scan_desktop_apps() -> Array[DesktopApp] {
///| The .desktop file names in the applications dirs, to tell when apps were added or removed.
fn desktop_files_in(dirs : Array[String]) -> Array[String] {
let out : Array[String] = []
for dir in dirs {
out.push(dir)
out.append(@sys.list_desktop_files(dir))
}
out
}
///| Fill the app catalog from the installed .desktop files.
fn DesktopShell::load_apps(self : DesktopShell) -> Unit {
let dirs = self.xdg_dirs.app_dirs()
self.app_files = desktop_files_in(dirs)
let old_icons = self.icon_names.copy()
self.apps.clear()
self.exec.clear()
self.wm_classes.clear()
self.icon_names.clear()
self.terminal_apps.clear()
for a in scan_desktop_apps(dirs) {
if a.terminal {
self.terminal_apps.set(a.id, true)
}
if a.icon.length() > 0 {
self.icon_names.set(a.id, a.icon)
}
if a.wm_class.length() > 0 {
self.wm_classes.set(a.wm_class.to_lower(), a.id)
}
let glyph = match a.name.to_array().get(0) {
Some(c) => c.to_string().to_upper()
None => "?"
}
self.apps.push({ id: a.id, name: a.name, comment: a.comment, category: a.category, glyph })
self.exec.set(a.id, a.command)
// A new app (or one with a new icon) may have been looked up before it had one.
if old_icons.get(a.id) != self.icon_names.get(a.id) {
self.icon_handles.remove(a.id)
}
}
self.order_apps()
self.apps_dirty = true
}
///| Read the catalog again if apps were installed or removed since (a web app installed from the
/// browser, say). Called as the Applications menu opens; only lists the dirs when nothing changed.
fn DesktopShell::refresh_apps(self : DesktopShell) -> Unit {
if desktop_files_in(self.xdg_dirs.app_dirs()) != self.app_files {
self.load_apps()
}
}
///| Scan every applications dir in `dirs` (highest priority first: a file there overrides one of
/// the same name further on), result sorted by name.
fn scan_desktop_apps(dirs : Array[String]) -> Array[DesktopApp] {
let by_id : Map[String, DesktopApp] = {}
let removed : Map[String, Bool] = {}
for dir in app_dirs() {
for dir in dirs.rev() {
for file in @sys.list_desktop_files(dir) {
let bytes = @sys.read_file_bytes(dir + "/" + file)
let id = file[:file.length() - 8].to_string()
@@ -126,11 +205,8 @@ fn scan_desktop_apps() -> Array[DesktopApp] {
apps.push(a)
}
}
apps.sort_by(fn(a, b) {
let x = a.name.to_lower()
let y = b.name.to_lower()
if x < y { -1 } else if x > y { 1 } else { 0 }
})
// Strings compare shortest first; menus want A-Z.
apps.sort_by(fn(a, b) { a.name.to_lower().lexical_compare(b.name.to_lower()) })
apps
}
@@ -141,7 +217,7 @@ test "parse_desktop reads a normal entry and strips field codes" {
Some(a) => {
assert_eq(a.name, "Firefox")
assert_eq(a.command, "firefox")
assert_eq(a.category, "Network")
assert_eq(a.category, "Internet")
assert_eq(a.comment, "Browse")
}
None => fail("expected entry")
@@ -162,6 +238,32 @@ test "parse_desktop keeps StartupWMClass" {
}
}
///|
test "parse_desktop puts a browser's web apps in their own category" {
let web = fn(exec : String) {
let t = "[Desktop Entry]\nType=Application\nName=YouTube\nExec=" + exec + "\nStartupWMClass=crx_agim\n" +
"Actions=Shorts\n[Desktop Action Shorts]\nName=Shorts\nExec=other\n"
match parse_desktop("chrome-agim-Default", t, true) {
Some(a) => (a.name, a.category, a.command)
None => ("", "", "")
}
}
let chrome = "/opt/google/chrome/google-chrome --profile-directory=Default --app-id=edgeop"
assert_eq(web(chrome), ("YouTube", "Chrome Apps", chrome))
assert_eq(web("/usr/bin/chromium --app-id=abc").1, "Chromium Apps")
assert_eq(web("/usr/bin/flatpak run --command=/app/bin/chrome com.google.Chrome --app-id=abc").1, "Chrome Apps")
assert_eq(web("/opt/microsoft/msedge/microsoft-edge --app-id=abc").1, "Edge Apps")
assert_eq(web("firefox"), ("YouTube", "Other", "firefox"))
}
///|
test "menu_category skips toolkit names and names the main category" {
assert_eq(menu_category("Qt;KDE;System;TerminalEmulator;"), "System")
assert_eq(menu_category("Game;Network;"), "Games")
assert_eq(menu_category("GTK;X-Own;"), "Other")
assert_eq(menu_category(""), "Other")
}
///|
test "parse_desktop hides NoDisplay entries" {
let t = "[Desktop Entry]\nType=Application\nName=X\nExec=x\nNoDisplay=true\n"
+2 -2
View File
@@ -199,7 +199,7 @@ pub fn XdgDirs::from_env() -> XdgDirs {
let parts = fn(s : String) -> Array[String] {
s.split(":").filter(p => p.length() > 0).map(p => p.to_string()).collect()
}
// Flatpak's exports, as the launcher scans them (flatpak usually puts them in XDG_DATA_DIRS).
// Flatpak's exports (flatpak usually puts them in XDG_DATA_DIRS).
let data_dirs = parts(or("XDG_DATA_DIRS", "/usr/local/share:/usr/share"))
for d in [home + "/.local/share/flatpak/exports/share", "/var/lib/flatpak/exports/share"] {
if !data_dirs.contains(d) {
@@ -235,7 +235,7 @@ pub fn XdgDirs::mimeapps_files(self : XdgDirs) -> Array[String] {
out
}
///| applications dirs, highest priority first (the launcher's `app_dirs` lists them lowest first).
///| applications dirs, highest priority first.
fn XdgDirs::app_dirs(self : XdgDirs) -> Array[String] {
let out = [self.data_home + "/applications"]
for d in self.data_dirs {
+1 -1
View File
@@ -395,7 +395,7 @@ fn DesktopShell::open_app_menu(self : DesktopShell, app : @types.AppEntry, x : I
fn DesktopShell::launcher_app_at(self : DesktopShell, x : Int, y : Int) -> @types.AppEntry? {
match self.popup_at(x, y) {
Some(w) if w.module_id == launcher_module => {
let shown = @launcher.filter(self.apps, self.launcher_state.query)
let shown = @launcher.listed(self.apps, self.launcher_state)
let i = @launcher.row_at(self.apps, self.launcher_state, { x: x - w.popup_rect.x, y: y - w.popup_rect.y })
if i >= 0 && i < shown.length() {
Some(shown[i])
+41 -19
View File
@@ -419,6 +419,10 @@ pub(all) struct DesktopShell {
mut menu_anchor_y : Int
/// Extra bottom inset reserved for panel popups (e.g. an open on-screen keyboard).
mut popup_bottom_inset : Int
/// The .desktop files there were when the catalog was read (`refresh_apps`).
mut app_files : Array[String]
/// Touchpad scrolling over the launcher's popup not yet worth a row, in pixels.
mut popup_scroll : Double
}
///|
@@ -428,23 +432,6 @@ pub fn DesktopShell::new(display : String) -> DesktopShell {
let wm_classes : Map[String, String] = {}
let icon_names : Map[String, String] = {}
let terminal_apps : Map[String, Bool] = {}
for a in scan_desktop_apps() {
if a.terminal {
terminal_apps.set(a.id, true)
}
if a.icon.length() > 0 {
icon_names.set(a.id, a.icon)
}
if a.wm_class.length() > 0 {
wm_classes.set(a.wm_class.to_lower(), a.id)
}
let glyph = match a.name.to_array().get(0) {
Some(c) => c.to_string().to_upper()
None => "?"
}
apps.push({ id: a.id, name: a.name, comment: a.comment, category: a.category, glyph })
exec.set(a.id, a.command)
}
let zero : @scene.Rect = { x: 0, y: 0, w: 0, h: 0 }
let sh : DesktopShell = {
apps,
@@ -559,8 +546,10 @@ pub fn DesktopShell::new(display : String) -> DesktopShell {
desk_saved: {},
menu_anchor_y: -1,
popup_bottom_inset: 0,
app_files: [],
popup_scroll: 0.0,
}
sh.order_apps()
sh.load_apps()
sh
}
@@ -624,7 +613,9 @@ fn DesktopShell::order_apps(self : DesktopShell) -> Unit {
for key in g {
if !found {
for a in self.apps {
if !found && a.id.to_lower().contains(key) {
// A web app's id holds its browser's name (chrome-<app id>-Default): not the browser.
let web = web_app_category(self.exec.get(a.id).unwrap_or("")) is Some(_)
if !found && !web && a.id.to_lower().contains(key) {
take(a, out, seen)
found = true
}
@@ -762,6 +753,9 @@ fn Widget::has_cap(self : Widget, cap : String) -> Bool {
///| Hand an event to a module, then carry out whatever it asked of the host.
fn DesktopShell::deliver(self : DesktopShell, w : Widget, popup : Bool, ev : @wasm.PlasmoidEvent) -> Bool {
if w.module_id == launcher_module && !popup && w.popup_rect.w == 0 && ev is PointerDown(_, _) {
self.refresh_apps() // the menu is about to open
}
self.publish_host_data()
let changed = w.pl.on_event(popup, ev)
self.process_requests()
@@ -816,6 +810,34 @@ pub fn DesktopShell::launcher_open(self : DesktopShell) -> Bool {
self.launcher_rect() is Some(_)
}
///| Wheel or touchpad over an open panel popup: `notches` wheel clicks, or (0 of those) `px`
/// pixels; + is down. The launcher's list scrolls by rows. False when (x, y) is on no popup.
pub fn DesktopShell::scroll_popup(self : DesktopShell, x : Int, y : Int, px : Double, notches : Int) -> Bool {
let w = match self.popup_at(x, y) {
Some(w) => w
None => return false
}
if w.module_id != launcher_module || (self.menu_open && inside(self.menu_rect, x, y)) {
return true
}
let mut rows = notches * 3
if notches == 0 {
self.popup_scroll = self.popup_scroll + px
rows = (self.popup_scroll / 15.0).to_int()
self.popup_scroll = self.popup_scroll - rows.to_double() * 15.0
}
let key = if rows < 0 { "ScrollUp" } else { "ScrollDown" }
let n = if rows < 0 { -rows } else { rows }
for _ in 0..<n {
ignore(self.deliver(w, true, KeyDown(key)))
}
if n > 0 {
// The rows moved under a still pointer.
ignore(self.deliver(w, true, PointerMove(x - w.popup_rect.x, y - w.popup_rect.y)))
}
true
}
///| Close the launcher's popup if it is open.
pub fn DesktopShell::close_launcher(self : DesktopShell) -> Unit {
for w in self.widgets {
+3
View File
@@ -597,6 +597,9 @@ fn DesktopShell::replace_slot_result(self : DesktopShell, slot : String, path :
pub fn DesktopShell::reload_modules(self : DesktopShell, name : String) -> (Array[String], Bool) {
self.ensure_booted()
self.scan_catalog() // a module installed since login shows up in Settings > Panel
if name == "" {
self.load_apps() // and an app's changed .desktop file in the Applications menu
}
let targets : Array[(String, String, String)] = []
for w in self.widgets {
if name == "" || w.module_id == name || stem(w.path) == name || w.slot == name || w.path == name {