mirror of
https://github.com/goatcorp/Dalamud.git
synced 2025-12-14 20:54:16 +01:00
Make it more likely for OpenLink target app to be focused
This commit is contained in:
parent
75a1742af9
commit
5440e9b0b8
1 changed files with 28 additions and 15 deletions
|
|
@ -9,6 +9,7 @@ using System.Reflection.Emit;
|
||||||
using System.Runtime.CompilerServices;
|
using System.Runtime.CompilerServices;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
using Dalamud.Bindings.ImGui;
|
using Dalamud.Bindings.ImGui;
|
||||||
|
|
@ -524,12 +525,15 @@ public static partial class Util
|
||||||
public static bool IsWindows11() => Environment.OSVersion.Version.Build >= 22000;
|
public static bool IsWindows11() => Environment.OSVersion.Version.Build >= 22000;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Open a link in the default browser.
|
/// Open a link in the default browser, and attempts to focus the newly launched application.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="url">The link to open.</param>
|
/// <param name="url">The link to open.</param>
|
||||||
public static void OpenLink(string url)
|
public static void OpenLink(string url) => new Thread(
|
||||||
|
static url =>
|
||||||
{
|
{
|
||||||
var process = new ProcessStartInfo(url)
|
try
|
||||||
|
{
|
||||||
|
var psi = new ProcessStartInfo((string)url!)
|
||||||
{
|
{
|
||||||
UseShellExecute = true,
|
UseShellExecute = true,
|
||||||
ErrorDialogParentHandle = Service<InterfaceManager>.GetNullable() is { } im
|
ErrorDialogParentHandle = Service<InterfaceManager>.GetNullable() is { } im
|
||||||
|
|
@ -537,11 +541,20 @@ public static partial class Util
|
||||||
: 0,
|
: 0,
|
||||||
Verb = "open",
|
Verb = "open",
|
||||||
};
|
};
|
||||||
if (Service<Framework>.GetNullable() is { } fw)
|
if (Process.Start(psi) is not { } process)
|
||||||
_ = fw.RunOnFrameworkThread(() => Process.Start(process));
|
return;
|
||||||
else
|
|
||||||
Process.Start(process);
|
if (process.Id != 0)
|
||||||
|
TerraFX.Interop.Windows.Windows.AllowSetForegroundWindow((uint)process.Id);
|
||||||
|
process.WaitForInputIdle();
|
||||||
|
TerraFX.Interop.Windows.Windows.SetForegroundWindow(
|
||||||
|
(TerraFX.Interop.Windows.HWND)process.MainWindowHandle);
|
||||||
}
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
Log.Error(e, "{fn}: failed to open {url}", nameof(OpenLink), url);
|
||||||
|
}
|
||||||
|
}).Start(url);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Perform a "zipper merge" (A, 1, B, 2, C, 3) of multiple enumerables, allowing for lists to end early.
|
/// Perform a "zipper merge" (A, 1, B, 2, C, 3) of multiple enumerables, allowing for lists to end early.
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue