mirror of
https://github.com/cyberarm/w3d_hub_linux_launcher.git
synced 2026-09-19 14:53:49 +00:00
Initial work on implementing tasks
This commit is contained in:
@@ -65,31 +65,36 @@ module W3DHubLauncher
|
||||
# request installation of application
|
||||
#
|
||||
# periodically reports progress until completion
|
||||
def self.install_application(app_id, channel_id)
|
||||
def self.install_application(app_id, channel_id, &block)
|
||||
Worker::Request.new(:task_install_application, { app_id: app_id, channel_id: channel_id }, &block)
|
||||
end
|
||||
|
||||
# request update of application
|
||||
#
|
||||
# periodically reports progress until completion
|
||||
def self.update_application(app_id, channel_id)
|
||||
def self.update_application(app_id, channel_id, &block)
|
||||
Worker::Request.new(:task_update_application, { app_id: app_id, channel_id: channel_id }, &block)
|
||||
end
|
||||
|
||||
# request repair of application
|
||||
#
|
||||
# periodically reports progress until completion
|
||||
def self.repair_application(app_id, channel_id)
|
||||
def self.repair_application(app_id, channel_id, &block)
|
||||
Worker::Request.new(:task_repair_application, { app_id: app_id, channel_id: channel_id }, &block)
|
||||
end
|
||||
|
||||
# request relocation of application
|
||||
#
|
||||
# periodically reports progress until completion
|
||||
def self.move_application(app_id, channel_id)
|
||||
def self.move_application(app_id, channel_id, target_directory, &block)
|
||||
Worker::Request.new(:task_move_application, { app_id: app_id, channel_id: channel_id, target_directory: target_directory }, &block)
|
||||
end
|
||||
|
||||
# request removal of application
|
||||
#
|
||||
# periodically reports progress until completion
|
||||
def self.uninstall_application(app_id, channel_id)
|
||||
def self.uninstall_application(app_id, channel_id, &block)
|
||||
Worker::Request.new(:task_uninstall_application, { app_id: app_id, channel_id: channel_id }, &block)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,4 +1,84 @@
|
||||
module W3DHubLauncher
|
||||
class Task
|
||||
attr_reader :request_id, :application, :channel, :installed_version, :target_version
|
||||
|
||||
def initialize(request_id:, application:, channel:, installed_version:, target_version:)
|
||||
@request_id = request_id
|
||||
@application = application
|
||||
@channel = channel
|
||||
@installed_version = installed_version
|
||||
@target_version = target_version
|
||||
|
||||
pp self
|
||||
|
||||
setup
|
||||
end
|
||||
|
||||
def setup
|
||||
end
|
||||
|
||||
def start(worker)
|
||||
@worker = worker
|
||||
|
||||
execute
|
||||
end
|
||||
|
||||
def fetch_manifests(version = @target_version)
|
||||
result = fetch_manifest(version)
|
||||
if result.okay?
|
||||
pp result
|
||||
else
|
||||
pp [:error, result]
|
||||
end
|
||||
end
|
||||
|
||||
def fetch_manifest(version)
|
||||
@worker.w3dhub_api.fetch_package_details([{category: "games", subcategory: @application.id, name: "manifest.xml", version: version }])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def execute_task
|
||||
show_application_taskbar
|
||||
|
||||
fail_fast
|
||||
return false if failed?
|
||||
|
||||
fetch_manifests
|
||||
return false if failed?
|
||||
|
||||
build_package_list
|
||||
return false if failed?
|
||||
|
||||
remove_deleted_files
|
||||
return false if failed?
|
||||
|
||||
verify_files
|
||||
return false if failed?
|
||||
|
||||
fetch_packages
|
||||
return false if failed?
|
||||
|
||||
verify_packages
|
||||
return false if failed?
|
||||
|
||||
unpack_packages
|
||||
return false if failed?
|
||||
|
||||
create_wine_prefix
|
||||
return false if failed?
|
||||
|
||||
install_dependencies
|
||||
return false if failed?
|
||||
|
||||
write_paths_ini
|
||||
return false if failed?
|
||||
|
||||
mark_application_installed
|
||||
return false if failed?
|
||||
|
||||
sleep 1
|
||||
hide_application_taskbar
|
||||
|
||||
true
|
||||
end
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
module W3DHubLauncher
|
||||
class Task
|
||||
class InstallApplication < Task
|
||||
def setup
|
||||
end
|
||||
|
||||
def execute
|
||||
# TODO:
|
||||
# fail_fast
|
||||
|
||||
# fetch manifests for currently installed version
|
||||
# AND the target version so we can detect files that need to be removed
|
||||
# between versions
|
||||
manifests_result = fetch_manifests
|
||||
abort_task!(manifests_result) unless manifests_result.okay?
|
||||
|
||||
package_list_result = build_package_list(manifests_result)
|
||||
abort_task!(package_list_result) unless package_list_result.okay?
|
||||
|
||||
# remove_deleted_files
|
||||
|
||||
verify_files
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -6,9 +6,13 @@ module W3DHubLauncher
|
||||
PRIMARY_W3DHUB_API_ENDPOINT = "https://secure.w3dhub.com".freeze
|
||||
ALTERNATIVE_W3DHUB_API_ENDPOINT = "https://backend.w3d.cyberarm.dev".freeze
|
||||
|
||||
attr_reader :applications
|
||||
|
||||
def initialize
|
||||
@access_token = nil
|
||||
|
||||
@applications = []
|
||||
|
||||
@http_clients = {}
|
||||
end
|
||||
|
||||
@@ -33,7 +37,7 @@ module W3DHubLauncher
|
||||
Sync do |task|
|
||||
task.with_timeout(API_TIMEOUT) do
|
||||
Async::HTTP::Internet.send(method, url, headers, body) do |response|
|
||||
# pp [method, url, headers, body]
|
||||
pp [method, url, headers, body, response]
|
||||
if response.success?
|
||||
result.data = response.read
|
||||
else
|
||||
@@ -104,23 +108,31 @@ module W3DHubLauncher
|
||||
primary_result = @access_token ? fetch("#{PRIMARY_W3DHUB_API_ENDPOINT}/apis/launcher/1/get-applications") : CyberarmEngine::Result.new(error: true)
|
||||
alternate_result = fetch("#{ALTERNATIVE_W3DHUB_API_ENDPOINT}/apis/launcher/1/get-applications")
|
||||
|
||||
single_source = false
|
||||
|
||||
# We've failed to retrieve data
|
||||
if primary_result.error? && alternate_result.error?
|
||||
return result
|
||||
# We've only gotten data back from the primary backend
|
||||
elsif primary_result.okay? && alternate_result.error?
|
||||
result.data = primary_result.data
|
||||
return result
|
||||
single_source = true
|
||||
# We've only gotten data back from the alternate backend
|
||||
elsif primary_result.error? && alternate_result.okay?
|
||||
result.data = alternate_result.data
|
||||
return result
|
||||
single_source = true
|
||||
end
|
||||
|
||||
# We've gotten data back from both backends, merge them.
|
||||
# pp [primary_result, alternate_result]
|
||||
unless single_source
|
||||
puts "FIXME: merge applications source"
|
||||
# We've gotten data back from both backends, merge them.
|
||||
# pp [primary_result, alternate_result]
|
||||
|
||||
# FIXME: Merge primary and alternate results
|
||||
end
|
||||
|
||||
@applications = JSON.parse(result.data)["applications"]&.map { |app| W3DHubLauncher::Worker::Api::Application.new(app) } || []
|
||||
|
||||
# FIXME: Merge primary and alternate results
|
||||
result
|
||||
end
|
||||
|
||||
@@ -140,15 +152,12 @@ module W3DHubLauncher
|
||||
result = CyberarmEngine::Result.new
|
||||
end
|
||||
|
||||
def fetch_manifests()
|
||||
result = CyberarmEngine::Result.new
|
||||
def fetch_package_details(packages)
|
||||
body = URI.encode_www_form("data": JSON.dump({ packages: packages }))
|
||||
fetch("#{@access_token ? PRIMARY_W3DHUB_API_ENDPOINT : ALTERNATIVE_W3DHUB_API_ENDPOINT}/apis/launcher/1/get-package-details", method: :post, body: body, headers: headers(form_encoded: true))
|
||||
end
|
||||
|
||||
def fetch_package_details()
|
||||
result = CyberarmEngine::Result.new
|
||||
end
|
||||
|
||||
def fetch_package()
|
||||
def download_package()
|
||||
download()
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user