mirror of
https://github.com/babalae/better-genshin-impact
synced 2025-01-08 11:57:53 +08:00
feat: restore from another instance
This commit is contained in:
parent
00447d3e78
commit
a960f76920
@ -405,7 +405,7 @@ public partial class AutoWoodTask : ISoloTask
|
||||
private void PressZ(WoodTaskParam taskParam)
|
||||
{
|
||||
// IMPORTANT: MUST try focus before press Z
|
||||
SystemControl.Focus(TaskContext.Instance().GameHandle);
|
||||
SystemControl.FocusWindow(TaskContext.Instance().GameHandle);
|
||||
|
||||
if (_first)
|
||||
{
|
||||
@ -457,7 +457,7 @@ public partial class AutoWoodTask : ISoloTask
|
||||
|
||||
private void PressEsc(WoodTaskParam taskParam)
|
||||
{
|
||||
SystemControl.Focus(TaskContext.Instance().GameHandle);
|
||||
SystemControl.FocusWindow(TaskContext.Instance().GameHandle);
|
||||
Simulation.SendInput.Keyboard.KeyPress(VK.VK_ESCAPE);
|
||||
// if (TaskContext.Instance().Config.AutoWoodConfig.PressTwoEscEnabled)
|
||||
// {
|
||||
|
@ -178,18 +178,37 @@ public class SystemControl
|
||||
ActivateWindow(TaskContext.Instance().GameHandle);
|
||||
}
|
||||
|
||||
public static void Focus(nint hWnd)
|
||||
public static void FocusWindow(nint hWnd)
|
||||
{
|
||||
if (User32.IsWindow(hWnd))
|
||||
{
|
||||
_ = User32.SendMessage(hWnd, User32.WindowMessage.WM_SYSCOMMAND, User32.SysCommand.SC_RESTORE, 0);
|
||||
_ = User32.SetForegroundWindow(hWnd);
|
||||
|
||||
while (User32.IsIconic(hWnd))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
_ = User32.BringWindowToTop(hWnd);
|
||||
_ = User32.SetActiveWindow(hWnd);
|
||||
}
|
||||
}
|
||||
|
||||
public static void RestoreWindow(nint hWnd)
|
||||
{
|
||||
if (User32.IsWindow(hWnd))
|
||||
{
|
||||
_ = User32.SendMessage(hWnd, User32.WindowMessage.WM_SYSCOMMAND, User32.SysCommand.SC_RESTORE, 0);
|
||||
_ = User32.SetForegroundWindow(hWnd);
|
||||
|
||||
if (User32.IsIconic(hWnd))
|
||||
{
|
||||
_ = User32.ShowWindow(hWnd, ShowWindowCommand.SW_RESTORE);
|
||||
}
|
||||
|
||||
_ = User32.BringWindowToTop(hWnd);
|
||||
_ = User32.SetActiveWindow(hWnd);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,5 @@
|
||||
using BetterGenshinImpact.Core.Config;
|
||||
using BetterGenshinImpact.GameTask;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
@ -9,6 +10,8 @@ using System.Security.Principal;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Interop;
|
||||
|
||||
namespace BetterGenshinImpact.Helpers;
|
||||
|
||||
@ -116,19 +119,18 @@ internal static class RuntimeHelper
|
||||
handle = new EventWaitHandle(false, EventResetMode.AutoReset, instanceName);
|
||||
}
|
||||
|
||||
Task.Factory.StartNew(() =>
|
||||
_ = Task.Factory.StartNew(() =>
|
||||
{
|
||||
while (handle.WaitOne())
|
||||
{
|
||||
#if false
|
||||
UIDispatcherHelper.BeginInvoke(main =>
|
||||
Application.Current.Dispatcher?.BeginInvoke(() =>
|
||||
{
|
||||
main?.Activate();
|
||||
main?.Show();
|
||||
Application.Current.MainWindow?.Show();
|
||||
Application.Current.MainWindow?.Activate();
|
||||
SystemControl.RestoreWindow(new WindowInteropHelper(Application.Current.MainWindow).Handle);
|
||||
});
|
||||
#endif
|
||||
}
|
||||
}, TaskCreationOptions.LongRunning);
|
||||
}, TaskCreationOptions.LongRunning).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
public static void CheckIntegration()
|
||||
|
Loading…
Reference in New Issue
Block a user