Added GSH game server data containing class, stub Account and Join Server dialogs, support 'lazy loading' remote images (downloading images in the background then calling a callback to replace temp image if host element is still in layout), misc. other changes.

This commit is contained in:
2026-09-02 11:17:04 -05:00
parent 59d884aad1
commit baec1e1e18
12 changed files with 248 additions and 25 deletions

View File

@@ -6,7 +6,11 @@ module W3DHubLauncher
def safe_get_image(path, retro: false)
raise RuntimeError, "Images may only be loaded from the main thread!" unless Thread.current == Thread.main
return get_image(path, retro: retro) if File.exist?(path)
begin
return get_image(path, retro: retro) if File.exist?(path)
rescue RuntimeError => e
pp e
end
path = "#{ROOT_PATH}/media/default.png"
return get_image(path, retro: retro) if File.exist?(path)
@@ -24,6 +28,30 @@ module W3DHubLauncher
end
end
# Downloads requested url and on success check if host element is still in the layout and call the block if so.
def remote_image(path, url:, element:, &block)
memcache_key = :"lock_net_download_#{element.style.tag}"
if !File.exist?(path) && MemCache[memcache_key].nil?
MemCache[memcache_key] = true
Worker::Api.download_url(url, path) do |result|
# ignore progress reports
next unless result.okay? && result.data == true
MemCache.delete(memcache_key)
# does the target element still exist in the layout?
e = find_element_by_tag(element.root, element.style.tag)
next unless e
if result.okay?
block.call(element, path)
end
end
end
end
def on_main_thread(block)
window.add_to_queue(block)
end