mirror of
https://github.com/cyberarm/w3d_hub_linux_launcher.git
synced 2025-12-15 16:52:34 +00:00
Partially working download manager details for packages (more work needed)
This commit is contained in:
@@ -93,5 +93,9 @@ class W3DHub
|
||||
def busy?
|
||||
@tasks.any? { |t| t.state == :running }
|
||||
end
|
||||
|
||||
def current_task
|
||||
@tasks.find { |t| t.state == :running }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -3,7 +3,8 @@ class W3DHub
|
||||
class Task
|
||||
include CyberarmEngine::Common
|
||||
|
||||
attr_reader :app_id, :release_channel
|
||||
attr_reader :app_id, :release_channel, :application, :channel,
|
||||
:total_bytes_to_download, :bytes_downloaded, :packages_to_download
|
||||
|
||||
def initialize(app_id, release_channel)
|
||||
@app_id = app_id
|
||||
@@ -14,6 +15,10 @@ class W3DHub
|
||||
@application = window.applications.games.find { |g| g.id == app_id }
|
||||
@channel = @application.channels.find { |c| c.name == release_channel }
|
||||
|
||||
@packages_to_download = []
|
||||
@total_bytes_to_download = -1
|
||||
@bytes_downloaded = -1
|
||||
|
||||
setup
|
||||
end
|
||||
|
||||
@@ -25,6 +30,9 @@ class W3DHub
|
||||
end
|
||||
|
||||
# Start task, inside its own thread
|
||||
# FIXME: Ruby 3 has parallelism now: Use a Ractor to do work on a seperate core to
|
||||
# prevent the UI for locking up while doing computation heavy work, i.e building
|
||||
# list of packages to download
|
||||
def start
|
||||
@task_state = :running
|
||||
|
||||
@@ -86,6 +94,14 @@ class W3DHub
|
||||
)
|
||||
end
|
||||
|
||||
def update_download_manager_task(checksum, message, status, progress)
|
||||
run_on_main_thread(
|
||||
proc do
|
||||
window.current_state.update_download_manager_task(checksum, message, status, progress)
|
||||
end
|
||||
)
|
||||
end
|
||||
|
||||
def hide_application_taskbar
|
||||
run_on_main_thread(
|
||||
proc do
|
||||
@@ -156,25 +172,35 @@ class W3DHub
|
||||
package_details = Api.package_details(hashes)
|
||||
|
||||
if package_details
|
||||
download_queue = []
|
||||
@packages_to_download = []
|
||||
|
||||
package_details.each do |pkg|
|
||||
unless verify_package(pkg, pkg.category, pkg.subcategory, pkg.name, pkg.version)
|
||||
download_queue << pkg
|
||||
@packages_to_download << pkg
|
||||
end
|
||||
end
|
||||
|
||||
total_bytes_to_download = download_queue.sum { |pkg| pkg.size }
|
||||
bytes_downloaded = 0
|
||||
@total_bytes_to_download = @packages_to_download.sum { |pkg| pkg.size }
|
||||
@bytes_downloaded = 0
|
||||
|
||||
@packages_to_download.each do |pkg|
|
||||
package_bytes_downloaded = 0
|
||||
|
||||
download_queue.each do |pkg|
|
||||
package_fetch(pkg.category, pkg.subcategory, pkg.name, pkg.version) do |chunk, remaining_bytes, total_bytes|
|
||||
bytes_downloaded += chunk.to_s.length
|
||||
@bytes_downloaded += chunk.to_s.length
|
||||
package_bytes_downloaded += chunk.to_s.length
|
||||
|
||||
update_application_taskbar(
|
||||
"Downloading #{@application.name}...",
|
||||
"#{W3DHub.format_size(bytes_downloaded)} / #{W3DHub.format_size(total_bytes_to_download)}",
|
||||
bytes_downloaded.to_f / total_bytes_to_download
|
||||
"#{W3DHub.format_size(@bytes_downloaded)} / #{W3DHub.format_size(@total_bytes_to_download)}",
|
||||
@bytes_downloaded.to_f / @total_bytes_to_download
|
||||
)
|
||||
|
||||
update_download_manager_task(
|
||||
pkg.checksum,
|
||||
pkg.name,
|
||||
"#{W3DHub.format_size(package_bytes_downloaded)} / #{W3DHub.format_size(total_bytes)}",
|
||||
package_bytes_downloaded.to_f / total_bytes
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,9 +1,14 @@
|
||||
class W3DHub
|
||||
class Pages
|
||||
class DownloadManager < Page
|
||||
attr_reader :download_package_info
|
||||
|
||||
def setup
|
||||
@download_package_info ||= {}
|
||||
|
||||
body.clear do
|
||||
stack(width: 1.0, height: 1.0) do
|
||||
# TODO: Show correct application details here
|
||||
flow(width: 1.0, height: 0.1, padding: 8) do
|
||||
background 0xff_252550
|
||||
flow(width: 0.70, height: 1.0) do
|
||||
@@ -28,17 +33,22 @@ class W3DHub
|
||||
end
|
||||
|
||||
# Operations
|
||||
stack(width: 1.0, height: 0.9, padding: 8, scroll: true) do
|
||||
window.applications.games.reject { |g| g.id == "ren" }.each_with_index do |game, i|
|
||||
@downloads_container = stack(width: 1.0, height: 0.9, padding: 8, scroll: true) do
|
||||
# TODO: Show actual list of downloads
|
||||
task = window.application_manager.current_task
|
||||
|
||||
pp task
|
||||
|
||||
task&.packages_to_download&.each_with_index do |pkg, i|
|
||||
stack(width: 1.0, height: 24, padding: 8) do
|
||||
background 0xff_333333 if i.odd?
|
||||
|
||||
flow(width: 1.0, height: 22) do
|
||||
inscription game.name, width: 0.7, text_wrap: :none
|
||||
inscription "Pending...", width: 0.3, text_align: :right, text_wrap: :none
|
||||
@download_package_info["#{pkg.checksum}_name"] = inscription pkg.name, width: 0.7, text_wrap: :none, tag: "#{pkg.checksum}_name"
|
||||
@download_package_info["#{pkg.checksum}_status"] = inscription "Pending...", width: 0.3, text_align: :right, text_wrap: :none, tag: "#{pkg.checksum}_status"
|
||||
end
|
||||
|
||||
progress fraction: rand(0.25..0.8), height: 2, width: 1.0
|
||||
@download_package_info["#{pkg.checksum}_progress"] = progress fraction: rand(0.25..0.8), height: 2, width: 1.0, tag: "#{pkg.checksum}_progress"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -240,6 +240,26 @@ class W3DHub
|
||||
@application_taskbar_status_label.value = status
|
||||
@application_taskbar_progressbar.value = progress.clamp(0.0, 1.0)
|
||||
end
|
||||
|
||||
# def update_download_manager_state(application, channel)
|
||||
# end
|
||||
|
||||
def update_download_manager_list
|
||||
end
|
||||
|
||||
def update_download_manager_task(checksum, name, status, progress)
|
||||
return unless @page.is_a?(Pages::DownloadManager)
|
||||
|
||||
download_package_info = @page.download_package_info
|
||||
|
||||
name_ = download_package_info["#{checksum}_name"]
|
||||
status_ = download_package_info["#{checksum}_status"]
|
||||
progress_ = download_package_info["#{checksum}_progress"]
|
||||
|
||||
name_.value = name if name
|
||||
status_.value = status if status
|
||||
progress_.value = progress if progress
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user