mirror of
https://github.com/cyberarm/w3d_hub_linux_launcher.git
synced 2025-12-16 09:12:35 +00:00
Replaced most Excon + Thread calls with Async
This commit is contained in:
@@ -56,23 +56,25 @@ class W3DHub
|
||||
if @w3dhub_news
|
||||
populate_w3dhub_news
|
||||
else
|
||||
Thread.new do
|
||||
fetch_w3dhub_news
|
||||
main_thread_queue << proc { populate_w3dhub_news }
|
||||
end
|
||||
|
||||
@wd3hub_news_container.clear do
|
||||
para I18n.t(:"games.fetching_news"), padding: 8
|
||||
end
|
||||
|
||||
Async do
|
||||
internet = Async::HTTP::Internet.instance
|
||||
|
||||
fetch_w3dhub_news(internet)
|
||||
populate_w3dhub_news
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def fetch_w3dhub_news
|
||||
news = Api.news("launcher-home")
|
||||
def fetch_w3dhub_news(internet)
|
||||
news = Api.news(internet, "launcher-home")
|
||||
|
||||
if news
|
||||
news.items[0..9].each do |item|
|
||||
Cache.fetch(item.image)
|
||||
Cache.fetch(internet, item.image)
|
||||
end
|
||||
|
||||
@w3dhub_news = news
|
||||
|
||||
@@ -159,23 +159,25 @@ class W3DHub
|
||||
if @game_news[game.id]
|
||||
populate_game_news(game)
|
||||
else
|
||||
Thread.new do
|
||||
fetch_game_news(game)
|
||||
main_thread_queue << proc { populate_game_news(game) }
|
||||
end
|
||||
|
||||
@game_news_container.clear do
|
||||
title I18n.t(:"games.fetching_news"), padding: 8
|
||||
end
|
||||
|
||||
Async do
|
||||
internet = Async::HTTP::Internet.instance
|
||||
|
||||
fetch_game_news(internet, game)
|
||||
populate_game_news(game)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def fetch_game_news(game)
|
||||
news = Api.news(game.id)
|
||||
def fetch_game_news(internet, game)
|
||||
news = Api.news(internet, game.id)
|
||||
|
||||
if news
|
||||
news.items[0..9].each do |item|
|
||||
Cache.fetch(item.image)
|
||||
Cache.fetch(internet, item.image)
|
||||
end
|
||||
|
||||
@game_news[game.id] = news
|
||||
|
||||
@@ -36,27 +36,27 @@ class W3DHub
|
||||
|
||||
# Do network stuff
|
||||
|
||||
Thread.new do
|
||||
account = Api.user_login(@username.value, @password.value)
|
||||
Async do
|
||||
internet = Async::HTTP::Internet.instance
|
||||
|
||||
account = Api.user_login(internet, @username.value, @password.value)
|
||||
|
||||
if account
|
||||
Store.account = account
|
||||
Store.settings[:account][:refresh_token] = account.refresh_token
|
||||
Store.settings.save_settings
|
||||
|
||||
Cache.fetch(account.avatar_uri)
|
||||
Cache.fetch(internet, account.avatar_uri)
|
||||
|
||||
main_thread_queue << proc { populate_account_info; page(W3DHub::Pages::Games) }
|
||||
populate_account_info; page(W3DHub::Pages::Games)
|
||||
else
|
||||
# An error occurred, enable account entry
|
||||
# NOTE: Too many incorrect entries causes lock out (Unknown duration)
|
||||
main_thread_queue << proc do
|
||||
@username.enabled = true
|
||||
@password.enabled = true
|
||||
btn.enabled = true
|
||||
@username.enabled = true
|
||||
@password.enabled = true
|
||||
btn.enabled = true
|
||||
|
||||
@error_label.value = "Incorrect username or password.\nOr too many failed login attempts."
|
||||
end
|
||||
@error_label.value = "Incorrect username or password.\nOr too many failed login attempts, try again in a few minutes."
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -318,9 +318,11 @@ class W3DHub
|
||||
return
|
||||
end
|
||||
|
||||
Thread.new do
|
||||
Async do
|
||||
internet = Async::HTTP::Internet.instance
|
||||
|
||||
begin
|
||||
list = Api.server_list(2)
|
||||
list = Api.server_list(internet, 2)
|
||||
|
||||
if list
|
||||
Store.server_list = list.sort_by! { |s| s&.status&.players&.size }.reverse
|
||||
|
||||
Reference in New Issue
Block a user