Class: Lich::Common::GUI::FrontendSelector

Inherits:
Object
  • Object
show all
Defined in:
documented/common/gui/frontend_selector.rb

Overview

Shared GTK frontend selector backed by the frontend catalog. Discovery annotates choices but never removes configurable frontends.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(selected_id: nil, refresh: true, locator: FrontendLocator, frontend: Frontend) ⇒ FrontendSelector

Initializes a catalog-backed frontend dropdown.

Parameters:

  • selected_id (String, nil) (defaults to: nil) —

    preferred frontend identifier

  • refresh (Boolean) (defaults to: true) —

    refresh executable discovery first

  • locator (FrontendLocator) (defaults to: FrontendLocator) —

    injectable locator API

  • frontend (Frontend) (defaults to: Frontend) —

    injectable frontend catalog API



25
26
27
28
29
30
# File 'documented/common/gui/frontend_selector.rb', line 25

def initialize(selected_id: nil, refresh: true, locator: FrontendLocator, frontend: Frontend)
  @locator = locator
  @frontend = frontend
  refresh_catalog(refresh: refresh)
  @widget = build_widget(selected_id)
end

Instance Attribute Details

#resolutions ⇒ Object (readonly)

Returns the value of attribute resolutions.



16
17
18
# File 'documented/common/gui/frontend_selector.rb', line 16

def resolutions
  @resolutions
end

#widget ⇒ Object (readonly)

Returns the value of attribute widget.



16
17
18
# File 'documented/common/gui/frontend_selector.rb', line 16

def widget
  @widget
end

Instance Method Details

#choices ⇒ Array<Array<String>>

Stable ids and annotated labels shared by form and inline selectors.

Returns:

  • (Array<Array<String>>) —

    frontend choices



109
110
111
# File 'documented/common/gui/frontend_selector.rb', line 109

def choices
  @definitions.map { |definition| [definition[:id], option_label(definition)] }
end

#empty? ⇒ Boolean

Returns whether the frontend catalog has no selectable definitions.

Returns:

  • (Boolean)


103
104
105
# File 'documented/common/gui/frontend_selector.rb', line 103

def empty?
  @definitions.empty?
end

#launchable?(refresh: true) ⇒ Boolean

Returns whether the selected frontend has enough configuration to attempt a launch. Custom commands may resolve through PATH or a shell, so executable discovery is intentionally limited to native adapters.

Parameters:

  • refresh (Boolean) (defaults to: true) —

    bypass cached discovery when true

Returns:

  • (Boolean)


89
90
91
92
93
94
95
96
97
98
# File 'documented/common/gui/frontend_selector.rb', line 89

def launchable?(refresh: true)
  return false unless selected_id

  FrontendLauncher.launchable?(
    selected_id,
    locator: @locator,
    frontend: @frontend,
    refresh: refresh
  )
end

#native_launch_only? ⇒ Boolean

Returns whether the selected frontend disallows custom launch.

Returns:

  • (Boolean)


60
61
62
63
64
# File 'documented/common/gui/frontend_selector.rb', line 60

def native_launch_only?
  return false unless selected_id

  @frontend.definition_for(selected_id).dig(:metadata, :native_launch_only) == true
end

#on_change {|FrontendSelector| ... } ⇒ void

This method returns an undefined value.

Registers a callback for changes to the selected frontend option.

Yields:



69
70
71
72
# File 'documented/common/gui/frontend_selector.rb', line 69

def on_change(&callback)
  @widget.signal_connect('changed') { callback.call(self) }
  nil
end

#reload!(refresh: true) ⇒ FrontendSelector

Reloads configured definitions and executable status in-place so callers do not need to replace widgets after the Frontends tab saves. The current stable frontend id is retained when it remains selectable.

Parameters:

  • refresh (Boolean) (defaults to: true) —

    refresh executable discovery first

Returns:



38
39
40
41
42
43
44
45
46
47
48
# File 'documented/common/gui/frontend_selector.rb', line 38

def reload!(refresh: true)
  selected_id = self.selected_id
  refresh_catalog(refresh: refresh)
  @widget.remove_all
  @definitions.each do |definition|
    @widget.append(definition[:id], option_label(definition))
  end
  @widget.active_id = preferred_id(selected_id)
  update_tooltip(@widget)
  self
end

#resolve_selected(refresh: true) ⇒ FrontendLocator::Resolution?

Revalidates the selected executable immediately before launch.

Parameters:

  • refresh (Boolean) (defaults to: true) —

    bypass cached discovery when true

Returns:



77
78
79
80
81
# File 'documented/common/gui/frontend_selector.rb', line 77

def resolve_selected(refresh: true)
  return nil unless selected_id

  @locator.resolve(selected_id, refresh: refresh)
end

#selected_id ⇒ String?

Returns the selected stable frontend identifier.

Returns:



53
54
55
# File 'documented/common/gui/frontend_selector.rb', line 53

def selected_id
  @widget.active_id
end