mirror of
https://github.com/owntone/owntone-server.git
synced 2025-03-13 21:12:56 -04:00
Make configurator show the config dialog if trying to start multiple copies of configurator.
This commit is contained in:
parent
9e0a9caa26
commit
cf1f862e9c
@ -6,6 +6,7 @@ using System.Threading;
|
||||
using System.ComponentModel;
|
||||
using System.Windows.Forms;
|
||||
using System.Data;
|
||||
using System.Diagnostics;
|
||||
using System.ServiceProcess;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
@ -31,7 +32,17 @@ namespace FireflyConfig
|
||||
|
||||
public class FireflyConfig : System.Windows.Forms.Form
|
||||
{
|
||||
[DllImport("Kernel32.dll", CharSet=CharSet.Auto)]
|
||||
private static extern IntPtr OpenEvent(UInt32
|
||||
dwDesiredAccess, Boolean bInheritHandle, String lpName);
|
||||
[DllImport("Kernel32.dll", CharSet=CharSet.Auto)]
|
||||
private static extern IntPtr CreateEvent(UInt32 dwDesiredAccess,
|
||||
Boolean bManualReset, Boolean bInitialState, String lpName);
|
||||
[DllImport("user32.dll", EntryPoint="PostMessageA")]
|
||||
static extern int PostMessage(IntPtr hwnd, int wMsg, int wParam, int lParam);
|
||||
|
||||
private System.Threading.Thread UDPThread;
|
||||
private System.Threading.Thread EventThread;
|
||||
|
||||
private System.Drawing.Icon icnRunning;
|
||||
private System.Drawing.Icon icnStopped;
|
||||
@ -77,6 +88,14 @@ namespace FireflyConfig
|
||||
private System.Windows.Forms.Label versionLabel;
|
||||
private System.ComponentModel.IContainer components;
|
||||
|
||||
public void ShowConfigWindow()
|
||||
{
|
||||
LoadIni();
|
||||
Show();
|
||||
WindowState = FormWindowState.Normal;
|
||||
ShowInTaskbar = true;
|
||||
}
|
||||
|
||||
protected override void WndProc(ref Message msg)
|
||||
{
|
||||
if(msg.Msg == 0x11) // WM_QUERYENDSESSION
|
||||
@ -89,8 +108,8 @@ namespace FireflyConfig
|
||||
Close();
|
||||
}
|
||||
else if(msg.Msg == 0x0401) // WM_USER + 1 (show config page)
|
||||
{
|
||||
Show();
|
||||
{
|
||||
ShowConfigWindow();
|
||||
}
|
||||
base.WndProc(ref msg);
|
||||
}
|
||||
@ -184,6 +203,40 @@ namespace FireflyConfig
|
||||
UDPThread.IsBackground=true;
|
||||
UDPThread.Start();
|
||||
|
||||
EventThread = new Thread(new ThreadStart(EventThreadFunction));
|
||||
EventThread.IsBackground = true;
|
||||
EventThread.Start();
|
||||
}
|
||||
|
||||
/* Wait for an event */
|
||||
public void EventThreadFunction()
|
||||
{
|
||||
IntPtr hEvent = IntPtr.Zero;
|
||||
|
||||
hEvent = CreateEvent(0,false,false,"FFCONFIG");
|
||||
if(IntPtr.Zero == hEvent)
|
||||
{
|
||||
return;
|
||||
}
|
||||
AutoResetEvent arEvent = new AutoResetEvent(false);
|
||||
arEvent.Handle = hEvent;
|
||||
|
||||
WaitHandle[] waitHandles;
|
||||
waitHandles = new WaitHandle[1];
|
||||
waitHandles[0] = arEvent;
|
||||
|
||||
while(arEvent.WaitOne())
|
||||
{
|
||||
try
|
||||
{
|
||||
PostMessage( this.Handle, 0x0401, 0, 0);
|
||||
arEvent.Reset();
|
||||
}
|
||||
catch(ThreadAbortException)
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void UDPThreadFunction()
|
||||
@ -593,7 +646,28 @@ namespace FireflyConfig
|
||||
[STAThread]
|
||||
static void Main()
|
||||
{
|
||||
Application.Run(new FireflyConfig());
|
||||
Process aProcess = Process.GetCurrentProcess();
|
||||
string aProcName = aProcess.ProcessName;
|
||||
|
||||
Process[] processList;
|
||||
IntPtr hEvent;
|
||||
processList = Process.GetProcessesByName(aProcName);
|
||||
|
||||
if (processList.Length > 1)
|
||||
{
|
||||
hEvent = OpenEvent(2031619,false,"FFCONFIG");
|
||||
if(IntPtr.Zero != hEvent)
|
||||
{
|
||||
AutoResetEvent arEvent = new AutoResetEvent(false);
|
||||
arEvent.Handle = hEvent;
|
||||
arEvent.Set();
|
||||
}
|
||||
Application.Exit();
|
||||
}
|
||||
else
|
||||
{
|
||||
Application.Run(new FireflyConfig());
|
||||
}
|
||||
}
|
||||
|
||||
private void notifyIcon_DoubleClick(object sender, System.EventArgs e)
|
||||
|
@ -160,15 +160,15 @@
|
||||
<data name="groupBox1.Modifiers" type="System.CodeDom.MemberAttributes, System, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||
<value>Private</value>
|
||||
</data>
|
||||
<data name="textBoxPassword.Modifiers" type="System.CodeDom.MemberAttributes, System, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||
<value>Private</value>
|
||||
</data>
|
||||
<data name="textBoxPassword.DefaultModifiers" type="System.CodeDom.MemberAttributes, System, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||
<value>Private</value>
|
||||
</data>
|
||||
<data name="textBoxPassword.Locked" type="System.Boolean, mscorlib, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||
<value>False</value>
|
||||
</data>
|
||||
<data name="textBoxPassword.Modifiers" type="System.CodeDom.MemberAttributes, System, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||
<value>Private</value>
|
||||
</data>
|
||||
<data name="textBoxPort.DefaultModifiers" type="System.CodeDom.MemberAttributes, System, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||
<value>Private</value>
|
||||
</data>
|
||||
@ -385,18 +385,18 @@
|
||||
<data name="$this.GridSize" type="System.Drawing.Size, System.Drawing, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>8, 8</value>
|
||||
</data>
|
||||
<data name="$this.Name">
|
||||
<value>FireflyConfig</value>
|
||||
</data>
|
||||
<data name="$this.DrawGrid" type="System.Boolean, mscorlib, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||
<value>True</value>
|
||||
</data>
|
||||
<data name="$this.TrayHeight" type="System.Int32, mscorlib, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||
<value>80</value>
|
||||
<value>52</value>
|
||||
</data>
|
||||
<data name="$this.SnapToGrid" type="System.Boolean, mscorlib, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||
<value>True</value>
|
||||
</data>
|
||||
<data name="$this.Name">
|
||||
<value>FireflyConfig</value>
|
||||
</data>
|
||||
<data name="$this.DefaultModifiers" type="System.CodeDom.MemberAttributes, System, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||
<value>Private</value>
|
||||
</data>
|
||||
|
Loading…
x
Reference in New Issue
Block a user