Fleshed out settings a bit more

This commit is contained in:
2026-09-03 10:53:26 -05:00
parent 1f33e125f6
commit ad0b9dbe7b

View File

@@ -6,16 +6,18 @@ module W3DHubLauncher
class Settings class Settings
SCHEMA = 0 SCHEMA = 0
attr_reader :schema, :preferences attr_accessor :last_selected_app, :last_selected_app_channel, :last_selected_server_app, :preferences, :applications, :account
def initialize(data) def initialize(data)
@schema = data["schema"] || SCHEMA @schema = data["schema"] || SCHEMA
@last_selected_app = data["last_selected_app"] || "ren" @last_selected_app = data["last_selected_app"] || "ren"
@last_selected_app_channel = data["last_selected_app_channel"] || "release" @last_selected_app_channel = data["last_selected_app_channel"] || "release"
@last_selected_server_app = data["last_selected_server_app"] || ""
@preferences = Preferences.new(data["preferences"]) @preferences = Preferences.new(data["preferences"])
@applications = (data["applications"] || []).map { |app_data| Application.new(app_data) } @applications = (data["applications"] || []).map { |app_data| Application.new(app_data) }
@account = Account.new(data["account"])
end end
def to_json(context = nil) def to_json(context = nil)
@@ -23,8 +25,10 @@ module W3DHubLauncher
schema: @schema, schema: @schema,
last_selected_app: @last_selected_app, last_selected_app: @last_selected_app,
last_selected_app_channel: @last_selected_app_channel, last_selected_app_channel: @last_selected_app_channel,
last_selected_server_app: @last_selected_server_app,
preferences: @preferences, preferences: @preferences,
applications: @applications applications: @applications,
account: @account
}.to_json(context) }.to_json(context)
end end
@@ -32,7 +36,12 @@ module W3DHubLauncher
class Preferences class Preferences
SCHEMA = 0 SCHEMA = 0
attr_accessor :language, :nickname, :launcher_package_cache_directory, :application_installation_directory,
:wine_prefix_path, :wine_command, :winetricks_command
def initialize(data) def initialize(data)
data ||= {}
@schema = data["schema"] || SCHEMA @schema = data["schema"] || SCHEMA
@language = data["language"] || "en" @language = data["language"] || "en"
@@ -46,7 +55,14 @@ module W3DHubLauncher
def to_json(context = nil) def to_json(context = nil)
{ {
schema: @schema,
language: @language,
nickname: @nickname,
launcher_package_cache_directory: @launcher_package_cache_directory,
application_installation_directory: @application_installation_directory,
wine_prefix_path: @wine_prefix_path,
wine_command: @wine_command,
winetricks_command: @winetricks_command
}.to_json(context) }.to_json(context)
end end
end end
@@ -55,12 +71,29 @@ module W3DHubLauncher
class Application class Application
SCHEMA = 0 SCHEMA = 0
attr_reader :id, :channel
attr_accessor :version, :installation_path, :wine_prefix_path, :launch_command
def self.create(id:, channel:, version:, installation_path:, wine_prefix_path:, launch_command:)
hash = {
"schema" => SCHEMA,
"id" => id,
"channel" => channel,
"version" => Gem::Version.new(version),
"installation_path" => installation_path,
"wine_prefix_path" => wine_prefix_path,
"launch_command" => launch_command,
}
self.new(hash)
end
def initialize(data) def initialize(data)
@schema = data["schema"] || SCHEMA @schema = data["schema"] || SCHEMA
@id = data["id"] @id = data["id"]
@channel = data["channel"] @channel = data["channel"]
@version = data["version"] @version = Gem::Version.new(data["version"])
@installation_path = data["installation_path"] @installation_path = data["installation_path"]
@wine_prefix_path = data["wine_prefix_path"] @wine_prefix_path = data["wine_prefix_path"]
@launch_command = data["launch_command"] @launch_command = data["launch_command"]
@@ -68,7 +101,67 @@ module W3DHubLauncher
def to_json(context = nil) def to_json(context = nil)
{ {
schema: @schema,
id: @id,
channel: @channel,
version: @version.to_s,
installation_path: @installation_path,
wine_prefix_path: @wine_prefix_path,
launch_command: @launch_command
}.to_json(context)
end
end
# User account data
class Account
SCHEMA = 0
attr_accessor :user_id, :username, :displayname, :avatar_uri, :access_token, :refresh_token,
:access_token_expiration_time
def self.create(user_id:, username:, displayname:, avatar_uri:, access_token:, refresh_token:, access_token_expiration_time:)
hash = {
"schema" => SCHEMA,
"user_id" => user_id,
"username" => username,
"displayname" => displayname,
"avatar_uri" => avatar_uri,
"access_token" => access_token,
"refresh_token" => refresh_token,
"access_token_expiration_time" => access_token_expiration_time
}
self.new(hash)
end
def initialize(data)
data ||= {}
@schema = data["schema"] || SCHEMA
@user_id = data["user_id"] || -1
@username = data["username"] || ""
@displayname = data["displayname"] || ""
@avatar_uri = data["avatar_uri"] || ""
@access_token = data["access_token"] || ""
@refresh_token = data["refresh_token"] || ""
@access_token_expiration_time = Time.at(data["access_token_expiration_time"] || 0)
end
def signed_in?
@user_id.positive?
end
def to_json(context = nil)
{
schema: @schema,
user_id: @user_id,
username: @username,
displayname: @displayname,
avatar_uri: @avatar_uri,
access_token: @access_token,
refresh_token: @refresh_token,
access_token_expiration_time: @access_token_expiration_time.to_i
}.to_json(context) }.to_json(context)
end end
end end