From c6ee9eab3150d5f219b5dd40bb730f1b408fdba0 Mon Sep 17 00:00:00 2001 From: Cyberarm Date: Tue, 30 Jun 2026 19:48:48 -0500 Subject: [PATCH] Sync --- lib/worker.rb | 1 + lib/worker/w3dhub_api.rb | 29 ++++++++++++++++------------- w3d_hub_linux_launcher.rb | 6 +++--- 3 files changed, 20 insertions(+), 16 deletions(-) diff --git a/lib/worker.rb b/lib/worker.rb index 3a000dd..07f82bb 100644 --- a/lib/worker.rb +++ b/lib/worker.rb @@ -55,6 +55,7 @@ module W3DHubLauncher def w3dhub_api_call(query) result = @w3dhub_api.send(query.data[:call], *(query.data[:arguments] || [])) + pp result response = Response.new(result.okay? ? Request::STATUS_COMPLETE : Request::STATUS_ERROR, query.request_id, result) Ractor.main.send(response) diff --git a/lib/worker/w3dhub_api.rb b/lib/worker/w3dhub_api.rb index 6f1c17b..03c4ee5 100644 --- a/lib/worker/w3dhub_api.rb +++ b/lib/worker/w3dhub_api.rb @@ -32,20 +32,20 @@ module W3DHubLauncher Sync do |task| task.with_timeout(API_TIMEOUT) do - endpoint = Async::HTTP::Endpoint.parse(url) - client = @http_clients[endpoint.hostname.downcase] ||= Async::HTTP::Client.new(endpoint) - - pp endpoint, endpoint.authority, client - response = client.get(endpoint.path) - pp response - # client.send(method, endpoint.path, headers, body) do |response| - # result.data = response.read - # rescue StandardError => e - # result.error = e - # end - # rescue Async::TimeoutError - # result.error = e + Async::HTTP::Internet.send(method, url, headers, body) do |response| + if response.success? + result.data = response.read + else + result.error = true + end + end + rescue StandardError => e + result.error = e + rescue Async::TimeoutError => e + result.error = e end + + result end result @@ -103,6 +103,9 @@ module W3DHubLauncher alternate_result = fetch("#{ALTERNATIVE_W3DHUB_API_ENDPOINT}/apis/launcher/1/get-applications") pp [primary_result, alternate_result] + + # FIXME: Merge primary and alternate results + result end def fetch_news() diff --git a/w3d_hub_linux_launcher.rb b/w3d_hub_linux_launcher.rb index c2ab135..f90107e 100644 --- a/w3d_hub_linux_launcher.rb +++ b/w3d_hub_linux_launcher.rb @@ -65,9 +65,9 @@ Thread.new do end # 10.times do -# W3DHubLauncher::Worker::Request.new(W3DHubLauncher::Worker::Request::W3DHUB_API_CALL, { call: :fetch_applications }) do |result| -# pp result -# end + W3DHubLauncher::Worker::Request.new(:w3dhub_api_call, { call: :fetch_applications }) do |result| + pp result + end # end window = W3DHubLauncher::Window.new(width: 1280, height: 800, resizable: true)