Fixed token refresh happening to often at startup, replace missing game icon image with question mark, add support for more wwconfig.exe naming funkiness...

This commit is contained in:
2022-02-04 18:36:20 -06:00
parent 7da254fd61
commit e3cb9805fe
7 changed files with 20 additions and 28 deletions

View File

@@ -9,7 +9,7 @@ class W3DHub
@games = [] @games = []
games.each { |hash| @games << Game.new(hash) } games.each { |hash| @games << Game.new(hash) }
@games.sort_by! { |a| a.slot }.reverse @games.sort_by! { |a| a.name }.reverse
end end
def games def games
@@ -17,13 +17,11 @@ class W3DHub
end end
class Game class Game
attr_reader :slot, :id, :name, :type, :category, :studio_id, :channels, :web_links, :color attr_reader :id, :name, :type, :category, :studio_id, :channels, :web_links, :color
def initialize(hash) def initialize(hash)
@data = hash @data = hash
@slot = slot_index(@data[:id])
@id = @data[:id] @id = @data[:id]
@name = @data[:name] @name = @data[:name]
@type = @data[:type] @type = @data[:type]
@@ -40,23 +38,6 @@ class W3DHub
@color = "ff#{color}".to_i(16) @color = "ff#{color}".to_i(16)
end end
private def slot_index(app_id)
case app_id
when "ren"
1
when "ecw"
2
when "ia"
3
when "apb"
4
when "tsr"
5
else
-10
end
end
class Channel class Channel
attr_reader :id, :name, :user_level, :current_version attr_reader :id, :name, :user_level, :current_version

View File

@@ -52,8 +52,15 @@ class W3DHub
# open wwconfig.exe or config.exe for ecw # open wwconfig.exe or config.exe for ecw
if (app_data = installed?(app_id, channel)) if (app_data = installed?(app_id, channel))
config_exe = app_id == "ecw" ? "config.exe" : "wwconfig.exe" exe = if File.exist?("#{app_data[:install_directory]}/wwconfig.exe")
exe = "#{app_data[:install_directory]}/#{config_exe}" "#{app_data[:install_directory]}/wwconfig.exe"
elsif File.exist?("#{app_data[:install_directory]}/WWConfig.exe")
"#{app_data[:install_directory]}/WWConfig.exe"
elsif File.exist?("#{app_data[:install_directory]}/config.exe")
"#{app_data[:install_directory]}/config.exe"
end
if File.exist?(exe) if File.exist?(exe)
pid = Process.spawn("#{wine_command(app_id, channel)}\"#{exe}\"") pid = Process.spawn("#{wine_command(app_id, channel)}\"#{exe}\"")

View File

@@ -115,10 +115,13 @@ class W3DHub
# Quick checks before network and computational work starts # Quick checks before network and computational work starts
def fail_fast def fail_fast
# Have enough disk space
# tar present? # tar present?
bsdtar_present = system("#{W3DHub.tar_command} --help") bsdtar_present = system("#{W3DHub.tar_command} --help")
fail!("FAIL FAST: `#{W3DHub.tar_command} --help` command failed, #{W3DHub.tar_command} is not installed. Will be unable to unpack packages.") unless bsdtar_present fail!("FAIL FAST: `#{W3DHub.tar_command} --help` command failed, #{W3DHub.tar_command} is not installed. Will be unable to unpack packages.") unless bsdtar_present
# Wine present?
if W3DHub.unix? if W3DHub.unix?
wine_present = system("which #{Store.settings[:wine_command]}") wine_present = system("which #{Store.settings[:wine_command]}")
fail!("FAIL FAST: `which #{Store.settings[:wine_command]}` command failed, wine is not installed. Will be unable to create prefixes or launch games.") unless wine_present fail!("FAIL FAST: `which #{Store.settings[:wine_command]}` command failed, wine is not installed. Will be unable to create prefixes or launch games.") unless wine_present

View File

@@ -28,7 +28,7 @@ class W3DHub
background task.application.color background task.application.color
flow(width: 0.70, height: 1.0) do flow(width: 0.70, height: 1.0) do
image_path = File.exist?("#{GAME_ROOT_PATH}/media/icons/#{task.app_id}.png") ? "#{GAME_ROOT_PATH}/media/icons/#{task.app_id}.png" : "#{GAME_ROOT_PATH}/media/icons/app.png" image_path = File.exist?("#{GAME_ROOT_PATH}/media/icons/#{task.app_id}.png") ? "#{GAME_ROOT_PATH}/media/icons/#{task.app_id}.png" : "#{GAME_ROOT_PATH}/media/ui_icons/question.png"
@application_image = image image_path, height: 1.0 @application_image = image image_path, height: 1.0
stack(margin_left: 8, width: 0.75) do stack(margin_left: 8, width: 0.75) do

