mirror of
https://github.com/cyberarm/w3d_hub_linux_launcher.git
synced 2026-09-19 14:53:49 +00:00
Fleshed out settings a bit more
This commit is contained in:
@@ -6,16 +6,18 @@ module W3DHubLauncher
|
||||
class Settings
|
||||
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)
|
||||
@schema = data["schema"] || SCHEMA
|
||||
|
||||
@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"] || ""
|
||||
|
||||
@preferences = Preferences.new(data["preferences"])
|
||||
@applications = (data["applications"] || []).map { |app_data| Application.new(app_data) }
|
||||
@account = Account.new(data["account"])
|
||||
end
|
||||
|
||||
def to_json(context = nil)
|
||||
@@ -23,8 +25,10 @@ module W3DHubLauncher
|
||||
schema: @schema,
|
||||
last_selected_app: @last_selected_app,
|
||||
last_selected_app_channel: @last_selected_app_channel,
|
||||
last_selected_server_app: @last_selected_server_app,
|
||||
preferences: @preferences,
|
||||
applications: @applications
|
||||
applications: @applications,
|
||||
account: @account
|
||||
}.to_json(context)
|
||||
end
|
||||
|
||||
@@ -32,7 +36,12 @@ module W3DHubLauncher
|
||||
class Preferences
|
||||
SCHEMA = 0
|
||||
|
||||
attr_accessor :language, :nickname, :launcher_package_cache_directory, :application_installation_directory,
|
||||
:wine_prefix_path, :wine_command, :winetricks_command
|
||||
|
||||
def initialize(data)
|
||||
data ||= {}
|
||||
|
||||
@schema = data["schema"] || SCHEMA
|
||||
|
||||
@language = data["language"] || "en"
|
||||
@@ -46,7 +55,14 @@ module W3DHubLauncher
|
||||
|
||||
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)
|
||||
end
|
||||
end
|
||||
@@ -55,12 +71,29 @@ module W3DHubLauncher
|
||||
class Application
|
||||
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)
|
||||
@schema = data["schema"] || SCHEMA
|
||||
|
||||
@id = data["id"]
|
||||
@channel = data["channel"]
|
||||
@version = data["version"]
|
||||
@version = Gem::Version.new(data["version"])
|
||||
@installation_path = data["installation_path"]
|
||||
@wine_prefix_path = data["wine_prefix_path"]
|
||||
@launch_command = data["launch_command"]
|
||||
@@ -68,7 +101,67 @@ module W3DHubLauncher
|
||||
|
||||
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)
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user