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:
parent
3b75549511
commit
abf6f5c8ba
5 changed files with 69 additions and 1 deletions
|
@ -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)
|
||||
|
|
|
@ -223,6 +223,10 @@ class App : public ElectronBrowserClient::Delegate,
|
|||
v8::Global<v8::Value> dock_;
|
||||
#endif
|
||||
|
||||
#if defined(OS_MAC) || defined(OS_WIN)
|
||||
bool IsRunningUnderARM64Translation() const;
|
||||
#endif
|
||||
|
||||
#if defined(MAS_BUILD)
|
||||
base::RepeatingCallback<void()> StartAccessingSecurityScopedResource(
|
||||
gin::Arguments* args);
|
||||
|
|
|
@ -60,6 +60,17 @@ void App::SetActivationPolicy(gin_helper::ErrorThrower thrower,
|
|||
}
|
||||
|
||||
bool App::IsRunningUnderRosettaTranslation() const {
|
||||
node::Environment* env =
|
||||
node::Environment::GetCurrent(JavascriptEnvironment::GetIsolate());
|
||||
|
||||
EmitWarning(env,
|
||||
"The app.runningUnderRosettaTranslation API is deprecated, use "
|
||||
"app.runningUnderARM64Translation instead.",
|
||||
"electron");
|
||||
return IsRunningUnderARM64Translation();
|
||||
}
|
||||
|
||||
bool App::IsRunningUnderARM64Translation() const {
|
||||
int proc_translated = 0;
|
||||
size_t size = sizeof(proc_translated);
|
||||
if (sysctlbyname("sysctl.proc_translated", &proc_translated, &size, NULL,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue