From c3e72182bb7dd722bd5d92e8a327ad28d62936c1 Mon Sep 17 00:00:00 2001 From: Simon Smith Date: Mon, 5 Aug 2024 12:42:38 +0100 Subject: [PATCH] add chat button to remote desktop view (#98) Signed-off-by: Simon Smith --- src/KVMViewer.Designer.cs | 98 ++++++++++++---------- src/KVMViewer.cs | 40 +++++++++ src/KVMViewer.resx | 171 +++++++++++++++++++++++--------------- src/MeshCentralServer.cs | 3 +- 4 files changed, 199 insertions(+), 113 deletions(-) diff --git a/src/KVMViewer.Designer.cs b/src/KVMViewer.Designer.cs index fa60aa0..0db32be 100644 --- a/src/KVMViewer.Designer.cs +++ b/src/KVMViewer.Designer.cs @@ -51,6 +51,11 @@ namespace MeshCentralRouter this.toolStripStatusLabel1 = new System.Windows.Forms.ToolStripStatusLabel(); this.updateTimer = new System.Windows.Forms.Timer(this.components); this.topPanel = new System.Windows.Forms.Panel(); + this.chatButton = new System.Windows.Forms.Button(); + this.consentContextMenuStrip = new System.Windows.Forms.ContextMenuStrip(this.components); + this.askConsentBarToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.askConsentToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.privacyBarToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.openRemoteFilesButton = new System.Windows.Forms.Button(); this.extraButtonsPanel = new System.Windows.Forms.Panel(); this.splitButton = new System.Windows.Forms.Button(); @@ -61,15 +66,11 @@ namespace MeshCentralRouter this.zoomButton = new System.Windows.Forms.Button(); this.cadButton = new System.Windows.Forms.Button(); this.connectButton = new System.Windows.Forms.Button(); - this.consentContextMenuStrip = new System.Windows.Forms.ContextMenuStrip(this.components); - this.askConsentBarToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.askConsentToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.privacyBarToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.consoleMessage = new System.Windows.Forms.Label(); this.consoleTimer = new System.Windows.Forms.Timer(this.components); this.mainToolTip = new System.Windows.Forms.ToolTip(this.components); - this.resizeKvmControl = new MeshCentralRouter.KVMResizeControl(); this.displaySelectorImageList = new System.Windows.Forms.ImageList(this.components); + this.resizeKvmControl = new MeshCentralRouter.KVMResizeControl(); this.mainStatusStrip.SuspendLayout(); this.topPanel.SuspendLayout(); this.consentContextMenuStrip.SuspendLayout(); @@ -105,6 +106,7 @@ namespace MeshCentralRouter // topPanel // this.topPanel.BackColor = System.Drawing.SystemColors.Control; + this.topPanel.Controls.Add(this.chatButton); this.topPanel.Controls.Add(this.openRemoteFilesButton); this.topPanel.Controls.Add(this.extraButtonsPanel); this.topPanel.Controls.Add(this.splitButton); @@ -118,6 +120,44 @@ namespace MeshCentralRouter resources.ApplyResources(this.topPanel, "topPanel"); this.topPanel.Name = "topPanel"; // + // chatButton + // + this.chatButton.ContextMenuStrip = this.consentContextMenuStrip; + resources.ApplyResources(this.chatButton, "chatButton"); + this.chatButton.Name = "chatButton"; + this.chatButton.TabStop = false; + this.chatButton.UseVisualStyleBackColor = true; + this.chatButton.Click += new System.EventHandler(this.chatButton_Click); + // + // consentContextMenuStrip + // + this.consentContextMenuStrip.ImageScalingSize = new System.Drawing.Size(20, 20); + this.consentContextMenuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.askConsentBarToolStripMenuItem, + this.askConsentToolStripMenuItem, + this.privacyBarToolStripMenuItem}); + this.consentContextMenuStrip.Name = "consentContextMenuStrip"; + resources.ApplyResources(this.consentContextMenuStrip, "consentContextMenuStrip"); + this.consentContextMenuStrip.Opening += new System.ComponentModel.CancelEventHandler(this.consentContextMenuStrip_Opening); + // + // askConsentBarToolStripMenuItem + // + this.askConsentBarToolStripMenuItem.Name = "askConsentBarToolStripMenuItem"; + resources.ApplyResources(this.askConsentBarToolStripMenuItem, "askConsentBarToolStripMenuItem"); + this.askConsentBarToolStripMenuItem.Click += new System.EventHandler(this.askConsentBarToolStripMenuItem_Click); + // + // askConsentToolStripMenuItem + // + this.askConsentToolStripMenuItem.Name = "askConsentToolStripMenuItem"; + resources.ApplyResources(this.askConsentToolStripMenuItem, "askConsentToolStripMenuItem"); + this.askConsentToolStripMenuItem.Click += new System.EventHandler(this.askConsentToolStripMenuItem_Click); + // + // privacyBarToolStripMenuItem + // + this.privacyBarToolStripMenuItem.Name = "privacyBarToolStripMenuItem"; + resources.ApplyResources(this.privacyBarToolStripMenuItem, "privacyBarToolStripMenuItem"); + this.privacyBarToolStripMenuItem.Click += new System.EventHandler(this.privacyBarToolStripMenuItem_Click); + // // openRemoteFilesButton // resources.ApplyResources(this.openRemoteFilesButton, "openRemoteFilesButton"); @@ -200,35 +240,6 @@ namespace MeshCentralRouter this.connectButton.UseVisualStyleBackColor = true; this.connectButton.Click += new System.EventHandler(this.MenuItemDisconnect_Click); // - // consentContextMenuStrip - // - this.consentContextMenuStrip.ImageScalingSize = new System.Drawing.Size(20, 20); - this.consentContextMenuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { - this.askConsentBarToolStripMenuItem, - this.askConsentToolStripMenuItem, - this.privacyBarToolStripMenuItem}); - this.consentContextMenuStrip.Name = "consentContextMenuStrip"; - resources.ApplyResources(this.consentContextMenuStrip, "consentContextMenuStrip"); - this.consentContextMenuStrip.Opening += new System.ComponentModel.CancelEventHandler(this.consentContextMenuStrip_Opening); - // - // askConsentBarToolStripMenuItem - // - this.askConsentBarToolStripMenuItem.Name = "askConsentBarToolStripMenuItem"; - resources.ApplyResources(this.askConsentBarToolStripMenuItem, "askConsentBarToolStripMenuItem"); - this.askConsentBarToolStripMenuItem.Click += new System.EventHandler(this.askConsentBarToolStripMenuItem_Click); - // - // askConsentToolStripMenuItem - // - this.askConsentToolStripMenuItem.Name = "askConsentToolStripMenuItem"; - resources.ApplyResources(this.askConsentToolStripMenuItem, "askConsentToolStripMenuItem"); - this.askConsentToolStripMenuItem.Click += new System.EventHandler(this.askConsentToolStripMenuItem_Click); - // - // privacyBarToolStripMenuItem - // - this.privacyBarToolStripMenuItem.Name = "privacyBarToolStripMenuItem"; - resources.ApplyResources(this.privacyBarToolStripMenuItem, "privacyBarToolStripMenuItem"); - this.privacyBarToolStripMenuItem.Click += new System.EventHandler(this.privacyBarToolStripMenuItem_Click); - // // consoleMessage // resources.ApplyResources(this.consoleMessage, "consoleMessage"); @@ -240,6 +251,15 @@ namespace MeshCentralRouter this.consoleTimer.Interval = 5000; this.consoleTimer.Tick += new System.EventHandler(this.consoleTimer_Tick); // + // displaySelectorImageList + // + this.displaySelectorImageList.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("displaySelectorImageList.ImageStream"))); + this.displaySelectorImageList.TransparentColor = System.Drawing.Color.Transparent; + this.displaySelectorImageList.Images.SetKeyName(0, "icon-monitor1.png"); + this.displaySelectorImageList.Images.SetKeyName(1, "icon-monitor1b.png"); + this.displaySelectorImageList.Images.SetKeyName(2, "icon-monitor2.png"); + this.displaySelectorImageList.Images.SetKeyName(3, "icon-monitor2b.png"); + // // resizeKvmControl // this.resizeKvmControl.BackColor = System.Drawing.Color.Gray; @@ -251,15 +271,6 @@ namespace MeshCentralRouter this.resizeKvmControl.Enter += new System.EventHandler(this.resizeKvmControl_Enter); this.resizeKvmControl.Leave += new System.EventHandler(this.resizeKvmControl_Leave); // - // displaySelectorImageList - // - this.displaySelectorImageList.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("displaySelectorImageList.ImageStream"))); - this.displaySelectorImageList.TransparentColor = System.Drawing.Color.Transparent; - this.displaySelectorImageList.Images.SetKeyName(0, "icon-monitor1.png"); - this.displaySelectorImageList.Images.SetKeyName(1, "icon-monitor1b.png"); - this.displaySelectorImageList.Images.SetKeyName(2, "icon-monitor2.png"); - this.displaySelectorImageList.Images.SetKeyName(3, "icon-monitor2b.png"); - // // KVMViewer // resources.ApplyResources(this, "$this"); @@ -309,6 +320,7 @@ namespace MeshCentralRouter private Panel extraButtonsPanel; private ImageList displaySelectorImageList; private Button openRemoteFilesButton; + private Button chatButton; } } diff --git a/src/KVMViewer.cs b/src/KVMViewer.cs index 0888c5b..60162b6 100644 --- a/src/KVMViewer.cs +++ b/src/KVMViewer.cs @@ -21,6 +21,8 @@ using System.Collections.Generic; using System.Security.Cryptography; using System.Web.Script.Serialization; using System.Threading; +using System.Diagnostics; +using System.IO; namespace MeshCentralRouter { @@ -771,5 +773,43 @@ namespace MeshCentralRouter node.fileViewer.Focus(); } } + + private void chatButton_Click(object sender, EventArgs e) + { + if (kvmControl == null) return; + server.sendCommand("{\"action\":\"meshmessenger\",\"nodeid\":\"" + node.nodeid + "\"}"); + string url = "https://" + server.serverinfo["name"]; + if (server.serverinfo.TryGetValue("port", out var value1) && value1 is int portNumber && portNumber != 443) + { + url += ":" + portNumber; + } + if (server.serverinfo.TryGetValue("domainsuffix", out var value) && value is string domainSuffix && !string.IsNullOrEmpty(domainSuffix)) + { + url += "/" + domainSuffix; + } + url += "/messenger?id=meshmessenger/" + Uri.EscapeDataString(node.nodeid) + "/" + Uri.EscapeDataString(server.userid) + "&title=" + node.name; + if ((server.authCookie != null) && (server.authCookie != "")) { url += "&auth=" + server.authCookie; } + try + { + if (server.debug) { try { File.AppendAllText("debug.log", "Opening chat window locally using ProcessStartInfo\r\n"); } catch (Exception) { } } + Process.Start(new ProcessStartInfo + { + FileName = url, + UseShellExecute = true + }); + } + catch (Exception) + { + try + { + if (server.debug) { try { File.AppendAllText("debug.log", "Opening chat window locally using cmd\r\n"); } catch (Exception) { } } + Process.Start(new ProcessStartInfo("cmd", $"/c start {url}") { CreateNoWindow = true }); + } + catch (Exception) + { + if (server.debug) { try { File.AppendAllText("debug.log", "Failed to open chat window locally\r\n"); } catch (Exception) { } } + } + } + } } } diff --git a/src/KVMViewer.resx b/src/KVMViewer.resx index 0131993..af3b236 100644 --- a/src/KVMViewer.resx +++ b/src/KVMViewer.resx @@ -167,13 +167,73 @@ 154, 17 + + 518, 17 + + + 171, 22 + + + Ask Consent + Bar + + + 171, 22 + + + Ask Consent + + + 171, 22 + + + Privacy Bar + + + 172, 70 + + + consentContextMenuStrip + + + System.Windows.Forms.ContextMenuStrip, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + + NoControl + + + 286, 3 + + + 89, 26 + + + 11 + + + Chat + + + chatButton + + + System.Windows.Forms.Button, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + topPanel + + + 0 + False + + NoControl + 192, 3 - 2, 2, 2, 2 @@ -196,19 +256,19 @@ topPanel - 0 + 1 Top, Left, Right - 380, 2 + 474, 2 2, 2, 2, 2 - 401, 27 + 307, 27 10 @@ -223,7 +283,7 @@ topPanel - 1 + 2 Top, Right @@ -256,7 +316,7 @@ topPanel - 2 + 3 Top, Right @@ -286,7 +346,7 @@ topPanel - 3 + 4 Top, Right @@ -322,7 +382,7 @@ topPanel - 4 + 5 Top, Right @@ -352,13 +412,13 @@ topPanel - 5 + 6 NoControl - 286, 3 + 380, 3 89, 26 @@ -379,7 +439,7 @@ topPanel - 6 + 7 Top, Right @@ -406,7 +466,7 @@ topPanel - 7 + 8 False @@ -436,37 +496,7 @@ topPanel - 8 - - - 518, 17 - - - 171, 22 - - - Ask Consent + Bar - - - 171, 22 - - - Ask Consent - - - 171, 22 - - - Privacy Bar - - - 172, 70 - - - consentContextMenuStrip - - - System.Windows.Forms.ContextMenuStrip, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + 9 NoControl @@ -493,7 +523,7 @@ topPanel - 9 + 10 Top @@ -561,30 +591,6 @@ 275, 17 - - Fill - - - 0, 32 - - - 1044, 695 - - - 10 - - - resizeKvmControl - - - MeshCentralRouter.KVMResizeControl, MeshCentralRouter, Version=1.8.8475.33354, Culture=neutral, PublicKeyToken=null - - - $this - - - 2 - 752, 17 @@ -593,7 +599,7 @@ AAEAAAD/////AQAAAAAAAAAMAgAAAFdTeXN0ZW0uV2luZG93cy5Gb3JtcywgVmVyc2lvbj00LjAuMC4w LCBDdWx0dXJlPW5ldXRyYWwsIFB1YmxpY0tleVRva2VuPWI3N2E1YzU2MTkzNGUwODkFAQAAACZTeXN0 ZW0uV2luZG93cy5Gb3Jtcy5JbWFnZUxpc3RTdHJlYW1lcgEAAAAERGF0YQcCAgAAAAkDAAAADwMAAADs - DgAAAk1TRnQBSQFMAgEBBAEAATABAAEwAQABEAEAARABAAT/AREBAAj/AUIBTQE2BwABNgMAASgDAAFA + DgAAAk1TRnQBSQFMAgEBBAEAAUgBAAFIAQABEAEAARABAAT/AREBAAj/AUIBTQE2BwABNgMAASgDAAFA AwABIAMAAQEBAAEQBgABEP8A/wD/AP8A/wD/AP8A/wAiAAH3AV4BpQEUAaUBFAGlARQBpQEUAaUBFAGl ARQB9wFeEAAB9wFeAaUBFAGlARQBpQEUAaUBFAGlARQBpQEUAfcBXhAAAfcBXgGlARQBpQEUAaUBFAGl ARQBpQEUAaUBFAH3AV4QAAH3AV4BpQEUAaUBFAGlARQBpQEUAaUBFAGlARQB9wFeEAAB3gF7ARgBYwFr @@ -659,6 +665,30 @@ AQ8B8AEPAfABDwHwAQ8B8AEPAfABDwHwAQ8B/AE/AfwBPwH8AT8B/AE/aAAL + + Fill + + + 0, 32 + + + 1044, 695 + + + 10 + + + resizeKvmControl + + + MeshCentralRouter.KVMResizeControl, MeshCentralRouter, Version=1.8.8983.22465, Culture=neutral, PublicKeyToken=null + + + $this + + + 2 + True @@ -1093,6 +1123,9 @@ /////wAA/P//////AAA= + + NoControl + 2, 2, 2, 2 diff --git a/src/MeshCentralServer.cs b/src/MeshCentralServer.cs index 779979b..d5e99e1 100644 --- a/src/MeshCentralServer.cs +++ b/src/MeshCentralServer.cs @@ -67,6 +67,7 @@ namespace MeshCentralRouter private JavaScriptSerializer JSON = new JavaScriptSerializer(); public int features = 0; // Bit flags of server features public int features2 = 0; // Bit flags of server features + public Dictionary serverinfo = null; public int connectionState { get { return constate; } } @@ -257,7 +258,7 @@ namespace MeshCentralRouter case "serverinfo": { // Get the bit flags of server features - Dictionary serverinfo = (Dictionary)jsonAction["serverinfo"]; + serverinfo = (Dictionary)jsonAction["serverinfo"]; if (serverinfo.ContainsKey("features") && (serverinfo["features"].GetType() == typeof(int))) { features = (int)serverinfo["features"]; } if (serverinfo.ContainsKey("features2") && (serverinfo["features2"].GetType() == typeof(int))) { features2 = (int)serverinfo["features2"]; }