Skip to content

Commit

Permalink
test plugin with mqtt settings UI
Browse files Browse the repository at this point in the history
  • Loading branch information
andrew-codes committed Nov 21, 2023
1 parent ae79123 commit 5824c45
Show file tree
Hide file tree
Showing 26 changed files with 457 additions and 388 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
.mongodb


.nx/cache

.dist
.test-runs
.packaged
.nuget
*.log
.vs
29 changes: 7 additions & 22 deletions Playnite-Web-Extension.sln
Original file line number Diff line number Diff line change
Expand Up @@ -3,38 +3,23 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.0.31903.59
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "apps", "apps", "{00172130-52A7-4DBA-9F4E-5361DE868BCD}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "playnite-web-plugin", "playnite-web-plugin", "{579FD8D9-5E3F-4385-AA2B-0C94920B94BF}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{2F45A914-AE3B-4391-B023-EC8BCFCB36F4}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Playnite-Web-Extension", "apps\playnite-web-extension\src\Playnite-Web-Extension.csproj", "{11E4F3D4-D252-4B55-8E3F-9A70192E3D74}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PlayniteWebExtension.Tests", "apps\playnite-web-extension\tests\unit\src\PlayniteWebExtension.Tests.csproj", "{FE091D18-D5AE-44FA-AF2C-7D7A56E7C39C}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Playnite-Web-Extension", "apps\playnite-web-extension\src\Playnite-Web-Extension.csproj", "{4FDF1E89-5BC3-4C72-8FDA-0D580E7A5D5F}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{11E4F3D4-D252-4B55-8E3F-9A70192E3D74}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{11E4F3D4-D252-4B55-8E3F-9A70192E3D74}.Debug|Any CPU.Build.0 = Debug|Any CPU
{11E4F3D4-D252-4B55-8E3F-9A70192E3D74}.Release|Any CPU.ActiveCfg = Release|Any CPU
{11E4F3D4-D252-4B55-8E3F-9A70192E3D74}.Release|Any CPU.Build.0 = Release|Any CPU
{FE091D18-D5AE-44FA-AF2C-7D7A56E7C39C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{FE091D18-D5AE-44FA-AF2C-7D7A56E7C39C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FE091D18-D5AE-44FA-AF2C-7D7A56E7C39C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FE091D18-D5AE-44FA-AF2C-7D7A56E7C39C}.Release|Any CPU.Build.0 = Release|Any CPU
{4FDF1E89-5BC3-4C72-8FDA-0D580E7A5D5F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4FDF1E89-5BC3-4C72-8FDA-0D580E7A5D5F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4FDF1E89-5BC3-4C72-8FDA-0D580E7A5D5F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4FDF1E89-5BC3-4C72-8FDA-0D580E7A5D5F}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{579FD8D9-5E3F-4385-AA2B-0C94920B94BF} = {00172130-52A7-4DBA-9F4E-5361DE868BCD}
{11E4F3D4-D252-4B55-8E3F-9A70192E3D74} = {2F45A914-AE3B-4391-B023-EC8BCFCB36F4}
{2F45A914-AE3B-4391-B023-EC8BCFCB36F4} = {579FD8D9-5E3F-4385-AA2B-0C94920B94BF}
{FE091D18-D5AE-44FA-AF2C-7D7A56E7C39C} = {579FD8D9-5E3F-4385-AA2B-0C94920B94BF}
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {105206CE-B5F8-4C68-983A-F7E7100B0B2E}
EndGlobalSection
EndGlobal
26 changes: 0 additions & 26 deletions apps/playnite-web-extension/src/Directory.Build.props

This file was deleted.

65 changes: 65 additions & 0 deletions apps/playnite-web-extension/src/IMqttSettings.cs
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 apps/playnite-web-extension/src/IntToStringValueConverter.cs
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 apps/playnite-web-extension/src/MqttSettingsViewModel.cs
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
}
}
Loading

0 comments on commit 5824c45

Please sign in to comment.