Class: Depot::Backends::FlatpakRefBackend
- Inherits:
-
Object
- Object
- Depot::Backends::FlatpakRefBackend
- Includes:
- Support
- Defined in:
- lib/depot/backends/flatpak_ref.rb
Instance Method Summary collapse
-
#initialize(store:) ⇒ FlatpakRefBackend
constructor
A new instance of FlatpakRefBackend.
- #install(inspection, settings: {}) ⇒ Object
Constructor Details
#initialize(store:) ⇒ FlatpakRefBackend
Returns a new instance of FlatpakRefBackend.
17 18 19 |
# File 'lib/depot/backends/flatpak_ref.rb', line 17 def initialize(store:) @store = store end |
Instance Method Details
#install(inspection, settings: {}) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/depot/backends/flatpak_ref.rb', line 21 def install(inspection, settings: {}) return Result.err("Flatpak backend cannot install #{inspection.format}") unless inspection.flatpakref? return Result.err("Flatpak is not installed on this system.") unless command_available?("flatpak") Paths.ensure_base_dirs ref = FlatpakRef.new(inspection.input) return Result.err("Invalid Flatpak reference.") unless ref.valid? return Result.err("Depot only installs Flatpak application refs right now.") if ref.runtime? app_id = Util.unique_id(Util.slug(ref.name), @store.ids) app_dir = File.join(Paths.apps_dir, app_id) FileUtils.mkdir_p(app_dir) stdout, stderr, status = Open3.capture3( "flatpak", "install", "--user", "--noninteractive", "-y", "--or-update", "--from", inspection.input ) unless status.success? = [stderr, stdout].map(&:to_s).find { |text| text.strip != "" } || "flatpak install failed" return Result.err("Flatpak install failed: #{.strip}") end launcher = write_launcher(app_dir, ref.name) desktop_entry = exported_desktop_entry(ref.name) display_name = desktop_entry ? desktop_name(File.read(desktop_entry)) : ref.display_name warnings = inspection.warnings + ["Flatpak handled the download, verification, sandbox, desktop integration, and runtime dependencies."] manifest = { "schema_version" => 1, "app_id" => app_id, "display_name" => display_name, "default_display_name" => display_name, "backend" => "flatpak", "install_source" => File.(inspection.input), "source_sha256" => inspection.sha256, "source_size" => inspection.size, "installed_executable" => launcher, "desktop_entry" => desktop_entry, "icons" => [], "created_files" => [launcher], "created_dirs" => [app_dir], "installed_at" => Time.now.utc.iso8601, "package" => ref.fields, "flatpak" => { "app_id" => ref.name, "branch" => ref.branch, "remote" => ref.remote_name, "origin" => flatpak_info(ref.name, "--show-origin"), "ref" => flatpak_info(ref.name, "--show-ref") }, "permissions" => { "executable" => true, "requires_sudo" => false, "writes_outside_depot" => false, "notes" => ["Flatpak manages this app, its sandbox, remotes, runtimes, and exported desktop integration."] }, "sandbox" => { "enabled" => true, "manager" => "flatpak", "preference" => settings.fetch("sandbox_preference", "ask") }, "update" => { "mechanism" => "flatpak", "source" => ref.url }, "warnings" => warnings } manifest_path = @store.write(manifest) Result.ok(manifest.merge("manifest_path" => manifest_path), warnings:) rescue FlatpakRef::FormatError, SystemCallError => e Result.err("Flatpak install failed: #{e.}") end |