Skip to content

Commit

Permalink
Fix broken --load-local option
Browse files Browse the repository at this point in the history
  • Loading branch information
ryonakano committed Dec 14, 2024
1 parent efb5ad2 commit 90ec1eb
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/Application.vala
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,16 @@ public class AppCenter.App : Gtk.Application {
return;
}

if (local_path != null) {
var file = File.new_for_commandline_arg (local_path);

try {
local_package = AppCenterCore.FlatpakBackend.get_default ().add_local_component_file (file);
} catch (Error e) {
warning ("Failed to load local AppStream XML file: %s", e.message);
}
}

if (active_window == null) {
// Force a Flatpak cache refresh when the window is created, so we get new apps
update_manager.update_cache.begin (true);
Expand Down
35 changes: 35 additions & 0 deletions src/Core/FlatpakBackend.vala
Original file line number Diff line number Diff line change
Expand Up @@ -1948,6 +1948,41 @@ public class AppCenterCore.FlatpakBackend : Object {
return job.result.get_boolean ();
}

public Package? add_local_component_file (File file) throws Error {
var metadata = new AppStream.Metadata ();
try {
metadata.parse_file (file, AppStream.FormatKind.XML);
} catch (Error e) {
throw e;
}

var component = metadata.get_component ();
if (component == null) {
return null;
}

string name = _("%s (local)").printf (component.get_name ());
string id = "%s%s".printf (component.get_id (), Package.LOCAL_ID_SUFFIX);

component.set_name (name, null);
component.set_id (id);
component.set_origin (Package.APPCENTER_PACKAGE_ORIGIN);

var component_box = new AppStream.ComponentBox.simple ();
try {
component_box.add (component);
} catch (Error e) {
throw e;
}

user_appstream_pool.add_components (component_box);

var package = new AppCenterCore.FlatpakPackage (user_installation, component);
package_list[id] = package;

return package;
}

private static GLib.Once<FlatpakBackend> instance;
public static unowned FlatpakBackend get_default () {
return instance.once (() => { return new FlatpakBackend (); });
Expand Down

0 comments on commit 90ec1eb

Please sign in to comment.