Class: Homebrew::Bundle::Flatpak Private

Inherits:
Extension show all
Defined in:
bundle/extensions/flatpak.rb

This class is part of a private API. This class may only be used in the Homebrew/brew repository. Third parties should avoid using this class if possible, as it may be removed or changed without warning.

Constant Summary collapse

Package =

This constant is part of a private API. This constant may only be used in the Homebrew/brew repository. Third parties should avoid using this constant if possible, as it may be removed or changed without warning.

T.type_alias { { name: String, remote: String, remote_url: T.nilable(String) } }

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Extension

add_supported?, check, cleanup!, cleanup_disable_description, cleanup_disable_env, cleanup_item_name, cleanup_supported?, disable_predicate_method, dump_disable_description, dump_disable_env, dump_disable_predicate_method, dump_disable_supported?, dump_name, dump_output, dump_supported?, dump_with, ensure_package_manager_installed!, flag, inherited, install_package!, install_supported?, install_verb, legacy_check_step, package_description, package_manager_env, package_manager_executable, package_manager_executable!, package_manager_installed?, package_manager_name, package_record, predicate_method, quote, remove_supported?, with_package_manager_env

Methods included from Utils::Output::Mixin

#issue_reporting_message, #odebug, #odeprecated, #odie, #odisabled, #ofail, #oh1, #oh1_title, #ohai, #ohai_title, #onoe, #opoo, #opoo_once, #opoo_outside_github_actions, #opoo_without_github_actions_annotation, #pretty_cannot_install, #pretty_deprecated, #pretty_disabled, #pretty_duration, #pretty_install_status, #pretty_installed, #pretty_removed, #pretty_uninstalled, #pretty_unmarked, #pretty_upgradable, #pretty_warning

Methods inherited from PackageType

check, #checkable_entries, dump_output, dump_supported?, #exit_early_check, #find_actionable, #full_check, inherited, install_supported?, install_verb

Class Method Details

.add_remote!(flatpak, remote_name, url, verbose:) ⇒ Boolean

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Add a remote with appropriate flags

Parameters:

Returns:

  • (Boolean)


378
379
380
381
382
383
384
385
386
387
# File 'bundle/extensions/flatpak.rb', line 378

def add_remote!(flatpak, remote_name, url, verbose:)
  if url.end_with?(".flatpakrepo")
    Bundle.system(flatpak, "remote-add", "--if-not-exists", "--system", remote_name, url, verbose:)
  else
    # For bare repository URLs, add with --no-gpg-verify for user repos
    Bundle.system(
      flatpak, "remote-add", "--if-not-exists", "--system", "--no-gpg-verify", remote_name, url, verbose:
    )
  end
end

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns:



19
# File 'bundle/extensions/flatpak.rb', line 19

def banner_name = "Flatpak packages"

.batch_installable?(_name, options = {}) ⇒ Boolean

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Parameters:

Returns:

  • (Boolean)


69
70
71
# File 'bundle/extensions/flatpak.rb', line 69

def batch_installable?(_name, options = {})
  !T.cast(options.fetch(:remote, "flathub"), String).start_with?("http://", "https://")
end

.check_label ⇒ String

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns:



16
# File 'bundle/extensions/flatpak.rb', line 16

def check_label = "Flatpak"

.cleanup_heading ⇒ String?

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns:



27
28
29
# File 'bundle/extensions/flatpak.rb', line 27

def cleanup_heading
  "flatpaks"
end

.cleanup_items(entries) ⇒ Array<String>

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Parameters:

Returns:



407
408
409
410
411
412
413
414
415
416
417
# File 'bundle/extensions/flatpak.rb', line 407

def cleanup_items(entries)
  return [].freeze unless package_manager_installed?

  kept_flatpaks = entries.filter_map do |entry|
    entry.name if entry.type == type
  end

  return [].freeze if kept_flatpaks.empty?

  packages - kept_flatpaks
end

.dump ⇒ String

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns:



193
194
195
# File 'bundle/extensions/flatpak.rb', line 193

def dump
  packages_with_remotes.map { |package| dump_entry(package) }.join("\n")
end

.dump_entry(package) ⇒ String

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Parameters:

Returns:



166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
# File 'bundle/extensions/flatpak.rb', line 166

