From b0fc380dfad764cb0dc16bca01a33f65eceb3093 Mon Sep 17 00:00:00 2001 From: Manuel Mayer Date: Fri, 10 May 2024 11:22:02 +0200 Subject: [PATCH] Add Quick Setup Qr Code --- Directory.Packages.props | 1 + .../QrCode/QuickConnectQrCodeData.cs | 20 ++ MacroDeck/GUI/MainWindow.Designer.cs | 207 +++++++----------- MacroDeck/GUI/MainWindow.cs | 32 +-- MacroDeck/GUI/MainWindow.resx | 62 +++++- MacroDeck/MacroDeck.csproj | 1 + MacroDeck/Services/QrCodeService.cs | 60 +++++ 7 files changed, 228 insertions(+), 155 deletions(-) create mode 100644 MacroDeck/DataTypes/QrCode/QuickConnectQrCodeData.cs create mode 100644 MacroDeck/Services/QrCodeService.cs diff --git a/Directory.Packages.props b/Directory.Packages.props index 4ae7caa6..6840d23c 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -12,6 +12,7 @@ + diff --git a/MacroDeck/DataTypes/QrCode/QuickConnectQrCodeData.cs b/MacroDeck/DataTypes/QrCode/QuickConnectQrCodeData.cs new file mode 100644 index 00000000..fdf8f8d1 --- /dev/null +++ b/MacroDeck/DataTypes/QrCode/QuickConnectQrCodeData.cs @@ -0,0 +1,20 @@ +namespace SuchByte.MacroDeck.DataTypes.QrCode; + +public class QuickConnectQrCodeData +{ + public string InstanceName { get; set; } + + public List NetworkInterfaces { get; set; } + + public int Port { get; set; } + + public bool Ssl { get; set; } + + public QuickConnectQrCodeData(string instanceName, List networkInterfaces, int port, bool ssl) + { + InstanceName = instanceName; + NetworkInterfaces = networkInterfaces; + Port = port; + Ssl = ssl; + } +} \ No newline at end of file diff --git a/MacroDeck/GUI/MainWindow.Designer.cs b/MacroDeck/GUI/MainWindow.Designer.cs index 30725f76..760ad934 100644 --- a/MacroDeck/GUI/MainWindow.Designer.cs +++ b/MacroDeck/GUI/MainWindow.Designer.cs @@ -59,6 +59,7 @@ private void InitializeComponent() lblVersion = new Label(); contentPanel = new BufferedPanel(); contentButtonPanel = new FlowLayoutPanel(); + btnNotifications = new NotificationButton(); btnDeck = new ContentSelectorButton(); panel1 = new Panel(); btnExtensions = new ContentSelectorButton(); @@ -67,12 +68,9 @@ private void InitializeComponent() panel2 = new Panel(); btnSettings = new ContentSelectorButton(); lblNumClientsConnected = new Label(); - label1 = new Label(); - lblPort = new Label(); - lblIpAddressHostname = new Label(); navigation = new RoundedPanel(); - btnNotifications = new NotificationButton(); - hosts = new RoundedComboBox(); + qrCodeBox = new PictureBox(); + label1 = new Label(); contentButtonPanel.SuspendLayout(); ((ISupportInitialize)btnDeck).BeginInit(); ((ISupportInitialize)btnExtensions).BeginInit(); @@ -80,6 +78,7 @@ private void InitializeComponent() ((ISupportInitialize)btnVariables).BeginInit(); ((ISupportInitialize)btnSettings).BeginInit(); navigation.SuspendLayout(); + ((ISupportInitialize)qrCodeBox).BeginInit(); SuspendLayout(); // // lblSafeMode @@ -89,29 +88,31 @@ private void InitializeComponent() // // lblVersion // - lblVersion.Anchor = AnchorStyles.Bottom | AnchorStyles.Left; + lblVersion.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; + lblVersion.Font = new Font("Tahoma", 8.25F, FontStyle.Regular, GraphicsUnit.Point, 0); lblVersion.ForeColor = Color.White; - lblVersion.Location = new Point(2, 603); + lblVersion.Location = new Point(1046, 613); lblVersion.Margin = new Padding(9, 0, 9, 0); lblVersion.Name = "lblVersion"; - lblVersion.Size = new Size(328, 30); + lblVersion.Size = new Size(154, 20); lblVersion.TabIndex = 3; lblVersion.Text = "2.0.0"; - lblVersion.TextAlign = ContentAlignment.MiddleLeft; + lblVersion.TextAlign = ContentAlignment.MiddleRight; lblVersion.UseMnemonic = false; // // contentPanel // contentPanel.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right; - contentPanel.Location = new Point(69, 94); + contentPanel.Location = new Point(65, 42); contentPanel.Margin = new Padding(9, 4, 9, 4); contentPanel.Name = "contentPanel"; - contentPanel.Size = new Size(1131, 509); + contentPanel.Size = new Size(981, 591); contentPanel.TabIndex = 4; // // contentButtonPanel // contentButtonPanel.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right; + contentButtonPanel.Controls.Add(btnNotifications); contentButtonPanel.Controls.Add(btnDeck); contentButtonPanel.Controls.Add(panel1); contentButtonPanel.Controls.Add(btnExtensions); @@ -119,21 +120,45 @@ private void InitializeComponent() contentButtonPanel.Controls.Add(btnVariables); contentButtonPanel.Controls.Add(panel2); contentButtonPanel.FlowDirection = FlowDirection.TopDown; - contentButtonPanel.Location = new Point(8, 9); + contentButtonPanel.Location = new Point(8, 7); contentButtonPanel.Margin = new Padding(0); contentButtonPanel.Name = "contentButtonPanel"; - contentButtonPanel.Size = new Size(45, 470); + contentButtonPanel.Size = new Size(45, 528); contentButtonPanel.TabIndex = 5; // + // btnNotifications + // + btnNotifications.BorderRadius = 8; + btnNotifications.Cursor = Cursors.Hand; + btnNotifications.FlatAppearance.BorderSize = 0; + btnNotifications.FlatStyle = FlatStyle.Flat; + btnNotifications.Font = new Font("Tahoma", 8F); + btnNotifications.ForeColor = Color.White; + btnNotifications.HoverColor = Color.Empty; + btnNotifications.Icon = Properties.Resources.Bell; + btnNotifications.Location = new Point(0, 4); + btnNotifications.Margin = new Padding(0, 4, 0, 4); + btnNotifications.Name = "btnNotifications"; + btnNotifications.NotificationCount = 0; + btnNotifications.Progress = 0; + btnNotifications.ProgressColor = Color.FromArgb(0, 103, 205); + btnNotifications.Size = new Size(44, 44); + btnNotifications.TabIndex = 16; + btnNotifications.UseVisualStyleBackColor = true; + btnNotifications.UseWindowsAccentColor = false; + btnNotifications.Visible = false; + btnNotifications.WriteProgress = true; + btnNotifications.Click += BtnNotifications_Click; + // // btnDeck // btnDeck.BackColor = Color.Transparent; btnDeck.BackgroundImage = Properties.Resources.deck; btnDeck.BackgroundImageLayout = ImageLayout.Stretch; btnDeck.Cursor = Cursors.Hand; - btnDeck.Font = new Font("Tahoma", 9.75F, FontStyle.Regular, GraphicsUnit.Point); + btnDeck.Font = new Font("Tahoma", 9.75F); btnDeck.ForeColor = Color.White; - btnDeck.Location = new Point(0, 0); + btnDeck.Location = new Point(0, 52); btnDeck.Margin = new Padding(0, 0, 0, 6); btnDeck.Name = "btnDeck"; btnDeck.Selected = false; @@ -145,7 +170,7 @@ private void InitializeComponent() // panel1 // panel1.BackColor = Color.Silver; - panel1.Location = new Point(0, 54); + panel1.Location = new Point(0, 106); panel1.Margin = new Padding(0, 4, 0, 4); panel1.Name = "panel1"; panel1.Size = new Size(66, 3); @@ -157,9 +182,9 @@ private void InitializeComponent() btnExtensions.BackgroundImage = Properties.Resources.Package_Manager_icon; btnExtensions.BackgroundImageLayout = ImageLayout.Stretch; btnExtensions.Cursor = Cursors.Hand; - btnExtensions.Font = new Font("Tahoma", 9.75F, FontStyle.Regular, GraphicsUnit.Point); + btnExtensions.Font = new Font("Tahoma", 9.75F); btnExtensions.ForeColor = Color.White; - btnExtensions.Location = new Point(0, 67); + btnExtensions.Location = new Point(0, 119); btnExtensions.Margin = new Padding(0, 6, 0, 6); btnExtensions.Name = "btnExtensions"; btnExtensions.Selected = false; @@ -174,9 +199,9 @@ private void InitializeComponent() btnDeviceManager.BackgroundImage = Properties.Resources.device_manager; btnDeviceManager.BackgroundImageLayout = ImageLayout.Stretch; btnDeviceManager.Cursor = Cursors.Hand; - btnDeviceManager.Font = new Font("Tahoma", 9.75F, FontStyle.Regular, GraphicsUnit.Point); + btnDeviceManager.Font = new Font("Tahoma", 9.75F); btnDeviceManager.ForeColor = Color.White; - btnDeviceManager.Location = new Point(0, 123); + btnDeviceManager.Location = new Point(0, 175); btnDeviceManager.Margin = new Padding(0, 6, 0, 6); btnDeviceManager.Name = "btnDeviceManager"; btnDeviceManager.Selected = false; @@ -191,9 +216,9 @@ private void InitializeComponent() btnVariables.BackgroundImage = Properties.Resources.variables; btnVariables.BackgroundImageLayout = ImageLayout.Stretch; btnVariables.Cursor = Cursors.Hand; - btnVariables.Font = new Font("Tahoma", 12.75F, FontStyle.Regular, GraphicsUnit.Point); + btnVariables.Font = new Font("Tahoma", 12.75F); btnVariables.ForeColor = Color.White; - btnVariables.Location = new Point(0, 179); + btnVariables.Location = new Point(0, 231); btnVariables.Margin = new Padding(0, 6, 0, 6); btnVariables.Name = "btnVariables"; btnVariables.Selected = false; @@ -206,7 +231,7 @@ private void InitializeComponent() // panel2 // panel2.BackColor = Color.Silver; - panel2.Location = new Point(0, 233); + panel2.Location = new Point(0, 285); panel2.Margin = new Padding(0, 4, 0, 4); panel2.Name = "panel2"; panel2.Size = new Size(66, 3); @@ -219,9 +244,9 @@ private void InitializeComponent() btnSettings.BackgroundImage = Properties.Resources.settings; btnSettings.BackgroundImageLayout = ImageLayout.Stretch; btnSettings.Cursor = Cursors.Hand; - btnSettings.Font = new Font("Tahoma", 9.75F, FontStyle.Regular, GraphicsUnit.Point); + btnSettings.Font = new Font("Tahoma", 9.75F); btnSettings.ForeColor = Color.White; - btnSettings.Location = new Point(8, 511); + btnSettings.Location = new Point(8, 541); btnSettings.Margin = new Padding(12, 6, 12, 6); btnSettings.Name = "btnSettings"; btnSettings.Selected = false; @@ -233,59 +258,17 @@ private void InitializeComponent() // lblNumClientsConnected // lblNumClientsConnected.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; - lblNumClientsConnected.Font = new Font("Tahoma", 9F, FontStyle.Regular, GraphicsUnit.Point); + lblNumClientsConnected.Font = new Font("Tahoma", 8.25F, FontStyle.Regular, GraphicsUnit.Point, 0); lblNumClientsConnected.ForeColor = Color.White; - lblNumClientsConnected.Location = new Point(936, 606); + lblNumClientsConnected.Location = new Point(1046, 593); lblNumClientsConnected.Margin = new Padding(9, 0, 9, 0); lblNumClientsConnected.Name = "lblNumClientsConnected"; - lblNumClientsConnected.Size = new Size(264, 27); + lblNumClientsConnected.Size = new Size(154, 20); lblNumClientsConnected.TabIndex = 8; lblNumClientsConnected.Text = "0 clients connected"; lblNumClientsConnected.TextAlign = ContentAlignment.MiddleRight; lblNumClientsConnected.UseMnemonic = false; // - // label1 - // - label1.Anchor = AnchorStyles.Top | AnchorStyles.Right; - label1.AutoSize = true; - label1.Font = new Font("Tahoma", 12F, FontStyle.Regular, GraphicsUnit.Point); - label1.Location = new Point(1094, 44); - label1.Margin = new Padding(9, 0, 9, 0); - label1.Name = "label1"; - label1.Size = new Size(15, 19); - label1.TabIndex = 10; - label1.Text = ":"; - label1.UseMnemonic = false; - // - // lblPort - // - lblPort.Anchor = AnchorStyles.Top | AnchorStyles.Right; - lblPort.BackColor = Color.FromArgb(45, 45, 45); - lblPort.Font = new Font("Tahoma", 12F, FontStyle.Regular, GraphicsUnit.Point); - lblPort.ForeColor = Color.White; - lblPort.Location = new Point(1127, 37); - lblPort.Margin = new Padding(9, 0, 9, 0); - lblPort.Name = "lblPort"; - lblPort.Size = new Size(69, 32); - lblPort.TabIndex = 11; - lblPort.Text = "8191"; - lblPort.TextAlign = ContentAlignment.MiddleLeft; - lblPort.UseMnemonic = false; - // - // lblIpAddressHostname - // - lblIpAddressHostname.Anchor = AnchorStyles.Top | AnchorStyles.Right; - lblIpAddressHostname.Font = new Font("Tahoma", 9F, FontStyle.Regular, GraphicsUnit.Point); - lblIpAddressHostname.ForeColor = Color.White; - lblIpAddressHostname.Location = new Point(225, 42); - lblIpAddressHostname.Margin = new Padding(9, 0, 9, 0); - lblIpAddressHostname.Name = "lblIpAddressHostname"; - lblIpAddressHostname.Size = new Size(468, 27); - lblIpAddressHostname.TabIndex = 13; - lblIpAddressHostname.Text = "IP address/hostname : Port"; - lblIpAddressHostname.TextAlign = ContentAlignment.MiddleRight; - lblIpAddressHostname.UseMnemonic = false; - // // navigation // navigation.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left; @@ -295,50 +278,32 @@ private void InitializeComponent() navigation.Location = new Point(0, 42); navigation.Margin = new Padding(0); navigation.Name = "navigation"; - navigation.Size = new Size(60, 561); + navigation.Size = new Size(60, 591); navigation.TabIndex = 15; // - // btnNotifications + // qrCodeBox // - btnNotifications.BorderRadius = 8; - btnNotifications.Cursor = Cursors.Hand; - btnNotifications.FlatAppearance.BorderSize = 0; - btnNotifications.FlatStyle = FlatStyle.Flat; - btnNotifications.Font = new Font("Tahoma", 8F, FontStyle.Regular, GraphicsUnit.Point); - btnNotifications.ForeColor = Color.White; - btnNotifications.HoverColor = Color.Empty; - btnNotifications.Icon = Properties.Resources.Bell; - btnNotifications.Location = new Point(69, 42); - btnNotifications.Margin = new Padding(4); - btnNotifications.Name = "btnNotifications"; - btnNotifications.NotificationCount = 0; - btnNotifications.Padding = new Padding(0, 4, 4, 0); - btnNotifications.Progress = 0; - btnNotifications.ProgressColor = Color.FromArgb(0, 103, 205); - btnNotifications.Size = new Size(44, 44); - btnNotifications.TabIndex = 16; - btnNotifications.UseVisualStyleBackColor = true; - btnNotifications.UseWindowsAccentColor = false; - btnNotifications.Visible = false; - btnNotifications.WriteProgress = true; - btnNotifications.Click += BtnNotifications_Click; + qrCodeBox.Anchor = AnchorStyles.Top | AnchorStyles.Right; + qrCodeBox.BackgroundImageLayout = ImageLayout.Stretch; + qrCodeBox.Location = new Point(1058, 66); + qrCodeBox.Name = "qrCodeBox"; + qrCodeBox.Size = new Size(130, 130); + qrCodeBox.TabIndex = 17; + qrCodeBox.TabStop = false; // - // hosts - // - hosts.Anchor = AnchorStyles.Top | AnchorStyles.Right; - hosts.BackColor = Color.FromArgb(65, 65, 65); - hosts.DropDownStyle = ComboBoxStyle.DropDownList; - hosts.Font = new Font("Tahoma", 9F, FontStyle.Regular, GraphicsUnit.Point); - hosts.Icon = null; - hosts.Location = new Point(706, 41); - hosts.Margin = new Padding(4); - hosts.Name = "hosts"; - hosts.Padding = new Padding(12, 3, 12, 3); - hosts.SelectedIndex = -1; - hosts.SelectedItem = null; - hosts.Size = new Size(375, 28); - hosts.TabIndex = 17; - hosts.SelectedIndexChanged += Hosts_SelectedIndexChanged; + // label1 + // + label1.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; + label1.Font = new Font("Tahoma", 9.75F, FontStyle.Bold, GraphicsUnit.Point, 0); + label1.ForeColor = Color.White; + label1.Location = new Point(1046, 42); + label1.Margin = new Padding(9, 0, 9, 0); + label1.Name = "label1"; + label1.Size = new Size(154, 20); + label1.TabIndex = 18; + label1.Text = "Quick Setup"; + label1.TextAlign = ContentAlignment.MiddleCenter; + label1.UseMnemonic = false; // // MainWindow // @@ -346,12 +311,9 @@ private void InitializeComponent() AutoScaleMode = AutoScaleMode.Dpi; BackColor = Color.FromArgb(45, 45, 45); ClientSize = new Size(1200, 635); - Controls.Add(hosts); - Controls.Add(btnNotifications); - Controls.Add(navigation); - Controls.Add(lblIpAddressHostname); - Controls.Add(lblPort); Controls.Add(label1); + Controls.Add(qrCodeBox); + Controls.Add(navigation); Controls.Add(lblNumClientsConnected); Controls.Add(contentPanel); Controls.Add(lblVersion); @@ -366,12 +328,9 @@ private void InitializeComponent() Controls.SetChildIndex(lblVersion, 0); Controls.SetChildIndex(contentPanel, 0); Controls.SetChildIndex(lblNumClientsConnected, 0); - Controls.SetChildIndex(label1, 0); - Controls.SetChildIndex(lblPort, 0); - Controls.SetChildIndex(lblIpAddressHostname, 0); Controls.SetChildIndex(navigation, 0); - Controls.SetChildIndex(btnNotifications, 0); - Controls.SetChildIndex(hosts, 0); + Controls.SetChildIndex(qrCodeBox, 0); + Controls.SetChildIndex(label1, 0); contentButtonPanel.ResumeLayout(false); ((ISupportInitialize)btnDeck).EndInit(); ((ISupportInitialize)btnExtensions).EndInit(); @@ -379,8 +338,8 @@ private void InitializeComponent() ((ISupportInitialize)btnVariables).EndInit(); ((ISupportInitialize)btnSettings).EndInit(); navigation.ResumeLayout(false); + ((ISupportInitialize)qrCodeBox).EndInit(); ResumeLayout(false); - PerformLayout(); } #endregion @@ -393,13 +352,11 @@ private void InitializeComponent() private ContentSelectorButton btnDeviceManager; private Label lblNumClientsConnected; private ContentSelectorButton btnVariables; - private Label label1; - private Label lblPort; - private Label lblIpAddressHostname; private Panel panel1; private Panel panel2; private RoundedPanel navigation; private NotificationButton btnNotifications; - private RoundedComboBox hosts; + private PictureBox qrCodeBox; + private Label label1; } } \ No newline at end of file diff --git a/MacroDeck/GUI/MainWindow.cs b/MacroDeck/GUI/MainWindow.cs index 579cb54b..3de19eed 100644 --- a/MacroDeck/GUI/MainWindow.cs +++ b/MacroDeck/GUI/MainWindow.cs @@ -58,7 +58,6 @@ private void UpdateAvailable(object? sender, UpdateApiVersionInfo e) private void UpdateTranslation() { - lblIpAddressHostname.Text = LanguageManager.Strings.IpAddressHostNamePort; } private void LanguageChanged(object? sender, EventArgs e) @@ -115,7 +114,6 @@ private void MainWindowShown(object? sender, EventArgs e) { Application.DoEvents(); RefreshPluginsLabels(); - LoadHosts(); if (MacroDeck.SafeMode) { @@ -138,6 +136,8 @@ private void MainWindowShown(object? sender, EventArgs e) using var updateAvailableDialog = new UpdateAvailableDialog(updateApiVersionInfo); updateAvailableDialog.ShowDialog(); } + + this.qrCodeBox.BackgroundImage = QrCodeService.Instance.GetQuickSetupQrCode(); } private void MainWindow_Load(object? sender, EventArgs e) @@ -158,26 +158,6 @@ private void MainWindow_Load(object? sender, EventArgs e) CenterToScreen(); } - private void LoadHosts() - { - hosts.SelectedIndexChanged -= Hosts_SelectedIndexChanged; - foreach (var networkInterface in NetworkInterface.GetAllNetworkInterfaces()) - { - var ipAddress = networkInterface - .GetIPProperties() - .UnicastAddresses - .FirstOrDefault(x => x.Address.AddressFamily == AddressFamily.InterNetwork) - ?.Address - .ToString(); - if (!string.IsNullOrWhiteSpace(ipAddress)) - { - hosts.Items.Add(ipAddress); - } - } - hosts.Text = MacroDeck.Configuration.HostAddress; - hosts.SelectedIndexChanged += Hosts_SelectedIndexChanged; - } - private void NotificationsChanged(object? sender, EventArgs e) { btnNotifications.NotificationCount = NotificationManager.Notifications.Count; @@ -254,7 +234,7 @@ private void BtnNotifications_Click(object? sender, EventArgs e) { _notificationsList = new NotificationsList { - Location = btnNotifications.Location with { Y = btnNotifications.Location.Y + btnNotifications.Height } + Location = btnNotifications.Location with { Y = btnNotifications.Location.Y + btnNotifications.Height, X = btnNotifications.Location.X + btnNotifications.Size.Width + 20 } }; _notificationsList.OnCloseRequested += (_, _) => { @@ -272,10 +252,4 @@ private void BtnNotifications_Click(object? sender, EventArgs e) _notificationsList.BringToFront(); } } - - private void Hosts_SelectedIndexChanged(object? sender, EventArgs e) - { - MacroDeck.Configuration.HostAddress = hosts.Text; - MacroDeck.Configuration.Save(ApplicationPaths.MainConfigFilePath); - } } \ No newline at end of file diff --git a/MacroDeck/GUI/MainWindow.resx b/MacroDeck/GUI/MainWindow.resx index f55fe35b..d8e4a5c6 100644 --- a/MacroDeck/GUI/MainWindow.resx +++ b/MacroDeck/GUI/MainWindow.resx @@ -1,4 +1,64 @@ - + + + diff --git a/MacroDeck/MacroDeck.csproj b/MacroDeck/MacroDeck.csproj index c81899cc..4a1b7436 100644 --- a/MacroDeck/MacroDeck.csproj +++ b/MacroDeck/MacroDeck.csproj @@ -49,6 +49,7 @@ + diff --git a/MacroDeck/Services/QrCodeService.cs b/MacroDeck/Services/QrCodeService.cs new file mode 100644 index 00000000..bceb8590 --- /dev/null +++ b/MacroDeck/Services/QrCodeService.cs @@ -0,0 +1,60 @@ +using System.IO; +using System.Net.NetworkInformation; +using System.Net.Sockets; +using System.Text.Json; +using QRCoder; +using SuchByte.MacroDeck.DataTypes.QrCode; +using SuchByte.MacroDeck.Logging; + +namespace SuchByte.MacroDeck.Services; + +public class QrCodeService +{ + public static readonly QrCodeService Instance = new(); + + private byte[]? _quickSetupQrCode; + + public Image GetQuickSetupQrCode() + { + if (_quickSetupQrCode is not null) + { + return FromSavedBytes(); + } + + var networkInterfaces = new List(); + try + { + networkInterfaces.AddRange(NetworkInterface.GetAllNetworkInterfaces() + .Select(adapter => adapter.GetIPProperties() + .UnicastAddresses.FirstOrDefault(x => x.Address.AddressFamily == AddressFamily.InterNetwork) + ?.Address.ToString()) + .Where(address => !string.IsNullOrWhiteSpace(address) && address != "127.0.0.1")); + } + catch (Exception ex) + { + MacroDeckLogger.Warning($"Error while searching for network interfaces\n{ex.Message}"); + } + + var data = new QuickConnectQrCodeData(Environment.MachineName, + networkInterfaces, + MacroDeck.Configuration.HostPort, + MacroDeck.Configuration.EnableSsl); + + var dataJson = JsonSerializer.Serialize(data); + var dataBase64 = Convert.ToBase64String(Encoding.UTF8.GetBytes(dataJson)); + var qrCodeLink = $"https://macro-deck.app/quick-setup/{dataBase64}"; + + using var qrGenerator = new QRCodeGenerator(); + using var qrCodeData = qrGenerator.CreateQrCode(qrCodeLink, QRCodeGenerator.ECCLevel.L); + using var qrCode = new BitmapByteQRCode(qrCodeData); + + _quickSetupQrCode = qrCode.GetGraphic(20); + return FromSavedBytes(); + + Image FromSavedBytes() + { + using var ms = new MemoryStream(_quickSetupQrCode); + return Image.FromStream(ms); + } + } +} \ No newline at end of file