From 82fc8a384ef79a498e6f75f71f9ca4d98b3da4f2 Mon Sep 17 00:00:00 2001
From: SherkeyXD <57581480+SherkeyXD@users.noreply.github.com>
Date: Sat, 28 Feb 2026 20:15:22 +0800
Subject: [PATCH] =?UTF-8?q?feat:=20PC=20=E7=AB=AF=E8=BF=90=E8=A1=8C?=
=?UTF-8?q?=E6=97=B6=E8=A6=81=E6=B1=82=E4=BB=A5=E7=AE=A1=E7=90=86=E5=91=98?=
=?UTF-8?q?=E8=BA=AB=E4=BB=BD=E9=87=8D=E5=90=AF=20MAA=20(#15748)?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/MaaWpfGui/Main/AsstProxy.cs | 19 ++++++++++
src/MaaWpfGui/Main/Bootstrapper.cs | 37 +++++++++++++++++++
src/MaaWpfGui/Res/Localizations/en-us.xaml | 4 ++
src/MaaWpfGui/Res/Localizations/ja-jp.xaml | 4 ++
src/MaaWpfGui/Res/Localizations/ko-kr.xaml | 4 ++
src/MaaWpfGui/Res/Localizations/zh-cn.xaml | 4 ++
src/MaaWpfGui/Res/Localizations/zh-tw.xaml | 4 ++
.../ViewModels/UI/SettingsViewModel.cs | 3 +-
8 files changed, 78 insertions(+), 1 deletion(-)
diff --git a/src/MaaWpfGui/Main/AsstProxy.cs b/src/MaaWpfGui/Main/AsstProxy.cs
index b2ec9e7e97..3cc03d875a 100644
--- a/src/MaaWpfGui/Main/AsstProxy.cs
+++ b/src/MaaWpfGui/Main/AsstProxy.cs
@@ -2475,6 +2475,25 @@ public class AsstProxy
/// 是否成功。
private bool AsstAttachWindowConnect(ref string error)
{
+ if (!Bootstrapper.IsUserAdministrator())
+ {
+ var result = Application.Current.Dispatcher.Invoke(() =>
+ MessageBoxHelper.Show(
+ LocalizationHelper.GetString("AttachWindowNeedAdmin"),
+ "MAA",
+ MessageBoxButton.YesNo,
+ MessageBoxImage.Question));
+
+ if (result == MessageBoxResult.No)
+ {
+ error = LocalizationHelper.GetString("RestartAsAdminFailed");
+ return false;
+ }
+
+ Bootstrapper.RestartAsAdmin();
+ return false;
+ }
+
Instances.TaskQueueViewModel.AddLog(LocalizationHelper.GetString("UseAttachWindowWarning"), UiLogColor.Warning);
const string TargetWindowName = "明日方舟";
diff --git a/src/MaaWpfGui/Main/Bootstrapper.cs b/src/MaaWpfGui/Main/Bootstrapper.cs
index 7f2fae7a43..12b739544d 100644
--- a/src/MaaWpfGui/Main/Bootstrapper.cs
+++ b/src/MaaWpfGui/Main/Bootstrapper.cs
@@ -668,6 +668,12 @@ public class Bootstrapper : Bootstrapper
}
}
+ if (_restartStartInfo is not null)
+ {
+ Process.Start(_restartStartInfo);
+ return;
+ }
+
if (!_isRestartingWithoutArgs)
{
return;
@@ -706,6 +712,7 @@ public class Bootstrapper : Bootstrapper
}
private static bool _isRestartingWithoutArgs;
+ private static ProcessStartInfo _restartStartInfo;
///
/// 重启,不带参数
@@ -718,6 +725,18 @@ public class Bootstrapper : Bootstrapper
Execute.OnUIThread(Application.Current.Shutdown);
}
+ ///
+ /// 重启,使用自定义启动参数
+ ///
+ /// 新进程的启动参数。
+ /// Caller Member Name
+ public static void ShutdownAndRestartWith(ProcessStartInfo startInfo, [CallerMemberName] string caller = "")
+ {
+ _restartStartInfo = startInfo;
+ _logger.Information("Shutdown and restart with custom StartInfo, call by `{Caller}`", caller);
+ Execute.OnUIThread(Application.Current.Shutdown);
+ }
+
private static bool _isRestartingAfterUpdate;
public static void RestartAfterUpdate([CallerMemberName] string caller = "")
@@ -732,6 +751,24 @@ public class Bootstrapper : Bootstrapper
Execute.OnUIThread(Application.Current.Shutdown);
}
+ ///
+ /// 以管理员权限重启应用,UAC 弹窗在退出时触发。
+ ///
+ public static void RestartAsAdmin()
+ {
+ if (Environment.ProcessPath is null)
+ {
+ return;
+ }
+
+ ShutdownAndRestartWith(new ProcessStartInfo
+ {
+ FileName = Environment.ProcessPath,
+ UseShellExecute = true,
+ Verb = "runas",
+ });
+ }
+
private static bool _isWaitingToRestart;
public static async Task RestartAfterIdleAsync()
diff --git a/src/MaaWpfGui/Res/Localizations/en-us.xaml b/src/MaaWpfGui/Res/Localizations/en-us.xaml
index d4955a76a2..73cb8ed3ec 100644
--- a/src/MaaWpfGui/Res/Localizations/en-us.xaml
+++ b/src/MaaWpfGui/Res/Localizations/en-us.xaml
@@ -1243,6 +1243,10 @@ Right-click to clear inactive jobs
Window "{0}" not found, please ensure the game is running
Found {0} "{1}" windows, using the first one
Found window "{0}"
+ Admin
+ PC connection requires administrator privileges.\nRestart MAA as administrator?
+ Restarting as administrator…
+ Please run MAA as administrator manually.
AttachWindow failed, please check screencap/input method settings
Use Win32 window binding for Arknights PC client instead of ADB connection for emulators or phones
PC connection (experimental feature, stability not guaranteed)
diff --git a/src/MaaWpfGui/Res/Localizations/ja-jp.xaml b/src/MaaWpfGui/Res/Localizations/ja-jp.xaml
index 3c7e9423f4..0493dc9192 100644
--- a/src/MaaWpfGui/Res/Localizations/ja-jp.xaml
+++ b/src/MaaWpfGui/Res/Localizations/ja-jp.xaml
@@ -1244,6 +1244,10 @@ C:\\leidian\\LDPlayer9
ウィンドウ "{0}" が見つかりません。ゲームが起動していることを確認してください
{0} 個の "{1}" ウィンドウが見つかりました。最初のものを使用します
ウィンドウ "{0}" が見つかりました
+ 管理者
+ PC 接続には管理者権限が必要です。\n管理者として MAA を再起動しますか?
+ 管理者として再起動しています…
+ 手動で管理者として MAA を実行してください。
AttachWindow の接続に失敗しました。スクリーンキャプチャ/入力方法の設定を確認してください
エミュレータや携帯電話への ADB 接続ではなく、アークナイツ PC クライアントに Win32 ウィンドウバインディングを使用します
PC 接続(実験的機能・動作の安定性は保証されません)
diff --git a/src/MaaWpfGui/Res/Localizations/ko-kr.xaml b/src/MaaWpfGui/Res/Localizations/ko-kr.xaml
index ec270179fc..2d682c72c9 100644
--- a/src/MaaWpfGui/Res/Localizations/ko-kr.xaml
+++ b/src/MaaWpfGui/Res/Localizations/ko-kr.xaml
@@ -1245,6 +1245,10 @@ C:\\leidian\\LDPlayer9
창 "{0}"을(를) 찾을 수 없습니다. 게임이 실행 중인지 확인하세요
{0}개의 "{1}" 창을 찾았습니다. 첫 번째 창을 사용합니다
창 "{0}"을(를) 찾았습니다
+ 관리자
+ PC 연결에는 관리자 권한이 필요합니다.\n관리자로 MAA를 다시 시작하시겠습니까?
+ 관리자로 다시 시작하는 중…
+ MAA를 관리자 권한으로 직접 실행해 주세요.
AttachWindow 연결에 실패했습니다. 스크린샷/입력 방법 설정을 확인하세요
에뮬레이터나 휴대폰용 ADB 연결 대신 명일방주 PC 클라이언트에 Win32 창 바인딩을 사용합니다
PC 연결 (실험적 기능이며 안정성은 보장되지 않습니다)
diff --git a/src/MaaWpfGui/Res/Localizations/zh-cn.xaml b/src/MaaWpfGui/Res/Localizations/zh-cn.xaml
index 4b53d570e3..cca51c68dd 100644
--- a/src/MaaWpfGui/Res/Localizations/zh-cn.xaml
+++ b/src/MaaWpfGui/Res/Localizations/zh-cn.xaml
@@ -1244,6 +1244,10 @@ C:\\leidian\\LDPlayer9。\n
未找到窗口 "{0}",请确保游戏已启动
找到 {0} 个 "{1}" 窗口,将使用第一个
找到窗口 "{0}"
+ 管理员
+ PC 端连接需要管理员权限。\n是否以管理员身份重启 MAA?
+ 正在以管理员身份重启…
+ 请手动以管理员身份运行 MAA
AttachWindow 绑定窗口失败,请检查截图/输入方式配置
使用 Win32 窗口绑定明日方舟 PC 端,而非 ADB 连接模拟器或手机
连接 PC 端(实验性功能,稳定性无法保证)
diff --git a/src/MaaWpfGui/Res/Localizations/zh-tw.xaml b/src/MaaWpfGui/Res/Localizations/zh-tw.xaml
index e555928712..8ce454d634 100644
--- a/src/MaaWpfGui/Res/Localizations/zh-tw.xaml
+++ b/src/MaaWpfGui/Res/Localizations/zh-tw.xaml
@@ -1244,6 +1244,10 @@ C:\\leidian\\LDPlayer9\n
未找到視窗 "{0}",請確保遊戲已啟動
找到 {0} 個 "{1}" 視窗,將使用第一個
找到視窗 "{0}"
+ 管理員
+ PC 端連接需要管理員權限。\n是否以管理員身分重啟 MAA?
+ 正在以管理員身分重啟…
+ 請手動以管理員身分執行 MAA
AttachWindow 綁定視窗失敗,請檢查截圖/輸入方式配置
使用 Win32 視窗綁定明日方舟 PC 端,而非 ADB 連接模擬器或手機
連接 PC 端(實驗性功能,穩定性無法保證)
diff --git a/src/MaaWpfGui/ViewModels/UI/SettingsViewModel.cs b/src/MaaWpfGui/ViewModels/UI/SettingsViewModel.cs
index 090d9e5ce1..d59b681b45 100644
--- a/src/MaaWpfGui/ViewModels/UI/SettingsViewModel.cs
+++ b/src/MaaWpfGui/ViewModels/UI/SettingsViewModel.cs
@@ -938,7 +938,8 @@ public class SettingsViewModel : Screen
? $" - {LocalizationHelper.FormatVersion(VersionUpdateSettings.ResourceVersion, VersionUpdateSettings.ResourceDateTime)}"
: string.Empty;
string uiVersionDisplay = LocalizationHelper.FormatVersion(uiVersion, VersionUpdateSettingsUserControlModel.BuildDateTime);
- rvm.WindowTitle = $"{prefix}MAA{currentConfiguration} - {uiVersionDisplay}{resourceVersionDisplay}{connectConfigName}{connectAddress}{clientName}";
+ string adminTag = Bootstrapper.IsAdministratorWithUac() ? $" ({LocalizationHelper.GetString("Administrator")})" : string.Empty;
+ rvm.WindowTitle = $"{prefix}MAA{adminTag}{currentConfiguration} - {uiVersionDisplay}{resourceVersionDisplay}{connectConfigName}{connectAddress}{clientName}";
}
///