diff --git a/lib/pages/boot/initial_setup.rb b/lib/pages/boot/initial_setup.rb
index 445c393..b557add 100644
--- a/lib/pages/boot/initial_setup.rb
+++ b/lib/pages/boot/initial_setup.rb
@@ -17,37 +17,44 @@ module W3DHubLauncher
flow(width: 1.0, height: 40, margin_top: PADDING) do
tagline "Nickname", height: 1.0, text_v_align: :center
- edit_line Etc.getlogin, fill: true
+ @nickname = edit_line Etc.getlogin, fill: true
end
inscription "Nickname to use when joining servers.", margin_left: PADDING
flow(width: 1.0, height: 40, margin_top: HALF_PADDING) do
tagline "Launcher package cache directory", height: 1.0, text_v_align: :center
- edit_line DEFAULT_PACKAGE_CACHE_PATH, fill: true
+ @launcher_package_cache_directory = edit_line DEFAULT_PACKAGE_CACHE_PATH, fill: true
button "Browse..."
end
inscription "Location where the launcher will download application packages.", margin_left: PADDING
flow(width: 1.0, height: 40, margin_top: HALF_PADDING) do
tagline "Application installation directory", height: 1.0, text_v_align: :center
- edit_line DEFAULT_APPLICATIONS_PATH, fill: true
+ @application_installation_directory = edit_line DEFAULT_APPLICATIONS_PATH, fill: true
button "Browse..."
end
inscription "Location where the launcher will install new applications.", margin_left: PADDING
flow(width: 1.0, height: 40, margin_top: HALF_PADDING) do
- tagline "Wine context", height: 1.0, text_v_align: :center
- edit_line "", fill: true
+ tagline "Wine prefix path", height: 1.0, text_v_align: :center
+ @wine_prefix_path = edit_line "", fill: true
button "Browse..."
end
- inscription "Location of wine context to use. Leave blank to use default.", margin_left: PADDING
+ inscription "Location of wine prefix to use. Leave blank to use default.", margin_left: PADDING
flow(width: 1.0, height: 40, margin_top: HALF_PADDING) do
tagline "Wine command", height: 1.0, text_v_align: :center
- edit_line "wine", fill: true
+ @wine_command = edit_line "wine", fill: true
button "Browse..."
end
inscription "Path to wine executable. Use wine for system installed wine.", margin_left: PADDING
+
+ flow(width: 1.0, height: 40, margin_top: HALF_PADDING) do
+ tagline "Winetricks command", height: 1.0, text_v_align: :center
+ @winetricks_command = edit_line "winetricks", fill: true
+ button "Browse..."
+ end
+ inscription "Path to winetricks executable. Use winetricks for system installed winetricks.", margin_left: PADDING
end
flow(width: 1.0, padding_top: PADDING) do
@@ -55,14 +62,27 @@ module W3DHubLauncher
button "Accept", **CTA_BUTTON_THEME do |btn|
btn.enabled = false
- Worker::Api.update_settings({}) do |result|
+ # initialize default settings
+ settings = Worker::Api::Settings.new({})
+
+ # update user preferences
+ settings.preferences.nickname = @nickname.value.strip
+ settings.preferences.launcher_package_cache_directory = @launcher_package_cache_directory.value.strip
+ settings.preferences.application_installation_directory = @application_installation_directory.value.strip
+ settings.preferences.wine_prefix_path = @wine_prefix_path.value.strip
+ settings.preferences.wine_command = @wine_command.value.strip
+ settings.preferences.winetricks_command = @winetricks_command.value.strip
+
+ Worker::Api.update_settings(settings) do |result|
if result.okay?
- on_main_thread(proc { page(Page::Boot::StartUp) })
+ on_main_thread(proc {
+ MemCache[:settings] = settings
+ page(Page::Boot::StartUp)
+ })
else
+ # FIXME: Somehow something went wrong... show an error message.
btn.enabled = true
end
-
- puts "NOW!"
end
end
end
diff --git a/lib/states/boot.rb b/lib/states/boot.rb
index 18e927a..851c62e 100644
--- a/lib/states/boot.rb
+++ b/lib/states/boot.rb
@@ -28,7 +28,18 @@ module W3DHubLauncher
end
end
- page(Page::Boot::Terms)
+ Worker::Api.load_settings do |result|
+ if result.okay?
+ on_main_thread( proc {
+ MemCache[:settings] = Worker::Api::Settings.new(JSON.parse(result.data))
+ page(Page::Boot::StartUp)
+ })
+ else
+ on_main_thread( proc {
+ page(Page::Boot::Terms)
+ })
+ end
+ end
end
end
end
diff --git a/lib/worker.rb b/lib/worker.rb
index 3694da8..69512f1 100644
--- a/lib/worker.rb
+++ b/lib/worker.rb
@@ -165,12 +165,37 @@ module W3DHubLauncher
deliver_response(result, query)
end
+ def load_settings(query)
+ result = CyberarmEngine::Result.new
+
+ path = "#{W3DHubLauncher::CONFIG_PATH}/settings.json"
+ begin
+ if File.exist?(path) && File.size(path).positive?
+ json = File.read(path)
+ result.data = json
+ else
+ result.error = RuntimeError.new("Launcher settings file does not exist or is empty.")
+ end
+ rescue => e
+ result.error = e
+ end
+
+ deliver_response(result, query)
+ end
+
def update_settings(query)
result = CyberarmEngine::Result.new
- FileUtils.mkdir_p(W3DHubLauncher::CONFIG_PATH) # FIXME: FAILABLE!
- File.write("#{W3DHubLauncher::CONFIG_PATH}/settings.json", query.data) # FIXME: FAILABLE!
- result.data = query.data
+ begin
+ @settings = Api::Settings.new(JSON.parse(query.data))
+ FileUtils.mkdir_p(W3DHubLauncher::CONFIG_PATH)
+ File.write("#{W3DHubLauncher::CONFIG_PATH}/settings.json", query.data)
+
+ result.data = query.data
+ rescue => e
+ result.error = e
+ end
+
deliver_response(result, query)
end
diff --git a/lib/worker/api.rb b/lib/worker/api.rb
index 3b3d5f0..6ac9a5d 100644
--- a/lib/worker/api.rb
+++ b/lib/worker/api.rb
@@ -22,6 +22,11 @@ module W3DHubLauncher
def self.settings
end
+ # returns raw json of launcher settings
+ def self.load_settings(&block)
+ Worker::Request.new(:load_settings, "", &block)
+ end
+
# write updated launcher settings
def self.update_settings(settings, &block)
Worker::Request.new(:update_settings, settings.to_json, &block)
diff --git a/lib/worker/api/settings.rb b/lib/worker/api/settings.rb
index bc7ed2c..6a4ff91 100644
--- a/lib/worker/api/settings.rb
+++ b/lib/worker/api/settings.rb
@@ -11,6 +11,8 @@ module W3DHubLauncher
def initialize(data)
@schema = data["schema"] || SCHEMA
+ raise "Data is not a hash!" unless data.is_a?(Hash)
+
@last_selected_app = data["last_selected_app"] || "ren"
@last_selected_app_channel = data["last_selected_app_channel"] || "release"
@last_selected_server_app = data["last_selected_server_app"] || ""
@@ -20,7 +22,7 @@ module W3DHubLauncher
@account = Account.new(data["account"])
end
- def to_json(context = nil)
+ def to_json(options = {})
{
schema: @schema,
last_selected_app: @last_selected_app,
@@ -29,7 +31,7 @@ module W3DHubLauncher
preferences: @preferences,
applications: @applications,
account: @account
- }.to_json(context)
+ }.to_json(options)
end
# User explictly set options
@@ -53,7 +55,7 @@ module W3DHubLauncher
@winetricks_command = data["winetricks_command"] || "winetricks"
end
- def to_json(context = nil)
+ def to_json(options = {})
{
schema: @schema,
language: @language,
@@ -63,7 +65,7 @@ module W3DHubLauncher
wine_prefix_path: @wine_prefix_path,
wine_command: @wine_command,
winetricks_command: @winetricks_command
- }.to_json(context)
+ }.to_json(options)
end
end
@@ -99,7 +101,7 @@ module W3DHubLauncher
@launch_command = data["launch_command"]
end
- def to_json(context = nil)
+ def to_json(options = {})
{
schema: @schema,
id: @id,
@@ -108,7 +110,7 @@ module W3DHubLauncher
installation_path: @installation_path,
wine_prefix_path: @wine_prefix_path,
launch_command: @launch_command
- }.to_json(context)
+ }.to_json(options)
end
end
@@ -152,7 +154,7 @@ module W3DHubLauncher
@user_id.positive?
end
- def to_json(context = nil)
+ def to_json(options = {})
{
schema: @schema,
user_id: @user_id,
@@ -162,7 +164,7 @@ module W3DHubLauncher
access_token: @access_token,
refresh_token: @refresh_token,
access_token_expiration_time: @access_token_expiration_time.to_i
- }.to_json(context)
+ }.to_json(options)
end
end
end
diff --git a/w3d_hub_linux_launcher.rb b/w3d_hub_linux_launcher.rb
index a95dd36..484e5e7 100644
--- a/w3d_hub_linux_launcher.rb
+++ b/w3d_hub_linux_launcher.rb
@@ -40,6 +40,7 @@ require_relative "lib/worker"
require_relative "lib/worker/api"
require_relative "lib/worker/api/application"
require_relative "lib/worker/api/game_server"
+require_relative "lib/worker/api/settings"
require_relative "lib/worker/request"
require_relative "lib/worker/w3dhub_api"
require_relative "lib/worker/task"