mirror of
https://github.com/owntone/owntone-server.git
synced 2025-03-19 20:14:18 -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.ComponentModel;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
using System.Data;
|
using System.Data;
|
||||||
|
using System.Diagnostics;
|
||||||
using System.ServiceProcess;
|
using System.ServiceProcess;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
@ -31,7 +32,17 @@ namespace FireflyConfig
|
|||||||
|
|
||||||
public class FireflyConfig : System.Windows.Forms.Form
|
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 UDPThread;
|
||||||
|
private System.Threading.Thread EventThread;
|
||||||
|
|
||||||
private System.Drawing.Icon icnRunning;
|
private System.Drawing.Icon icnRunning;
|
||||||
private System.Drawing.Icon icnStopped;
|
private System.Drawing.Icon icnStopped;
|
||||||
@ -77,6 +88,14 @@ namespace FireflyConfig
|
|||||||
private System.Windows.Forms.Label versionLabel;
|
private System.Windows.Forms.Label versionLabel;
|
||||||
private System.ComponentModel.IContainer components;
|
private System.ComponentModel.IContainer components;
|
||||||
|
|
||||||
|
public void ShowConfigWindow()
|
||||||
|
{
|
||||||
|
LoadIni();
|
||||||
|
Show();
|
||||||
|
WindowState = FormWindowState.Normal;
|
||||||
|
ShowInTaskbar = true;
|
||||||
|
}
|
||||||
|
|
||||||
protected override void WndProc(ref Message msg)
|
protected override void WndProc(ref Message msg)
|
||||||
{
|
{
|
||||||
if(msg.Msg == 0x11) // WM_QUERYENDSESSION
|
if(msg.Msg == 0x11) // WM_QUERYENDSESSION
|
||||||
@ -89,8 +108,8 @@ namespace FireflyConfig
|
|||||||
Close();
|
Close();
|
||||||
}
|
}
|
||||||
else if(msg.Msg == 0x0401) // WM_USER + 1 (show config page)
|
else if(msg.Msg == 0x0401) // WM_USER + 1 (show config page)
|
||||||
{
|
{
|
||||||
Show();
|
ShowConfigWindow();
|
||||||
}
|
}
|
||||||
base.WndProc(ref msg);
|
base.WndProc(ref msg);
|
||||||
}
|
}
|
||||||
@ -184,6 +203,40 @@ namespace FireflyConfig
|
|||||||
UDPThread.IsBackground=true;
|
UDPThread.IsBackground=true;
|
||||||
UDPThread.Start();
|
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()
|
public void UDPThreadFunction()
|
||||||
@ -593,7 +646,28 @@ namespace FireflyConfig
|
|||||||
[STAThread]
|
[STAThread]
|
||||||
static void Main()
|
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)
|
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">
|
<data name="groupBox1.Modifiers" type="System.CodeDom.MemberAttributes, System, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||||
<value>Private</value>
|
<value>Private</value>
|
||||||
</data>
|
</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">
|
<data name="textBoxPassword.DefaultModifiers" type="System.CodeDom.MemberAttributes, System, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||||
<value>Private</value>
|
<value>Private</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="textBoxPassword.Locked" type="System.Boolean, mscorlib, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
<data name="textBoxPassword.Locked" type="System.Boolean, mscorlib, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||||
<value>False</value>
|
<value>False</value>
|
||||||
</data>
|
</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">
|
<data name="textBoxPort.DefaultModifiers" type="System.CodeDom.MemberAttributes, System, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||||
<value>Private</value>
|
<value>Private</value>
|
||||||
</data>
|
</data>
|
||||||
@ -385,18 +385,18 @@
|
|||||||
<data name="$this.GridSize" type="System.Drawing.Size, System.Drawing, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
<data name="$this.GridSize" type="System.Drawing.Size, System.Drawing, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||||
<value>8, 8</value>
|
<value>8, 8</value>
|
||||||
</data>
|
</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">
|
<data name="$this.DrawGrid" type="System.Boolean, mscorlib, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||||
<value>True</value>
|
<value>True</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="$this.TrayHeight" type="System.Int32, mscorlib, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
<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>
|
||||||
<data name="$this.SnapToGrid" type="System.Boolean, mscorlib, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
<data name="$this.SnapToGrid" type="System.Boolean, mscorlib, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||||
<value>True</value>
|
<value>True</value>
|
||||||
</data>
|
</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">
|
<data name="$this.DefaultModifiers" type="System.CodeDom.MemberAttributes, System, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||||
<value>Private</value>
|
<value>Private</value>
|
||||||
</data>
|
</data>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user