diff --git a/lib/pages/community.rb b/lib/pages/community.rb index 36e4987..c268709 100644 --- a/lib/pages/community.rb +++ b/lib/pages/community.rb @@ -3,6 +3,7 @@ class W3DHub class Community < Page def setup @w3dhub_news ||= nil + @w3dhub_news_expires ||= 0 body.clear do stack(width: 1.0, height: 1.0, padding: 8) do @@ -76,6 +77,30 @@ class W3DHub 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 lock = Cache.acquire_net_lock("w3dhub_news") return false unless lock @@ -90,6 +115,7 @@ class W3DHub end @w3dhub_news = news + @w3dhub_news_expires = Gosu.milliseconds + (60 * 60 * 1000) # 1 hour (in ms) "w3dhub_news" end diff --git a/lib/pages/games.rb b/lib/pages/games.rb index 44b07c6..f84e7bc 100644 --- a/lib/pages/games.rb +++ b/lib/pages/games.rb @@ -37,6 +37,7 @@ class W3DHub if Gosu.milliseconds >= @game_news["#{key}_expires"] @game_news.delete(key) + @game_news["#{key}_expires"] = Gosu.milliseconds + 10_000 # seconds if @focused_game && @focused_game.id == key @game_news_container.clear do