Skip to content

Commit d601963

Browse files
feat: add app.runningUnderRosettaTranslation to detect running under rosetta (electron#26444)
* feat: add app.isRunningUnderRosettaTranslation to detect running under rosetta * chore: fixup * chore: make const * chore: add missing import
1 parent d6431a0 commit d601963

4 files changed

Lines changed: 23 additions & 0 deletions

File tree

docs/api/app.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1489,3 +1489,12 @@ which native modules you can use in the renderer process. For more information
14891489
on the direction Electron is going with renderer process restarts and usage of
14901490
native modules in the renderer process please check out this
14911491
[Tracking Issue](https://github.com/electron/electron/issues/18397).
1492+
1493+
### `app.runningUnderRosettaTranslation` _macOS_ _Readonly_
1494+
1495+
A `Boolean` which when `true` indicates that the app is currently running
1496+
under the [Rosetta Translator Environment](https://en.wikipedia.org/wiki/Rosetta_(software)).
1497+
1498+
You can use this property to prompt users to download the arm64 version of
1499+
your application when they are running the x64 version under Rosetta
1500+
incorrectly.

shell/browser/api/electron_api_app.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1666,6 +1666,8 @@ gin::ObjectTemplateBuilder App::GetObjectTemplateBuilder(v8::Isolate* isolate) {
16661666
#endif
16671667
#if defined(OS_MAC)
16681668
.SetProperty("dock", &App::GetDockAPI)
1669+
.SetProperty("runningUnderRosettaTranslation",
1670+
&App::IsRunningUnderRosettaTranslation)
16691671
#endif
16701672
.SetProperty("userAgentFallback", &App::GetUserAgentFallback,
16711673
&App::SetUserAgentFallback)

shell/browser/api/electron_api_app.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,7 @@ class App : public ElectronBrowserClient::Delegate,
221221
bool MoveToApplicationsFolder(gin_helper::ErrorThrower, gin::Arguments* args);
222222
bool IsInApplicationsFolder();
223223
v8::Local<v8::Value> GetDockAPI(v8::Isolate* isolate);
224+
bool IsRunningUnderRosettaTranslation() const;
224225
v8::Global<v8::Value> dock_;
225226
#endif
226227

shell/browser/api/electron_api_app_mac.mm

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "shell/common/electron_paths.h"
1010

1111
#import <Cocoa/Cocoa.h>
12+
#import <sys/sysctl.h>
1213

1314
namespace electron {
1415

@@ -58,6 +59,16 @@
5859
[NSApp setActivationPolicy:activation_policy];
5960
}
6061

62+
bool App::IsRunningUnderRosettaTranslation() const {
63+
int proc_translated = 0;
64+
size_t size = sizeof(proc_translated);
65+
if (sysctlbyname("sysctl.proc_translated", &proc_translated, &size, NULL,
66+
0) == -1) {
67+
return false;
68+
}
69+
return proc_translated == 1;
70+
}
71+
6172
} // namespace api
6273

6374
} // namespace electron

0 commit comments

Comments
 (0)