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

Fix broken --load-local option #2231

Merged
merged 3 commits into from
Feb 5, 2025
Merged
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
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