feat: add new runningUnderARM64Translation property to detect x64 translated apps running on Windows ARM (#29168)

* feat: add new runningUnderARM64Translation property to detect x64 translated apps running on Windows ARM

* docs: add documentation for the new runningUnderARM64Translation property

* refactor: clean up `IsRunningUnderARM64Translation` Windows implementation

* Return false if IsWow64Process2 doesn't exist

* Emit deprecation warning in runningUnderRosettaTranslation
This commit is contained in:
Sergio Padrino 2021-06-02 09:16:33 +02:00 committed by GitHub
parent 3b75549511
commit abf6f5c8ba
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 69 additions and 1 deletions

View file

@ -1440,6 +1440,27 @@ void App::SetUserAgentFallback(const std::string& user_agent) {
ElectronBrowserClient::Get()->SetUserAgent(user_agent);
}
#if defined(OS_WIN)
bool App::IsRunningUnderARM64Translation() const {
USHORT processMachine = 0;
USHORT nativeMachine = 0;
auto IsWow64Process2 = reinterpret_cast<decltype(&::IsWow64Process2)>(
GetProcAddress(GetModuleHandle(L"kernel32.dll"), "IsWow64Process2"));
if (IsWow64Process2 == nullptr) {
return false;
}
if (!IsWow64Process2(GetCurrentProcess(), &processMachine, &nativeMachine)) {
return false;
}
return nativeMachine == IMAGE_FILE_MACHINE_ARM64;
}
#endif
std::string App::GetUserAgentFallback() {
return ElectronBrowserClient::Get()->GetUserAgent();
}
@ -1642,6 +1663,10 @@ gin::ObjectTemplateBuilder App::GetObjectTemplateBuilder(v8::Isolate* isolate) {
.SetProperty("dock", &App::GetDockAPI)
.SetProperty("runningUnderRosettaTranslation",
&App::IsRunningUnderRosettaTranslation)
#endif
#if defined(OS_MAC) || defined(OS_WIN)
.SetProperty("runningUnderARM64Translation",
&App::IsRunningUnderARM64Translation)
#endif
.SetProperty("userAgentFallback", &App::GetUserAgentFallback,
&App::SetUserAgentFallback)