Fixed boot saving in a thread causing png based icons to be blank, improvements to server browser to show same team and score data as android app, fixed settings page not using a find height for containers causing them to not position properly on initial gui regeneration, task fail fast now checks for write access to target path, fail fast now raises an exception to prevent incorrect fail fast check from being reported.

This commit is contained in:
2022-02-21 09:29:40 -06:00
parent 9be118b1ad
commit 8ba577d5fd
8 changed files with 72 additions and 49 deletions

View File

@@ -1,6 +1,9 @@
class W3DHub
class ApplicationManager
class Task
class FailFast < RuntimeError
end
include CyberarmEngine::Common
attr_reader :app_id, :release_channel, :application, :channel,
@@ -59,6 +62,8 @@ class W3DHub
rescue RuntimeError => e
status = false
@task_failure_reason = e.message[0..512]
rescue FailFast
# no-op
end
# Force free some bytes
@@ -74,7 +79,8 @@ class W3DHub
end
end
def execute_task; end
def execute_task
end
# Suspend operation, if possible
def pause
@@ -111,6 +117,8 @@ class W3DHub
@task_failure_reason = reason.to_s
hide_application_taskbar
raise FailFast, @task_failure_reason
end
def fail_silently!
@@ -119,6 +127,20 @@ class W3DHub
# Quick checks before network and computational work starts
def fail_fast
# Have write permissions to target directory
path = Cache.install_path(@application, @channel)
path = Store.settings[:app_install_dir] unless File.exist?(path)
begin
File.write("#{path}/___can_write.wlh", "")
File.delete("#{path}/___can_write.wlh")
Dir.mkdir("#{path}/__can_write")
Dir.rmdir("#{path}/__can_write")
rescue Errno::EACCES
fail!("FAIL FAST: Cannot write to #{path}")
end
# Have enough disk space
# tar present?
@@ -133,7 +155,7 @@ class W3DHub
end
def run_on_main_thread(block)
window.main_thread_queue << block
Store.main_thread_queue << block
end
def send_message_dialog(type, title, message)

View File

@@ -71,7 +71,7 @@ class W3DHub
def deliver(result)
if @deliver_to_queue
$window.main_thread_queue << -> { @callback.call(result) }
Store.main_thread_queue << -> { @callback.call(result) }
else
@callback.call(result)
end

View File

@@ -15,10 +15,6 @@ class W3DHub
@options = {}
end
def main_thread_queue
@host.main_thread_queue
end
def options=(options)
@options = options
end

View File

@@ -170,7 +170,7 @@ class W3DHub
Store.server_list.each do |server|
next unless @filters[server.game.to_sym]
next unless server.region == @filter_region || @filter_region == "Any"
next unless server.channel == "release"
# next unless server.channel == "release"
i += 1
@@ -251,7 +251,7 @@ class W3DHub
game_updatable = Store.application_manager.updateable?(server.game, server.channel)
style = server.channel != "release" ? TESTING_BUTTON : {}
button "<b>#{I18n.t(:"server_browser.join_server")}</b>", enabled: (game_installed && !game_updatable), **style do
button "<b>#{I18n.t(:"server_browser.join_server")}</b>", margin_left: 96, enabled: (game_installed && !game_updatable), **style do
# Check for nickname
# prompt for nickname
# !abort unless nickname set
@@ -310,19 +310,24 @@ class W3DHub
game_balance = server_game_balance(server)
flow(width: 1.0, height: 0.05) do
stack(width: 0.465, height: 1.0) do
para "<b>#{server.status.teams[0].name}</b>", width: 1.0, text_align: :center
flow(width: 1.0, height: 0.1, border_thickness_bottom: 2, border_color_bottom: 0x44_ffffff) do
stack(width: 0.4, height: 1.0) do
para "<b>#{server.status.teams[0].name} (#{server.status.players.select { |pl| pl.team == 0 }.count})</b>", width: 1.0, text_align: :center
para game_balance[:team_0_score].to_i.to_s, width: 1.0, text_align: :center
end
image game_balance[:icon], height: 1.0, tip: game_balance[:message], color: game_balance[:color]
stack(width: 0.2, height: 1.0) do
image game_balance[:icon], height: 0.5, margin_left: 20, tip: game_balance[:message], color: game_balance[:color]
para game_balance[:ratio].round(2).to_s, width: 1.0, text_align: :center
end
stack(width: 0.46, height: 1.0) do
para "<b>#{server.status.teams[1].name}</b>", width: 1.0, text_align: :center
stack(width: 0.4, height: 1.0) do
para "<b>#{server.status.teams[1].name} (#{server.status.players.select { |pl| pl.team == 1 }.count})</b>", width: 1.0, text_align: :center
para game_balance[:team_1_score].to_i.to_s, width: 1.0, text_align: :center
end
end
flow(width: 1.0, height: 0.65, scroll: true) do
flow(width: 1.0, height: 0.60, scroll: true) do
stack(width: 0.5) do
server.status.players.select { |ply| ply.team == 0 }.sort_by { |ply| ply.score }.reverse.each do |player|
flow(width: 1.0, height: 18) do
@@ -392,14 +397,24 @@ class W3DHub
}
# team 0 is left side
team_0_score = server.status.players.select { |ply| ply.team == 0 }.map(&:score).sum.to_f
team_0_score = server.status.teams[0].score
team_0_score = nil if team_0_score.zero?
team_0_score ||= server.status.players.select { |ply| ply.team == 0 }.map(&:score).sum
team_0_score = team_0_score.to_f
# team 1 is right side
team_1_score = server.status.players.select { |ply| ply.team == 1 }.map(&:score).sum.to_f
team_1_score = server.status.teams[1].score
team_1_score = nil if team_1_score.zero?
team_1_score ||= server.status.players.select { |ply| ply.team == 1 }.map(&:score).sum
team_1_score = team_1_score.to_f
ratio = 1.0 / (team_0_score / team_1_score)
ratio = 1.0 if ratio.to_s == "NaN"
data[:ratio] = ratio
data[:team_0_score] = team_0_score
data[:team_1_score] = team_1_score
data[:icon] = if server.status.players.size < 20 && server.game != "ren"
data[:color] = 0xff_600000
data[:message] = "Too few players for a balanced game"

