-
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ae79123
commit 5824c45
Showing
26 changed files
with
457 additions
and
388 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
.mongodb | ||
|
||
|
||
.nx/cache | ||
|
||
.dist | ||
.test-runs | ||
.packaged | ||
.nuget | ||
*.log | ||
.vs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
namespace PlayniteWebExtension | ||
{ | ||
public interface IMqttSettings | ||
{ | ||
string ClientId | ||
{ | ||
get; | ||
} | ||
|
||
string DeviceName | ||
{ | ||
get; | ||
} | ||
|
||
string DeviceId | ||
{ | ||
get; | ||
} | ||
|
||
string ServerAddress | ||
{ | ||
get; | ||
} | ||
|
||
string Username | ||
{ | ||
get; | ||
} | ||
|
||
string HomeAssistantTopic | ||
{ | ||
get; | ||
} | ||
|
||
string Password | ||
{ | ||
get; | ||
} | ||
|
||
int? Port | ||
{ | ||
get; | ||
} | ||
|
||
bool UseSecureConnection | ||
{ | ||
get; | ||
} | ||
|
||
bool PublishCoverColors | ||
{ | ||
get; | ||
} | ||
|
||
bool PublishCover | ||
{ | ||
get; | ||
} | ||
|
||
bool PublishBackground | ||
{ | ||
get; | ||
} | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
apps/playnite-web-extension/src/IntToStringValueConverter.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
using System; | ||
using System.Globalization; | ||
using System.Windows.Data; | ||
|
||
namespace PlayniteWebExtension | ||
{ | ||
public class IntToStringValueConverter : IValueConverter | ||
{ | ||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) | ||
{ | ||
return value.ToString(); | ||
} | ||
|
||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) | ||
{ | ||
int ret = 0; | ||
return int.TryParse((string)value, out ret) ? ret : 0; | ||
} | ||
} | ||
} |
114 changes: 114 additions & 0 deletions
114
apps/playnite-web-extension/src/MqttSettingsViewModel.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
using System.Collections.Generic; | ||
using System.Security.Cryptography; | ||
using System.Text; | ||
using Playnite.SDK; | ||
using Playnite.SDK.Data; | ||
using Playnite.SDK.Plugins; | ||
|
||
namespace PlayniteWebExtension.UI | ||
{ | ||
|
||
public class MqttPluginSettingsViewModel : ObservableObject, ISettings, IMqttSettings | ||
{ | ||
private readonly Plugin plugin; | ||
|
||
private PluginSettings settings; | ||
public PluginSettings Settings | ||
{ | ||
get => settings; | ||
set | ||
{ | ||
settings = value; | ||
OnPropertyChanged(); | ||
} | ||
} | ||
private PluginSettings editingClone { get; set; } | ||
|
||
public string ClientId => ((IMqttSettings)settings).ClientId; | ||
|
||
public string DeviceName => ((IMqttSettings)settings).DeviceName; | ||
|
||
public string DeviceId => ((IMqttSettings)settings).DeviceId; | ||
|
||
public string ServerAddress => ((IMqttSettings)settings).ServerAddress; | ||
|
||
public string Username => ((IMqttSettings)settings).Username; | ||
|
||
public string HomeAssistantTopic => ((IMqttSettings)settings).HomeAssistantTopic; | ||
|
||
public string Password => Encoding.UTF8.GetString(ProtectedData.Unprotect(settings.Password, plugin.Id.ToByteArray(), DataProtectionScope.CurrentUser)); | ||
|
||
public int? Port => ((IMqttSettings)settings).Port; | ||
|
||
public bool UseSecureConnection => ((IMqttSettings)settings).UseSecureConnection; | ||
|
||
public bool PublishCoverColors => ((IMqttSettings)settings).PublishCoverColors; | ||
|
||
public bool PublishCover => ((IMqttSettings)settings).PublishCover; | ||
|
||
public bool PublishBackground => ((IMqttSettings)settings).PublishBackground; | ||
|
||
public MqttPluginSettingsViewModel(Plugin plugin) | ||
{ | ||
// Injecting your plugin instance is required for Save/Load method because Playnite saves data to a location based on what plugin requested the operation. | ||
this.plugin = plugin; | ||
|
||
// Load saved settings. | ||
var savedSettings = plugin.LoadPluginSettings<PluginSettings>(); | ||
|
||
// LoadPluginSettings returns null if not saved data is available. | ||
if (savedSettings != null) | ||
{ | ||
Settings = savedSettings; | ||
} | ||
else | ||
{ | ||
Settings = new PluginSettings(); | ||
} | ||
} | ||
|
||
public void SavePassword(string password) | ||
{ | ||
settings.Password = ProtectedData.Protect(Encoding.UTF8.GetBytes(password), plugin.Id.ToByteArray(), DataProtectionScope.CurrentUser); | ||
} | ||
|
||
#region Implementation of IEditableObject | ||
|
||
public void BeginEdit() | ||
{ | ||
// Code executed when settings view is opened and user starts editing values. | ||
editingClone = Serialization.GetClone(Settings); | ||
} | ||
|
||
public void CancelEdit() | ||
{ | ||
// Code executed when user decides to cancel any changes made since BeginEdit was called. | ||
// This method should revert any changes made to Option1 and Option2. | ||
Settings = editingClone; | ||
} | ||
|
||
public void EndEdit() | ||
{ | ||
// Code executed when user decides to confirm changes made since BeginEdit was called. | ||
// This method should save settings made to Option1 and Option2. | ||
plugin.SavePluginSettings(Settings); | ||
} | ||
|
||
#endregion | ||
|
||
#region Implementation of ISettings | ||
|
||
public bool VerifySettings(out List<string> errors) | ||
{ | ||
// Code execute when user decides to confirm changes made since BeginEdit was called. | ||
// Executed before EndEdit is called and EndEdit is not called if false is returned. | ||
// List of errors is presented to user if verification fails. | ||
errors = new List<string>(); | ||
// plugin.StartDisconnect().Wait(); | ||
// plugin.StartConnection(); | ||
return true; | ||
} | ||
|
||
#endregion | ||
} | ||
} |
Oops, something went wrong.