mirror of
https://github.com/Macro-Deck-App/Macro-Deck.git
synced 2026-05-06 13:41:22 +08:00
Add ssl support
This commit is contained in:
26
Directory.Packages.props
Normal file
26
Directory.Packages.props
Normal file
@@ -0,0 +1,26 @@
|
||||
<Project>
|
||||
<PropertyGroup>
|
||||
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<PackageVersion Include="CommandLineParser" Version="2.9.1" />
|
||||
<PackageVersion Include="Cottle" Version="2.0.9" />
|
||||
<PackageVersion Include="Dax-FCTB" Version="2.16.26.120" />
|
||||
<PackageVersion Include="Magick.NET-Q16-x64" Version="13.0.0" />
|
||||
<PackageVersion Include="Magick.NET.SystemDrawing" Version="7.0.0" />
|
||||
<PackageVersion Include="Microsoft.Extensions.Logging.Abstractions" Version="7.0.0" />
|
||||
<PackageVersion Include="Microsoft.Win32.Registry" Version="5.0.0" />
|
||||
<PackageVersion Include="Newtonsoft.Json" Version="13.0.3" />
|
||||
<PackageVersion Include="sharpadbclient" Version="2.3.23" />
|
||||
<PackageVersion Include="sqlite-net-pcl" Version="1.8.116" />
|
||||
<PackageVersion Include="System.Collections" Version="4.3.0" />
|
||||
<PackageVersion Include="System.Drawing.Common" Version="7.0.0" />
|
||||
<PackageVersion Include="Microsoft.Extensions.DependencyInjection" Version="7.0.0" />
|
||||
<PackageVersion Include="Microsoft.Extensions.Hosting" Version="7.0.1" />
|
||||
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.6.1" />
|
||||
<PackageVersion Include="NUnit" Version="3.13.3" />
|
||||
<PackageVersion Include="NUnit3TestAdapter" Version="4.5.0" />
|
||||
<PackageVersion Include="NUnit.Analyzers" Version="3.6.1" />
|
||||
<PackageVersion Include="coverlet.collector" Version="6.0.0" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
@@ -1,8 +1,8 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="7.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Hosting" Version="7.0.1" />
|
||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" />
|
||||
<PackageReference Include="Microsoft.Extensions.Hosting" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using System.Security.Cryptography.X509Certificates;
|
||||
|
||||
namespace MacroDeck.Server;
|
||||
|
||||
@@ -7,7 +8,7 @@ public static class MacroDeckServerHelper
|
||||
{
|
||||
private static IHost? _host;
|
||||
|
||||
public static async Task Setup(int port)
|
||||
public static async Task Setup(int port, bool enableSsl, string? certificatePath, string? certificatePassword)
|
||||
{
|
||||
if (_host is not null)
|
||||
{
|
||||
@@ -20,7 +21,16 @@ public static class MacroDeckServerHelper
|
||||
hostBuilder.UseStartup<Startup>();
|
||||
hostBuilder.ConfigureKestrel(options =>
|
||||
{
|
||||
options.ListenAnyIP(port);
|
||||
if (enableSsl && !string.IsNullOrWhiteSpace(certificatePath))
|
||||
{
|
||||
options.ListenAnyIP(port, listenOptions =>
|
||||
{
|
||||
listenOptions.UseHttps(new X509Certificate2(certificatePath, certificatePassword));
|
||||
});
|
||||
} else
|
||||
{
|
||||
options.ListenAnyIP(port);
|
||||
}
|
||||
});
|
||||
}).Build();
|
||||
|
||||
|
||||
@@ -5,14 +5,14 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.6.1" />
|
||||
<PackageReference Include="NUnit" Version="3.13.3" />
|
||||
<PackageReference Include="NUnit3TestAdapter" Version="4.5.0" />
|
||||
<PackageReference Include="NUnit.Analyzers" Version="3.6.1">
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" />
|
||||
<PackageReference Include="NUnit" />
|
||||
<PackageReference Include="NUnit3TestAdapter" />
|
||||
<PackageReference Include="NUnit.Analyzers">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="coverlet.collector" Version="6.0.0">
|
||||
<PackageReference Include="coverlet.collector">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
|
||||
@@ -23,6 +23,7 @@ EndProject
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution", "Solution", "{4B7E0868-7875-41AA-8670-479175ADBEAC}"
|
||||
ProjectSection(SolutionItems) = preProject
|
||||
Directory.Build.props = Directory.Build.props
|
||||
Directory.Packages.props = Directory.Packages.props
|
||||
EndProjectSection
|
||||
EndProject
|
||||
Global
|
||||
|
||||
@@ -33,8 +33,6 @@ public class MainConfiguration
|
||||
}
|
||||
}
|
||||
}
|
||||
[JsonProperty("Icons.Cache")]
|
||||
public bool CacheIcons { get; set; } = true;
|
||||
|
||||
[JsonProperty("Update.Auto")]
|
||||
public bool AutoUpdates { get; set; } = true;
|
||||
@@ -42,6 +40,15 @@ public class MainConfiguration
|
||||
[JsonProperty("Update.InstallBeta")]
|
||||
public bool UpdateBetaVersions { get; set; }
|
||||
|
||||
[JsonProperty("Connection.Ssl.Enabled")]
|
||||
public bool EnableSsl { get; set; }
|
||||
|
||||
[JsonProperty("Connection.Ssl.Certificate.Path")]
|
||||
public string? SslCertificatePath { get; set; }
|
||||
|
||||
[JsonProperty("Connection.Ssl.Certificate.Password")]
|
||||
public string? SslCertificatePassword { get; set; }
|
||||
|
||||
[JsonProperty("Connection.Host.Address")]
|
||||
public string HostAddress { get; set; } = "127.0.0.1";
|
||||
|
||||
@@ -53,6 +60,7 @@ public class MainConfiguration
|
||||
|
||||
[JsonProperty("Connection.BlockNewConnections")]
|
||||
public bool BlockNewConnections { get; set; }
|
||||
|
||||
[JsonProperty("Language")]
|
||||
public string Language { get; set; } = "English";
|
||||
|
||||
|
||||
@@ -72,11 +72,7 @@ public partial class ExtensionStoreDownloader : DialogForm
|
||||
{
|
||||
if (PluginManager.UpdatedPlugins.Count > 0)
|
||||
{
|
||||
using var msgBox = new MessageBox();
|
||||
if (msgBox.ShowDialog(LanguageManager.Strings.MacroDeckNeedsARestart, LanguageManager.Strings.MacroDeckMustBeRestartedForTheChanges, MessageBoxButtons.YesNo) == DialogResult.Yes)
|
||||
{
|
||||
MacroDeck.RestartMacroDeck();
|
||||
}
|
||||
MacroDeck.RequestRestart();
|
||||
}
|
||||
Close();
|
||||
}
|
||||
|
||||
269
MacroDeck/GUI/MainWindowViews/SettingsView.Designer.cs
generated
269
MacroDeck/GUI/MainWindowViews/SettingsView.Designer.cs
generated
@@ -39,22 +39,23 @@ namespace SuchByte.MacroDeck.GUI.MainWindowContents
|
||||
ComponentResourceManager resources = new ComponentResourceManager(typeof(SettingsView));
|
||||
verticalTabControl = new VerticalTabControl();
|
||||
tabGeneral = new TabPage();
|
||||
checkIconCache = new CheckBox();
|
||||
language = new RoundedComboBox();
|
||||
lblLanguage = new Label();
|
||||
checkStartWindows = new CheckBox();
|
||||
lblBehaviour = new Label();
|
||||
lblGeneral = new Label();
|
||||
tabConnection = new TabPage();
|
||||
btnApplySslConfiguration = new ButtonPrimary();
|
||||
btnBrowseCertificatePath = new ButtonPrimary();
|
||||
label4 = new Label();
|
||||
certificatePassword = new RoundedTextBox();
|
||||
label3 = new Label();
|
||||
certificatePath = new RoundedTextBox();
|
||||
checkEnableSsl = new CheckBox();
|
||||
labelSsl = new Label();
|
||||
btnChangePort = new ButtonPrimary();
|
||||
groupConnectionInfo = new GroupBox();
|
||||
lblConnectionInfo = new Label();
|
||||
port = new NumericUpDown();
|
||||
lblPort = new Label();
|
||||
lblIpAddessLabel = new Label();
|
||||
lblIpAddress = new Label();
|
||||
networkAdapter = new RoundedComboBox();
|
||||
lblNetworkAdapter = new Label();
|
||||
lblConnection = new Label();
|
||||
tabUpdater = new TabPage();
|
||||
label2 = new Label();
|
||||
@@ -86,7 +87,6 @@ namespace SuchByte.MacroDeck.GUI.MainWindowContents
|
||||
verticalTabControl.SuspendLayout();
|
||||
tabGeneral.SuspendLayout();
|
||||
tabConnection.SuspendLayout();
|
||||
groupConnectionInfo.SuspendLayout();
|
||||
((ISupportInitialize)port).BeginInit();
|
||||
tabUpdater.SuspendLayout();
|
||||
tabBackups.SuspendLayout();
|
||||
@@ -119,7 +119,6 @@ namespace SuchByte.MacroDeck.GUI.MainWindowContents
|
||||
// tabGeneral
|
||||
//
|
||||
tabGeneral.BackColor = Color.FromArgb(45, 45, 45);
|
||||
tabGeneral.Controls.Add(checkIconCache);
|
||||
tabGeneral.Controls.Add(language);
|
||||
tabGeneral.Controls.Add(lblLanguage);
|
||||
tabGeneral.Controls.Add(checkStartWindows);
|
||||
@@ -134,18 +133,6 @@ namespace SuchByte.MacroDeck.GUI.MainWindowContents
|
||||
tabGeneral.TabIndex = 0;
|
||||
tabGeneral.Text = "General";
|
||||
//
|
||||
// checkIconCache
|
||||
//
|
||||
checkIconCache.AutoSize = true;
|
||||
checkIconCache.Location = new Point(13, 112);
|
||||
checkIconCache.Name = "checkIconCache";
|
||||
checkIconCache.Size = new Size(375, 23);
|
||||
checkIconCache.TabIndex = 14;
|
||||
checkIconCache.Text = "Enable icon cache (faster; higher memory usage)";
|
||||
checkIconCache.UseMnemonic = false;
|
||||
checkIconCache.UseVisualStyleBackColor = true;
|
||||
checkIconCache.CheckedChanged += CheckIconCache_CheckedChanged;
|
||||
//
|
||||
// language
|
||||
//
|
||||
language.BackColor = Color.FromArgb(65, 65, 65);
|
||||
@@ -213,14 +200,17 @@ namespace SuchByte.MacroDeck.GUI.MainWindowContents
|
||||
// tabConnection
|
||||
//
|
||||
tabConnection.BackColor = Color.FromArgb(45, 45, 45);
|
||||
tabConnection.Controls.Add(btnApplySslConfiguration);
|
||||
tabConnection.Controls.Add(btnBrowseCertificatePath);
|
||||
tabConnection.Controls.Add(label4);
|
||||
tabConnection.Controls.Add(certificatePassword);
|
||||
tabConnection.Controls.Add(label3);
|
||||
tabConnection.Controls.Add(certificatePath);
|
||||
tabConnection.Controls.Add(checkEnableSsl);
|
||||
tabConnection.Controls.Add(labelSsl);
|
||||
tabConnection.Controls.Add(btnChangePort);
|
||||
tabConnection.Controls.Add(groupConnectionInfo);
|
||||
tabConnection.Controls.Add(port);
|
||||
tabConnection.Controls.Add(lblPort);
|
||||
tabConnection.Controls.Add(lblIpAddessLabel);
|
||||
tabConnection.Controls.Add(lblIpAddress);
|
||||
tabConnection.Controls.Add(networkAdapter);
|
||||
tabConnection.Controls.Add(lblNetworkAdapter);
|
||||
tabConnection.Controls.Add(lblConnection);
|
||||
tabConnection.Font = new Font("Tahoma", 9F, FontStyle.Regular, GraphicsUnit.Point);
|
||||
tabConnection.ForeColor = Color.White;
|
||||
@@ -230,6 +220,138 @@ namespace SuchByte.MacroDeck.GUI.MainWindowContents
|
||||
tabConnection.TabIndex = 3;
|
||||
tabConnection.Text = "Connection";
|
||||
//
|
||||
// btnApplySslConfiguration
|
||||
//
|
||||
btnApplySslConfiguration.BorderRadius = 8;
|
||||
btnApplySslConfiguration.Cursor = Cursors.Hand;
|
||||
btnApplySslConfiguration.FlatAppearance.BorderSize = 0;
|
||||
btnApplySslConfiguration.FlatStyle = FlatStyle.Flat;
|
||||
btnApplySslConfiguration.Font = new Font("Tahoma", 9.75F, FontStyle.Regular, GraphicsUnit.Point);
|
||||
btnApplySslConfiguration.ForeColor = Color.White;
|
||||
btnApplySslConfiguration.HoverColor = Color.FromArgb(0, 89, 184);
|
||||
btnApplySslConfiguration.Icon = null;
|
||||
btnApplySslConfiguration.Location = new Point(410, 294);
|
||||
btnApplySslConfiguration.Name = "btnApplySslConfiguration";
|
||||
btnApplySslConfiguration.Progress = 0;
|
||||
btnApplySslConfiguration.ProgressColor = Color.FromArgb(0, 46, 94);
|
||||
btnApplySslConfiguration.Size = new Size(206, 30);
|
||||
btnApplySslConfiguration.TabIndex = 24;
|
||||
btnApplySslConfiguration.Text = "Apply SSL configuration";
|
||||
btnApplySslConfiguration.UseMnemonic = false;
|
||||
btnApplySslConfiguration.UseVisualStyleBackColor = false;
|
||||
btnApplySslConfiguration.UseWindowsAccentColor = true;
|
||||
btnApplySslConfiguration.WriteProgress = true;
|
||||
btnApplySslConfiguration.Click += BtnApplySslConfiguration_Click;
|
||||
//
|
||||
// btnBrowseCertificatePath
|
||||
//
|
||||
btnBrowseCertificatePath.BorderRadius = 8;
|
||||
btnBrowseCertificatePath.Cursor = Cursors.Hand;
|
||||
btnBrowseCertificatePath.FlatAppearance.BorderSize = 0;
|
||||
btnBrowseCertificatePath.FlatStyle = FlatStyle.Flat;
|
||||
btnBrowseCertificatePath.Font = new Font("Tahoma", 9.75F, FontStyle.Regular, GraphicsUnit.Point);
|
||||
btnBrowseCertificatePath.ForeColor = Color.White;
|
||||
btnBrowseCertificatePath.HoverColor = Color.FromArgb(0, 89, 184);
|
||||
btnBrowseCertificatePath.Icon = null;
|
||||
btnBrowseCertificatePath.Location = new Point(570, 222);
|
||||
btnBrowseCertificatePath.Name = "btnBrowseCertificatePath";
|
||||
btnBrowseCertificatePath.Progress = 0;
|
||||
btnBrowseCertificatePath.ProgressColor = Color.FromArgb(0, 46, 94);
|
||||
btnBrowseCertificatePath.Size = new Size(46, 30);
|
||||
btnBrowseCertificatePath.TabIndex = 23;
|
||||
btnBrowseCertificatePath.Text = "...";
|
||||
btnBrowseCertificatePath.UseMnemonic = false;
|
||||
btnBrowseCertificatePath.UseVisualStyleBackColor = false;
|
||||
btnBrowseCertificatePath.UseWindowsAccentColor = true;
|
||||
btnBrowseCertificatePath.WriteProgress = true;
|
||||
btnBrowseCertificatePath.Click += BtnBrowseCertificatePath_Click;
|
||||
//
|
||||
// label4
|
||||
//
|
||||
label4.Font = new Font("Tahoma", 11.25F, FontStyle.Regular, GraphicsUnit.Point);
|
||||
label4.Location = new Point(17, 258);
|
||||
label4.Name = "label4";
|
||||
label4.Size = new Size(159, 30);
|
||||
label4.TabIndex = 22;
|
||||
label4.Text = "Certificate password:";
|
||||
label4.TextAlign = ContentAlignment.MiddleLeft;
|
||||
label4.UseMnemonic = false;
|
||||
//
|
||||
// certificatePassword
|
||||
//
|
||||
certificatePassword.BackColor = Color.FromArgb(65, 65, 65);
|
||||
certificatePassword.Font = new Font("Tahoma", 12F, FontStyle.Regular, GraphicsUnit.Point);
|
||||
certificatePassword.Icon = null;
|
||||
certificatePassword.Location = new Point(182, 258);
|
||||
certificatePassword.MaxCharacters = 32767;
|
||||
certificatePassword.Multiline = false;
|
||||
certificatePassword.Name = "certificatePassword";
|
||||
certificatePassword.Padding = new Padding(8, 5, 8, 5);
|
||||
certificatePassword.PasswordChar = true;
|
||||
certificatePassword.PlaceHolderColor = Color.Gray;
|
||||
certificatePassword.PlaceHolderText = "";
|
||||
certificatePassword.ReadOnly = false;
|
||||
certificatePassword.ScrollBars = ScrollBars.None;
|
||||
certificatePassword.SelectionStart = 0;
|
||||
certificatePassword.Size = new Size(382, 30);
|
||||
certificatePassword.TabIndex = 21;
|
||||
certificatePassword.TextAlignment = HorizontalAlignment.Left;
|
||||
//
|
||||
// label3
|
||||
//
|
||||
label3.Font = new Font("Tahoma", 11.25F, FontStyle.Regular, GraphicsUnit.Point);
|
||||
label3.Location = new Point(17, 222);
|
||||
label3.Name = "label3";
|
||||
label3.Size = new Size(159, 30);
|
||||
label3.TabIndex = 20;
|
||||
label3.Text = "Certificate path:";
|
||||
label3.TextAlign = ContentAlignment.MiddleLeft;
|
||||
label3.UseMnemonic = false;
|
||||
//
|
||||
// certificatePath
|
||||
//
|
||||
certificatePath.BackColor = Color.FromArgb(65, 65, 65);
|
||||
certificatePath.Font = new Font("Tahoma", 12F, FontStyle.Regular, GraphicsUnit.Point);
|
||||
certificatePath.Icon = null;
|
||||
certificatePath.Location = new Point(182, 222);
|
||||
certificatePath.MaxCharacters = 32767;
|
||||
certificatePath.Multiline = false;
|
||||
certificatePath.Name = "certificatePath";
|
||||
certificatePath.Padding = new Padding(8, 5, 8, 5);
|
||||
certificatePath.PasswordChar = false;
|
||||
certificatePath.PlaceHolderColor = Color.Gray;
|
||||
certificatePath.PlaceHolderText = "";
|
||||
certificatePath.ReadOnly = false;
|
||||
certificatePath.ScrollBars = ScrollBars.None;
|
||||
certificatePath.SelectionStart = 0;
|
||||
certificatePath.Size = new Size(382, 30);
|
||||
certificatePath.TabIndex = 19;
|
||||
certificatePath.TextAlignment = HorizontalAlignment.Left;
|
||||
//
|
||||
// checkEnableSsl
|
||||
//
|
||||
checkEnableSsl.AutoSize = true;
|
||||
checkEnableSsl.Font = new Font("Tahoma", 12F, FontStyle.Regular, GraphicsUnit.Point);
|
||||
checkEnableSsl.Location = new Point(12, 193);
|
||||
checkEnableSsl.Name = "checkEnableSsl";
|
||||
checkEnableSsl.Size = new Size(106, 23);
|
||||
checkEnableSsl.TabIndex = 18;
|
||||
checkEnableSsl.Text = "Enable SSL";
|
||||
checkEnableSsl.UseMnemonic = false;
|
||||
checkEnableSsl.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// labelSsl
|
||||
//
|
||||
labelSsl.AutoSize = true;
|
||||
labelSsl.Font = new Font("Tahoma", 14.25F, FontStyle.Regular, GraphicsUnit.Point);
|
||||
labelSsl.ForeColor = Color.Gray;
|
||||
labelSsl.Location = new Point(3, 167);
|
||||
labelSsl.Name = "labelSsl";
|
||||
labelSsl.Size = new Size(41, 23);
|
||||
labelSsl.TabIndex = 13;
|
||||
labelSsl.Text = "SSL";
|
||||
labelSsl.UseMnemonic = false;
|
||||
//
|
||||
// btnChangePort
|
||||
//
|
||||
btnChangePort.BorderRadius = 8;
|
||||
@@ -253,30 +375,6 @@ namespace SuchByte.MacroDeck.GUI.MainWindowContents
|
||||
btnChangePort.WriteProgress = true;
|
||||
btnChangePort.Click += BtnChangePort_Click;
|
||||
//
|
||||
// groupConnectionInfo
|
||||
//
|
||||
groupConnectionInfo.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
|
||||
groupConnectionInfo.Controls.Add(lblConnectionInfo);
|
||||
groupConnectionInfo.Font = new Font("Tahoma", 14.25F, FontStyle.Regular, GraphicsUnit.Point);
|
||||
groupConnectionInfo.ForeColor = Color.White;
|
||||
groupConnectionInfo.Location = new Point(12, 342);
|
||||
groupConnectionInfo.Name = "groupConnectionInfo";
|
||||
groupConnectionInfo.Size = new Size(896, 173);
|
||||
groupConnectionInfo.TabIndex = 11;
|
||||
groupConnectionInfo.TabStop = false;
|
||||
groupConnectionInfo.Text = "Info";
|
||||
//
|
||||
// lblConnectionInfo
|
||||
//
|
||||
lblConnectionInfo.Dock = DockStyle.Fill;
|
||||
lblConnectionInfo.Font = new Font("Tahoma", 11.25F, FontStyle.Regular, GraphicsUnit.Point);
|
||||
lblConnectionInfo.Location = new Point(3, 26);
|
||||
lblConnectionInfo.Name = "lblConnectionInfo";
|
||||
lblConnectionInfo.Size = new Size(890, 144);
|
||||
lblConnectionInfo.TabIndex = 0;
|
||||
lblConnectionInfo.Text = resources.GetString("lblConnectionInfo.Text");
|
||||
lblConnectionInfo.UseMnemonic = false;
|
||||
//
|
||||
// port
|
||||
//
|
||||
port.BackColor = Color.FromArgb(65, 65, 65);
|
||||
@@ -302,61 +400,6 @@ namespace SuchByte.MacroDeck.GUI.MainWindowContents
|
||||
lblPort.Text = "Port";
|
||||
lblPort.UseMnemonic = false;
|
||||
//
|
||||
// lblIpAddessLabel
|
||||
//
|
||||
lblIpAddessLabel.AutoSize = true;
|
||||
lblIpAddessLabel.Font = new Font("Tahoma", 11.25F, FontStyle.Regular, GraphicsUnit.Point);
|
||||
lblIpAddessLabel.Location = new Point(18, 280);
|
||||
lblIpAddessLabel.Name = "lblIpAddessLabel";
|
||||
lblIpAddessLabel.Size = new Size(83, 18);
|
||||
lblIpAddessLabel.TabIndex = 7;
|
||||
lblIpAddessLabel.Text = "IP address:";
|
||||
lblIpAddessLabel.UseMnemonic = false;
|
||||
lblIpAddessLabel.Visible = false;
|
||||
//
|
||||
// lblIpAddress
|
||||
//
|
||||
lblIpAddress.Font = new Font("Tahoma", 11.25F, FontStyle.Regular, GraphicsUnit.Point);
|
||||
lblIpAddress.Location = new Point(107, 280);
|
||||
lblIpAddress.Name = "lblIpAddress";
|
||||
lblIpAddress.Size = new Size(187, 17);
|
||||
lblIpAddress.TabIndex = 6;
|
||||
lblIpAddress.Text = "0.0.0.0";
|
||||
lblIpAddress.UseMnemonic = false;
|
||||
lblIpAddress.Visible = false;
|
||||
//
|
||||
// networkAdapter
|
||||
//
|
||||
networkAdapter.BackColor = Color.FromArgb(65, 65, 65);
|
||||
networkAdapter.Cursor = Cursors.Hand;
|
||||
networkAdapter.DropDownStyle = ComboBoxStyle.DropDownList;
|
||||
networkAdapter.Font = new Font("Tahoma", 12F, FontStyle.Regular, GraphicsUnit.Point);
|
||||
networkAdapter.ForeColor = Color.White;
|
||||
networkAdapter.Icon = null;
|
||||
networkAdapter.Location = new Point(18, 245);
|
||||
networkAdapter.Margin = new Padding(4);
|
||||
networkAdapter.Name = "networkAdapter";
|
||||
networkAdapter.Padding = new Padding(8, 2, 8, 2);
|
||||
networkAdapter.SelectedIndex = -1;
|
||||
networkAdapter.SelectedItem = null;
|
||||
networkAdapter.Size = new Size(276, 31);
|
||||
networkAdapter.TabIndex = 5;
|
||||
networkAdapter.Visible = false;
|
||||
networkAdapter.SelectedIndexChanged += NetworkAdapter_SelectedIndexChanged;
|
||||
//
|
||||
// lblNetworkAdapter
|
||||
//
|
||||
lblNetworkAdapter.AutoSize = true;
|
||||
lblNetworkAdapter.Font = new Font("Tahoma", 14.25F, FontStyle.Regular, GraphicsUnit.Point);
|
||||
lblNetworkAdapter.ForeColor = Color.Gray;
|
||||
lblNetworkAdapter.Location = new Point(9, 221);
|
||||
lblNetworkAdapter.Name = "lblNetworkAdapter";
|
||||
lblNetworkAdapter.Size = new Size(150, 23);
|
||||
lblNetworkAdapter.TabIndex = 2;
|
||||
lblNetworkAdapter.Text = "Network adapter";
|
||||
lblNetworkAdapter.UseMnemonic = false;
|
||||
lblNetworkAdapter.Visible = false;
|
||||
//
|
||||
// lblConnection
|
||||
//
|
||||
lblConnection.AutoSize = true;
|
||||
@@ -732,7 +775,6 @@ namespace SuchByte.MacroDeck.GUI.MainWindowContents
|
||||
tabGeneral.PerformLayout();
|
||||
tabConnection.ResumeLayout(false);
|
||||
tabConnection.PerformLayout();
|
||||
groupConnectionInfo.ResumeLayout(false);
|
||||
((ISupportInitialize)port).EndInit();
|
||||
tabUpdater.ResumeLayout(false);
|
||||
tabUpdater.PerformLayout();
|
||||
@@ -763,14 +805,8 @@ namespace SuchByte.MacroDeck.GUI.MainWindowContents
|
||||
private CheckBox checkStartWindows;
|
||||
private Label lblLanguage;
|
||||
private RoundedComboBox language;
|
||||
private RoundedComboBox networkAdapter;
|
||||
private Label lblNetworkAdapter;
|
||||
private Label lblIpAddress;
|
||||
private Label lblIpAddessLabel;
|
||||
private Label lblPort;
|
||||
private NumericUpDown port;
|
||||
private GroupBox groupConnectionInfo;
|
||||
private Label lblConnectionInfo;
|
||||
private ButtonPrimary btnChangePort;
|
||||
private ButtonPrimary btnCheckUpdates;
|
||||
private Label lblInstalledVersion;
|
||||
@@ -781,7 +817,6 @@ namespace SuchByte.MacroDeck.GUI.MainWindowContents
|
||||
private Label lblWebSocketAPILabel;
|
||||
private ButtonPrimary btnLicenses;
|
||||
private Label lblTranslationBy;
|
||||
private CheckBox checkIconCache;
|
||||
private ImageList tabIcons;
|
||||
private Label label1;
|
||||
private CheckBox checkInstallBetaVersions;
|
||||
@@ -792,5 +827,13 @@ namespace SuchByte.MacroDeck.GUI.MainWindowContents
|
||||
private ButtonPrimary btnCreateBackup;
|
||||
private PictureButton btnGitHub;
|
||||
private Label label2;
|
||||
private ButtonPrimary btnApplySslConfiguration;
|
||||
private ButtonPrimary btnBrowseCertificatePath;
|
||||
private Label label4;
|
||||
private RoundedTextBox certificatePassword;
|
||||
private Label label3;
|
||||
private RoundedTextBox certificatePath;
|
||||
private CheckBox checkEnableSsl;
|
||||
private Label labelSsl;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,5 @@
|
||||
using System.Diagnostics;
|
||||
using System.Net;
|
||||
using System.Net.NetworkInformation;
|
||||
using System.Net.Sockets;
|
||||
using System.Threading;
|
||||
using System.Windows.Forms;
|
||||
using System.IO;
|
||||
using SuchByte.MacroDeck.Backups;
|
||||
using SuchByte.MacroDeck.GUI.CustomControls.Settings;
|
||||
using SuchByte.MacroDeck.GUI.Dialogs;
|
||||
@@ -49,15 +45,10 @@ public partial class SettingsView : UserControl
|
||||
lblGeneral.Text = LanguageManager.Strings.General;
|
||||
lblBehaviour.Text = LanguageManager.Strings.Behaviour;
|
||||
checkStartWindows.Text = LanguageManager.Strings.AutomaticallyStartWithWindows;
|
||||
checkIconCache.Text = LanguageManager.Strings.EnableIconCache;
|
||||
lblLanguage.Text = LanguageManager.Strings.Language;
|
||||
lblConnection.Text = LanguageManager.Strings.Connection;
|
||||
lblNetworkAdapter.Text = LanguageManager.Strings.NetworkAdapter;
|
||||
lblIpAddessLabel.Text = LanguageManager.Strings.IPAddress;
|
||||
lblPort.Text = LanguageManager.Strings.Port;
|
||||
btnChangePort.Text = LanguageManager.Strings.Ok;
|
||||
groupConnectionInfo.Text = LanguageManager.Strings.Info;
|
||||
lblConnectionInfo.Text = LanguageManager.Strings.ConfigureNetworkInfo;
|
||||
lblUpdates.Text = LanguageManager.Strings.Updates;
|
||||
checkAutoUpdate.Text = LanguageManager.Strings.AutomaticallyCheckUpdates;
|
||||
lblInstalledVersionLabel.Text = LanguageManager.Strings.InstalledVersion;
|
||||
@@ -76,10 +67,9 @@ public partial class SettingsView : UserControl
|
||||
{
|
||||
LoadAutoStart();
|
||||
LoadLanguage();
|
||||
LoadNetworkAdapters();
|
||||
LoadUpdateChannel();
|
||||
LoadNetworkConfiguration();
|
||||
LoadAutoUpdate();
|
||||
LoadIconCache();
|
||||
LoadBackups();
|
||||
|
||||
lblInstalledVersion.Text = MacroDeck.Version.ToString();
|
||||
@@ -108,6 +98,14 @@ public partial class SettingsView : UserControl
|
||||
checkAutoUpdate.CheckedChanged += CheckAutoUpdate_CheckedChanged;
|
||||
}
|
||||
|
||||
private void LoadNetworkConfiguration()
|
||||
{
|
||||
port.Value = MacroDeck.Configuration.HostPort;
|
||||
checkEnableSsl.Checked = MacroDeck.Configuration.EnableSsl;
|
||||
certificatePath.Text = MacroDeck.Configuration.SslCertificatePath;
|
||||
certificatePassword.Text = MacroDeck.Configuration.SslCertificatePassword;
|
||||
}
|
||||
|
||||
private void LoadAutoStart()
|
||||
{
|
||||
checkStartWindows.CheckedChanged -= CheckStartWindows_CheckedChanged;
|
||||
@@ -115,14 +113,6 @@ public partial class SettingsView : UserControl
|
||||
checkStartWindows.CheckedChanged += CheckStartWindows_CheckedChanged;
|
||||
}
|
||||
|
||||
private void LoadIconCache()
|
||||
{
|
||||
checkIconCache.CheckedChanged -= CheckIconCache_CheckedChanged;
|
||||
checkIconCache.Checked = MacroDeck.Configuration.CacheIcons;
|
||||
checkIconCache.CheckedChanged += CheckIconCache_CheckedChanged;
|
||||
|
||||
}
|
||||
|
||||
private void LoadUpdateChannel()
|
||||
{
|
||||
checkInstallBetaVersions.CheckedChanged -= CheckInstallBetaVersions_CheckedChanged;
|
||||
@@ -162,84 +152,12 @@ public partial class SettingsView : UserControl
|
||||
}
|
||||
}
|
||||
|
||||
private void LoadNetworkAdapters()
|
||||
{
|
||||
networkAdapter.SelectedIndexChanged -= NetworkAdapter_SelectedIndexChanged;
|
||||
networkAdapter.Items.Clear();
|
||||
try
|
||||
{
|
||||
var adapters = NetworkInterface.GetAllNetworkInterfaces();
|
||||
foreach (var adapter in adapters)
|
||||
{
|
||||
networkAdapter.Items.Add(adapter.Name);
|
||||
}
|
||||
}
|
||||
catch { }
|
||||
networkAdapter.Text = GetAdapterFromIPAddress(MacroDeck.Configuration.HostAddress);
|
||||
lblIpAddress.Text = MacroDeck.Configuration.HostAddress;
|
||||
networkAdapter.SelectedIndexChanged += NetworkAdapter_SelectedIndexChanged;
|
||||
}
|
||||
|
||||
private string GetAdapterFromIPAddress(string address)
|
||||
{
|
||||
var adapters = NetworkInterface.GetAllNetworkInterfaces();
|
||||
foreach (var adapter in adapters)
|
||||
{
|
||||
foreach (var ip in adapter.GetIPProperties().UnicastAddresses)
|
||||
{
|
||||
if (ip.Address.AddressFamily == AddressFamily.InterNetwork && ip.Address.ToString().Equals(address))
|
||||
{
|
||||
return adapter.Name;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
public IPAddress GetDefaultIPAddress()
|
||||
{
|
||||
if (!NetworkInterface.GetIsNetworkAvailable())
|
||||
{
|
||||
return null;
|
||||
}
|
||||
var host = Dns.GetHostEntry(Dns.GetHostName());
|
||||
|
||||
return host
|
||||
.AddressList
|
||||
.FirstOrDefault(ip => ip.AddressFamily == AddressFamily.InterNetwork);
|
||||
}
|
||||
|
||||
public string GetIPAddressFromAdapter(string adapterName)
|
||||
{
|
||||
var adapters = NetworkInterface.GetAllNetworkInterfaces();
|
||||
foreach (var adapter in adapters)
|
||||
{
|
||||
if (adapter.Name.Equals(adapterName))
|
||||
{
|
||||
foreach (var ip in adapter.GetIPProperties().UnicastAddresses)
|
||||
{
|
||||
if (ip.Address.AddressFamily == AddressFamily.InterNetwork)
|
||||
return ip.Address.ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
return "0.0.0.0";
|
||||
}
|
||||
|
||||
private void NetworkAdapter_SelectedIndexChanged(object sender, EventArgs e)
|
||||
{
|
||||
lblIpAddress.Text = GetIPAddressFromAdapter(networkAdapter.SelectedItem.ToString());
|
||||
MacroDeck.Configuration.HostAddress = lblIpAddress.Text;
|
||||
MacroDeck.Configuration.Save(ApplicationPaths.MainConfigFilePath);
|
||||
}
|
||||
|
||||
private async void BtnChangePort_Click(object sender, EventArgs e)
|
||||
private void BtnChangePort_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (port.Value == MacroDeck.Configuration.HostPort) return;
|
||||
MacroDeck.Configuration.HostPort = (int)port.Value;
|
||||
MacroDeck.Configuration.Save(ApplicationPaths.MainConfigFilePath);
|
||||
await MacroDeckServer.Start(MacroDeck.Configuration.HostPort);
|
||||
MacroDeck.RequestRestart();
|
||||
}
|
||||
|
||||
private void CheckStartWindows_CheckedChanged(object sender, EventArgs e)
|
||||
@@ -311,12 +229,6 @@ public partial class SettingsView : UserControl
|
||||
UpdateTranslation();
|
||||
}
|
||||
|
||||
private void CheckIconCache_CheckedChanged(object sender, EventArgs e)
|
||||
{
|
||||
MacroDeck.Configuration.CacheIcons = checkIconCache.Checked;
|
||||
MacroDeck.Configuration.Save(ApplicationPaths.MainConfigFilePath);
|
||||
}
|
||||
|
||||
private void BackupManager_BackupFailed(object sender, BackupFailedEventArgs e)
|
||||
{
|
||||
Invoke(() =>
|
||||
@@ -365,4 +277,40 @@ public partial class SettingsView : UserControl
|
||||
};
|
||||
p.Start();
|
||||
}
|
||||
|
||||
private void BtnApplySslConfiguration_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (checkEnableSsl.Checked
|
||||
&& (string.IsNullOrWhiteSpace(certificatePath.Text) || !File.Exists(certificatePath.Text)))
|
||||
{
|
||||
var messageBox = new MessageBox();
|
||||
messageBox.ShowDialog(
|
||||
"SSL Certificate not found",
|
||||
"You enabled SSL but don't provide a valid certificate path.",
|
||||
MessageBoxButtons.OK);
|
||||
return;
|
||||
}
|
||||
|
||||
MacroDeck.Configuration.EnableSsl = checkEnableSsl.Checked;
|
||||
MacroDeck.Configuration.SslCertificatePath = certificatePath.Text;
|
||||
MacroDeck.Configuration.SslCertificatePassword = certificatePassword.Text;
|
||||
MacroDeck.Configuration.Save(ApplicationPaths.MainConfigFilePath);
|
||||
MacroDeck.RequestRestart();
|
||||
}
|
||||
|
||||
private void BtnBrowseCertificatePath_Click(object sender, EventArgs e)
|
||||
{
|
||||
using var openFileDialog = new OpenFileDialog
|
||||
{
|
||||
Title = "Select certificate",
|
||||
CheckFileExists = true,
|
||||
CheckPathExists = true,
|
||||
DefaultExt = ".pfx",
|
||||
Filter = "Personal Information Exchange File (*.pfx)|*.pfx",
|
||||
};
|
||||
if (openFileDialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
certificatePath.Text = openFileDialog.FileName;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -57,11 +57,6 @@
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<data name="lblConnectionInfo.Text" xml:space="preserve">
|
||||
<value>It's really important to select the correct network adapter or otherwise you will not be able to connect with the client to the server. In most cases the name of the Network adapter looks like "Ethernet" or "Wi-Fi" and the ip address in most cases looks like "192.168.178.xxx".
|
||||
|
||||
The default port for Macro Deck is 8191. If some other application uses this port, you can change it.</value>
|
||||
</data>
|
||||
<metadata name="tabIcons.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>17, 17</value>
|
||||
</metadata>
|
||||
@@ -70,7 +65,7 @@ The default port for Macro Deck is 8191. If some other application uses this por
|
||||
AAEAAAD/////AQAAAAAAAAAMAgAAAEZTeXN0ZW0uV2luZG93cy5Gb3JtcywgQ3VsdHVyZT1uZXV0cmFs
|
||||
LCBQdWJsaWNLZXlUb2tlbj1iNzdhNWM1NjE5MzRlMDg5BQEAAAAmU3lzdGVtLldpbmRvd3MuRm9ybXMu
|
||||
SW1hZ2VMaXN0U3RyZWFtZXIBAAAABERhdGEHAgIAAAAJAwAAAA8DAAAAfg4AAAJNU0Z0AUkBTAIBAQUB
|
||||
AAFoAQABaAEAATABAAEwAQAE/wEFAQAI/wFCAU0BdgcAAXYDAAEoAwABwAMAAWADAAEBAQABBAYAASQY
|
||||
AAGQAQABkAEAATABAAEwAQAE/wEFAQAI/wFCAU0BdgcAAXYDAAEoAwABwAMAAWADAAEBAQABBAYAASQY
|
||||
AAGAAgABgAMAAoABAAGAAwABgAEAAYABAAKAAgADwAEAA4ADAAH/AgAB/wMAAv8BAAH/AwAB/wEAAf8B
|
||||
AAL/AgAD//8A/wD/AA0AAQ8C/10AAQ8D/1wAAQ8D/wHwWwABDwT/AfBaAAEPBf9aAAEPAv8B8AEPAf9a
|
||||
AAEPAv8B8FwAAQ8C/wHwXQAD/10AA/9dAAP/XQAD/10AAQ8C/wHwXAABDwL/AfBcAAEPAv8B8FoAAQ8B
|
||||
|
||||
@@ -101,8 +101,7 @@ public class MacroDeck : NativeWindow
|
||||
ProfileManager.Load();
|
||||
|
||||
SearchNetworkInterfaces();
|
||||
Task.Run(async () =>
|
||||
await MacroDeckServer.Start(StartParameters.Port <= 0 ? Configuration.HostPort : StartParameters.Port));
|
||||
MacroDeckServer.Start(StartParameters.Port <= 0 ? Configuration.HostPort : StartParameters.Port);
|
||||
BroadcastServer.Start();
|
||||
ADBServerHelper.Initialize();
|
||||
|
||||
@@ -239,6 +238,15 @@ public class MacroDeck : NativeWindow
|
||||
}
|
||||
}
|
||||
|
||||
public static void RequestRestart()
|
||||
{
|
||||
using var msgBox = new GUI.CustomControls.MessageBox();
|
||||
if (msgBox.ShowDialog(LanguageManager.Strings.MacroDeckNeedsARestart, LanguageManager.Strings.MacroDeckMustBeRestartedForTheChanges, MessageBoxButtons.YesNo) == DialogResult.Yes)
|
||||
{
|
||||
MacroDeck.RestartMacroDeck();
|
||||
}
|
||||
}
|
||||
|
||||
public static void RestartMacroDeck(string parameters = "")
|
||||
{
|
||||
TrayIcon.Visible = false;
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
<Platforms>AnyCPU;x64</Platforms>
|
||||
<SelfContained>true</SelfContained>
|
||||
<OutputType>WinExe</OutputType>
|
||||
<Nullable>false</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
@@ -36,18 +37,18 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="CommandLineParser" Version="2.9.1" />
|
||||
<PackageReference Include="Cottle" Version="2.0.9" />
|
||||
<PackageReference Include="Dax-FCTB" Version="2.16.26.120" />
|
||||
<PackageReference Include="Magick.NET-Q16-x64" Version="13.0.0" />
|
||||
<PackageReference Include="Magick.NET.SystemDrawing" Version="7.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="7.0.0" />
|
||||
<PackageReference Include="Microsoft.Win32.Registry" Version="5.0.0" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
||||
<PackageReference Include="sharpadbclient" Version="2.3.23" />
|
||||
<PackageReference Include="sqlite-net-pcl" Version="1.8.116" />
|
||||
<PackageReference Include="System.Collections" Version="4.3.0" />
|
||||
<PackageReference Include="System.Drawing.Common" Version="7.0.0" />
|
||||
<PackageReference Include="CommandLineParser" />
|
||||
<PackageReference Include="Cottle" />
|
||||
<PackageReference Include="Dax-FCTB" />
|
||||
<PackageReference Include="Magick.NET-Q16-x64" />
|
||||
<PackageReference Include="Magick.NET.SystemDrawing" />
|
||||
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" />
|
||||
<PackageReference Include="Microsoft.Win32.Registry" />
|
||||
<PackageReference Include="Newtonsoft.Json" />
|
||||
<PackageReference Include="sharpadbclient" />
|
||||
<PackageReference Include="sqlite-net-pcl" />
|
||||
<PackageReference Include="System.Collections" />
|
||||
<PackageReference Include="System.Drawing.Common" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -155,7 +155,7 @@
|
||||
"NewConnection": "New connection",
|
||||
"XIsAnUnknownDevice": "{0} is an unknown device and wants to connect to Macro Deck. Allow connection?",
|
||||
"ShouldMacroDeckBlockConnectionsFromX": "Should Macro Deck automatically block future connections from {0}?",
|
||||
"FailedToStartServer": "Failed to start the server. Perhaps the configured port is already in use or you set the incorrect network adapter. Confirm you set the correct network adapter in the settings and try to change the port.",
|
||||
"FailedToStartServer": "Failed to start the server. Perhaps the configured port is already in use.",
|
||||
"ErrorWhileLoadingPlugins": "Error while loading plugins",
|
||||
"PluginXCouldNotBeLoaded": "{0} version {1} could not be loaded.Perhaps it is not compatible with this version of Macro Deck. Actions that uses this plugin, will not work until the plugin is updated.",
|
||||
"InstallationSuccessfull": "Installation successfull",
|
||||
|
||||
@@ -155,7 +155,7 @@
|
||||
"NewConnection": "Neue Verbindung",
|
||||
"XIsAnUnknownDevice": "{0} ist ein unbekanntes Gerät. Verbindung erlauben?",
|
||||
"ShouldMacroDeckBlockConnectionsFromX": "Sollen Verbindungsversuche von {0} immer blockiert werden?",
|
||||
"FailedToStartServer": "Server konnte nicht gestartet werden. Möglicherweise wird der Port schon benutzt oder der falsche Netzwerkadapter ist eingestellt.",
|
||||
"FailedToStartServer": "Server konnte nicht gestartet werden. Möglicherweise wird der Port schon benutzt.",
|
||||
"ErrorWhileLoadingPlugins": "Fehler beim Laden von Plugins",
|
||||
"PluginXCouldNotBeLoaded": "{0} Version {1} konnte nicht geladen werden. Möglicherweise ist die Version nicht kompatibel. Tasten, welche dieses Plugin nutzen, funktionieren möglicherweise nicht.",
|
||||
"InstallationSuccessfull": "Installation erfolgreich",
|
||||
|
||||
@@ -2,10 +2,12 @@
|
||||
using MacroDeck.Server;
|
||||
using MacroDeck.Server.DataTypes;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using SuchByte.MacroDeck.Configuration;
|
||||
using SuchByte.MacroDeck.Device;
|
||||
using SuchByte.MacroDeck.Enums;
|
||||
using SuchByte.MacroDeck.Folders;
|
||||
using SuchByte.MacroDeck.JSON;
|
||||
using SuchByte.MacroDeck.Language;
|
||||
using SuchByte.MacroDeck.Logging;
|
||||
using SuchByte.MacroDeck.Profiles;
|
||||
|
||||
@@ -19,55 +21,33 @@ public static class MacroDeckServer
|
||||
|
||||
public static List<MacroDeckClient> Clients { get; } = new();
|
||||
|
||||
public static async Task Start(int port)
|
||||
public static void Start(int port)
|
||||
{
|
||||
DeviceManager.LoadKnownDevices();
|
||||
await StartWebSocketServer(IPAddress.Any.ToString(), port);
|
||||
Task.Run(async () => await StartWebSocketServer(port));
|
||||
}
|
||||
|
||||
private static async Task StartWebSocketServer(string ipAddress, int port)
|
||||
private static async Task StartWebSocketServer(int port)
|
||||
{
|
||||
Clients.Clear();
|
||||
WebSocketHandler.SessionDisconnected += WebSocketHandlerOnSessionDisconnected;
|
||||
WebSocketHandler.SessionConnected += WebSocketHandlerOnSessionConnected;
|
||||
WebSocketHandler.MessageReceived += WebSocketHandlerOnMessageReceived;
|
||||
await MacroDeckServerHelper.Setup(port);
|
||||
/*if (WebSocketServer != null)
|
||||
{
|
||||
MacroDeckLogger.Info("Stopping websocket server...");
|
||||
foreach (var macroDeckClient in Clients.Where(macroDeckClient => macroDeckClient.SocketConnection is { IsAvailable: true }))
|
||||
{
|
||||
macroDeckClient.SocketConnection.Close();
|
||||
}
|
||||
WebSocketServer.Dispose();
|
||||
Clients.Clear();
|
||||
MacroDeckLogger.Info("Websocket server stopped");
|
||||
OnServerStateChanged?.Invoke(WebSocketServer, EventArgs.Empty);
|
||||
}
|
||||
MacroDeckLogger.Info($"Starting websocket server @ {ipAddress}:{port}");
|
||||
WebSocketServer = new WebSocketServer("ws://" + ipAddress + ":" + port);
|
||||
WebSocketServer.ListenerSocket.NoDelay = true;
|
||||
var enableSsl = MacroDeck.Configuration.EnableSsl;
|
||||
var certificatePath = MacroDeck.Configuration.SslCertificatePath;
|
||||
var certificatePassword = MacroDeck.Configuration.SslCertificatePassword;
|
||||
try
|
||||
{
|
||||
WebSocketServer.Start(socket =>
|
||||
{
|
||||
var macroDeckClient = new MacroDeckClient(socket);
|
||||
socket.OnOpen = () => OnOpen(macroDeckClient);
|
||||
socket.OnClose = () => OnClose(macroDeckClient);
|
||||
socket.OnError = delegate { OnClose(macroDeckClient); };
|
||||
socket.OnMessage = message => OnMessage(macroDeckClient, message);
|
||||
});
|
||||
OnServerStateChanged?.Invoke(WebSocketServer, EventArgs.Empty);
|
||||
await MacroDeckServerHelper.Setup(port, enableSsl, certificatePath, certificatePassword);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
OnServerStateChanged?.Invoke(WebSocketServer, EventArgs.Empty);
|
||||
|
||||
MacroDeckLogger.Error("Failed to start server: " + ex.Message + Environment.NewLine + ex.StackTrace);
|
||||
|
||||
using var msgBox = new MessageBox();
|
||||
using var msgBox = new GUI.CustomControls.MessageBox();
|
||||
msgBox.ShowDialog(LanguageManager.Strings.Error, LanguageManager.Strings.FailedToStartServer + Environment.NewLine + ex.Message, MessageBoxButtons.OK);
|
||||
}*/
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static void WebSocketHandlerOnMessageReceived(object? sender, string message)
|
||||
|
||||
Reference in New Issue
Block a user