mirror of
https://github.com/cyberarm/w3d_hub_linux_launcher.git
synced 2025-12-15 16:52:34 +00:00
Fixed race condition where images for user avatar or news icons were not blocking execution until after they were downloaded causing a possible crash due to trying to save and load at the same time (sometimes also causing images to be only partly saved making them corrupt causing another crash)
This commit is contained in:
@@ -7,16 +7,19 @@ class W3DHub
|
||||
end
|
||||
|
||||
# Fetch a generic uri
|
||||
def self.fetch(uri, force_fetch = false)
|
||||
def self.fetch(uri:, force_fetch: false, async: true)
|
||||
path = path(uri)
|
||||
|
||||
if !force_fetch && File.exist?(path)
|
||||
path
|
||||
else
|
||||
elsif async
|
||||
BackgroundWorker.job(
|
||||
-> { Async::HTTP::Internet.instance.get(uri, W3DHub::Api::DEFAULT_HEADERS) },
|
||||
->(response) { response.save(path, "wb") if response.success? }
|
||||
)
|
||||
else
|
||||
response = Async::HTTP::Internet.instance.get(uri, W3DHub::Api::DEFAULT_HEADERS)
|
||||
response.save(path, "wb") if response.success?
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -70,7 +70,7 @@ class W3DHub
|
||||
return unless news
|
||||
|
||||
news.items[0..9].each do |item|
|
||||
Cache.fetch(item.image)
|
||||
Cache.fetch(uri: item.image, async: false)
|
||||
end
|
||||
|
||||
@w3dhub_news = news
|
||||
|
||||
@@ -181,7 +181,7 @@ class W3DHub
|
||||
return unless news
|
||||
|
||||
news.items[0..9].each do |item|
|
||||
Cache.fetch(item.image)
|
||||
Cache.fetch(uri: item.image, async: false)
|
||||
end
|
||||
|
||||
@game_news[game.id] = news
|
||||
|
||||
@@ -46,7 +46,7 @@ class W3DHub
|
||||
Store.settings[:account][:data] = account
|
||||
Store.settings.save_settings
|
||||
|
||||
Cache.fetch(account.avatar_uri, true) if account
|
||||
Cache.fetch(account.avatar_uri, force_fetch: true, async: false) if account
|
||||
applications = Api.applications if account
|
||||
end
|
||||
|
||||
@@ -81,7 +81,7 @@ class W3DHub
|
||||
|
||||
if Store.account
|
||||
BackgroundWorker.foreground_job(
|
||||
-> { Cache.fetch(Store.account.avatar_uri) },
|
||||
-> { Cache.fetch(uri: Store.account.avatar_uri, async: false) },
|
||||
->(result) {
|
||||
populate_account_info
|
||||
page(W3DHub::Pages::Games)
|
||||
|
||||
@@ -71,7 +71,7 @@ class W3DHub
|
||||
end
|
||||
|
||||
else
|
||||
update_account_data(account)
|
||||
BackgroundWorker.foreground_job(-> { update_account_data(account) }, ->(_) {})
|
||||
end
|
||||
|
||||
else
|
||||
@@ -85,7 +85,7 @@ class W3DHub
|
||||
|
||||
Store.settings[:account][:data] = account
|
||||
|
||||
Cache.fetch(account.avatar_uri, true)
|
||||
Cache.fetch(uri: account.avatar_uri, force_fetch: true, async: false)
|
||||
else
|
||||
Store.settings[:account] = {}
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user