mirror of
https://github.com/cyberarm/w3d_hub_linux_launcher.git
synced 2025-12-16 09:12:35 +00:00
Downloading packages now works most of the time, primary download indictator is now driven by the Task
This commit is contained in:
@@ -144,8 +144,8 @@ class W3DHub
|
|||||||
# /apis/launcher/1/get-package-details
|
# /apis/launcher/1/get-package-details
|
||||||
# client requests package details: data={"packages":[{"category":"games","name":"apb.ico","subcategory":"apb","version":""}]}
|
# client requests package details: data={"packages":[{"category":"games","name":"apb.ico","subcategory":"apb","version":""}]}
|
||||||
def self.package_details(packages)
|
def self.package_details(packages)
|
||||||
response = W3DHUB_API_CONNECTION.post(
|
response = Excon.post(
|
||||||
path: "apis/launcher/1/get-package-details",
|
"#{ENDPOINT}/apis/launcher/1/get-package-details",
|
||||||
headers: DEFAULT_HEADERS.merge({"Content-Type": "application/x-www-form-urlencoded"}),
|
headers: DEFAULT_HEADERS.merge({"Content-Type": "application/x-www-form-urlencoded"}),
|
||||||
body: "data=#{JSON.dump({ packages: packages })}"
|
body: "data=#{JSON.dump({ packages: packages })}"
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -77,6 +77,27 @@ class W3DHub
|
|||||||
window.main_thread_queue << block
|
window.main_thread_queue << block
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def update_application_taskbar(message, status, progress)
|
||||||
|
run_on_main_thread(
|
||||||
|
proc do
|
||||||
|
window.current_state.show_application_taskbar
|
||||||
|
window.current_state.update_application_taskbar(message, status, progress)
|
||||||
|
end
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
def hide_application_taskbar
|
||||||
|
run_on_main_thread(
|
||||||
|
proc do
|
||||||
|
window.current_state.hide_application_taskbar
|
||||||
|
end
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
###############
|
||||||
|
# Tasks/Steps #
|
||||||
|
###############
|
||||||
|
|
||||||
def fetch_manifests
|
def fetch_manifests
|
||||||
manifests = []
|
manifests = []
|
||||||
|
|
||||||
@@ -135,9 +156,26 @@ class W3DHub
|
|||||||
package_details = Api.package_details(hashes)
|
package_details = Api.package_details(hashes)
|
||||||
|
|
||||||
if package_details
|
if package_details
|
||||||
|
download_queue = []
|
||||||
|
|
||||||
package_details.each do |pkg|
|
package_details.each do |pkg|
|
||||||
unless verify_package(pkg, pkg.category, pkg.subcategory, pkg.name, pkg.version)
|
unless verify_package(pkg, pkg.category, pkg.subcategory, pkg.name, pkg.version)
|
||||||
package_fetch(pkg.category, pkg.subcategory, pkg.name, pkg.version)
|
download_queue << pkg
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
total_bytes_to_download = download_queue.sum { |pkg| pkg.size }
|
||||||
|
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
|
||||||
|
|
||||||
|
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
|
||||||
|
)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
@@ -163,7 +201,11 @@ class W3DHub
|
|||||||
puts "#{@app_id} has been installed."
|
puts "#{@app_id} has been installed."
|
||||||
end
|
end
|
||||||
|
|
||||||
def fetch_manifest(category, subcategory, name, version)
|
#############
|
||||||
|
# Functions #
|
||||||
|
#############
|
||||||
|
|
||||||
|
def fetch_manifest(category, subcategory, name, version, &block)
|
||||||
# Check for and integrity of local manifest
|
# Check for and integrity of local manifest
|
||||||
if File.exist?(Cache.package_path(category, subcategory, name, version))
|
if File.exist?(Cache.package_path(category, subcategory, name, version))
|
||||||
package = Api.package_details([{ category: category, subcategory: subcategory, name: name, version: version }])
|
package = Api.package_details([{ category: category, subcategory: subcategory, name: name, version: version }])
|
||||||
@@ -178,16 +220,18 @@ class W3DHub
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def package_fetch(category, subcategory, name, version)
|
def package_fetch(category, subcategory, name, version, &block)
|
||||||
puts "Downloading: #{category}:#{subcategory}:#{name}-#{version}"
|
puts "Downloading: #{category}:#{subcategory}:#{name}-#{version}"
|
||||||
|
|
||||||
Api.package(category, subcategory, name, version) do |chunk, remaining_bytes, total_bytes|
|
Api.package(category, subcategory, name, version) do |chunk, remaining_bytes, total_bytes|
|
||||||
# Store progress somewhere
|
# Store progress somewhere
|
||||||
# Kernel.puts "#{name}-#{version}: #{(remaining_bytes.to_f / total_bytes).round}%"
|
# Kernel.puts "#{name}-#{version}: #{(remaining_bytes.to_f / total_bytes).round}%"
|
||||||
|
|
||||||
|
block&.call(chunk, remaining_bytes, total_bytes)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def verify_package(package, category, subcategory, name, version)
|
def verify_package(package, category, subcategory, name, version, &block)
|
||||||
puts "Verifying: #{category}:#{subcategory}:#{name}-#{version}"
|
puts "Verifying: #{category}:#{subcategory}:#{name}-#{version}"
|
||||||
|
|
||||||
digest = Digest::SHA256.new
|
digest = Digest::SHA256.new
|
||||||
|
|||||||
@@ -2,30 +2,45 @@ class W3DHub
|
|||||||
class ApplicationManager
|
class ApplicationManager
|
||||||
class Installer < Task
|
class Installer < Task
|
||||||
def execute_task
|
def execute_task
|
||||||
|
update_application_taskbar("Downloading #{@application.name}...", "Fetching manifests...", 0.0)
|
||||||
manifests = fetch_manifests
|
manifests = fetch_manifests
|
||||||
return false if failed?
|
return false if failed?
|
||||||
|
|
||||||
|
# update_application_taskbar("Downloading #{@application.name}...", "Building package list...", 0.0)
|
||||||
packages = build_package_list(manifests)
|
packages = build_package_list(manifests)
|
||||||
return false if failed?
|
return false if failed?
|
||||||
|
|
||||||
|
# update_application_taskbar("Downloading #{@application.name}...", "Downloading packages...", 0.0)
|
||||||
fetch_packages(packages)
|
fetch_packages(packages)
|
||||||
return false if failed?
|
return false if failed?
|
||||||
|
|
||||||
|
update_application_taskbar("Downloading #{@application.name}...", "Verifying packages...", 0.0)
|
||||||
verify_packages(packages)
|
verify_packages(packages)
|
||||||
return false if failed?
|
return false if failed?
|
||||||
|
|
||||||
|
update_application_taskbar("Installing #{@application.name}...", "Unpacking...", 0.0)
|
||||||
unpack_packages(packages)
|
unpack_packages(packages)
|
||||||
return false if failed?
|
return false if failed?
|
||||||
|
sleep 1
|
||||||
|
|
||||||
|
update_application_taskbar("Installing #{@application.name}...", "Creating wine prefix...", 0.0)
|
||||||
create_wine_prefix
|
create_wine_prefix
|
||||||
return false if failed?
|
return false if failed?
|
||||||
|
sleep 1
|
||||||
|
|
||||||
|
update_application_taskbar("Installing #{@application.name}...", "Installing dependencies...", 0.0)
|
||||||
|
|
||||||
install_dependencies(packages)
|
install_dependencies(packages)
|
||||||
return false if failed?
|
return false if failed?
|
||||||
|
sleep 1
|
||||||
|
|
||||||
mark_application_installed
|
mark_application_installed
|
||||||
return false if failed?
|
return false if failed?
|
||||||
|
|
||||||
|
update_application_taskbar("Installed #{@application.name}", "", 1.0)
|
||||||
|
sleep 5
|
||||||
|
hide_application_taskbar
|
||||||
|
|
||||||
true
|
true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -57,8 +57,9 @@ class W3DHub
|
|||||||
# Create a new connection due to some weirdness somewhere in Excon
|
# Create a new connection due to some weirdness somewhere in Excon
|
||||||
response = Excon.post(
|
response = Excon.post(
|
||||||
"#{Api::ENDPOINT}/apis/launcher/1/get-package",
|
"#{Api::ENDPOINT}/apis/launcher/1/get-package",
|
||||||
headers: Api::DEFAULT_HEADERS.merge({"Content-Type": "application/x-www-form-urlencoded"}),
|
headers: Api::DEFAULT_HEADERS.merge({ "Content-Type": "application/x-www-form-urlencoded" }),
|
||||||
body: "data=#{JSON.dump({ category: category, subcategory: subcategory, name: name, version: version })}",
|
body: "data=#{JSON.dump({ category: category, subcategory: subcategory, name: name, version: version })}",
|
||||||
|
chunk_size: 4_000_000,
|
||||||
response_block: streamer
|
response_block: streamer
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -27,42 +27,18 @@ class W3DHub
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# UPDATES
|
# Operations
|
||||||
stack(width: 1.0, height: 0.1) do
|
stack(width: 1.0, height: 0.9, padding: 8, scroll: true) do
|
||||||
background 0x44_000000
|
|
||||||
inscription "Something something updates...", width: 1.0, text_align: :center, margin_top: 18
|
|
||||||
end
|
|
||||||
|
|
||||||
# Available to download
|
|
||||||
stack(width: 1.0, height: 0.8, padding: 8, scroll: true) do
|
|
||||||
window.applications.games.reject { |g| g.id == "ren" }.each_with_index do |game, i|
|
window.applications.games.reject { |g| g.id == "ren" }.each_with_index do |game, i|
|
||||||
flow(width: 1.0, height: 64, padding: 8) do
|
stack(width: 1.0, height: 24, padding: 8) do
|
||||||
background 0xff_333333 if i.odd?
|
background 0xff_333333 if i.odd?
|
||||||
|
|
||||||
flow(width: 0.7, height: 1.0) do
|
flow(width: 1.0, height: 22) do
|
||||||
image "#{GAME_ROOT_PATH}/media/icons/#{game.id}.png", width: 0.1, margin_right: 8
|
inscription game.name, width: 0.7, text_wrap: :none
|
||||||
|
inscription "Pending...", width: 0.3, text_align: :right, text_wrap: :none
|
||||||
stack(width: 0.9, height: 1.0) do
|
|
||||||
title game.name
|
|
||||||
inscription "This is a brief description of the game", width: 1.0
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
flow(width: 0.3, height: 1.0) do
|
progress fraction: rand(0.25..0.8), height: 2, width: 1.0
|
||||||
version_selector = list_box items: game.channels.map { |c| c.name }, width: 0.499, enabled: game.channels.count > 1
|
|
||||||
version_selector.subscribe(:changed) do |item|
|
|
||||||
p item.value
|
|
||||||
end
|
|
||||||
|
|
||||||
button "Install", width: 0.5 do
|
|
||||||
# Download/verify game-channel manifest
|
|
||||||
# Download broken/missing files
|
|
||||||
# Unpack
|
|
||||||
# Configure
|
|
||||||
# Disable install
|
|
||||||
# Enable Uninstall
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -141,7 +141,7 @@ class W3DHub
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
button "<b>Import</b>", margin_left: 24 do
|
button "<b>Import</b>", margin_left: 24, enabled: false do
|
||||||
window.application_manager.import(game.id, channel.name, "?")
|
window.application_manager.import(game.id, channel.name, "?")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -65,6 +65,10 @@ class W3DHub
|
|||||||
width: 18,
|
width: 18,
|
||||||
image_width: 18,
|
image_width: 18,
|
||||||
checkmark_image: "#{GAME_ROOT_PATH}/media/ui_icons/checkmark.png"
|
checkmark_image: "#{GAME_ROOT_PATH}/media/ui_icons/checkmark.png"
|
||||||
|
},
|
||||||
|
Progress: {
|
||||||
|
fraction_background: 0xff_00acff,
|
||||||
|
border_thickness: 0
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -111,13 +115,13 @@ class W3DHub
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
stack(width: 0.77, height: 1.0, margin_left: 16) do
|
@application_taskbar_container = stack(width: 0.77, height: 1.0, margin_left: 16) do
|
||||||
flow(width: 1.0, height: 0.65) do
|
flow(width: 1.0, height: 0.65) do
|
||||||
inscription "Downloading Expansive Civilian Warfare...", width: 0.7, text_wrap: :none
|
@application_taskbar_label = inscription "Downloading Expansive Civilian Warfare...", width: 0.65, text_wrap: :none
|
||||||
inscription "460.2 MB / 254.5 GB", width: 0.3, text_align: :right, text_wrap: :none
|
@application_taskbar_status_label = inscription "460.2 MB / 254.5 GB", width: 0.35, text_align: :right, text_wrap: :none
|
||||||
end
|
end
|
||||||
|
|
||||||
progress fraction: 0.4, height: 2, width: 1.0, fraction_background: 0xff_00acff, border_thickness: 0
|
@application_taskbar_progressbar = progress fraction: 0.4, height: 2, width: 1.0
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -172,6 +176,8 @@ class W3DHub
|
|||||||
else
|
else
|
||||||
page(W3DHub::Pages::Games)
|
page(W3DHub::Pages::Games)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
hide_application_taskbar
|
||||||
end
|
end
|
||||||
|
|
||||||
def draw
|
def draw
|
||||||
@@ -220,6 +226,20 @@ class W3DHub
|
|||||||
@page.setup
|
@page.setup
|
||||||
@page.focus
|
@page.focus
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def show_application_taskbar
|
||||||
|
@application_taskbar_container.show
|
||||||
|
end
|
||||||
|
|
||||||
|
def hide_application_taskbar
|
||||||
|
@application_taskbar_container.hide
|
||||||
|
end
|
||||||
|
|
||||||
|
def update_application_taskbar(message, status, progress)
|
||||||
|
@application_taskbar_label.value = message
|
||||||
|
@application_taskbar_status_label.value = status
|
||||||
|
@application_taskbar_progressbar.value = progress.clamp(0.0, 1.0)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -19,5 +19,15 @@ class W3DHub
|
|||||||
|
|
||||||
super if @application_manager.idle?
|
super if @application_manager.idle?
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def main_thread_queue
|
||||||
|
if current_state.is_a?(W3DHub::States::Interface)
|
||||||
|
current_state.main_thread_queue
|
||||||
|
else
|
||||||
|
warn "Task will not be run for:"
|
||||||
|
warn caller
|
||||||
|
[]
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
Reference in New Issue
Block a user