diff options
author | Sefa Eyeoglu <contact@scrumplex.net> | 2023-08-02 18:35:35 +0200 |
---|---|---|
committer | Sefa Eyeoglu <contact@scrumplex.net> | 2023-08-02 18:35:35 +0200 |
commit | 1d468ac35ad88d8c77cc83f25e3704d9bd7df01b (patch) | |
tree | 8644b1574c947a1a87c5c7b2567f746cfe17882f /launcher/updater | |
parent | ce2ca1381519a2e261d7f76dffa874d559d979c2 (diff) | |
download | PrismLauncher-1d468ac35ad88d8c77cc83f25e3704d9bd7df01b.tar.gz PrismLauncher-1d468ac35ad88d8c77cc83f25e3704d9bd7df01b.tar.bz2 PrismLauncher-1d468ac35ad88d8c77cc83f25e3704d9bd7df01b.zip |
chore: reformat
Signed-off-by: Sefa Eyeoglu <contact@scrumplex.net>
Diffstat (limited to 'launcher/updater')
-rw-r--r-- | launcher/updater/ExternalUpdater.h | 9 | ||||
-rw-r--r-- | launcher/updater/MacSparkleUpdater.h | 11 | ||||
-rw-r--r-- | launcher/updater/MacSparkleUpdater.mm | 107 |
3 files changed, 49 insertions, 78 deletions
diff --git a/launcher/updater/ExternalUpdater.h b/launcher/updater/ExternalUpdater.h index a053e081..6c0803a7 100644 --- a/launcher/updater/ExternalUpdater.h +++ b/launcher/updater/ExternalUpdater.h @@ -31,11 +31,10 @@ * The initializer of the new class should have the side effect of starting the automatic updater. That is, * once the class is initialized, the program should automatically check for updates if necessary. */ -class ExternalUpdater : public QObject -{ +class ExternalUpdater : public QObject { Q_OBJECT -public: + public: /*! * Check for updates manually, showing the user a progress bar and an alert if no updates are found. */ @@ -71,7 +70,7 @@ public: */ virtual void setBetaAllowed(bool allowed) = 0; -signals: + signals: /*! * Emits whenever the user's ability to check for updates changes. * @@ -84,4 +83,4 @@ signals: void canCheckForUpdatesChanged(bool canCheck); }; -#endif //LAUNCHER_EXTERNALUPDATER_H +#endif // LAUNCHER_EXTERNALUPDATER_H diff --git a/launcher/updater/MacSparkleUpdater.h b/launcher/updater/MacSparkleUpdater.h index cee19f7c..3f6b5f4a 100644 --- a/launcher/updater/MacSparkleUpdater.h +++ b/launcher/updater/MacSparkleUpdater.h @@ -26,11 +26,10 @@ /*! * An implementation for the updater on macOS that uses the Sparkle framework. */ -class MacSparkleUpdater : public ExternalUpdater -{ +class MacSparkleUpdater : public ExternalUpdater { Q_OBJECT -public: + public: /*! * Start the Sparkle updater, which automatically checks for updates if necessary. */ @@ -115,10 +114,10 @@ public: */ void setBetaAllowed(bool allowed) override; -private: + private: class Private; - Private *priv; + Private* priv; }; -#endif //LAUNCHER_MACSPARKLEUPDATER_H +#endif // LAUNCHER_MACSPARKLEUPDATER_H diff --git a/launcher/updater/MacSparkleUpdater.mm b/launcher/updater/MacSparkleUpdater.mm index 07337176..1c1f5cd2 100644 --- a/launcher/updater/MacSparkleUpdater.mm +++ b/launcher/updater/MacSparkleUpdater.mm @@ -28,7 +28,7 @@ @property(nonatomic, readonly) SPUUpdater* updater; /// A callback to run when the state of `canCheckForUpdates` for the `updater` changes. -@property(nonatomic, copy) void (^callback) (bool); +@property(nonatomic, copy) void (^callback)(bool); - (id)initWithUpdater:(SPUUpdater*)updater; @@ -36,8 +36,7 @@ @implementation UpdaterObserver -- (id)initWithUpdater:(SPUUpdater*)updater -{ +- (id)initWithUpdater:(SPUUpdater*)updater { self = [super init]; _updater = updater; [self addObserver:self forKeyPath:@"updater.canCheckForUpdates" options:NSKeyValueObservingOptionNew context:nil]; @@ -45,13 +44,11 @@ return self; } -- (void)observeValueForKeyPath:(NSString *)keyPath +- (void)observeValueForKeyPath:(NSString*)keyPath ofObject:(id)object - change:(NSDictionary<NSKeyValueChangeKey, id> *)change - context:(void *)context -{ - if ([keyPath isEqualToString:@"updater.canCheckForUpdates"]) - { + change:(NSDictionary<NSKeyValueChangeKey, id>*)change + context:(void*)context { + if ([keyPath isEqualToString:@"updater.canCheckForUpdates"]) { bool canCheck = [change[NSKeyValueChangeNewKey] boolValue]; self.callback(canCheck); } @@ -59,34 +56,29 @@ @end - @interface UpdaterDelegate : NSObject <SPUUpdaterDelegate> -@property(nonatomic, copy) NSSet<NSString *> *allowedChannels; +@property(nonatomic, copy) NSSet<NSString*>* allowedChannels; @end @implementation UpdaterDelegate -- (NSSet<NSString *> *)allowedChannelsForUpdater:(SPUUpdater *)updater -{ +- (NSSet<NSString*>*)allowedChannelsForUpdater:(SPUUpdater*)updater { return _allowedChannels; } @end - -class MacSparkleUpdater::Private -{ -public: - SPUStandardUpdaterController *updaterController; - UpdaterObserver *updaterObserver; - UpdaterDelegate *updaterDelegate; - NSAutoreleasePool *autoReleasePool; +class MacSparkleUpdater::Private { + public: + SPUStandardUpdaterController* updaterController; + UpdaterObserver* updaterObserver; + UpdaterDelegate* updaterDelegate; + NSAutoreleasePool* autoReleasePool; }; -MacSparkleUpdater::MacSparkleUpdater() -{ +MacSparkleUpdater::MacSparkleUpdater() { priv = new MacSparkleUpdater::Private(); // Enable Cocoa's memory management. @@ -98,18 +90,17 @@ MacSparkleUpdater::MacSparkleUpdater() // Controller is the interface for actually doing the updates. priv->updaterController = [[SPUStandardUpdaterController alloc] initWithStartingUpdater:true - updaterDelegate:priv->updaterDelegate - userDriverDelegate:nil]; + updaterDelegate:priv->updaterDelegate + userDriverDelegate:nil]; priv->updaterObserver = [[UpdaterObserver alloc] initWithUpdater:priv->updaterController.updater]; // Use KVO to run a callback that emits a Qt signal when `canCheckForUpdates` changes, so the UI can respond accordingly. priv->updaterObserver.callback = ^(bool canCheck) { - emit canCheckForUpdatesChanged(canCheck); + emit canCheckForUpdatesChanged(canCheck); }; } -MacSparkleUpdater::~MacSparkleUpdater() -{ +MacSparkleUpdater::~MacSparkleUpdater() { [priv->updaterObserver removeObserver:priv->updaterObserver forKeyPath:@"updater.canCheckForUpdates"]; [priv->updaterController release]; @@ -119,77 +110,63 @@ MacSparkleUpdater::~MacSparkleUpdater() delete priv; } -void MacSparkleUpdater::checkForUpdates() -{ +void MacSparkleUpdater::checkForUpdates() { [priv->updaterController checkForUpdates:nil]; } -bool MacSparkleUpdater::getAutomaticallyChecksForUpdates() -{ +bool MacSparkleUpdater::getAutomaticallyChecksForUpdates() { return priv->updaterController.updater.automaticallyChecksForUpdates; } -double MacSparkleUpdater::getUpdateCheckInterval() -{ +double MacSparkleUpdater::getUpdateCheckInterval() { return priv->updaterController.updater.updateCheckInterval; } -QSet<QString> MacSparkleUpdater::getAllowedChannels() -{ +QSet<QString> MacSparkleUpdater::getAllowedChannels() { // Convert NSSet<NSString> -> QSet<QString> __block QSet<QString> channels; - [priv->updaterDelegate.allowedChannels enumerateObjectsUsingBlock:^(NSString *channel, BOOL *stop) - { - channels.insert(QString::fromNSString(channel)); + [priv->updaterDelegate.allowedChannels enumerateObjectsUsingBlock:^(NSString* channel, BOOL* stop) { + channels.insert(QString::fromNSString(channel)); }]; return channels; } -bool MacSparkleUpdater::getBetaAllowed() -{ +bool MacSparkleUpdater::getBetaAllowed() { return getAllowedChannels().contains("beta"); } -void MacSparkleUpdater::setAutomaticallyChecksForUpdates(bool check) -{ - priv->updaterController.updater.automaticallyChecksForUpdates = check ? YES : NO; // make clang-tidy happy +void MacSparkleUpdater::setAutomaticallyChecksForUpdates(bool check) { + priv->updaterController.updater.automaticallyChecksForUpdates = check ? YES : NO; // make clang-tidy happy } -void MacSparkleUpdater::setUpdateCheckInterval(double seconds) -{ +void MacSparkleUpdater::setUpdateCheckInterval(double seconds) { priv->updaterController.updater.updateCheckInterval = seconds; } -void MacSparkleUpdater::clearAllowedChannels() -{ +void MacSparkleUpdater::clearAllowedChannels() { priv->updaterDelegate.allowedChannels = [NSSet set]; } -void MacSparkleUpdater::setAllowedChannel(const QString &channel) -{ - if (channel.isEmpty()) - { +void MacSparkleUpdater::setAllowedChannel(const QString& channel) { + if (channel.isEmpty()) { clearAllowedChannels(); return; } - NSSet<NSString *> *nsChannels = [NSSet setWithObject:channel.toNSString()]; + NSSet<NSString*>* nsChannels = [NSSet setWithObject:channel.toNSString()]; priv->updaterDelegate.allowedChannels = nsChannels; } -void MacSparkleUpdater::setAllowedChannels(const QSet<QString> &channels) -{ - if (channels.isEmpty()) - { +void MacSparkleUpdater::setAllowedChannels(const QSet<QString>& channels) { + if (channels.isEmpty()) { clearAllowedChannels(); return; } QString channelsConfig = ""; // Convert QSet<QString> -> NSSet<NSString> - NSMutableSet<NSString *> *nsChannels = [NSMutableSet setWithCapacity:channels.count()]; - foreach (const QString channel, channels) - { + NSMutableSet<NSString*>* nsChannels = [NSMutableSet setWithCapacity:channels.count()]; + foreach (const QString channel, channels) { [nsChannels addObject:channel.toNSString()]; channelsConfig += channel + " "; } @@ -197,14 +174,10 @@ void MacSparkleUpdater::setAllowedChannels(const QSet<QString> &channels) priv->updaterDelegate.allowedChannels = nsChannels; } -void MacSparkleUpdater::setBetaAllowed(bool allowed) -{ - if (allowed) - { +void MacSparkleUpdater::setBetaAllowed(bool allowed) { + if (allowed) { setAllowedChannel("beta"); - } - else - { + } else { clearAllowedChannels(); } } |