Module: Lich::Common::Authentication::GUI
- Defined in:
- documented/common/authentication/gui.rb
Constant Summary collapse
- BUTTON_REENABLE_DEBOUNCE_MS =
Debounce duration (ms) before restoring Play button after successful launch. This limits accidental rapid repeat launches while keeping persistent UI usable. Debounce duration (ms) before restoring Play button after successful launch. This limits accidental rapid repeat launches while keeping persistent UI usable.
2000
Class Method Summary collapse
-
.authenticate_and_launch(button:, login_info:, on_success:, on_error: nil) ⇒ void
Authenticates the user and launches the game.
-
.handle_auth_error(button, error, on_error) ⇒ void
Handles authentication errors by updating the button state and invoking error callbacks.
-
.schedule_button_reenable(button) ⇒ void
Schedules the re-enabling of the button after a debounce period.
-
.show_error_dialog(button, message) ⇒ void
Displays an error dialog to the user when authentication fails.
Class Method Details
.authenticate_and_launch(button:, login_info:, on_success:, on_error: nil) ⇒ void
This method returns an undefined value.
Authenticates the user and launches the game.
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 |
# File 'documented/common/authentication/gui.rb', line 25 def self.authenticate_and_launch(button:, login_info:, on_success:, on_error: nil) .sensitive = false begin # Authenticate with game server auth_data = Authentication.authenticate( account: login_info[:user_id], password: login_info[:password], character: login_info[:char_name], game_code: login_info[:game_code] ) # Format launch data for frontend launch_data = LaunchData.prepare( auth_data, login_info[:frontend], login_info[:custom_launch], login_info[:custom_launch_dir] ) if on_success # Backward compatibility: existing callbacks may still expect 1 arg. if on_success.respond_to?(:arity) && on_success.arity == 1 on_success.call(launch_data) else on_success.call(launch_data, login_info) end end () rescue FatalAuthError => e handle_auth_error(, e, on_error) rescue StandardError => e Lich.log "error: GUI auth unexpected error: #{e.class}: #{e.}" Lich.log e.backtrace.join("\n\t") if e.backtrace handle_auth_error(, StandardError.new("Unexpected login error. See debug log for details."), on_error) raise end end |
.handle_auth_error(button, error, on_error) ⇒ void
This method returns an undefined value.
Handles authentication errors by updating the button state and invoking error callbacks.
71 72 73 74 75 76 77 78 79 |
# File 'documented/common/authentication/gui.rb', line 71 def self.handle_auth_error(, error, on_error) .sensitive = true if on_error on_error.call(error.) else show_error_dialog(, error.) end end |
.schedule_button_reenable(button) ⇒ void
This method returns an undefined value.
Schedules the re-enabling of the button after a debounce period.
103 104 105 106 107 108 |
# File 'documented/common/authentication/gui.rb', line 103 def self.() GLib::Timeout.add(BUTTON_REENABLE_DEBOUNCE_MS) do .sensitive = true unless .respond_to?(:destroyed?) && .destroyed? false end end |
.show_error_dialog(button, message) ⇒ void
This method returns an undefined value.
Displays an error dialog to the user when authentication fails.
86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'documented/common/authentication/gui.rb', line 86 def self.show_error_dialog(, ) dialog = Gtk::MessageDialog.new( parent: .toplevel, flags: :modal, type: :error, buttons: :ok, message: "Authentication Failed" ) dialog.secondary_text = dialog.run dialog.destroy end |