From 39b70f8ebb174e35d9ff7791b7eb362aab5a2ed8 Mon Sep 17 00:00:00 2001 From: John Simon Date: Wed, 18 May 2016 21:10:21 -0400 Subject: [PATCH] Create a menu item and rpc command for reloading the config --- MainForm.Designer.cs | 146 +++++++++++++++++++++++-------------------- MainForm.cs | 4 ++ MainForm.resx | 6 +- RPCServer.cs | 25 +++----- 4 files changed, 93 insertions(+), 88 deletions(-) diff --git a/MainForm.Designer.cs b/MainForm.Designer.cs index 20edebe..1e75625 100644 --- a/MainForm.Designer.cs +++ b/MainForm.Designer.cs @@ -28,80 +28,89 @@ protected override void Dispose(bool disposing) /// private void InitializeComponent() { - this.components = new System.ComponentModel.Container(); - this.mnuNotifyIcon = new System.Windows.Forms.ContextMenuStrip(this.components); - this.mnuTrayStart = new System.Windows.Forms.ToolStripMenuItem(); - this.mnuTrayStop = new System.Windows.Forms.ToolStripMenuItem(); - this.mnuTraySep1 = new System.Windows.Forms.ToolStripSeparator(); - this.mnuTrayShow = new System.Windows.Forms.ToolStripMenuItem(); - this.mnuTrayExit = new System.Windows.Forms.ToolStripMenuItem(); - this.mnuTrayKeyCheck = new System.Windows.Forms.ToolStripMenuItem(); - this.mnuNotifyIcon.SuspendLayout(); - this.SuspendLayout(); - // - // mnuNotifyIcon - // - this.mnuNotifyIcon.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.components = new System.ComponentModel.Container(); + this.mnuNotifyIcon = new System.Windows.Forms.ContextMenuStrip(this.components); + this.mnuTrayStart = new System.Windows.Forms.ToolStripMenuItem(); + this.mnuTrayStop = new System.Windows.Forms.ToolStripMenuItem(); + this.mnuTraySep1 = new System.Windows.Forms.ToolStripSeparator(); + this.mnuReloadConfig = new System.Windows.Forms.ToolStripMenuItem(); + this.mnuTrayKeyCheck = new System.Windows.Forms.ToolStripMenuItem(); + this.mnuTrayShow = new System.Windows.Forms.ToolStripMenuItem(); + this.mnuTrayExit = new System.Windows.Forms.ToolStripMenuItem(); + this.mnuNotifyIcon.SuspendLayout(); + this.SuspendLayout(); + // + // mnuNotifyIcon + // + this.mnuNotifyIcon.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { this.mnuTrayStart, this.mnuTrayStop, this.mnuTraySep1, + this.mnuReloadConfig, this.mnuTrayKeyCheck, this.mnuTrayShow, this.mnuTrayExit}); - this.mnuNotifyIcon.Name = "mnuNotifyIcon"; - this.mnuNotifyIcon.Size = new System.Drawing.Size(153, 142); - // - // mnuTrayStart - // - this.mnuTrayStart.Name = "mnuTrayStart"; - this.mnuTrayStart.Size = new System.Drawing.Size(152, 22); - this.mnuTrayStart.Text = "&Start"; - this.mnuTrayStart.Click += new System.EventHandler(this.mnuTrayStart_Click); - // - // mnuTrayStop - // - this.mnuTrayStop.Name = "mnuTrayStop"; - this.mnuTrayStop.Size = new System.Drawing.Size(152, 22); - this.mnuTrayStop.Text = "S&top"; - this.mnuTrayStop.Click += new System.EventHandler(this.mnuTrayStop_Click); - // - // mnuTraySep1 - // - this.mnuTraySep1.Name = "mnuTraySep1"; - this.mnuTraySep1.Size = new System.Drawing.Size(149, 6); - // - // mnuTrayShow - // - this.mnuTrayShow.Name = "mnuTrayShow"; - this.mnuTrayShow.Size = new System.Drawing.Size(152, 22); - this.mnuTrayShow.Text = "Sh&ow"; - this.mnuTrayShow.Click += new System.EventHandler(this.mnuTrayShow_Click); - // - // mnuTrayExit - // - this.mnuTrayExit.Name = "mnuTrayExit"; - this.mnuTrayExit.Size = new System.Drawing.Size(152, 22); - this.mnuTrayExit.Text = "E&xit"; - this.mnuTrayExit.Click += new System.EventHandler(this.mnuTrayExit_Click); - // - // mnuTrayKeyCheck - // - this.mnuTrayKeyCheck.Name = "mnuTrayKeyCheck"; - this.mnuTrayKeyCheck.Size = new System.Drawing.Size(152, 22); - this.mnuTrayKeyCheck.Text = "&Key check"; - this.mnuTrayKeyCheck.Click += new System.EventHandler(this.mnuTrayKeyCheck_Click); - // - // MainForm - // - this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(292, 273); - this.Name = "MainForm"; - this.Text = "Souse"; - this.FormClosed += new System.Windows.Forms.FormClosedEventHandler(this.MainForm_FormClosed); - this.Resize += new System.EventHandler(this.MainForm_Resize); - this.mnuNotifyIcon.ResumeLayout(false); - this.ResumeLayout(false); + this.mnuNotifyIcon.Name = "mnuNotifyIcon"; + this.mnuNotifyIcon.Size = new System.Drawing.Size(153, 164); + // + // mnuTrayStart + // + this.mnuTrayStart.Name = "mnuTrayStart"; + this.mnuTrayStart.Size = new System.Drawing.Size(152, 22); + this.mnuTrayStart.Text = "&Start"; + this.mnuTrayStart.Click += new System.EventHandler(this.mnuTrayStart_Click); + // + // mnuTrayStop + // + this.mnuTrayStop.Name = "mnuTrayStop"; + this.mnuTrayStop.Size = new System.Drawing.Size(152, 22); + this.mnuTrayStop.Text = "S&top"; + this.mnuTrayStop.Click += new System.EventHandler(this.mnuTrayStop_Click); + // + // mnuTraySep1 + // + this.mnuTraySep1.Name = "mnuTraySep1"; + this.mnuTraySep1.Size = new System.Drawing.Size(149, 6); + // + // mnuReloadConfig + // + this.mnuReloadConfig.Name = "mnuReloadConfig"; + this.mnuReloadConfig.Size = new System.Drawing.Size(152, 22); + this.mnuReloadConfig.Text = "&Reload config"; + this.mnuReloadConfig.Click += new System.EventHandler(this.mnuReloadConfig_Click); + // + // mnuTrayKeyCheck + // + this.mnuTrayKeyCheck.Name = "mnuTrayKeyCheck"; + this.mnuTrayKeyCheck.Size = new System.Drawing.Size(152, 22); + this.mnuTrayKeyCheck.Text = "&Key check"; + this.mnuTrayKeyCheck.Click += new System.EventHandler(this.mnuTrayKeyCheck_Click); + // + // mnuTrayShow + // + this.mnuTrayShow.Name = "mnuTrayShow"; + this.mnuTrayShow.Size = new System.Drawing.Size(152, 22); + this.mnuTrayShow.Text = "Sh&ow"; + this.mnuTrayShow.Click += new System.EventHandler(this.mnuTrayShow_Click); + // + // mnuTrayExit + // + this.mnuTrayExit.Name = "mnuTrayExit"; + this.mnuTrayExit.Size = new System.Drawing.Size(152, 22); + this.mnuTrayExit.Text = "E&xit"; + this.mnuTrayExit.Click += new System.EventHandler(this.mnuTrayExit_Click); + // + // MainForm + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(292, 273); + this.Name = "MainForm"; + this.Text = "Souse"; + this.FormClosed += new System.Windows.Forms.FormClosedEventHandler(this.MainForm_FormClosed); + this.Resize += new System.EventHandler(this.MainForm_Resize); + this.mnuNotifyIcon.ResumeLayout(false); + this.ResumeLayout(false); } @@ -114,6 +123,7 @@ private void InitializeComponent() private System.Windows.Forms.ToolStripMenuItem mnuTrayStop; private System.Windows.Forms.ToolStripSeparator mnuTraySep1; private System.Windows.Forms.ToolStripMenuItem mnuTrayKeyCheck; + private System.Windows.Forms.ToolStripMenuItem mnuReloadConfig; } } diff --git a/MainForm.cs b/MainForm.cs index f692cde..7ed1411 100644 --- a/MainForm.cs +++ b/MainForm.cs @@ -83,5 +83,9 @@ public partial class MainForm : Form { private void mnuTrayKeyCheck_Click(object sender, EventArgs e) { MessageBox.Show(InputState.WhichNonModKeyIsDown().ToString()); } + + private void mnuReloadConfig_Click(object sender, EventArgs e) { + App.config.Reload(); + } } } diff --git a/MainForm.resx b/MainForm.resx index a81d2fe..7423f99 100644 --- a/MainForm.resx +++ b/MainForm.resx @@ -112,12 +112,12 @@ 2.0 - System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - + 17, 17 \ No newline at end of file diff --git a/RPCServer.cs b/RPCServer.cs index 8a238c8..78a8269 100644 --- a/RPCServer.cs +++ b/RPCServer.cs @@ -80,24 +80,15 @@ private void HandleContext(HttpListenerContext context) } } - private JToken HandleRequest(string method, JArray param) - { - if (method == "setRunning") - { + private JToken HandleRequest(string method, JArray param) { + if (method == "setRunning") { var running = param[0].Value(); - if (running) - { - App.audioMaster.Enabled = true; - return new JValue("Audio listening started"); - } - else - { - App.audioMaster.Enabled = false; - return new JValue("Audio listening stopped"); - } - } - else - { + App.audioMaster.Enabled = running; + return JValue.CreateNull(); + } else if (method == "reloadConfig") { + App.config.Reload(); + return JValue.CreateNull(); + } else { throw new ArgumentException(""); } }