1
0
mirror of https://github.com/chylex/TweetDuck.git synced 2025-10-08 22:27:02 +02:00

Fix tray restoration from another process if the original process is hung

This commit is contained in:
2017-06-30 20:44:39 +02:00
parent fb94bf1b80
commit 06c0153cf5
2 changed files with 5 additions and 2 deletions

@@ -68,6 +68,9 @@ namespace TweetDuck.Core.Utils{
[DllImport("user32.dll")] [DllImport("user32.dll")]
public static extern IntPtr SendMessage(IntPtr hWnd, uint msg, int wParam, IntPtr lParam); public static extern IntPtr SendMessage(IntPtr hWnd, uint msg, int wParam, IntPtr lParam);
[DllImport("user32.dll")]
public static extern bool PostMessage(IntPtr hWnd, uint msg, int wParam, IntPtr lParam);
[DllImport("user32.dll")] [DllImport("user32.dll")]
public static extern uint RegisterWindowMessage(string messageName); public static extern uint RegisterWindowMessage(string messageName);

@@ -100,13 +100,13 @@ namespace TweetDuck{
if (lockResult == LockManager.Result.HasProcess){ if (lockResult == LockManager.Result.HasProcess){
if (LockManager.LockingProcess.MainWindowHandle == IntPtr.Zero){ // restore if the original process is in tray if (LockManager.LockingProcess.MainWindowHandle == IntPtr.Zero){ // restore if the original process is in tray
NativeMethods.SendMessage(NativeMethods.HWND_BROADCAST, WindowRestoreMessage, LockManager.LockingProcess.Id, IntPtr.Zero); NativeMethods.PostMessage(NativeMethods.HWND_BROADCAST, WindowRestoreMessage, LockManager.LockingProcess.Id, IntPtr.Zero);
if (WindowsUtils.TrySleepUntil(() => { if (WindowsUtils.TrySleepUntil(() => {
LockManager.LockingProcess.Refresh(); LockManager.LockingProcess.Refresh();
return LockManager.LockingProcess.HasExited || (LockManager.LockingProcess.MainWindowHandle != IntPtr.Zero && LockManager.LockingProcess.Responding); return LockManager.LockingProcess.HasExited || (LockManager.LockingProcess.MainWindowHandle != IntPtr.Zero && LockManager.LockingProcess.Responding);
}, 2000, 250)){ }, 2000, 250)){
return; // should trigger on first attempt if succeeded, but wait just in case return;
} }
} }