mirror of
https://github.com/cyberarm/w3d_hub_linux_launcher.git
synced 2025-12-16 09:12:35 +00:00
Update community news every hour, added 10 second delay between fetch attempts to prevent making a bunch of unneeded requests
This commit is contained in:
@@ -3,6 +3,7 @@ class W3DHub
|
|||||||
class Community < Page
|
class Community < Page
|
||||||
def setup
|
def setup
|
||||||
@w3dhub_news ||= nil
|
@w3dhub_news ||= nil
|
||||||
|
@w3dhub_news_expires ||= 0
|
||||||
|
|
||||||
body.clear do
|
body.clear do
|
||||||
stack(width: 1.0, height: 1.0, padding: 8) do
|
stack(width: 1.0, height: 1.0, padding: 8) do
|
||||||
@@ -76,6 +77,30 @@ class W3DHub
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def update
|
||||||
|
super
|
||||||
|
|
||||||
|
|
||||||
|
if Gosu.milliseconds >= @w3dhub_news_expires
|
||||||
|
@w3dhub_news = nil
|
||||||
|
@w3dhub_news_expires = Gosu.milliseconds + 10_000 # seconds
|
||||||
|
|
||||||
|
@wd3hub_news_container.clear do
|
||||||
|
title I18n.t(:"games.fetching_news"), padding: 8
|
||||||
|
end
|
||||||
|
|
||||||
|
BackgroundWorker.foreground_job(
|
||||||
|
-> { fetch_w3dhub_news },
|
||||||
|
lambda do |result|
|
||||||
|
if result
|
||||||
|
populate_w3dhub_news
|
||||||
|
Cache.release_net_lock(result)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def fetch_w3dhub_news
|
def fetch_w3dhub_news
|
||||||
lock = Cache.acquire_net_lock("w3dhub_news")
|
lock = Cache.acquire_net_lock("w3dhub_news")
|
||||||
return false unless lock
|
return false unless lock
|
||||||
@@ -90,6 +115,7 @@ class W3DHub
|
|||||||
end
|
end
|
||||||
|
|
||||||
@w3dhub_news = news
|
@w3dhub_news = news
|
||||||
|
@w3dhub_news_expires = Gosu.milliseconds + (60 * 60 * 1000) # 1 hour (in ms)
|
||||||
|
|
||||||
"w3dhub_news"
|
"w3dhub_news"
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -37,6 +37,7 @@ class W3DHub
|
|||||||
|
|
||||||
if Gosu.milliseconds >= @game_news["#{key}_expires"]
|
if Gosu.milliseconds >= @game_news["#{key}_expires"]
|
||||||
@game_news.delete(key)
|
@game_news.delete(key)
|
||||||
|
@game_news["#{key}_expires"] = Gosu.milliseconds + 10_000 # seconds
|
||||||
|
|
||||||
if @focused_game && @focused_game.id == key
|
if @focused_game && @focused_game.id == key
|
||||||
@game_news_container.clear do
|
@game_news_container.clear do
|
||||||
|
|||||||
Reference in New Issue
Block a user