1
0
Fork 0
mirror of https://github.com/transmission/transmission synced 2025-02-23 14:40:43 +00:00
transmission/macosx/SparkleProxy.mm
A Cœur 4906349e3a
Make Sparkle optional to allow running Transmission without Apple Developer Program (#3050)
* Make Sparkle optional to allow building without Apple Developer Program

* Display a nice alert for developers clicking "checkForUpdates" when app isn't signed for Sparkle

Co-authored-by: Charles Kerr <charles@charleskerr.com>
2022-06-03 12:47:33 -05:00

30 lines
1.3 KiB
Text

// This file Copyright © 2005-2022 Transmission authors and contributors.
// It may be used under the MIT (SPDX: MIT) license.
// License text can be found in the licenses/ folder.
#import <objc/runtime.h>
#import <AppKit/AppKit.h>
void SUUpdater_checkForUpdates(id self, SEL _cmd, ...)
{
dispatch_async(dispatch_get_main_queue(), ^{
NSAlert* alert = [[NSAlert alloc] init];
alert.messageText = @"Sparkle not configured";
alert.informativeText = [NSString
stringWithFormat:@"App needs to be codesigned for Development to support Sparkle with Hardened Runtime. Alternatively, re-codesign without the Hardened Runtime option: `sudo codesign -s - %@`",
NSBundle.mainBundle.bundleURL.lastPathComponent];
[alert runModal];
});
}
/// Proxy SUUpdater if isn't registered at program startup due to codesigning.
__attribute__((constructor)) static void registerSUUpdater()
{
if (!objc_getClass("SUUpdater"))
{
NSLog(@"App is not signed for running Sparkle");
Class SUUpdaterClass = objc_allocateClassPair(objc_getClass("NSObject"), "SUUpdater", 0);
class_addMethod(SUUpdaterClass, sel_getUid("checkForUpdates:"), (IMP)SUUpdater_checkForUpdates, "v@:@");
objc_registerClassPair(SUUpdaterClass);
}
}