[vlc-devel] [PATCH] macosx: add a nag screen when executing the Intel binary on ARM-64

Felix Paul Kühne fkuehne at videolan.org
Sun Dec 6 16:23:21 CET 2020


From: Felix Paul Kühne <felix at feepk.net>

---
 modules/gui/macosx/VLCMain.m | 47 +++++++++++++++++++++++++++++++++++-
 1 file changed, 46 insertions(+), 1 deletion(-)

diff --git a/modules/gui/macosx/VLCMain.m b/modules/gui/macosx/VLCMain.m
index 3e08c48da9..a2872c2dc8 100644
--- a/modules/gui/macosx/VLCMain.m
+++ b/modules/gui/macosx/VLCMain.m
@@ -1,7 +1,7 @@
 /*****************************************************************************
  * VLCMain.m: MacOS X interface module
  *****************************************************************************
- * Copyright (C) 2002-2016 VLC authors and VideoLAN
+ * Copyright (C) 2002-2020 VLC authors and VideoLAN
  * $Id$
  *
  * Authors: Derk-Jan Hartman <hartman at videolan.org>
@@ -35,6 +35,7 @@
 
 #include <stdlib.h>                                      /* malloc(), free() */
 #include <string.h>
+#include <sys/sysctl.h>
 #include <vlc_common.h>
 #include <vlc_atomic.h>
 #include <vlc_actions.h>
@@ -319,6 +320,50 @@ - (void)applicationDidFinishLaunching:(NSNotification *)aNotification
     if (kidsAround && var_GetBool(p_playlist, "playlist-autostart"))
         playlist_Control(p_playlist, PLAYLIST_PLAY, true);
     PL_UNLOCK;
+
+    /* on macOS 11 and later, check whether the user attempts to deploy
+     * the x86_64 binary on ARM-64 - if yes, run a nag screen */
+    if (OSX_BIGSUR_AND_HIGHER) {
+        if ([self processIsTranslated] > 0) {
+            msg_Warn(p_intf, "Process is translated!");
+            [self runNagScreen];
+        }
+    }
+}
+
+- (int)processIsTranslated
+{
+   int ret = 0;
+   size_t size = sizeof(ret);
+   if (sysctlbyname("sysctl.proc_translated", &ret, &size, NULL, 0) == -1) {
+      if (errno == ENOENT)
+         return 0;
+      return -1;
+   }
+   return ret;
+}
+
+- (void)runNagScreen
+{
+    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
+    if ([defaults boolForKey:@"NeverRunIntelNagScreenAgain"]) {
+        return;;
+    }
+
+    NSAlert *alert = [NSAlert alertWithMessageText:_NS("VLC runs in translation mode")
+                                     defaultButton:_NS("Open Website")
+                                   alternateButton:_NS("Continue")
+                                       otherButton:_NS("Don't ask again")
+                         informativeTextWithFormat:@"%@", _NS("This version of VLC is intended for Intel-based Macs only. For vastly improved performance, download VLC for Apple Silicon from our website.")];
+    [alert setAlertStyle:NSCriticalAlertStyle];
+
+    NSInteger returnValue = [alert runModal];
+    if (returnValue == NSAlertDefaultReturn) {
+        NSURL *url = [NSURL URLWithString: @"https://www.videolan.org/vlc/download-macosx.html"];
+        [[NSWorkspace sharedWorkspace] openURL: url];
+    } else if (returnValue == NSAlertOtherReturn) {
+        [defaults setBool:YES forKey:@"NeverRunIntelNagScreenAgain"];
+    }
 }
 
 #pragma mark -
-- 
2.24.3 (Apple Git-128)



More information about the vlc-devel mailing list