mirror of
https://github.com/cyberarm/w3d_hub_linux_launcher.git
synced 2026-03-22 04:06:18 +00:00
Compare commits
5 Commits
f651143937
...
ebc045019a
| Author | SHA1 | Date | |
|---|---|---|---|
| ebc045019a | |||
| 79858a02ce | |||
| 68df923bea | |||
| ddbec8d72c | |||
| 70d4e0c40f |
@@ -61,7 +61,7 @@ class W3DHub
|
|||||||
States::Interface.instance&.update_server_ping(self)
|
States::Interface.instance&.update_server_ping(self)
|
||||||
end
|
end
|
||||||
|
|
||||||
return unless W3DHub.windows?
|
return #unless W3DHub.windows?
|
||||||
|
|
||||||
W3DHub::BackgroundWorker.foreground_parallel_job(
|
W3DHub::BackgroundWorker.foreground_parallel_job(
|
||||||
lambda do
|
lambda do
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
14
lib/cache.rb
14
lib/cache.rb
@@ -9,19 +9,17 @@ class W3DHub
|
|||||||
end
|
end
|
||||||
|
|
||||||
# Fetch a generic uri
|
# Fetch a generic uri
|
||||||
def self.fetch(uri:, force_fetch: false, async: true, backend: :w3dhub)
|
def self.fetch(uri:, force_fetch: false, backend: :w3dhub)
|
||||||
path = path(uri)
|
path = path(uri)
|
||||||
|
|
||||||
if !force_fetch && File.exist?(path)
|
if !force_fetch && File.exist?(path)
|
||||||
path
|
path
|
||||||
elsif async
|
|
||||||
BackgroundWorker.job(
|
|
||||||
-> { Api.fetch(uri, W3DHub::Api::DEFAULT_HEADERS, nil, backend) },
|
|
||||||
->(response) { File.open(path, "wb") { |f| f.write response.body } if response.status == 200 }
|
|
||||||
)
|
|
||||||
else
|
else
|
||||||
response = Api.fetch(uri, W3DHub::Api::DEFAULT_HEADERS, nil, backend)
|
Api.fetch(uri, W3DHub::Api::DEFAULT_HEADERS, nil, backend) do |result|
|
||||||
File.open(path, "wb") { |f| f.write response.body } if response.status == 200
|
if result.okay?
|
||||||
|
File.open(path, "wb") { |f| f.write result.data }
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ class W3DHub
|
|||||||
# all http(s) requests for API calls and downloading images run through here
|
# all http(s) requests for API calls and downloading images run through here
|
||||||
class NetworkManager
|
class NetworkManager
|
||||||
NetworkEvent = Data.define(:context, :result)
|
NetworkEvent = Data.define(:context, :result)
|
||||||
Request = Struct.new(:context, :callback)
|
Request = Struct.new(:active, :context, :callback)
|
||||||
Context = Data.define(
|
Context = Data.define(
|
||||||
:request_id,
|
:request_id,
|
||||||
:method,
|
:method,
|
||||||
@@ -21,7 +21,7 @@ class W3DHub
|
|||||||
|
|
||||||
Sync do
|
Sync do
|
||||||
while @running
|
while @running
|
||||||
request = @requests.shift
|
request = @requests.find { |r| !r.active }
|
||||||
|
|
||||||
# goto sleep for an second if there is no work to be doing
|
# goto sleep for an second if there is no work to be doing
|
||||||
unless request
|
unless request
|
||||||
@@ -29,11 +29,13 @@ class W3DHub
|
|||||||
next
|
next
|
||||||
end
|
end
|
||||||
|
|
||||||
|
request.active = true
|
||||||
|
|
||||||
Async do |task|
|
Async do |task|
|
||||||
assigned_request = request
|
assigned_request = request
|
||||||
result = http_client.handle(task, assigned_request)
|
result = http_client.handle(task, assigned_request)
|
||||||
|
|
||||||
pp [assigned_request, result]
|
@requests.delete(assigned_request)
|
||||||
|
|
||||||
Store.main_thread_queue << -> { assigned_request.callback.call(result) }
|
Store.main_thread_queue << -> { assigned_request.callback.call(result) }
|
||||||
end
|
end
|
||||||
@@ -46,6 +48,7 @@ class W3DHub
|
|||||||
request_id = SecureRandom.hex
|
request_id = SecureRandom.hex
|
||||||
|
|
||||||
request = Request.new(
|
request = Request.new(
|
||||||
|
false,
|
||||||
Context.new(
|
Context.new(
|
||||||
request_id,
|
request_id,
|
||||||
method,
|
method,
|
||||||
@@ -61,5 +64,9 @@ class W3DHub
|
|||||||
|
|
||||||
request_id
|
request_id
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def busy?
|
||||||
|
@requests.any?(&:active)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -295,15 +295,15 @@ class W3DHub
|
|||||||
if @game_events[game.id]
|
if @game_events[game.id]
|
||||||
populate_game_events(game)
|
populate_game_events(game)
|
||||||
else
|
else
|
||||||
BackgroundWorker.foreground_job(
|
# BackgroundWorker.foreground_job(
|
||||||
-> { fetch_game_events(game) },
|
# -> { fetch_game_events(game) },
|
||||||
lambda do |result|
|
# lambda do |result|
|
||||||
if result
|
# if result
|
||||||
populate_game_events(game)
|
# populate_game_events(game)
|
||||||
Cache.release_net_lock(result)
|
# Cache.release_net_lock(result)
|
||||||
end
|
# end
|
||||||
end
|
# end
|
||||||
)
|
# )
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -315,15 +315,15 @@ class W3DHub
|
|||||||
title I18n.t(:"games.fetching_news"), padding: 8
|
title I18n.t(:"games.fetching_news"), padding: 8
|
||||||
end
|
end
|
||||||
|
|
||||||
BackgroundWorker.foreground_job(
|
# BackgroundWorker.foreground_job(
|
||||||
-> { fetch_game_news(game) },
|
# -> { fetch_game_news(game) },
|
||||||
lambda do |result|
|
# lambda do |result|
|
||||||
if result
|
# if result
|
||||||
populate_game_news(game)
|
# populate_game_news(game)
|
||||||
Cache.release_net_lock(result)
|
# Cache.release_net_lock(result)
|
||||||
end
|
# end
|
||||||
end
|
# end
|
||||||
)
|
# )
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -34,9 +34,8 @@ class W3DHub
|
|||||||
|
|
||||||
# Do network stuff
|
# Do network stuff
|
||||||
|
|
||||||
BackgroundWorker.foreground_job(
|
Api.user_login(@username.value, @password.value) do |result|
|
||||||
lambda do
|
if result.okay?
|
||||||
account = Api.user_login(@username.value, @password.value)
|
|
||||||
applications = nil
|
applications = nil
|
||||||
|
|
||||||
if account
|
if account
|
||||||
@@ -45,14 +44,15 @@ class W3DHub
|
|||||||
Store.settings.save_settings
|
Store.settings.save_settings
|
||||||
|
|
||||||
if account
|
if account
|
||||||
Cache.fetch(uri: account.avatar_uri, force_fetch: true, async: false, backend: :w3dhub)
|
Cache.fetch(uri: account.avatar_uri, force_fetch: true, backend: :w3dhub) {}
|
||||||
applications = Api._applications
|
Api._applications do |r|
|
||||||
|
applications = r.result if r.okay?
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
[account, applications]
|
[account, applications]
|
||||||
end,
|
else
|
||||||
lambda do |result|
|
|
||||||
account, applications = result
|
account, applications = result
|
||||||
|
|
||||||
if account
|
if account
|
||||||
@@ -70,7 +70,7 @@ class W3DHub
|
|||||||
@error_label.value = "Incorrect username or password.\nOr too many failed login attempts, try again in a few minutes."
|
@error_label.value = "Incorrect username or password.\nOr too many failed login attempts, try again in a few minutes."
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
)
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@error_label = caption "", width: 1.0, text_align: :center, color: 0xff_800000
|
@error_label = caption "", width: 1.0, text_align: :center, color: 0xff_800000
|
||||||
@@ -80,13 +80,10 @@ class W3DHub
|
|||||||
end
|
end
|
||||||
|
|
||||||
if Store.account
|
if Store.account
|
||||||
BackgroundWorker.foreground_job(
|
Cache.fetch(uri: Store.account.avatar_uri, backend: :w3dhub) do |result|
|
||||||
-> { Cache.fetch(uri: Store.account.avatar_uri, async: false, backend: :w3dhub) },
|
|
||||||
->(result) {
|
|
||||||
populate_account_info
|
populate_account_info
|
||||||
page(W3DHub::Pages::Games)
|
page(W3DHub::Pages::Games)
|
||||||
}
|
end
|
||||||
)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -153,11 +150,9 @@ class W3DHub
|
|||||||
Store.settings.save_settings
|
Store.settings.save_settings
|
||||||
Store.account = nil
|
Store.account = nil
|
||||||
|
|
||||||
BackgroundWorker.foreground_job(
|
Api._applications do |result|
|
||||||
-> { Api._applications },
|
if result.okay?
|
||||||
lambda do |applications|
|
Store.applications = result.data
|
||||||
if applications
|
|
||||||
Store.applications = applications
|
|
||||||
page(W3DHub::Pages::Games) if @host.current_page.is_a?(W3DHub::Pages::Games)
|
page(W3DHub::Pages::Games) if @host.current_page.is_a?(W3DHub::Pages::Games)
|
||||||
page(W3DHub::Pages::ServerBrowser) if @host.current_page.is_a?(W3DHub::Pages::ServerBrowser)
|
page(W3DHub::Pages::ServerBrowser) if @host.current_page.is_a?(W3DHub::Pages::ServerBrowser)
|
||||||
end
|
end
|
||||||
@@ -175,7 +170,6 @@ class W3DHub
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -115,9 +115,8 @@ class W3DHub
|
|||||||
Api.on_thread(:refresh_user_login, account.refresh_token) do |refreshed_account|
|
Api.on_thread(:refresh_user_login, account.refresh_token) do |refreshed_account|
|
||||||
update_account_data(refreshed_account)
|
update_account_data(refreshed_account)
|
||||||
end
|
end
|
||||||
|
|
||||||
else
|
else
|
||||||
BackgroundWorker.foreground_job(-> { update_account_data(account) }, ->(_) {})
|
Store.main_thread_queue << -> { update_account_data(account) }
|
||||||
end
|
end
|
||||||
|
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
class W3DHub
|
class W3DHub
|
||||||
DIR_NAME = "W3DHubAlt".freeze
|
DIR_NAME = "W3DHubAlt".freeze
|
||||||
VERSION = "0.9.0".freeze
|
VERSION = "0.9.1".freeze
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -36,6 +36,8 @@ class W3DHub
|
|||||||
while (block = Store.main_thread_queue.shift)
|
while (block = Store.main_thread_queue.shift)
|
||||||
block&.call
|
block&.call
|
||||||
end
|
end
|
||||||
|
|
||||||
|
sleep(update_interval / 1000.0) if Store.application_manager.busy? || Store.network_manager.busy?
|
||||||
end
|
end
|
||||||
|
|
||||||
def needs_redraw?
|
def needs_redraw?
|
||||||
|
|||||||
@@ -228,27 +228,34 @@ class W3DHub
|
|||||||
@encrypted
|
@encrypted
|
||||||
end
|
end
|
||||||
|
|
||||||
def add_file(path:)
|
def add_file(path:, replace: false)
|
||||||
return false unless File.exist?(path)
|
return false unless File.exist?(path)
|
||||||
return false if File.directory?(path)
|
return false if File.directory?(path)
|
||||||
|
|
||||||
info = EntryInfoHeader.new(0, 0, File.size(path))
|
entry = Entry.new(name: File.basename(path), path: path, info: EntryInfoHeader.new(0, 0, File.size(path)))
|
||||||
@entries << Entry.new(name: File.basename(path), path: path, info: info)
|
add_entry(entry: entry, replace: replace)
|
||||||
|
|
||||||
true
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def add_blob(path:, blob:)
|
def add_blob(path:, blob:, replace: false)
|
||||||
info = EntryInfoHeader.new(0, 0, blob.size)
|
info = EntryInfoHeader.new(0, 0, blob.size)
|
||||||
@entries << Entry.new(name: File.basename(path), path: path, info: info, blob: blob)
|
entry = Entry.new(name: File.basename(path), path: path, info: info, blob: blob)
|
||||||
into.crc32 = @entries.last.calculate_crc32
|
into.crc32 = @entries.last.calculate_crc32
|
||||||
|
|
||||||
true
|
add_entry(entry: entry, replace: replace)
|
||||||
end
|
end
|
||||||
|
|
||||||
def add_entry(entry:)
|
def add_entry(entry:, replace: false)
|
||||||
@entries << entry
|
duplicate = @entries.find { |e| e.name.upcase == entry.name.upcase }
|
||||||
|
|
||||||
|
if duplicate
|
||||||
|
if replace
|
||||||
|
@entries.delete(duplicate)
|
||||||
|
else
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
@entries << entry
|
||||||
true
|
true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user