From 675ab3b1a891191371a8f04efda695d9e71d7101 Mon Sep 17 00:00:00 2001 From: Cyberarm Date: Mon, 22 Jun 2026 10:55:51 -0500 Subject: [PATCH] Sync --- lib/worker.rb | 60 +++++++++++++++++++++++++++++++++++------------ lib/worker/api.rb | 20 ++++++++++------ 2 files changed, 58 insertions(+), 22 deletions(-) diff --git a/lib/worker.rb b/lib/worker.rb index 61cf164..3a000dd 100644 --- a/lib/worker.rb +++ b/lib/worker.rb @@ -28,24 +28,12 @@ module W3DHubLauncher query = Ractor.receive pp query - case query.type - when Request::FETCH_URL - when Request::DOWNLOAD_URL - when Request::W3DHUB_API_CALL + if respond_to?(query.type) Async do - result = @w3dhub_api.send(query.data[:call], *(query.data[:arguments] || [])) - response = Response.new(result.okay? ? Request::STATUS_COMPLETE : Request::STATUS_ERROR, query.request_id, result) - Ractor.main.send(response) + send(query.type, query) 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" + raise "UNKNOWN REQUEST: #{query}" end end end @@ -55,5 +43,47 @@ module W3DHubLauncher def backend_websocket end + + # + # ------------ query / request handlers ------------ + # + def fetch_url(query) + end + + def download_url(query) + end + + def w3dhub_api_call(query) + result = @w3dhub_api.send(query.data[:call], *(query.data[:arguments] || [])) + response = Response.new(result.okay? ? Request::STATUS_COMPLETE : Request::STATUS_ERROR, query.request_id, result) + + Ractor.main.send(response) + end + + def update_settings(query) + result = CyberarmEngine::Result.new + + FileUtils.mkdir_p(W3DHubLauncher::CONFIG_PATH) # FIXME: FAILABLE! + File.write("#{W3DHubLauncher::CONFIG_PATH}/settings.json", query.data) # FIXME: FAILABLE! + result.data = query.data + response = Response.new(result.okay? ? Request::STATUS_COMPLETE : Request::STATUS_ERROR, query.request_id, result) + + Ractor.main.send(response) + end + + def install_application(query) + end + + def update_application(query) + end + + def repair_application(query) + end + + def move_application(query) + end + + def uninstall_application(query) + end end end diff --git a/lib/worker/api.rb b/lib/worker/api.rb index 4ef2252..539b135 100644 --- a/lib/worker/api.rb +++ b/lib/worker/api.rb @@ -23,7 +23,7 @@ module W3DHubLauncher # write updated launcher settings def self.update_settings(settings, &block) - Worker::Request.new(Request::LAUNCHER_UPDATE_SETTINGS, settings.to_json, &block) + Worker::Request.new(:update_settings, settings.to_json, &block) end # returns list of available applications @@ -37,37 +37,43 @@ module W3DHubLauncher end # returns news for application - def self.news + def self.news(category = "launcher-home", &block) + Worker::Request.new(:news, category, &block) + end + + # returns news for application + def self.events(app_id, &block) + Worker::Request.new(:events, app_id, &block) end # request installation of application # # periodically reports progress until completion - def self.install_application + def self.install_application(app_id, channel_id) end # request update of application # # periodically reports progress until completion - def self.update_application + def self.update_application(app_id, channel_id) end # request repair of application # # periodically reports progress until completion - def self.repair_application + def self.repair_application(app_id, channel_id) end # request relocation of application # # periodically reports progress until completion - def self.move_application + def self.move_application(app_id, channel_id) end # request removal of application # # periodically reports progress until completion - def self.uninstall_application + def self.uninstall_application(app_id, channel_id) end end end