mirror of
https://github.com/cyberarm/w3d_hub_linux_launcher.git
synced 2025-12-16 09:12:35 +00:00
Window is no longer a fiber, should prevent window from locking up due to a fiber not yielding, replaced ui's direct async calls with BackgroundWorker.foreground_job, show pulsing circle behind app logo on boot
This commit is contained in:
18
lib/api.rb
18
lib/api.rb
@@ -9,6 +9,10 @@ class W3DHub
|
|||||||
DEFAULT_HEADERS + [["Content-Type", "application/x-www-form-urlencoded"]]
|
DEFAULT_HEADERS + [["Content-Type", "application/x-www-form-urlencoded"]]
|
||||||
).freeze
|
).freeze
|
||||||
|
|
||||||
|
def self.on_fiber(method, *args, &callback)
|
||||||
|
BackgroundWorker.job(-> { Api.send(method, *args) }, callback)
|
||||||
|
end
|
||||||
|
|
||||||
#! === W3D Hub API === !#
|
#! === W3D Hub API === !#
|
||||||
|
|
||||||
ENDPOINT = "https://secure.w3dhub.com".freeze
|
ENDPOINT = "https://secure.w3dhub.com".freeze
|
||||||
@@ -165,6 +169,12 @@ class W3DHub
|
|||||||
|
|
||||||
SERVER_LIST_ENDPOINT = "https://gsh.w3dhub.com".freeze
|
SERVER_LIST_ENDPOINT = "https://gsh.w3dhub.com".freeze
|
||||||
|
|
||||||
|
def self.get(url, headers = DEFAULT_HEADERS, body = nil)
|
||||||
|
@client ||= Async::HTTP::Client.new(Async::HTTP::Endpoint.parse(SERVER_LIST_ENDPOINT, protocol: Async::HTTP::Protocol::HTTP10))
|
||||||
|
|
||||||
|
@client.get(url, headers, body)
|
||||||
|
end
|
||||||
|
|
||||||
# Method: GET
|
# Method: GET
|
||||||
# FORMAT: JSON
|
# FORMAT: JSON
|
||||||
|
|
||||||
@@ -182,8 +192,8 @@ class W3DHub
|
|||||||
# id, name, score, kills, deaths
|
# id, name, score, kills, deaths
|
||||||
# ...players[]:
|
# ...players[]:
|
||||||
# nick, team (index of teams array), score, kills, deaths
|
# nick, team (index of teams array), score, kills, deaths
|
||||||
def self.server_list(internet, level = 1)
|
def self.server_list(level = 1)
|
||||||
response = internet.get("#{SERVER_LIST_ENDPOINT}/listings/getAll/v2?statusLevel=#{level}", DEFAULT_HEADERS)
|
response = get("#{SERVER_LIST_ENDPOINT}/listings/getAll/v2?statusLevel=#{level}")
|
||||||
|
|
||||||
if response.success?
|
if response.success?
|
||||||
data = JSON.parse(response.read, symbolize_names: true)
|
data = JSON.parse(response.read, symbolize_names: true)
|
||||||
@@ -204,8 +214,8 @@ class W3DHub
|
|||||||
# id, name, score, kills, deaths
|
# id, name, score, kills, deaths
|
||||||
# ...players[]:
|
# ...players[]:
|
||||||
# nick, team (index of teams array), score, kills, deaths
|
# nick, team (index of teams array), score, kills, deaths
|
||||||
def self.server_details(internet, id, level)
|
def self.server_details(id, level)
|
||||||
response = internet.get("#{SERVER_LIST_ENDPOINT}/listings/getStatus/v2/#{id}?statusLevel=#{level}", DEFAULT_HEADERS)
|
response = get("#{SERVER_LIST_ENDPOINT}/listings/getStatus/v2/#{id}?statusLevel=#{level}")
|
||||||
|
|
||||||
if response.success?
|
if response.success?
|
||||||
hash = JSON.parse(response.read, symbolize_names: true)
|
hash = JSON.parse(response.read, symbolize_names: true)
|
||||||
|
|||||||
@@ -74,45 +74,47 @@ class W3DHub
|
|||||||
end
|
end
|
||||||
|
|
||||||
def run
|
def run
|
||||||
Async do |task|
|
Thread.new do
|
||||||
internet = Async::HTTP::Internet.instance
|
Async do |task|
|
||||||
|
internet = Async::HTTP::Internet.instance
|
||||||
|
|
||||||
response = internet.post("https://gsh.w3dhub.com/listings/push/v2/negotiate?negotiateVersion=1", Api::DEFAULT_HEADERS, [""])
|
response = internet.post("https://gsh.w3dhub.com/listings/push/v2/negotiate?negotiateVersion=1", Api::DEFAULT_HEADERS, [""])
|
||||||
data = JSON.parse(response.read, symbolize_names: true)
|
data = JSON.parse(response.read, symbolize_names: true)
|
||||||
|
|
||||||
id = data[:connectionToken]
|
id = data[:connectionToken]
|
||||||
endpoint = Async::HTTP::Endpoint.parse("https://gsh.w3dhub.com/listings/push/v2?id=#{id}", alpn_protocols: Async::HTTP::Protocol::HTTP11.names)
|
endpoint = Async::HTTP::Endpoint.parse("https://gsh.w3dhub.com/listings/push/v2?id=#{id}", alpn_protocols: Async::HTTP::Protocol::HTTP11.names)
|
||||||
|
|
||||||
Async::WebSocket::Client.connect(endpoint, headers: Api::DEFAULT_HEADERS, handler: PatchedConnection) do |connection|
|
Async::WebSocket::Client.connect(endpoint, headers: Api::DEFAULT_HEADERS, handler: PatchedConnection) do |connection|
|
||||||
connection.write({ protocol: "json", version: 1 })
|
connection.write({ protocol: "json", version: 1 })
|
||||||
connection.flush
|
connection.flush
|
||||||
pp connection.read
|
pp connection.read
|
||||||
connection.write({ "type": 6 })
|
connection.write({ "type": 6 })
|
||||||
|
|
||||||
Store.server_list.each_with_index do |server, i|
|
Store.server_list.each_with_index do |server, i|
|
||||||
i += 1
|
i += 1
|
||||||
mode = 1 # 2 full details, 1 basic details
|
mode = 1 # 2 full details, 1 basic details
|
||||||
out = { "type": 1, "invocationId": "#{i}", "target": "SubscribeToServerStatusUpdates", "arguments": [server.id, mode] }
|
out = { "type": 1, "invocationId": "#{i}", "target": "SubscribeToServerStatusUpdates", "arguments": [server.id, mode] }
|
||||||
connection.write(out)
|
connection.write(out)
|
||||||
end
|
end
|
||||||
|
|
||||||
while (message = connection.read)
|
while (message = connection.read)
|
||||||
connection.write({ type: 6 }) if message.first[:type] == 6
|
connection.write({ type: 6 }) if message.first[:type] == 6
|
||||||
|
|
||||||
if message&.first&.fetch(:type) == 1
|
if message&.first&.fetch(:type) == 1
|
||||||
message.each do |rpc|
|
message.each do |rpc|
|
||||||
next unless rpc[:target] == "ServerStatusChanged"
|
next unless rpc[:target] == "ServerStatusChanged"
|
||||||
|
|
||||||
id, data = rpc[:arguments]
|
id, data = rpc[:arguments]
|
||||||
server = Store.server_list.find { |s| s.id == id }
|
server = Store.server_list.find { |s| s.id == id }
|
||||||
server_updated = server&.update(data)
|
server_updated = server&.update(data)
|
||||||
States::Interface.instance&.update_server_browser(server) if server_updated
|
States::Interface.instance&.update_server_browser(server) if server_updated
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
ensure
|
||||||
|
@@instance = nil
|
||||||
end
|
end
|
||||||
ensure
|
|
||||||
@@instance = nil
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
77
lib/background_worker.rb
Normal file
77
lib/background_worker.rb
Normal file
@@ -0,0 +1,77 @@
|
|||||||
|
class W3DHub
|
||||||
|
class BackgroundWorker
|
||||||
|
@@instance = nil
|
||||||
|
@@alive = false
|
||||||
|
|
||||||
|
def self.create
|
||||||
|
raise "BackgroundWorker instance already exists!" if @@instance
|
||||||
|
|
||||||
|
@@alive = true
|
||||||
|
@@instance = self.new
|
||||||
|
|
||||||
|
Async do
|
||||||
|
@@instance.handle_jobs
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.instance
|
||||||
|
@@instance
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.alive?
|
||||||
|
@@alive
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.shutdown!
|
||||||
|
@@alive = false
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.job(job, callback)
|
||||||
|
@@instance.add_job(Job.new(job, callback))
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.foreground_job(job, callback)
|
||||||
|
@@instance.add_job(Job.new(job, callback, true))
|
||||||
|
end
|
||||||
|
|
||||||
|
def initialize
|
||||||
|
@jobs = []
|
||||||
|
end
|
||||||
|
|
||||||
|
def handle_jobs
|
||||||
|
while BackgroundWorker.alive?
|
||||||
|
job = @jobs.shift
|
||||||
|
|
||||||
|
job&.do
|
||||||
|
|
||||||
|
sleep 0.1
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def add_job(job)
|
||||||
|
@jobs << job
|
||||||
|
end
|
||||||
|
|
||||||
|
class Job
|
||||||
|
def initialize(job, callback, deliver_to_queue = false)
|
||||||
|
@job = job
|
||||||
|
@callback = callback
|
||||||
|
|
||||||
|
@deliver_to_queue = deliver_to_queue
|
||||||
|
end
|
||||||
|
|
||||||
|
def do
|
||||||
|
result = @job.call
|
||||||
|
deliver(result)
|
||||||
|
end
|
||||||
|
|
||||||
|
def deliver(result)
|
||||||
|
if @deliver_to_queue
|
||||||
|
$window.main_thread_queue << -> { @callback.call(result) }
|
||||||
|
else
|
||||||
|
@callback.call(result)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
15
lib/cache.rb
15
lib/cache.rb
@@ -13,17 +13,10 @@ class W3DHub
|
|||||||
if !force_fetch && File.exist?(path)
|
if !force_fetch && File.exist?(path)
|
||||||
path
|
path
|
||||||
else
|
else
|
||||||
internet = Async::HTTP::Internet.instance
|
BackgroundWorker.job(
|
||||||
|
-> { Async::HTTP::Internet.instance.get(uri, W3DHub::Api::DEFAULT_HEADERS) },
|
||||||
response = internet.get(uri, W3DHub::Api::DEFAULT_HEADERS)
|
->(response) { response.save(path, "wb") if response.success? }
|
||||||
|
)
|
||||||
if response.success?
|
|
||||||
response.save(path, "wb")
|
|
||||||
|
|
||||||
return path
|
|
||||||
end
|
|
||||||
|
|
||||||
false
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -60,25 +60,20 @@ class W3DHub
|
|||||||
para I18n.t(:"games.fetching_news"), padding: 8
|
para I18n.t(:"games.fetching_news"), padding: 8
|
||||||
end
|
end
|
||||||
|
|
||||||
Async do
|
BackgroundWorker.foreground_job(-> { fetch_w3dhub_news }, ->(result) { populate_w3dhub_news })
|
||||||
internet = Async::HTTP::Internet.instance
|
|
||||||
|
|
||||||
fetch_w3dhub_news
|
|
||||||
populate_w3dhub_news
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def fetch_w3dhub_news
|
def fetch_w3dhub_news
|
||||||
news = Api.news("launcher-home")
|
news = Api.news("launcher-home")
|
||||||
|
|
||||||
if news
|
return unless news
|
||||||
news.items[0..9].each do |item|
|
|
||||||
Cache.fetch(item.image)
|
|
||||||
end
|
|
||||||
|
|
||||||
@w3dhub_news = news
|
news.items[0..9].each do |item|
|
||||||
|
Cache.fetch(item.image)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@w3dhub_news = news
|
||||||
end
|
end
|
||||||
|
|
||||||
def populate_w3dhub_news
|
def populate_w3dhub_news
|
||||||
|
|||||||
@@ -171,23 +171,20 @@ class W3DHub
|
|||||||
title I18n.t(:"games.fetching_news"), padding: 8
|
title I18n.t(:"games.fetching_news"), padding: 8
|
||||||
end
|
end
|
||||||
|
|
||||||
Async do
|
BackgroundWorker.foreground_job(-> { fetch_game_news(game) }, ->(result) { populate_game_news(game) })
|
||||||
fetch_game_news(game)
|
|
||||||
populate_game_news(game)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def fetch_game_news(game)
|
def fetch_game_news(game)
|
||||||
news = Api.news(game.id)
|
news = Api.news(game.id)
|
||||||
|
|
||||||
if news
|
return unless news
|
||||||
news.items[0..9].each do |item|
|
|
||||||
Cache.fetch(item.image)
|
|
||||||
end
|
|
||||||
|
|
||||||
@game_news[game.id] = news
|
news.items[0..9].each do |item|
|
||||||
|
Cache.fetch(item.image)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@game_news[game.id] = news
|
||||||
end
|
end
|
||||||
|
|
||||||
def populate_game_news(game)
|
def populate_game_news(game)
|
||||||
|
|||||||
@@ -36,15 +36,12 @@ class W3DHub
|
|||||||
|
|
||||||
# Do network stuff
|
# Do network stuff
|
||||||
|
|
||||||
Async do
|
Api.on_fiber(:user_login, @username.value, @password.value) do |account|
|
||||||
account = Api.user_login(@username.value, @password.value)
|
|
||||||
|
|
||||||
if account
|
if account
|
||||||
Store.account = account
|
Store.account = account
|
||||||
Store.settings[:account][:data] = account
|
Store.settings[:account][:data] = account
|
||||||
Store.settings.save_settings
|
Store.settings.save_settings
|
||||||
|
|
||||||
internet = Async::HTTP::Internet.instance
|
|
||||||
Cache.fetch(account.avatar_uri, true)
|
Cache.fetch(account.avatar_uri, true)
|
||||||
|
|
||||||
populate_account_info
|
populate_account_info
|
||||||
@@ -71,12 +68,13 @@ class W3DHub
|
|||||||
end
|
end
|
||||||
|
|
||||||
if Store.account
|
if Store.account
|
||||||
Async do
|
BackgroundWorker.foreground_job(
|
||||||
Cache.fetch(Store.account.avatar_uri)
|
-> { Cache.fetch(Store.account.avatar_uri) },
|
||||||
|
->(result) {
|
||||||
populate_account_info
|
populate_account_info
|
||||||
page(W3DHub::Pages::Games)
|
page(W3DHub::Pages::Games)
|
||||||
end
|
}
|
||||||
|
)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -130,11 +130,14 @@ class W3DHub
|
|||||||
populate_server_list
|
populate_server_list
|
||||||
|
|
||||||
if @selected_server&.id == @refresh_server&.id
|
if @selected_server&.id == @refresh_server&.id
|
||||||
Async do
|
if @refresh_server
|
||||||
fetch_server_details(@refresh_server) if @refresh_server
|
BackgroundWorker.foreground_job(
|
||||||
populate_server_info(@refresh_server) if @refresh_server && @refresh_server == @selected_server
|
-> { fetch_server_details(@refresh_server) },
|
||||||
|
->(result) {
|
||||||
@refresh_server = nil
|
populate_server_info(@refresh_server) if @refresh_server == @selected_server
|
||||||
|
@refresh_server = nil
|
||||||
|
}
|
||||||
|
)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -222,10 +225,10 @@ class W3DHub
|
|||||||
|
|
||||||
@selected_server = server
|
@selected_server = server
|
||||||
|
|
||||||
Async do
|
BackgroundWorker.foreground_job(
|
||||||
fetch_server_details(server)
|
-> { fetch_server_details(server) },
|
||||||
populate_server_info(server) if server == @selected_server
|
->(result) { populate_server_info(server) if server == @selected_server }
|
||||||
end
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
stylize_selected_server(server_container) if server.id == @selected_server&.id
|
stylize_selected_server(server_container) if server.id == @selected_server&.id
|
||||||
@@ -352,12 +355,10 @@ class W3DHub
|
|||||||
end
|
end
|
||||||
|
|
||||||
def fetch_server_details(server)
|
def fetch_server_details(server)
|
||||||
Async do
|
BackgroundWorker.foreground_job(
|
||||||
internet = Async::HTTP::Internet.instance
|
-> { Api.server_details(server.id, 2) },
|
||||||
|
->(server_data) { server.update(server_data) if server_data }
|
||||||
server_data = Api.server_details(internet, server.id, 2)
|
)
|
||||||
server.update(server_data) if server_data
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def game_icon(server)
|
def game_icon(server)
|
||||||
|
|||||||
@@ -31,17 +31,10 @@ class W3DHub
|
|||||||
inscription "#{I18n.t(:app_name)} #{W3DHub::VERSION}", width: 0.5, text_align: :right
|
inscription "#{I18n.t(:app_name)} #{W3DHub::VERSION}", width: 0.5, text_align: :right
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
Async do
|
|
||||||
@tasks.keys.each do |key|
|
|
||||||
Sync do
|
|
||||||
send(key)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def draw
|
def draw
|
||||||
|
Gosu.draw_circle(window.width / 2, window.height / 2, @w3dhub_logo.width * Gosu.milliseconds / 1000.0 % 500, 128, 0x44_000000, 32)
|
||||||
@w3dhub_logo.draw_rot(window.width / 2, window.height / 2, 32)
|
@w3dhub_logo.draw_rot(window.width / 2, window.height / 2, 32)
|
||||||
|
|
||||||
super
|
super
|
||||||
@@ -57,69 +50,94 @@ class W3DHub
|
|||||||
|
|
||||||
push_state(States::Interface) if @progressbar.value >= 1.0 && @task_index == @tasks.size
|
push_state(States::Interface) if @progressbar.value >= 1.0 && @task_index == @tasks.size
|
||||||
|
|
||||||
|
task = @tasks[@tasks.keys[@task_index]]
|
||||||
|
|
||||||
|
if task && !task[:started]
|
||||||
|
task[:started] = true
|
||||||
|
send(@tasks.keys[@task_index])
|
||||||
|
end
|
||||||
|
|
||||||
@task_index += 1 if @tasks.dig(@tasks.keys[@task_index], :complete)
|
@task_index += 1 if @tasks.dig(@tasks.keys[@task_index], :complete)
|
||||||
end
|
end
|
||||||
|
|
||||||
def refresh_user_token
|
def refresh_user_token
|
||||||
|
p :refresh_user_token
|
||||||
|
|
||||||
if Store.settings[:account, :data]
|
if Store.settings[:account, :data]
|
||||||
account = Api::Account.new(Store.settings[:account, :data], {})
|
account = Api::Account.new(Store.settings[:account, :data], {})
|
||||||
|
|
||||||
if (account.access_token_expiry - Time.now) / 60 <= 60 * 3 # Refresh if token expires within 3 hours
|
if (account.access_token_expiry - Time.now) / 60 <= 60 * 3 # Refresh if token expires within 3 hours
|
||||||
puts "Refreshing user login..."
|
puts "Refreshing user login..."
|
||||||
@account = Api.refresh_user_login(account.refresh_token)
|
|
||||||
|
Api.on_fiber(:refresh_user_login, account.refresh_token) do |refreshed_account|
|
||||||
|
update_account_data(refreshed_account)
|
||||||
|
end
|
||||||
|
|
||||||
else
|
else
|
||||||
@account = account
|
update_account_data(account)
|
||||||
end
|
end
|
||||||
|
|
||||||
if @account
|
|
||||||
Store.account = @account
|
|
||||||
|
|
||||||
Store.settings[:account][:data] = @account
|
|
||||||
|
|
||||||
Cache.fetch(@account.avatar_uri, true)
|
|
||||||
else
|
|
||||||
Store.settings[:account] = {}
|
|
||||||
end
|
|
||||||
|
|
||||||
Store.settings.save_settings
|
|
||||||
|
|
||||||
@tasks[:refresh_user_token][:complete] = true
|
|
||||||
else
|
else
|
||||||
@tasks[:refresh_user_token][:complete] = true
|
@tasks[:refresh_user_token][:complete] = true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def service_status
|
def update_account_data(account)
|
||||||
@service_status = Api.service_status
|
if account
|
||||||
|
Store.account = account
|
||||||
|
|
||||||
if @service_status
|
Store.settings[:account][:data] = account
|
||||||
Store.service_status = @service_status
|
|
||||||
|
|
||||||
if !@service_status.authentication? || !@service_status.package_download?
|
Cache.fetch(account.avatar_uri, true)
|
||||||
@status_label.value = "Authentication is #{@service_status.authentication? ? 'Okay' : 'Down'}. Package Download is #{@service_status.package_download? ? 'Okay' : 'Down'}."
|
|
||||||
end
|
|
||||||
|
|
||||||
@tasks[:service_status][:complete] = true
|
|
||||||
else
|
else
|
||||||
@status_label.value = I18n.t(:"boot.w3dhub_service_is_down")
|
Store.settings[:account] = {}
|
||||||
|
end
|
||||||
|
|
||||||
|
Store.settings.save_settings
|
||||||
|
|
||||||
|
@tasks[:refresh_user_token][:complete] = true
|
||||||
|
end
|
||||||
|
|
||||||
|
def service_status
|
||||||
|
p :service_status
|
||||||
|
|
||||||
|
Api.on_fiber(:service_status) do |service_status|
|
||||||
|
@service_status = service_status
|
||||||
|
|
||||||
|
if @service_status
|
||||||
|
Store.service_status = @service_status
|
||||||
|
|
||||||
|
if !@service_status.authentication? || !@service_status.package_download?
|
||||||
|
@status_label.value = "Authentication is #{@service_status.authentication? ? 'Okay' : 'Down'}. Package Download is #{@service_status.package_download? ? 'Okay' : 'Down'}."
|
||||||
|
end
|
||||||
|
|
||||||
|
@tasks[:service_status][:complete] = true
|
||||||
|
else
|
||||||
|
@status_label.value = I18n.t(:"boot.w3dhub_service_is_down")
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def applications
|
def applications
|
||||||
|
p :applications
|
||||||
|
|
||||||
@status_label.value = I18n.t(:"boot.checking_for_updates")
|
@status_label.value = I18n.t(:"boot.checking_for_updates")
|
||||||
|
|
||||||
@applications = Api.applications
|
Api.on_fiber(:applications) do |applications|
|
||||||
|
if applications
|
||||||
|
Store.applications = applications
|
||||||
|
|
||||||
if @applications
|
@tasks[:applications][:complete] = true
|
||||||
Store.applications = @applications
|
else
|
||||||
|
# FIXME: Failed to retreive!
|
||||||
@tasks[:applications][:complete] = true
|
@status_label.value = "FAILED TO RETREIVE APPS LIST"
|
||||||
else
|
end
|
||||||
# FIXME: Failed to retreive!
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def app_icons
|
def app_icons
|
||||||
|
puts :app_icons
|
||||||
|
|
||||||
return unless Store.applications
|
return unless Store.applications
|
||||||
|
|
||||||
packages = []
|
packages = []
|
||||||
@@ -127,8 +145,10 @@ class W3DHub
|
|||||||
packages << { category: app.category, subcategory: app.id, name: "#{app.id}.ico", version: "" }
|
packages << { category: app.category, subcategory: app.id, name: "#{app.id}.ico", version: "" }
|
||||||
end
|
end
|
||||||
|
|
||||||
if (package_details = Api.package_details(packages))
|
Api.on_fiber(:package_details, packages) do |package_details|
|
||||||
package_details.each do |package|
|
puts "Got response?"
|
||||||
|
|
||||||
|
package_details&.each do |package|
|
||||||
path = Cache.package_path(package.category, package.subcategory, package.name, package.version)
|
path = Cache.package_path(package.category, package.subcategory, package.name, package.version)
|
||||||
generated_icon_path = "#{GAME_ROOT_PATH}/media/icons/#{package.subcategory}.png"
|
generated_icon_path = "#{GAME_ROOT_PATH}/media/icons/#{package.subcategory}.png"
|
||||||
|
|
||||||
@@ -145,37 +165,29 @@ class W3DHub
|
|||||||
|
|
||||||
if regenerate
|
if regenerate
|
||||||
ico = ICO.new(file: path)
|
ico = ICO.new(file: path)
|
||||||
image = ico.images.sort_by(&:width).last
|
image = ico.images.max_by(&:width)
|
||||||
|
|
||||||
ico.save(image, generated_icon_path)
|
ico.save(image, generated_icon_path)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
@tasks[:app_icons][:complete] = true
|
@tasks[:app_icons][:complete] = true
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def server_list
|
def server_list
|
||||||
|
puts :server_list
|
||||||
|
|
||||||
@status_label.value = I18n.t(:"server_browser.fetching_server_list")
|
@status_label.value = I18n.t(:"server_browser.fetching_server_list")
|
||||||
|
|
||||||
begin
|
Api.on_fiber(:server_list, 2) do |list|
|
||||||
internet = Async::HTTP::Internet.instance
|
Store.server_list = list.sort_by! { |s| s&.status&.players&.size }.reverse if list
|
||||||
|
|
||||||
list = Api.server_list(internet, 2)
|
|
||||||
|
|
||||||
if list
|
|
||||||
Store.server_list = list.sort_by! { |s| s&.status&.players&.size }.reverse
|
|
||||||
end
|
|
||||||
|
|
||||||
Store.server_list_last_fetch = Gosu.milliseconds
|
Store.server_list_last_fetch = Gosu.milliseconds
|
||||||
|
|
||||||
Api::ServerListUpdater.instance
|
Api::ServerListUpdater.instance
|
||||||
|
|
||||||
@tasks[:server_list][:complete] = true
|
@tasks[:server_list][:complete] = true
|
||||||
rescue => e
|
|
||||||
# Something went wrong!
|
|
||||||
pp e
|
|
||||||
Store.server_list = []
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -23,9 +23,6 @@ class W3DHub
|
|||||||
super
|
super
|
||||||
|
|
||||||
Store.application_manager.start_next_available_task if Store.application_manager.idle?
|
Store.application_manager.start_next_available_task if Store.application_manager.idle?
|
||||||
|
|
||||||
current = Async::Task.current?
|
|
||||||
current&.yield
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def gain_focus
|
def gain_focus
|
||||||
|
|||||||
@@ -45,6 +45,7 @@ require_relative "lib/settings"
|
|||||||
require_relative "lib/mixer"
|
require_relative "lib/mixer"
|
||||||
require_relative "lib/ico"
|
require_relative "lib/ico"
|
||||||
require_relative "lib/multicast_server"
|
require_relative "lib/multicast_server"
|
||||||
|
require_relative "lib/background_worker"
|
||||||
require_relative "lib/application_manager"
|
require_relative "lib/application_manager"
|
||||||
require_relative "lib/application_manager/manifest"
|
require_relative "lib/application_manager/manifest"
|
||||||
require_relative "lib/application_manager/status"
|
require_relative "lib/application_manager/status"
|
||||||
@@ -79,8 +80,8 @@ require_relative "lib/pages/login"
|
|||||||
require_relative "lib/pages/settings"
|
require_relative "lib/pages/settings"
|
||||||
require_relative "lib/pages/download_manager"
|
require_relative "lib/pages/download_manager"
|
||||||
|
|
||||||
Async do
|
Thread.new do
|
||||||
W3DHub::Window.new(width: 980, height: 720, borderless: false).show
|
W3DHub::BackgroundWorker.create
|
||||||
|
|
||||||
exit # ensure reactor is shutdown when window is closed
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
W3DHub::Window.new(width: 980, height: 720, borderless: false).show
|
||||||
|
|||||||
Reference in New Issue
Block a user