Skip to content

Commit

Permalink
macosx: log if the process is translated and if the user tries to upd…
Browse files Browse the repository at this point in the history
…ate, install the native binary
  • Loading branch information
fkuehne committed Dec 9, 2020
1 parent 2d58cd6 commit 91179db
Showing 1 changed file with 57 additions and 1 deletion.
58 changes: 57 additions & 1 deletion modules/gui/macosx/main/VLCMain.m
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*****************************************************************************
* VLCMain.m: MacOS X interface module
*****************************************************************************
* Copyright (C) 2002-2019 VLC authors and VideoLAN
* Copyright (C) 2002-2020 VLC authors and VideoLAN
*
* Authors: Derk-Jan Hartman <hartman at videolan.org>
* Felix Paul Kühne <fkuehne at videolan dot org>
Expand Down Expand Up @@ -35,6 +35,7 @@
#include <stdlib.h> /* malloc(), free() */
#include <string.h>
#include <stdatomic.h>
#include <sys/sysctl.h>

#include <vlc_common.h>
#include <vlc_actions.h>
Expand Down Expand Up @@ -80,6 +81,8 @@

#ifdef HAVE_SPARKLE
#import <Sparkle/Sparkle.h> /* we're the update delegate */
NSString *const kIntel64UpdateURLString = @"https://update.videolan.org/vlc/sparkle/vlc-intel64.xml";
NSString *const kARM64UpdateURLString = @"https://update.videolan.org/vlc/sparkle/vlc-arm64.xml";
#endif

NSString *VLCConfigurationChangedNotification = @"VLCConfigurationChangedNotification";
Expand Down Expand Up @@ -270,6 +273,26 @@ - (void)applicationDidFinishLaunching:(NSNotification *)aNotification
[self migrateOldPreferences];

_statusBarIcon = [[VLCStatusBarIcon alloc] init];

/* on macOS 11 and later, check whether the user attempts to deploy
* the x86_64 binary on ARM-64 - if yes, log it */
if (OSX_BIGSUR_AND_HIGHER) {
if ([self processIsTranslated] > 0) {
msg_Warn(getIntf(), "Process is translated!");
}
}
}

- (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;
}

#pragma mark -
Expand Down Expand Up @@ -319,6 +342,39 @@ - (BOOL)updaterMayCheckForUpdates:(SUUpdater *)bundle

return YES;
}

/* use the correct feed depending on the hardware architecture */
- (nullable NSString *)feedURLStringForUpdater:(SUUpdater *)updater
{
#ifdef __x86_64__
if (OSX_BIGSUR_AND_HIGHER) {
if ([self processIsTranslated] > 0) {
msg_Dbg(getIntf(), "Process is translated. On update, VLC will install the native ARM-64 binary.");
return kARM64UpdateURLString;
}
}
return kIntel64UpdateURLString;
#elif __arm64__
return kARM64UpdateURLString;
#else
#error unsupported architecture
#endif
}

- (void)updaterDidNotFindUpdate:(SUUpdater *)updater
{
msg_Dbg(getIntf(), "No update found");
}

- (void)updater:(SUUpdater *)updater failedToDownloadUpdate:(SUAppcastItem *)item error:(NSError *)error
{
msg_Warn(getIntf(), "Failed to download update with error %li", error.code);
}

- (void)updater:(SUUpdater *)updater didAbortWithError:(NSError *)error
{
msg_Err(getIntf(), "Updater aborted with error %li", error.code);
}
#endif

#pragma mark -
Expand Down

0 comments on commit 91179db

Please sign in to comment.