mirror of
https://github.com/cyberarm/w3d_hub_linux_launcher.git
synced 2025-12-16 09:12:35 +00:00
Cache application data for offline use
This commit is contained in:
@@ -1,6 +1,8 @@
|
|||||||
class W3DHub
|
class W3DHub
|
||||||
class Api
|
class Api
|
||||||
class Applications
|
class Applications
|
||||||
|
attr_reader :data
|
||||||
|
|
||||||
def initialize(response)
|
def initialize(response)
|
||||||
@data = JSON.parse(response, symbolize_names: true)
|
@data = JSON.parse(response, symbolize_names: true)
|
||||||
|
|
||||||
|
|||||||
@@ -102,6 +102,8 @@ class W3DHub
|
|||||||
end
|
end
|
||||||
|
|
||||||
def populate_account_info
|
def populate_account_info
|
||||||
|
return if Store.offline_mode
|
||||||
|
|
||||||
@host.instance_variable_get(:"@account_container").clear do
|
@host.instance_variable_get(:"@account_container").clear do
|
||||||
flow(fill: true, height: 1.0) do
|
flow(fill: true, height: 1.0) do
|
||||||
avatar_image = begin
|
avatar_image = begin
|
||||||
|
|||||||
@@ -71,5 +71,15 @@ class W3DHub
|
|||||||
def save_settings
|
def save_settings
|
||||||
File.write(SETTINGS_FILE_PATH, @settings.to_json)
|
File.write(SETTINGS_FILE_PATH, @settings.to_json)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def save_application_cache(json)
|
||||||
|
File.write(APPLICATIONS_CACHE_FILE_PATH, json)
|
||||||
|
end
|
||||||
|
|
||||||
|
def load_application_cache
|
||||||
|
JSON.parse(File.read(APPLICATIONS_CACHE_FILE_PATH), symbolize_names: true)
|
||||||
|
rescue
|
||||||
|
nil
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -29,8 +29,8 @@ class W3DHub
|
|||||||
|
|
||||||
stack(width: 1.0, height: 60) do
|
stack(width: 1.0, height: 60) do
|
||||||
flow(width: 1.0, height: 26, margin_left: 16, margin_right: 16, margin_bottom: 8, margin_top: 8) do
|
flow(width: 1.0, height: 26, margin_left: 16, margin_right: 16, margin_bottom: 8, margin_top: 8) do
|
||||||
@status_label = caption "Starting #{I18n.t(:app_name_simple)}...", width: 0.5
|
@status_label = caption "Starting #{I18n.t(:app_name_simple)}...", fill: true
|
||||||
para "#{I18n.t(:app_name)} #{W3DHub::VERSION}", width: 0.5, text_align: :right
|
para "#{I18n.t(:app_name)} #{W3DHub::VERSION}", text_align: :right
|
||||||
end
|
end
|
||||||
|
|
||||||
@progressbar = progress height: 4, width: 1.0, margin_left: 16, margin_right: 16, margin_bottom: 8
|
@progressbar = progress height: 4, width: 1.0, margin_left: 16, margin_right: 16, margin_bottom: 8
|
||||||
@@ -52,7 +52,16 @@ class W3DHub
|
|||||||
|
|
||||||
@progressbar.value = @fraction
|
@progressbar.value = @fraction
|
||||||
|
|
||||||
load_offline_applications_list if @offline_mode
|
if @offline_mode
|
||||||
|
load_offline_applications_list
|
||||||
|
|
||||||
|
unless Store.applications
|
||||||
|
@progressbar.value = 0.0
|
||||||
|
@status_label.value = "<c=f80>Unable to connect to W3D Hub API. No application data cached, unable to continue.</c>"
|
||||||
|
|
||||||
|
return
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
if @offline_mode || (@progressbar.value >= 1.0 && @task_index == @tasks.size)
|
if @offline_mode || (@progressbar.value >= 1.0 && @task_index == @tasks.size)
|
||||||
pop_state
|
pop_state
|
||||||
@@ -156,7 +165,7 @@ class W3DHub
|
|||||||
Api.on_thread(:applications) do |applications|
|
Api.on_thread(:applications) do |applications|
|
||||||
if applications
|
if applications
|
||||||
Store.applications = applications
|
Store.applications = applications
|
||||||
|
Store.settings.save_application_cache(applications.data.to_json)
|
||||||
@tasks[:applications][:complete] = true
|
@tasks[:applications][:complete] = true
|
||||||
else
|
else
|
||||||
# FIXME: Failed to retreive!
|
# FIXME: Failed to retreive!
|
||||||
@@ -227,6 +236,12 @@ class W3DHub
|
|||||||
end
|
end
|
||||||
|
|
||||||
def load_offline_applications_list
|
def load_offline_applications_list
|
||||||
|
if (application_cache = Store.settings.load_application_cache)
|
||||||
|
Store.applications = Api::Applications.new(application_cache.to_json)
|
||||||
|
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
hash = {
|
hash = {
|
||||||
applications: []
|
applications: []
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ class W3DHub
|
|||||||
GAME_ROOT_PATH = File.expand_path(".", __dir__)
|
GAME_ROOT_PATH = File.expand_path(".", __dir__)
|
||||||
CACHE_PATH = "#{GAME_ROOT_PATH}/data/cache"
|
CACHE_PATH = "#{GAME_ROOT_PATH}/data/cache"
|
||||||
SETTINGS_FILE_PATH = "#{GAME_ROOT_PATH}/data/settings.json"
|
SETTINGS_FILE_PATH = "#{GAME_ROOT_PATH}/data/settings.json"
|
||||||
|
APPLICATIONS_CACHE_FILE_PATH = "#{GAME_ROOT_PATH}/data/applications_cache.json"
|
||||||
|
|
||||||
LOGGER = Logger.new("#{GAME_ROOT_PATH}/data/logs/w3d_hub_linux_launcher.log", "daily")
|
LOGGER = Logger.new("#{GAME_ROOT_PATH}/data/logs/w3d_hub_linux_launcher.log", "daily")
|
||||||
LOGGER.level = Logger::Severity::DEBUG # W3DHUB_DEBUG ? Logger::Severity::DEBUG : Logger::Severity::WARN
|
LOGGER.level = Logger::Severity::DEBUG # W3DHUB_DEBUG ? Logger::Severity::DEBUG : Logger::Severity::WARN
|
||||||
|
|||||||
Reference in New Issue
Block a user