From 0eb188f72e5221c47a6dd2d01f567d12489aca73 Mon Sep 17 00:00:00 2001 From: Cyberarm Date: Wed, 22 Apr 2026 23:12:30 -0500 Subject: [PATCH] More work on Ractor communication. Need to have a proper think about how to keep it DRY and KISS :) --- Gemfile | 1 + Gemfile.lock | 1 + lib/pages/boot/initial_setup.rb | 25 ++++++++++++++----------- lib/window.rb | 4 ++-- lib/worker.rb | 9 +++++++++ lib/worker/api.rb | 33 ++++++++++++++------------------- lib/worker/request.rb | 7 ++++--- w3d_hub_linux_launcher.rb | 11 ++++++----- 8 files changed, 51 insertions(+), 40 deletions(-) diff --git a/Gemfile b/Gemfile index 792ff00..b72db0e 100644 --- a/Gemfile +++ b/Gemfile @@ -4,6 +4,7 @@ source "https://gem.coop" gem "base64" gem "rexml" gem "logger" +gem "json" # "game" library gem gem "cyberarm_engine" diff --git a/Gemfile.lock b/Gemfile.lock index 55fb3bf..69d387d 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -80,6 +80,7 @@ DEPENDENCIES cyberarm_engine digest-crc ircparser + json logger rexml rubyzip diff --git a/lib/pages/boot/initial_setup.rb b/lib/pages/boot/initial_setup.rb index 3d51f55..d5b3481 100644 --- a/lib/pages/boot/initial_setup.rb +++ b/lib/pages/boot/initial_setup.rb @@ -15,23 +15,16 @@ module W3DHubLauncher title "Initial Setup" caption "Please confirm launcher's default settings and make any desired tweaks.", font: FONT_REGULAR - flow(width: 1.0, height: 40, margin_top: PADDING) do - tagline "Launcher data directory", height: 1.0, text_v_align: :center - edit_line format("%s/.local/share/W3D Hub", Dir.home), fill: true - button "Browse..." - end - inscription "Location where the launcher stores it's configuration files and cache interface data." - flow(width: 1.0, height: 40, margin_top: HALF_PADDING) do tagline "Launcher package cache directory", height: 1.0, text_v_align: :center - edit_line format("%s/.local/share/W3D Hub/package-cache", Dir.home), fill: true + edit_line DEFAULT_PACKAGE_CACHE_PATH, fill: true button "Browse..." end inscription "Location where the launcher will download application packages." flow(width: 1.0, height: 40, margin_top: HALF_PADDING) do tagline "Application installation directory", height: 1.0, text_v_align: :center - edit_line format("%s/.local/share/W3D Hub/applications", Dir.home), fill: true + edit_line DEFAULT_APPLICATIONS_PATH, fill: true button "Browse..." end inscription "Location where the launcher will install new applications." @@ -53,8 +46,18 @@ module W3DHubLauncher flow(width: 1.0, padding_top: PADDING) do flow(fill: true) - button "Accept" do - page(Page::Boot::StartUp) + button "Accept" do |btn| + btn.enabled = false + + Worker::Api.update_settings({}) do |result| + if result.okay? + page(Page::Boot::StartUp) + else + btn.enabled = true + end + + puts "NOW!" + end end end end diff --git a/lib/window.rb b/lib/window.rb index a8e4fe5..440a29e 100644 --- a/lib/window.rb +++ b/lib/window.rb @@ -4,8 +4,8 @@ module W3DHubLauncher self.show_cursor = true self.caption = format("%s | v%s (%s)", NAME, VERSION, VERSION_NAME) # "Cyberarm's W3D Hub Linux Launcher | v2.0.0 alpha" - # push_state(States::Boot) - push_state(States::Interface) + push_state(States::Boot) + # push_state(States::Interface) end def needs_redraw? diff --git a/lib/worker.rb b/lib/worker.rb index df585ca..61cf164 100644 --- a/lib/worker.rb +++ b/lib/worker.rb @@ -6,6 +6,8 @@ module W3DHubLauncher @threads = [] @requests = [] + @settings = # Settings.new + # next available request_id to assign incoming requests @request_id = 0 @@ -35,6 +37,13 @@ module W3DHubLauncher response = Response.new(result.okay? ? Request::STATUS_COMPLETE : Request::STATUS_ERROR, query.request_id, result) Ractor.main.send(response) end + when Request::LAUNCHER_UPDATE_SETTINGS + result = CyberarmEngine::Result.new + FileUtils.mkdir_p(W3DHubLauncher::CONFIG_PATH) # FAILABLE! + File.write("#{W3DHubLauncher::CONFIG_PATH}/settings.json", query.data) # FAILABLE! + result.data = query.data + response = Response.new(result.okay? ? Request::STATUS_COMPLETE : Request::STATUS_ERROR, query.request_id, result) + Ractor.main.send(response) else raise "UNKNOWN REQUEST" end diff --git a/lib/worker/api.rb b/lib/worker/api.rb index 0cc21d1..4ef2252 100644 --- a/lib/worker/api.rb +++ b/lib/worker/api.rb @@ -3,76 +3,71 @@ module W3DHubLauncher class Worker class Api - Request = Data.define(:coming_soon) - - def initialize - @requests = [] - end - # downloads requested resource, returns raw string - def fetch_url + def self.fetch_url end # downloads requested resource, periodically reporting progress until completion, returning path for file on disk - def download_url + def self.download_url end # returns user account data # # automatically handles signing in / refreshing token (DOES NOT remove account data if failed to refresh token due to network timeout) - def account + def self.account end # returns launcher settings - def settings + def self.settings end # write updated launcher settings - def update_settings + def self.update_settings(settings, &block) + Worker::Request.new(Request::LAUNCHER_UPDATE_SETTINGS, settings.to_json, &block) end # returns list of available applications # # if updated list is requested, return cached version immediately and then the updated list later. - def applications + def self.applications end # returns current list of servers as reported from GSH / cache - def servers + def self.servers end # returns news for application - def news + def self.news end # request installation of application # # periodically reports progress until completion - def install_application + def self.install_application end # request update of application # # periodically reports progress until completion - def update_application + def self.update_application end # request repair of application # # periodically reports progress until completion - def repair_application + def self.repair_application end # request relocation of application # # periodically reports progress until completion - def move_application + def self.move_application end # request removal of application # # periodically reports progress until completion - def uninstall_application + def self.uninstall_application end end end diff --git a/lib/worker/request.rb b/lib/worker/request.rb index 7d52ac5..7d3cc7c 100644 --- a/lib/worker/request.rb +++ b/lib/worker/request.rb @@ -6,6 +6,8 @@ module W3DHubLauncher FETCH_URL = 0 DOWNLOAD_URL = 1 W3DHUB_API_CALL = 10 + LAUNCHER_SETTINGS = 1000 + LAUNCHER_UPDATE_SETTINGS = 1001 STATUS_ERROR = -1 # request has failed STATUS_PENDING = 0 # request has not yet started @@ -53,9 +55,8 @@ module W3DHubLauncher pp [event, data] case event - when STATUS_COMPLETE - Request.requests.delete(self) - when STATUS_ERROR + when STATUS_ERROR, STATUS_COMPLETE + @callback&.call(data) Request.requests.delete(self) end end diff --git a/w3d_hub_linux_launcher.rb b/w3d_hub_linux_launcher.rb index c1f53b4..c2ab135 100644 --- a/w3d_hub_linux_launcher.rb +++ b/w3d_hub_linux_launcher.rb @@ -28,6 +28,7 @@ require_relative "lib/pages/boot/terms" require_relative "lib/pages/boot/initial_setup" require_relative "lib/pages/boot/start_up" require_relative "lib/dialogs/about" +require_relative "lib/dialogs/downloads" require_relative "lib/states/boot" require_relative "lib/states/interface" require_relative "lib/window" @@ -63,11 +64,11 @@ Thread.new do end end -10.times do - W3DHubLauncher::Worker::Request.new(W3DHubLauncher::Worker::Request::W3DHUB_API_CALL, { call: :fetch_applications }) do |result| - pp result - end -end +# 10.times do +# W3DHubLauncher::Worker::Request.new(W3DHubLauncher::Worker::Request::W3DHUB_API_CALL, { call: :fetch_applications }) do |result| +# pp result +# end +# end window = W3DHubLauncher::Window.new(width: 1280, height: 800, resizable: true) # window = W3DHubLauncher::Window.new(width: 1920, height: 1080, resizable: true)