Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitf7f3903

Browse files
committed
Use IPC pipe messages to restore existing tray minimized instance,fixes#67
1 parent8c7d355 commitf7f3903

File tree

1 file changed

+84
-7
lines changed

1 file changed

+84
-7
lines changed

‎UnityLauncherPro/MainWindow.xaml.cs‎

Lines changed: 84 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
usingSystem.Diagnostics;
1010
usingSystem.Drawing;// for notifyicon
1111
usingSystem.IO;
12+
usingSystem.IO.Pipes;
1213
usingSystem.Runtime.InteropServices;
1314
usingSystem.Text.RegularExpressions;
1415
usingSystem.Threading;
@@ -70,6 +71,9 @@ public partial class MainWindow : Window
7071
List<BuildReport>buildReports=newList<BuildReport>();// multiple reports, each contains their own stats and items
7172
intcurrentBuildReport=0;
7273

74+
privateNamedPipeServerStreampipeServer;
75+
privateconststringPipeName=appName;
76+
7377
[DllImport("user32",CharSet=CharSet.Unicode)]
7478
staticexternIntPtrFindWindow(stringcls,stringwin);
7579
[DllImport("user32")]
@@ -118,14 +122,22 @@ void Start()
118122
// check for duplicate instance, and activate that instead
119123
if(chkAllowSingleInstanceOnly.IsChecked==true)
120124
{
121-
boolaIsNewInstance=false;
122-
myMutex=newMutex(true,appName,outaIsNewInstance);
123-
if(!aIsNewInstance)
125+
boolisNewInstance;
126+
myMutex=newMutex(true,appName,outisNewInstance);
127+
128+
if(!isNewInstance)
124129
{
125-
// NOTE doesnt work if its minized to tray
126-
ActivateOtherWindow();
130+
// Send a wake-up message to the running instance
131+
ActivateRunningInstance();
132+
133+
// Exit the current instance
127134
App.Current.Shutdown();
128135
}
136+
else
137+
{
138+
// Start pipe server in the first instance
139+
StartPipeServer();
140+
}
129141
}
130142

131143
// TEST erase custom history data
@@ -134,7 +146,7 @@ void Start()
134146

135147
projectsSource=GetProjects.Scan(getGitBranch:(bool)chkShowGitBranchColumn.IsChecked,getPlasticBranch:(bool)chkCheckPlasticBranch.IsChecked,getArguments:(bool)chkShowLauncherArgumentsColumn.IsChecked,showMissingFolders:(bool)chkShowMissingFolderProjects.IsChecked,showTargetPlatform:(bool)chkShowPlatform.IsChecked,AllProjectPaths:Properties.Settings.Default.projectPaths,searchGitbranchRecursivly:(bool)chkGetGitBranchRecursively.IsChecked);
136148

137-
Console.WriteLine("projectsSource.Count: "+projectsSource.Count);
149+
//Console.WriteLine("projectsSource.Count: " + projectsSource.Count);
138150

139151
gridRecent.Items.Clear();
140152
gridRecent.ItemsSource=projectsSource;
@@ -825,6 +837,11 @@ public void RefreshRecentProjects()
825837

826838
// maximize window
827839
voidNotifyIcon_MouseClick(objectsender,System.Windows.Forms.MouseEventArgse)
840+
{
841+
RestoreFromTray();
842+
}
843+
844+
voidRestoreFromTray()
828845
{
829846
this.Show();
830847
this.WindowState=WindowState.Normal;
@@ -2938,7 +2955,7 @@ public void ProcessExitedCallBack(Project proj)
29382955
gridRecent.CancelEdit(DataGridEditingUnit.Cell);
29392956
}
29402957

2941-
// FIXME nobody likes extra loops.. but only40 items to find correct project? but still..
2958+
// FIXME nobody likes extra loops.. but only# items to find correct project? but still..
29422959
for(inti=0,len=projectsSource.Count;i<len;i++)
29432960
{
29442961
if(projectsSource[i].Path==proj.Path)
@@ -3680,6 +3697,66 @@ private void UseAlphaReleaseNotes_Checked(object sender, RoutedEventArgs e)
36803697
Settings.Default.Save();
36813698
}
36823699

3700+
privatevoidActivateRunningInstance()
3701+
{
3702+
try
3703+
{
3704+
using(varpipeClient=newNamedPipeClientStream(".",PipeName,PipeDirection.Out))
3705+
{
3706+
pipeClient.Connect(1000);// Wait for 1 second to connect
3707+
using(varwriter=newStreamWriter(pipeClient))
3708+
{
3709+
writer.WriteLine("WakeUp");
3710+
writer.Flush();
3711+
}
3712+
}
3713+
}
3714+
catch(Exceptionex)
3715+
{
3716+
// Handle connection failure (e.g., pipe not available)
3717+
Console.WriteLine("Could not connect to the running instance: "+ex.Message);
3718+
}
3719+
}
3720+
3721+
privatevoidStartPipeServer()
3722+
{
3723+
pipeServer=newNamedPipeServerStream(PipeName,PipeDirection.In,1,PipeTransmissionMode.Message,PipeOptions.Asynchronous);
3724+
pipeServer.BeginWaitForConnection(OnPipeConnection,null);
3725+
}
3726+
3727+
privatevoidOnPipeConnection(IAsyncResultresult)
3728+
{
3729+
try
3730+
{
3731+
pipeServer.EndWaitForConnection(result);
3732+
3733+
// Read the message
3734+
using(varreader=newStreamReader(pipeServer))
3735+
{
3736+
stringmessage=reader.ReadLine();
3737+
if(message=="WakeUp")
3738+
{
3739+
Dispatcher.Invoke(()=>
3740+
{
3741+
// Bring the app to the foreground
3742+
RestoreFromTray();
3743+
});
3744+
}
3745+
}
3746+
}
3747+
catch(Exceptionex)
3748+
{
3749+
// Handle exceptions
3750+
Console.WriteLine(ex);
3751+
}
3752+
finally
3753+
{
3754+
// Restart pipe server to listen for new messages
3755+
StartPipeServer();
3756+
}
3757+
}
3758+
3759+
36833760
//private void menuProjectProperties_Click(object sender, RoutedEventArgs e)
36843761
//{
36853762
// var proj = GetSelectedProject();

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp