diff --git a/src/AppSystem/App.vala b/src/AppSystem/App.vala index 5c1f8e8d..41ce3061 100644 --- a/src/AppSystem/App.vala +++ b/src/AppSystem/App.vala @@ -24,7 +24,7 @@ public class Dock.App : Object { public signal void removed (); public bool pinned { get; construct set; } - public GLib.DesktopAppInfo app_info { get; construct; } + public Dock.AppInfo app_info { get; construct; } public bool count_visible { get; private set; default = false; } public int64 current_count { get; private set; default = 0; } @@ -55,7 +55,7 @@ public class Dock.App : Object { private SimpleAction pinned_action; - public App (GLib.DesktopAppInfo app_info, bool pinned) { + public App (Dock.AppInfo app_info, bool pinned) { Object (app_info: app_info, pinned: pinned); } diff --git a/src/AppSystem/AppInfo.vala b/src/AppSystem/AppInfo.vala new file mode 100644 index 00000000..41552835 --- /dev/null +++ b/src/AppSystem/AppInfo.vala @@ -0,0 +1,107 @@ +/* + * SPDX-License-Identifier: GPL-3.0 + * SPDX-FileCopyrightText: 2025 elementary, Inc. (https://elementary.io) + */ + +public class Dock.AppInfo : GLib.Object { + private const string[] NULL_ACTIONS = {}; + private GLib.Icon fallback_icon = new GLib.ThemedIcon ("application-default-icon"); + + public GLib.DesktopAppInfo? desktop_app_info { get; construct; } + + private string _fake_id = "Unknown"; + public string? fake_id { + private get { + return _fake_id; + } + set { + _fake_id = value ?? "Unknown"; + } + } + + private string _fake_name = "Unknown"; + public string? fake_name { + private get { + return _fake_name; + } + set { + _fake_name = value ?? "Unknown"; + } + } + + public AppInfo (GLib.DesktopAppInfo? desktop_app_info) { + Object (desktop_app_info: desktop_app_info); + } + + public unowned string get_id () { + if (desktop_app_info == null) { + return fake_id; + } + + return desktop_app_info.get_id (); + } + + public unowned string get_display_name () { + if (desktop_app_info == null) { + return fake_name; + } + + return desktop_app_info.get_display_name (); + } + + public unowned GLib.Icon get_icon () { + if (desktop_app_info == null) { + return fallback_icon; + } + + return desktop_app_info.get_icon () ?? fallback_icon; + } + + public bool get_boolean (string key) { + if (desktop_app_info == null) { + return false; + } + + return desktop_app_info.get_boolean (key); + } + + public string get_string (string key) { + if (desktop_app_info == null) { + return ""; + } + + return desktop_app_info.get_string (key); + } + + public unowned string[] list_actions () { + if (desktop_app_info == null) { + return NULL_ACTIONS; + } + + return desktop_app_info.list_actions (); + } + + public string get_action_name (string action_name) { + if (desktop_app_info == null) { + return "Something went wrong if you see this"; + } + + return desktop_app_info.get_action_name (action_name); + } + + public void launch_action (string action_name, GLib.AppLaunchContext launch_context) { + if (desktop_app_info == null) { + return; + } + + desktop_app_info.launch_action (action_name, launch_context); + } + + public bool launch (GLib.List? files, GLib.AppLaunchContext? context) throws GLib.Error { + if (desktop_app_info == null) { + return false; + } + + return desktop_app_info.launch (files, context); + } +} diff --git a/src/AppSystem/AppSystem.vala b/src/AppSystem/AppSystem.vala index 6148b170..372e6a0b 100644 --- a/src/AppSystem/AppSystem.vala +++ b/src/AppSystem/AppSystem.vala @@ -31,15 +31,14 @@ public class Dock.AppSystem : Object, UnityClient { public async void load () { foreach (string app_id in settings.get_strv ("launchers")) { - var app_info = new GLib.DesktopAppInfo (app_id); - add_app (app_info, true); + add_app (new Dock.AppInfo (new GLib.DesktopAppInfo (app_id)), true); } yield sync_windows (); WindowSystem.get_default ().notify["windows"].connect (sync_windows); } - private App add_app (DesktopAppInfo app_info, bool pinned) { + private App add_app (Dock.AppInfo app_info, bool pinned) { var app = new App (app_info, pinned); id_to_app[app_info.get_id ()] = app; app.removed.connect ((_app) => id_to_app.remove (_app.app_info.get_id ())); @@ -54,9 +53,12 @@ public class Dock.AppSystem : Object, UnityClient { foreach (var window in windows) { App? app = id_to_app[window.app_id]; if (app == null) { - var app_info = new GLib.DesktopAppInfo (window.app_id); - if (app_info == null) { - continue; + var desktop_app_info = new GLib.DesktopAppInfo (window.app_id); + var app_info = new Dock.AppInfo (desktop_app_info); + + if (desktop_app_info == null) { + app_info.fake_name = window.title != null ? window.title : window.app_id; + app_info.fake_id = window.app_id; } app = add_app (app_info, false); @@ -85,14 +87,14 @@ public class Dock.AppSystem : Object, UnityClient { return; } - var app_info = new DesktopAppInfo (app_id); + var desktop_app_info = new DesktopAppInfo (app_id); - if (app_info == null) { + if (desktop_app_info == null) { warning ("App not found: %s", app_id); return; } - add_app (app_info, true); + add_app (new Dock.AppInfo (desktop_app_info), true); } public void remove_app_by_id (string app_id) { diff --git a/src/AppSystem/Launcher.vala b/src/AppSystem/Launcher.vala index 21cdc75a..6df4d443 100644 --- a/src/AppSystem/Launcher.vala +++ b/src/AppSystem/Launcher.vala @@ -232,7 +232,9 @@ public class Dock.Launcher : BaseItem { } break; case Gdk.BUTTON_SECONDARY: - popover.popup (); + if (app.app_info.desktop_app_info != null) { + popover.popup (); + } break; } } diff --git a/src/ItemManager.vala b/src/ItemManager.vala index 3233e6f1..d5ee410a 100644 --- a/src/ItemManager.vala +++ b/src/ItemManager.vala @@ -84,7 +84,7 @@ } var file = (File) drop_target_file.get_value ().get_object (); - var app_info = new DesktopAppInfo.from_filename (file.get_path ()); + var app_info = new GLib.DesktopAppInfo.from_filename (file.get_path ()); if (app_info == null) { return; diff --git a/src/WindowSystem/Window.vala b/src/WindowSystem/Window.vala index 76dd3159..617c9d5f 100644 --- a/src/WindowSystem/Window.vala +++ b/src/WindowSystem/Window.vala @@ -6,8 +6,8 @@ public class Dock.Window : GLib.Object { public uint64 uid { get; construct set; } - public string app_id { get; private set; default = ""; } + public string? title { get; private set; default = null; } public bool has_focus { get; private set; default = false; } public int workspace_index { get; private set; default = 0; } public int64 time_appeared_on_workspace { get; private set; default = 0; } @@ -23,6 +23,10 @@ public class Dock.Window : GLib.Object { app_id = properties["app-id"].get_string (); } + if ("title" in properties) { + title = properties["title"].get_string (); + } + if ("has-focus" in properties) { has_focus = (bool) properties["has-focus"]; } diff --git a/src/meson.build b/src/meson.build index 30137571..4ef25bb2 100644 --- a/src/meson.build +++ b/src/meson.build @@ -5,6 +5,7 @@ sources = [ 'ItemManager.vala', 'MainWindow.vala', 'AppSystem' / 'App.vala', + 'AppSystem' / 'AppInfo.vala', 'AppSystem' / 'AppSystem.vala', 'AppSystem' / 'Launcher.vala', 'AppSystem' / 'PoofPopover.vala',