View File

@@ -40,7 +40,7 @@ class W3DHub
image "#{GAME_ROOT_PATH}/media/ui_icons/return.png", width: 1.0, color: Gosu::Color::GRAY if Store.application_manager.updateable?(game.id, game.channels.first.id) image "#{GAME_ROOT_PATH}/media/ui_icons/return.png", width: 1.0, color: Gosu::Color::GRAY if Store.application_manager.updateable?(game.id, game.channels.first.id)
image "#{GAME_ROOT_PATH}/media/ui_icons/import.png", width: 0.5, color: 0x88_ffffff unless Store.application_manager.installed?(game.id, game.channels.first.id) image "#{GAME_ROOT_PATH}/media/ui_icons/import.png", width: 0.5, color: 0x88_ffffff unless Store.application_manager.installed?(game.id, game.channels.first.id)
end end
image_path = File.exist?("#{GAME_ROOT_PATH}/media/icons/#{game.id}.png") ? "#{GAME_ROOT_PATH}/media/icons/#{game.id}.png" : "#{GAME_ROOT_PATH}/media/icons/app.png" image_path = File.exist?("#{GAME_ROOT_PATH}/media/icons/#{game.id}.png") ? "#{GAME_ROOT_PATH}/media/icons/#{game.id}.png" : "#{GAME_ROOT_PATH}/media/ui_icons/question.png"
image image_path, height: 48, color: Store.application_manager.installed?(game.id, game.channels.first.id) ? 0xff_ffffff : 0x88_ffffff image image_path, height: 48, color: Store.application_manager.installed?(game.id, game.channels.first.id) ? 0xff_ffffff : 0x88_ffffff
end end

View File

@@ -26,7 +26,7 @@ class W3DHub
@filters.each do |app_id, enabled| @filters.each do |app_id, enabled|
app = Store.applications.games.find { |a| a.id == app_id.to_s } app = Store.applications.games.find { |a| a.id == app_id.to_s }
image_path = File.exist?("#{GAME_ROOT_PATH}/media/icons/#{app_id}.png") ? "#{GAME_ROOT_PATH}/media/icons/#{app_id}.png" : "#{GAME_ROOT_PATH}/media/icons/app.png" image_path = File.exist?("#{GAME_ROOT_PATH}/media/icons/#{app_id}.png") ? "#{GAME_ROOT_PATH}/media/icons/#{app_id}.png" : "#{GAME_ROOT_PATH}/media/ui_icons/question.png"
image image_path, tip: "#{app.name}", height: 1.0, image image_path, tip: "#{app.name}", height: 1.0,
border_thickness_bottom: 1, border_color_bottom: 0x00_000000, border_thickness_bottom: 1, border_color_bottom: 0x00_000000,
@@ -361,7 +361,7 @@ class W3DHub
end end
def game_icon(server) def game_icon(server)
image_path = File.exist?("#{GAME_ROOT_PATH}/media/icons/#{server.game.nil? ? 'ren' : server.game}.png") ? "#{GAME_ROOT_PATH}/media/icons/#{server.game.nil? ? 'ren' : server.game}.png" : "#{GAME_ROOT_PATH}/media/icons/app.png" image_path = File.exist?("#{GAME_ROOT_PATH}/media/icons/#{server.game.nil? ? 'ren' : server.game}.png") ? "#{GAME_ROOT_PATH}/media/icons/#{server.game.nil? ? 'ren' : server.game}.png" : "#{GAME_ROOT_PATH}/media/ui_icons/question.png"
if server.status.password if server.status.password
@server_locked_icons[server.game] ||= Gosu.render(96, 96) do @server_locked_icons[server.game] ||= Gosu.render(96, 96) do

View File

@@ -63,7 +63,8 @@ class W3DHub
if Store.settings[:account, :data] if Store.settings[:account, :data]
account = Api::Account.new(Store.settings[:account, :data], {}) account = Api::Account.new(Store.settings[:account, :data], {})
if (Time.now.to_i - account.access_token_expiry.to_i) >= 60 * 3 # Older than 3 hours then refresh if (account.access_token_expiry - Time.now) / 60 <= 60 * 3 # Refresh if token expires within 3 hours
puts "Refreshing user login..."
@account = Api.refresh_user_login(account.refresh_token) @account = Api.refresh_user_login(account.refresh_token)
else else
@account = account @account = account