From 0bb8ef5f197907653f441b2f67d580897b33f6b6 Mon Sep 17 00:00:00 2001 From: Cyberarm Date: Wed, 25 Jun 2025 19:45:23 -0500 Subject: [PATCH] Initial work launcher (self) updater --- lib/pages/settings.rb | 2 +- lib/states/boot.rb | 27 ++++++++ lib/states/dialogs/launcher_updater_dialog.rb | 62 +++++++++++++++++++ w3d_hub_linux_launcher.rb | 1 + 4 files changed, 91 insertions(+), 1 deletion(-) create mode 100644 lib/states/dialogs/launcher_updater_dialog.rb diff --git a/lib/pages/settings.rb b/lib/pages/settings.rb index 378bfed..3fd0049 100644 --- a/lib/pages/settings.rb +++ b/lib/pages/settings.rb @@ -51,7 +51,7 @@ class W3DHub end end - stack(width: 128, height: 48, h_align: :center, margin_top: 16) do + stack(width: 128, max_height: 256, h_align: :center, margin_top: 16, fill: true) do button "Save", width: 1.0 do save_settings! end diff --git a/lib/states/boot.rb b/lib/states/boot.rb index 689bf23..8f8b9ed 100644 --- a/lib/states/boot.rb +++ b/lib/states/boot.rb @@ -12,6 +12,7 @@ class W3DHub @w3dhub_logo = get_image("#{GAME_ROOT_PATH}/media/icons/app.png") @tasks = { # connectivity_check: { started: false, complete: false }, # HEAD connectivity-check.ubuntu.com or HEAD secure.w3dhub.com? + # launcher_updater: { started: false, complete: false }, server_list: { started: false, complete: false }, refresh_user_token: { started: false, complete: false }, service_status: { started: false, complete: false }, @@ -159,6 +160,32 @@ class W3DHub end end + def launcher_updater + @status_label.value = "Checking for Launcher updates..." # I18n.t(:"boot.checking_for_updates") + + Api.on_thread(:fetch, "https://api.github.com/repos/Inq8/CAmod/releases/latest") do |response| + if response.status == 200 + hash = JSON.parse(response.body, symbolize_names: true) + available_version = hash[:tag_name].downcase.sub("v", "") + + pp Gem::Version.new(available_version) > Gem::Version.new(W3DHub::VERSION) + pp [Gem::Version.new(available_version), Gem::Version.new(W3DHub::VERSION)] + + push_state( + LauncherUpdaterDialog, + release_data: hash, + available_version: available_version, + cancel_callback: -> { @tasks[:launcher_updater][:complete] = true }, + accept_callback: -> { @tasks[:launcher_updater][:complete] = true } + ) + else + # Failed to retrieve release data from github + log "Failed to retrieve release data from Github" + @tasks[:launcher_updater][:complete] = true + end + end + end + def applications @status_label.value = I18n.t(:"boot.checking_for_updates") diff --git a/lib/states/dialogs/launcher_updater_dialog.rb b/lib/states/dialogs/launcher_updater_dialog.rb new file mode 100644 index 0000000..282c303 --- /dev/null +++ b/lib/states/dialogs/launcher_updater_dialog.rb @@ -0,0 +1,62 @@ +class W3DHub + class States + class LauncherUpdaterDialog < Dialog + BUTTON_STYLE = { text_size: 18, padding_top: 3, padding_bottom: 3, padding_left: 3, padding_right: 3, height: 18 } + LIST_ITEM_THEME = Marshal.load(Marshal.dump(THEME)) + BUTTON_STYLE.each do |key, value| + LIST_ITEM_THEME[:Button][key] = value + end + + def setup + window.show_cursor = true + + theme(THEME) + + background 0xaa_525252 + + stack(width: 1.0, max_width: 760, height: 1.0, max_height: 640, v_align: :center, h_align: :center, background: 0xee_222222, border_thickness: 2, border_color: 0xee_222222, padding: 16) do + flow(width: 1.0, height: 36, padding: 8) do + background 0xff_0052c0 + + title @options[:title] || "Launcher Update Available", fill: true, text_align: :center, font: BOLD_FONT + end + + stack(width: 1.0, fill: true, margin_top: 14) do + subtitle "Release Notes - #{@options[:available_version]}" + + # case launcher_release_type + # when :git + # when :tebako + # end + + pp @options[:release_data] + + stack(width: 1.0, fill: true, scroll: true, padding: 8, border_thickness: 1, border_color: 0x44_ffffff) do + # para @options[:release_data][:body], width: 1.0 + # FIXME: Finish this bit + @options[:release_data][:body].lines.each do |line| + line.strip + end + end + end + + flow(width: 1.0, height: 46, margin_top: 16) do + background 0xff_ffffff + + button "Cancel", width: 0.25 do + pop_state + @options[:cancel_callback]&.call + end + + flow(fill: true) + + button "Update", width: 0.25 do + pop_state + @options[:accept_callback]&.call + end + end + end + end + end + end +end diff --git a/w3d_hub_linux_launcher.rb b/w3d_hub_linux_launcher.rb index 9af7df7..622b8ad 100644 --- a/w3d_hub_linux_launcher.rb +++ b/w3d_hub_linux_launcher.rb @@ -121,6 +121,7 @@ require_relative "lib/states/dialogs/confirm_dialog" require_relative "lib/states/dialogs/direct_connect_dialog" require_relative "lib/states/dialogs/game_settings_dialog" require_relative "lib/states/dialogs/import_game_dialog" +require_relative "lib/states/dialogs/launcher_updater_dialog" require_relative "lib/api" require_relative "lib/api/service_status"