def dump_entry(package)
  package = T.cast(package, Package)
  remote = package[:remote]
  remote_url = package[:remote_url]
  name = package[:name]

  if remote == "flathub"
    # Tier 1: Don't specify remote for flathub (default)
    "flatpak #{quote(name)}"
  elsif remote&.end_with?("-origin")
    # Tier 2: Single-app remote - dump with URL only
    if remote_url.present?
      "flatpak #{quote(name)}, remote: #{quote(remote_url)}"
    else
      # Fallback if URL not available (shouldn't happen for -origin remotes)
      "flatpak #{quote(name)}, remote: #{quote(remote)}"
    end
  elsif remote_url.present?
    # Tier 3: Named shared remote - dump with name and URL
    "flatpak #{quote(name)}, remote: #{quote(remote)}, url: #{quote(remote_url)}"
  else
    # Named remote without URL (user-defined or system remote)
    "flatpak #{quote(name)}, remote: #{quote(remote)}"
  end
end

.ensure_named_remote_exists!(flatpak, remote_name, url, verbose:) ⇒ void

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

This method returns an undefined value.

Ensure a named shared remote exists (Tier 3) Warn but don't change if URL differs (user explicitly named it)

Parameters:



350
351
352
353
354
355
356
357
358
359
360
361
362
363
# File 'bundle/extensions/flatpak.rb', line 350

def ensure_named_remote_exists!(flatpak, remote_name, url, verbose:)
  existing_url = get_remote_url(flatpak, remote_name)

  if existing_url && existing_url != url
    # Named remote with different URL - warn but don't change (user explicitly named it)
    puts "Warning: Remote '#{remote_name}' exists with different URL (#{existing_url}), using existing"
    return
  end

  return if existing_url

  puts "Adding named remote #{remote_name} from #{url}" if verbose
  add_remote!(flatpak, remote_name, url, verbose:)
end

.ensure_single_app_remote_exists!(flatpak, remote_name, url, verbose:) ⇒ void

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

This method returns an undefined value.

Ensure a single-app remote exists (Tier 2) Safe to replace if URL differs since it's isolated per-app

Parameters:



331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
# File 'bundle/extensions/flatpak.rb', line 331

def ensure_single_app_remote_exists!(flatpak, remote_name, url, verbose:)
  existing_url = get_remote_url(flatpak, remote_name)

  if existing_url && existing_url != url
    # Single-app remote with different URL - safe to replace
    puts "Replacing single-app remote #{remote_name} (URL changed)" if verbose
    Bundle.system(flatpak, "remote-delete", "--system", "--force", remote_name, verbose:)
    existing_url = nil
  end

  return if existing_url

  puts "Adding single-app remote #{remote_name} from #{url}" if verbose
  add_remote!(flatpak, remote_name, url, verbose:)
end

.entry(name, options = {}) ⇒ Dsl::Entry

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Parameters:

Returns:



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'bundle/extensions/flatpak.rb', line 32

def entry(name, options = {})
  unknown_options = options.keys - [:remote, :url]
  raise "unknown options(#{unknown_options.inspect}) for flatpak" if unknown_options.present?

  remote = options[:remote]
  url = options[:url]
  if !remote.nil? && !remote.is_a?(String)
    raise "options[:remote](#{remote.inspect}) should be a String object"
  end
  raise "options[:url](#{url.inspect}) should be a String object" if !url.nil? && !url.is_a?(String)

  # Validate: url: can only be used with a named remote (not a URL remote)
  if url && remote&.start_with?("http://", "https://")
    raise "url: parameter cannot be used when remote: is already a URL"
  end

  normalized_options = {}
  normalized_options[:remote] = remote || "flathub"
  normalized_options[:url] = url if url

  Dsl::Entry.new(type, name, normalized_options)
end

