3 * C wrapper for the Sparkle API
5 * Wireshark - Network traffic analyzer
6 * By Gerald Combs <gerald@wireshark.org>
7 * Copyright 1998 Gerald Combs
9 * SPDX-License-Identifier: GPL-2.0-or-later
12 #include <ws_diag_control.h>
14 #include <ui/macosx/sparkle_bridge.h>
16 #import <Cocoa/Cocoa.h>
20 // https://sparkle-project.org/documentation/customization/
21 // Sparkle stores its state in ~/Library/Preferences/org.wireshark.Wireshark.plist.
22 // You can check its log output via `log stream | grep -i sparkle`.
24 // The Sparkle 1 UI provided a sharedUpdater singleton, which is deprecated
26 // https://sparkle-project.org/documentation/upgrading/
27 // Create our own singleton which uses the updated API.
28 // https://sparkle-project.org/documentation/programmatic-setup/
30 // https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/ObjectiveC/Introduction/introObjectiveC.html
31 // http://pierre.chachatelier.fr/programmation/fichiers/cpp-objc-en.pdf
33 // We should update this each time our preferences change.
34 static NSString *appUpdateURL = nil;
36 @interface AppUpdaterDelegate :NSObject <SPUUpdaterDelegate>
39 @implementation AppUpdaterDelegate
40 - (nullable NSString *)feedURLStringForUpdater:(SPUUpdater *)updater {
46 @interface SparkleBridge : NSObject
47 + (SPUStandardUpdaterController *)sharedStandardUpdaterController;
50 @implementation SparkleBridge
52 + (SPUStandardUpdaterController *)sharedStandardUpdaterController {
53 static AppUpdaterDelegate *updaterDelegate_ = nil;
54 static SPUStandardUpdaterController *sharedStandardUpdaterController_ = nil;
55 static dispatch_once_t onceToken;
56 dispatch_once(&onceToken, ^{
57 updaterDelegate_ = [AppUpdaterDelegate alloc];
58 sharedStandardUpdaterController_ = [[SPUStandardUpdaterController alloc] initWithUpdaterDelegate: updaterDelegate_ userDriverDelegate: nil];
60 return sharedStandardUpdaterController_;
65 DIAG_OFF(objc-method-access)
67 void sparkle_software_update_init(const char *url, bool enabled, int interval)
69 appUpdateURL = [[NSString alloc] initWithUTF8String: url];
70 [[[SparkleBridge sharedStandardUpdaterController] updater] setAutomaticallyChecksForUpdates: enabled];
71 [[[SparkleBridge sharedStandardUpdaterController] updater] setUpdateCheckInterval: interval];
72 // The documentation recommends calling clearFeedURLFromUserDefaults if we've called
73 // setFeedURL (and we have in 4.4 and earlier), but it was added in Sparkle 2.4.0
74 if ([[[SparkleBridge sharedStandardUpdaterController] updater] respondsToSelector:@selector(clearFeedURLFromUserDefaults:)]) {
75 [[[SparkleBridge sharedStandardUpdaterController] updater] clearFeedURLFromUserDefaults];
79 DIAG_ON(objc-method-access)
81 void sparkle_software_update_check(void)
83 [[SparkleBridge sharedStandardUpdaterController] checkForUpdates: [[NSApplication sharedApplication] delegate]];