Revert "TODO epan/dissectors/asn1/kerberos/packet-kerberos-template.c new GSS flags"
[wireshark-sm.git] / ui / macosx / sparkle_bridge.m
blobc4157ee36a38047884f9bf71c1e60b2b0d3996ad
1 /* sparkle_bridge.m
2  *
3  * C wrapper for the Sparkle API
4  *
5  * Wireshark - Network traffic analyzer
6  * By Gerald Combs <gerald@wireshark.org>
7  * Copyright 1998 Gerald Combs
8  *
9  * SPDX-License-Identifier: GPL-2.0-or-later
10  */
12 #include <ws_diag_control.h>
14 #include <ui/macosx/sparkle_bridge.h>
16 #import <Cocoa/Cocoa.h>
18 #import <Sparkle.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
25 // in Sparkle 2:
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>
37 @end
39 @implementation AppUpdaterDelegate
40 - (nullable NSString *)feedURLStringForUpdater:(SPUUpdater *)updater {
41     return appUpdateURL;
44 @end
46 @interface SparkleBridge : NSObject
47 + (SPUStandardUpdaterController *)sharedStandardUpdaterController;
48 @end
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];
59     });
60     return sharedStandardUpdaterController_;
63 @end
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];
76     }
79 DIAG_ON(objc-method-access)
81 void sparkle_software_update_check(void)
83     [[SparkleBridge sharedStandardUpdaterController] checkForUpdates: [[NSApplication sharedApplication] delegate]];