.generate_single_app_remote_name(app_id) ⇒ String

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Generate a single-app remote name (Tier 2) Pattern: -origin (matches Flatpak's native behavior for .flatpakref)

Parameters:

Returns:



324
325
326
# File 'bundle/extensions/flatpak.rb', line 324

def generate_single_app_remote_name(app_id)
  "#{app_id}-origin"
end

.get_remote_url(flatpak, remote_name) ⇒ String?

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Get URL for an existing remote, or nil if not found

Parameters:

Returns:



367
368
369
370
371
372
373
374
# File 'bundle/extensions/flatpak.rb', line 367

def get_remote_url(flatpak, remote_name)
  output = command_output(flatpak, args: ["remote-list", "--system", "--columns=name,url"])
  output.each_line(chomp: true) do |line|
    name, url = line.split("\t")
    return url if name == remote_name
  end
  nil
end

.install!(name, with: nil, preinstall: true, no_upgrade: false, verbose: false, force: false, remote: "flathub", url: nil, **_options) ⇒ Boolean

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Parameters:

  • name (String)
  • with (Array<String>, nil) (defaults to: nil)
  • preinstall (Boolean) (defaults to: true)
  • no_upgrade (Boolean) (defaults to: false)
  • verbose (Boolean) (defaults to: false)
  • force (Boolean) (defaults to: false)
  • remote (String) (defaults to: "flathub")
  • url (String, nil) (defaults to: nil)
  • _options (Homebrew::Bundle::EntryOption)

Returns:

  • (Boolean)


238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
# File 'bundle/extensions/flatpak.rb', line 238

def install!(name, with: nil, preinstall: true, no_upgrade: false, verbose: false, force: false,
             remote: "flathub", url: nil, **_options)
  _ = with
  _ = no_upgrade
  _ = force

  return true unless preinstall

  flatpak = package_manager_executable
  if flatpak.nil?
    $stderr.puts "flatpak is not installed. Install it with your distribution's package manager."
    return false
  end
  flatpak = flatpak.to_s
  if package_installed?(name)
    return Bundle.system(flatpak, "update", "-y", "--noninteractive", name, verbose:)
  end

  # 3-tier remote handling:
  # - Tier 1: no URL → use named remote (default: flathub)
  # - Tier 2: URL only → single-app remote (<app-id>-origin)
  # - Tier 3: URL + name → named shared remote

  if url.present?
    # Tier 3: Named remote with URL - create shared remote
    puts "Installing #{name} Flatpak from #{remote} (#{url}). It is not currently installed." if verbose
    ensure_named_remote_exists!(flatpak, remote, url, verbose:)
    actual_remote = remote
  elsif remote.start_with?("http://", "https://")
    if remote.end_with?(".flatpakref")
      # .flatpakref files - install directly (Flatpak handles single-app remote natively)
      puts "Installing #{name} Flatpak from #{remote}. It is not currently installed." if verbose
      return install_flatpakref!(flatpak, name, remote, verbose:)
    else
      # Tier 2: URL only - create single-app remote
      actual_remote = generate_single_app_remote_name(name)
      if verbose
        puts "Installing #{name} Flatpak from #{actual_remote} (#{remote}). It is not currently installed."
      end
      ensure_single_app_remote_exists!(flatpak, actual_remote, remote, verbose:)
    end
  else
    # Tier 1: Named remote (default: flathub)
    puts "Installing #{name} Flatpak from #{remote}. It is not currently installed." if verbose
    actual_remote = remote
  end

  # Install from the remote
  return false unless Bundle.system(flatpak, "install", "-y", "--system", actual_remote, name, verbose:)

  package = { name:, remote: actual_remote, remote_url: url }
  packages_with_remotes = T.let(@packages_with_remotes || [], T::Array[Package])
  packages_with_remotes << package
  @packages_with_remotes = packages_with_remotes
  @installed_packages = packages_with_remotes.dup
  @packages = packages_with_remotes.map { |pkg| pkg[:name] }
  true
end

.install_batch!(entries, verbose: false) ⇒ Boolean

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Parameters:

Returns:

  • (Boolean)


74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'bundle/extensions/flatpak.rb', line 74

def install_batch!(entries, verbose: false)
  flatpak = package_manager_executable
  unless flatpak
    $stderr.puts "flatpak is not installed. Install it with your distribution's package manager."
    return false
  end
  flatpak = flatpak.to_s

  upgrades, entries = entries.partition { |entry| package_installed?(entry.name) }
  success = upgrades.empty? || Bundle.system(flatpak, "update", "-y", "--noninteractive",
                                             *upgrades.map(&:name), verbose:)
  entries.group_by { |entry| [entry.options.fetch(:remote, "flathub"), entry.options[:url]] }
         .each do |(remote, url), remote_entries|
    remote = T.cast(remote, String)
    ensure_named_remote_exists!(flatpak, remote, T.cast(url, String), verbose:) if url
    installed = Bundle.system(flatpak, "install", "-y", "--system", remote,
                              *remote_entries.map(&:name), verbose:)
    success &&= installed
  end
  success
end

.install_flatpakref!(flatpak, name, url, verbose:) ⇒ Boolean

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Install from a .flatpakref file (Tier 2 variant - Flatpak handles single-app remote natively)

Parameters:

Returns:

  • (Boolean)


299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
# File 'bundle/extensions/flatpak.rb', line 299

def install_flatpakref!(flatpak, name, url, verbose:)
  return false unless Bundle.system(flatpak, "install", "-y", "--system", url, verbose:)

  # Get the actual remote name used by Flatpak
  output = command_output(flatpak, args: ["list", "--app", "--columns=application,origin"])
  installed_line = output.each_line(chomp: true).find { |line| line.start_with?(name) }
  _application, actual_remote = installed_line&.split("\t")
  actual_remote ||= "#{name}-origin"
  package = { name:, remote: actual_remote, remote_url: nil }
  packages_with_remotes = T.let(@packages_with_remotes || [], T::Array[Package])
  packages_with_remotes << package
  @packages_with_remotes = packages_with_remotes
  @installed_packages = packages_with_remotes.dup
  @packages = packages_with_remotes.map { |pkg| pkg[:name] }
  true
rescue ErrorDuringExecution
  reset!
  opoo "Flatpak installation succeeded, but inventory refresh failed. " \
       "Run Bundle again to rediscover installed applications."
  raise
end

.installed_packages ⇒ Array<Package>

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns:



149
150
151
152
153
154
# File 'bundle/extensions/flatpak.rb', line 149

def installed_packages
  installed_packages = @installed_packages
  return installed_packages if installed_packages

  @installed_packages = packages_with_remotes.dup
end

.package_installed?(name, with: nil, remote: nil) ⇒ Boolean

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Parameters:

Returns:

  • (Boolean)


396
397
398
399
400
401
402
403
404
# File 'bundle/extensions/flatpak.rb', line 396

def package_installed?(name, with: nil, remote: nil)
  _ = with

  if remote
    installed_packages.any? { |pkg| pkg[:name] == name && pkg[:remote] == remote }
  else
    installed_packages.any? { |pkg| pkg[:name] == name }
  end
end

.package_outdated?(name, with: nil, source: nil) ⇒ Boolean

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Parameters:

Returns:

  • (Boolean)


159
160
161
162
163
# File 'bundle/extensions/flatpak.rb', line 159

def package_outdated?(name, with: nil, source: nil)
  command_output(package_manager_executable!,
                 args: ["remote-ls", "--app", "--updates", "--columns=application"])
    .lines(chomp: true).include?(name)
end

.packages ⇒ Array<String>

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns:



141
142
143
144
145
146
# File 'bundle/extensions/flatpak.rb', line 141

def packages
  packages = @packages
  return packages if packages

  @packages = packages_with_remotes.map { |pkg| pkg[:name] }
end

.packages_with_remotes ⇒ Array<Package>

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns:



116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
# File 'bundle/extensions/flatpak.rb', line 116

def packages_with_remotes
  packages_with_remotes = @packages_with_remotes
  return packages_with_remotes if packages_with_remotes

  @packages_with_remotes = if (flatpak = package_manager_executable)
    # List applications with their origin remote
    # Using --app to filter applications only
    # Using --columns=application,origin to get app IDs and their remotes
    output = command_output(flatpak, args: ["list", "--app", "--columns=application,origin"])

    packages = output.split("\n").filter_map do |line|
      name, remote = line.strip.split("\t")
      next if name.nil?

      remote ||= "flathub"
      { name:, remote:, remote_url: remote_urls[remote] }
    end
    packages.sort_by { |pkg| pkg[:name] }
  end
  return [] if @packages_with_remotes.nil?

  @packages_with_remotes
end

.preinstall!(name, with: nil, no_upgrade: false, verbose: false, remote: "flathub", url: nil, **_options) ⇒ Boolean

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Parameters:

Returns:

  • (Boolean)


208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
# File 'bundle/extensions/flatpak.rb', line 208

def preinstall!(name, with: nil, no_upgrade: false, verbose: false, remote: "flathub", url: nil, **_options)
  _ = with
  _ = url

  return true unless package_manager_installed?

  # Check if package is installed at all (regardless of remote)
  if package_installed?(name)
    return true if !no_upgrade && package_outdated?(name)

    puts "Skipping install of #{name} Flatpak. It is already installed." if verbose
    return false
  end

  true
end

.remote_urls ⇒ Hash{String => String}

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns:



97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'bundle/extensions/flatpak.rb', line 97

def remote_urls
  remote_urls = @remote_urls
  return remote_urls if remote_urls

  @remote_urls = if (flatpak = package_manager_executable)
    output = command_output(flatpak, args: ["remote-list", "--system", "--columns=name,url"])
    urls = {}
    output.split("\n").each do |line|
      name, url = line.strip.split("\t")
      urls[name] = url if name && url
    end
    urls
  end
  return {} if @remote_urls.nil?

  @remote_urls
end

.reset! ⇒ void

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

This method returns an undefined value.



56
57
58
59
60
61
# File 'bundle/extensions/flatpak.rb', line 56

def reset!
  @packages = T.let(nil, T.nilable(T::Array[String]))
  @packages_with_remotes = T.let(nil, T.nilable(T::Array[Package]))
  @remote_urls = T.let(nil, T.nilable(T::Hash[String, String]))
  @installed_packages = T.let(nil, T.nilable(T::Array[Package]))
end

.switch_description(description) ⇒ String

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Parameters:

Returns:



22
23
24
# File 'bundle/extensions/flatpak.rb', line 22

def switch_description(description)
  "#{super} Note: Linux only."
end

.type ⇒ Symbol

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns:



13
# File 'bundle/extensions/flatpak.rb', line 13

def type = :flatpak

.uninstall_package!(name, executable: Pathname.new("")) ⇒ Boolean

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Parameters:

Returns:

  • (Boolean)


420
421
422
# File 'bundle/extensions/flatpak.rb', line 420

def uninstall_package!(name, executable: Pathname.new(""))
  Kernel.system(executable.to_s, "uninstall", "-y", "--system", name) == true
end

Instance Method Details

#failure_reason(package, no_upgrade:) ⇒ String

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Parameters:

  • package (Object)
  • no_upgrade (Boolean)

Returns:



433
434
435
436
437
438
439
440
441
# File 'bundle/extensions/flatpak.rb', line 433

def failure_reason(package, no_upgrade:)
  name = if package.is_a?(Hash)
    package[:name]
  else
    package
  end
  "#{self.class.check_label} #{name} needs to be " \
    "#{(!no_upgrade && installed_and_up_to_date?(package, no_upgrade: true)) ? "upgraded" : "installed"}."
end

#format_checkable(entries) ⇒ Array<Object>

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Parameters:

Returns:



426
427
428
429
430
# File 'bundle/extensions/flatpak.rb', line 426

def format_checkable(entries)
  checkable_entries(entries).map do |entry|
    { name: entry.name, options: entry.options }
  end
end

#installed_and_up_to_date?(package, no_upgrade: false) ⇒ Boolean

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Parameters:

  • package (Object)
  • no_upgrade (Boolean) (defaults to: false)

Returns:

  • (Boolean)


444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
# File 'bundle/extensions/flatpak.rb', line 444

def installed_and_up_to_date?(package, no_upgrade: false)
  return super unless package.is_a?(Hash)

  flatpak = package
  name = T.cast(flatpak[:name], String)
  options = T.cast(flatpak[:options], T::Hash[Symbol, String])
  remote = options.fetch(:remote, "flathub")
  url = options[:url]

  # 3-tier remote handling:
  # - Tier 1: Named remote → check with that remote name
  # - Tier 2: URL only → resolve to single-app remote name (<app-id>-origin)
  # - Tier 3: URL + name → check with the named remote
  actual_remote = if url.blank? && remote.start_with?("http://", "https://")
    # Tier 2: URL only - resolve to single-app remote name
    # (.flatpakref - check by name only since remote name varies)
    return super(name, no_upgrade:) if remote.end_with?(".flatpakref")

    self.class.generate_single_app_remote_name(name)
  else
    # Tier 1 (named remote) and Tier 3 (named remote with URL) both use the remote name
    remote
  end

  self.class.package_installed?(name, remote: actual_remote) &&
    (no_upgrade || !self.class.package_outdated?(name))
end