Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create fake app info for unknown windows #330

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/App.vala
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class Dock.App : Object {
}

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; }
Expand Down Expand Up @@ -52,7 +52,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);
}

Expand Down
104 changes: 104 additions & 0 deletions src/AppInfo.vala
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
// TODO: Copyright

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<GLib.File>? files, GLib.AppLaunchContext? context) throws GLib.Error {
if (desktop_app_info == null) {
return false;
}

return desktop_app_info.launch (files, context);
}
}
4 changes: 3 additions & 1 deletion src/Launcher.vala
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,9 @@ public class Dock.Launcher : Gtk.Box {
}
break;
case Gdk.BUTTON_SECONDARY:
popover.popup ();
if (app.app_info.desktop_app_info != null) {
popover.popup ();
}
break;
}
}
Expand Down
30 changes: 18 additions & 12 deletions src/LauncherManager.vala
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,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;
Expand All @@ -82,7 +82,8 @@
}

var position = (int) Math.round (drop_x / get_launcher_size ());
added_launcher = add_launcher (new DesktopAppInfo.from_filename (file.get_path ()), true, true, position);
var desktop_app_info = new GLib.DesktopAppInfo.from_filename (file.get_path ());
added_launcher = add_launcher (new Dock.AppInfo (desktop_app_info), true, true, position);
added_launcher.moving = true;
});

Expand All @@ -99,7 +100,8 @@

Idle.add (() => {
foreach (string app_id in settings.get_strv ("launchers")) {
var app_info = new GLib.DesktopAppInfo (app_id);
var desktop_app_info = new GLib.DesktopAppInfo (app_id);
var app_info = new Dock.AppInfo (desktop_app_info);
add_launcher (app_info, true, false);
}
reposition_launchers ();
Expand Down Expand Up @@ -145,7 +147,7 @@
return settings.get_int ("icon-size") + Launcher.PADDING * 2;
}

private Launcher add_launcher (GLib.DesktopAppInfo app_info, bool pinned = false, bool reposition = true, int index = -1) {
private Launcher add_launcher (Dock.AppInfo app_info, bool pinned = false, bool reposition = true, int index = -1) {
var app = new App (app_info, pinned);
var launcher = new Launcher (app);

Expand Down Expand Up @@ -247,9 +249,13 @@
unowned var app_id = window.properties["app-id"].get_string ();
App? app = id_to_app[app_id];
if (app == null) {
var app_info = new GLib.DesktopAppInfo (app_id);
if (app_info == null) {
continue;
var desktop_app_info = new GLib.DesktopAppInfo (app_id);
var app_info = new Dock.AppInfo (desktop_app_info);

if (desktop_app_info == null) {
var title = window.properties.get ("title");
app_info.fake_name = title != null ? title.get_string () : app_id;
app_info.fake_id = app_id;
}

app = add_launcher (app_info).app;
Expand Down Expand Up @@ -308,7 +314,7 @@
Launcher[] launchers_to_remove = {};

foreach (var launcher in launchers) {
if (launcher.app.pinned) {
if (launcher.app.pinned && launcher.app.app_info.desktop_app_info != null) {
new_pinned_ids += launcher.app.app_info.get_id ();
} else if (!launcher.app.pinned && launcher.app.windows.is_empty) {
launchers_to_remove += launcher;
Expand Down Expand Up @@ -338,14 +344,14 @@
return;
}

var app_info = new DesktopAppInfo (app_id);
var desktop_app_info = new GLib.DesktopAppInfo (app_id);

if (app_info == null) {
warning ("App not found: %s", app_id);
if (desktop_app_info == null) {
warning ("LauncherManager.add_launcher_for_id: Desktop app info not found: %s", app_id);
return;
}

add_launcher (app_info).app.pinned = true;
add_launcher (new Dock.AppInfo (desktop_app_info)).app.pinned = true;
}

public void remove_launcher_by_id (string app_id) {
Expand Down
1 change: 1 addition & 0 deletions src/meson.build
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
sources = [
'App.vala',
'AppInfo.vala',
'Application.vala',
'AppWindow.vala',
'DesktopIntegration.vala',
Expand Down
Loading