mirror of
https://github.com/cyberarm/w3d_hub_linux_launcher.git
synced 2025-12-16 09:12:35 +00:00
Refresh token at start up now works, added a bit of a hack to populate account info by opening the login page first and having it populate the data then load the games page, added Cache, and Settings
This commit is contained in:
78
lib/settings.rb
Normal file
78
lib/settings.rb
Normal file
@@ -0,0 +1,78 @@
|
||||
class W3DHub
|
||||
class Settings
|
||||
def self.defaults
|
||||
{
|
||||
language: Gosu.user_languages.first.split("_").first,
|
||||
app_install_dir: default_app_install_dir,
|
||||
package_cache_dir: default_package_cache_dir,
|
||||
allow_diagnostic_reports: false,
|
||||
server_list_username: nil,
|
||||
account: {},
|
||||
applications: {},
|
||||
games: {}
|
||||
}
|
||||
end
|
||||
|
||||
def self.default_app_install_dir
|
||||
if windows?
|
||||
"#{home_directory}/#{W3DHub::DIR_NAME}"
|
||||
elsif linux?
|
||||
"#{home_directory}/.local/share/#{W3DHub::DIR_NAME}"
|
||||
elsif mac?
|
||||
"#{home_directory}/.local/share/#{W3DHub::DIR_NAME}"
|
||||
else
|
||||
raise "Unknown platform: #{RbConfig::CONFIG["host_os"]}"
|
||||
end
|
||||
end
|
||||
|
||||
def self.default_package_cache_dir
|
||||
if windows?
|
||||
"#{home_directory}/#{W3DHub::DIR_NAME}/Launcher/package-cache"
|
||||
elsif linux?
|
||||
"#{home_directory}/.local/share/#{W3DHub::DIR_NAME}/package-cache"
|
||||
elsif mac?
|
||||
"#{home_directory}/.local/share/#{W3DHub::DIR_NAME}/package-cache"
|
||||
else
|
||||
raise "Unknown platform: #{RbConfig::CONFIG["host_os"]}"
|
||||
end
|
||||
end
|
||||
|
||||
def self.windows?
|
||||
RbConfig::CONFIG["host_os"] =~ /(mingw|mswin|windows)/i
|
||||
end
|
||||
|
||||
def self.mac?
|
||||
RbConfig::CONFIG["host_os"] =~ /(darwin|mac os)/i
|
||||
end
|
||||
|
||||
def self.linux?
|
||||
RbConfig::CONFIG["host_os"] =~ /(linux|bsd|aix|solaris)/i
|
||||
end
|
||||
|
||||
def self.home_directory
|
||||
File.expand_path("~")
|
||||
end
|
||||
|
||||
def initialize
|
||||
unless File.exist?(SETTINGS_FILE_PATH)
|
||||
@settings = Settings.defaults
|
||||
|
||||
save_settings
|
||||
else
|
||||
load_settings
|
||||
end
|
||||
end
|
||||
|
||||
def [](*args)
|
||||
@settings.dig(*args)
|
||||
end
|
||||
|
||||
def load_settings
|
||||
@settings = JSON.parse(File.read(SETTINGS_FILE_PATH), symbolize_names: true)
|
||||
end
|
||||
|
||||
def save_settings
|
||||
File.write(SETTINGS_FILE_PATH, @settings.to_json)
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user