View File

@@ -5,18 +5,18 @@ class W3DHub
body.clear do
stack(width: 1.0, height: 1.0, padding: 16, scroll: true) do
para "<b>Language</b>"
flow(width: 1.0) do
para "<b>Launcher Language</b>", width: 0.249
flow(width: 1.0, height: 0.12) do
para "<b>Launcher Language</b>", width: 0.249, margin_left: 32, margin_top: 12
stack(width: 0.75) do
@language_menu = list_box items: I18n.available_locales.map { |l| expand_language_code(l.to_s) }, choose: expand_language_code(Store.settings[:language]), width: 1.0
inscription "Select the UI language you'd like to use in the W3D Hub Launcher. You should restart the launcher after changing this setting before the UI will update"
inscription "Select the UI language you'd like to use in the W3D Hub Launcher."
end
end
para "<b>Folder Paths</b>", margin_top: 32
stack(width: 1.0) do
flow(width: 1.0) do
para "<b>App Install Folder</b>", width: 0.249
para "<b>Folder Paths</b>", margin_top: 8, padding_top: 8, border_thickness_top: 2, border_color_top: 0xee_ffffff, width: 1.0
stack(width: 1.0, height: 0.3) do
flow(width: 1.0, height: 0.5) do
para "<b>App Install Folder</b>", width: 0.249, margin_left: 32, margin_top: 12
stack(width: 0.75) do
@app_install_dir_input = edit_line Store.settings[:app_install_dir], width: 1.0
@@ -25,7 +25,7 @@ class W3DHub
end
flow(width: 1.0, margin_top: 16) do
para "<b>Package Cache Folder</b>", width: 0.249
para "<b>Package Cache Folder</b>", width: 0.249, margin_left: 32, margin_top: 12
stack(width: 0.75) do
@package_cache_dir_input = edit_line Store.settings[:package_cache_dir], width: 1.0
@@ -35,17 +35,17 @@ class W3DHub
end
if true # W3DHub.unix?
para "<b>Wine</b>", margin_top: 32
flow(width: 1.0) do
para "<b>Wine Command</b>", width: 0.249
para "<b>Wine</b>", margin_top: 8, padding_top: 8, border_thickness_top: 2, border_color_top: 0xee_ffffff, width: 1.0
flow(width: 1.0, height: 0.12) do
para "<b>Wine Command</b>", width: 0.249, margin_left: 32, margin_top: 12
stack(width: 0.75) do
@wine_command_input = edit_line Store.settings[:wine_command], width: 1.0
inscription "Command to use to for Windows compatiblity layer"
end
end
flow(width: 1.0, margin_top: 16) do
para "<b>Wine Prefix</b>", width: 0.249
flow(width: 1.0, height: 0.13, margin_top: 16) do
para "<b>Wine Prefix</b>", width: 0.249, margin_left: 32, margin_top: 12
stack(width: 0.75) do
@wine_prefix_toggle = toggle_button checked: Store.settings[:wine_prefix]
inscription "Whether each game gets its own prefix. Uses global/default prefix by default."

View File

@@ -153,10 +153,7 @@ class W3DHub
end
if regenerate
ico = ICO.new(file: path)
image = ico.images.max_by(&:width)
ico.save(image, generated_icon_path)
BackgroundWorker.foreground_job(-> { ICO.new(file: path) }, ->(result) { result.save(result.images.max_by(&:width), generated_icon_path) })
end
end

View File

@@ -1,7 +1,6 @@
class W3DHub
class States
class Interface < CyberarmEngine::GuiState
attr_reader :main_thread_queue
attr_accessor :interface_task_update_pending
@@instance = nil
@@ -24,8 +23,6 @@ class W3DHub
@page = nil
@pages = {}
@main_thread_queue = []
Store.application_manager.auto_import
theme(W3DHub::THEME)
@@ -122,10 +119,6 @@ class W3DHub
@page&.update
while(block = @main_thread_queue.shift)
block&.call
end
update_interface_task_status(@interface_task_update_pending) if @interface_task_update_pending
end

View File

@@ -7,6 +7,8 @@ class W3DHub
Store[:settings] = Settings.new
Store[:application_manager] = ApplicationManager.new
Store[:main_thread_queue] = []
Store.settings.save_settings
begin
@@ -23,6 +25,10 @@ class W3DHub
super
Store.application_manager.start_next_available_task if Store.application_manager.idle?
while (block = Store.main_thread_queue.shift)
block&.call
end
end
def gain_focus
@@ -52,13 +58,7 @@ class W3DHub
end
def main_thread_queue
if current_state.is_a?(W3DHub::States::Interface)
current_state.main_thread_queue
else
warn "Task will not be run for:"
warn caller
[]
end
Store.main_thread_queue
end
end
end