aurora/Aurora/Services/Settings/SettingsService.cs

76 lines
2.1 KiB
C#
Raw Normal View History

2019-07-05 18:17:09 +00:00
using System;
using System.Threading;
using Plugin.Settings;
using Plugin.Settings.Abstractions;
2020-02-01 01:41:45 +00:00
namespace Aurora.Services.Settings
2019-07-05 18:17:09 +00:00
{
2020-02-01 01:41:45 +00:00
public class SettingsService : ISettingsService
2019-07-05 18:17:09 +00:00
{
private Lazy<ISettings> _appSettings;
2019-07-06 19:52:28 +00:00
private string _usernameKey = "username";
private string _defaultPortKey = "port";
2019-07-05 18:17:09 +00:00
private string _libraryLocationKey = "libraryLocation";
2019-07-05 18:17:09 +00:00
public SettingsService()
{
}
public ISettings AppSettings
{
get
{
if (_appSettings == null)
{
_appSettings = new Lazy<ISettings>(() => CrossSettings.Current, LazyThreadSafetyMode.PublicationOnly);
}
return _appSettings.Value;
}
set
{
_appSettings = new Lazy<ISettings>(() => value, LazyThreadSafetyMode.PublicationOnly);
}
}
/// <summary>
/// The user's username. This is persisted.
/// </summary>
/// <value></value>
2019-07-05 18:17:09 +00:00
public string Username
{
get { return AppSettings.GetValueOrDefault(_usernameKey, ""); }
set
{
AppSettings.AddOrUpdateValue(_usernameKey, value);
}
}
2019-07-06 19:52:28 +00:00
/// <summary>
/// The default port to use. This is persisted.
/// </summary>
/// <value></value>
2019-07-06 19:52:28 +00:00
public int DefaultPort
{
get { return AppSettings.GetValueOrDefault(_defaultPortKey, 4005); }
set { AppSettings.AddOrUpdateValue(_defaultPortKey, value); }
}
public string LibraryLocation
{
get { return AppSettings.GetValueOrDefault(_libraryLocationKey, "~/Music"); }
set { AppSettings.AddOrUpdateValue(_libraryLocationKey, value); }
}
/// <summary>
/// The current sessions clientId. This is assigned by the server. This is not persisted.
/// </summary>
/// <value></value>
public string ClientName
{
get; set;
}
2019-07-05 18:17:09 +00:00
}
}