fix crash on late Sparkle updater init

Signed-off-by: Octol1ttle <l1ttleofficial@outlook.com>
This commit is contained in:
Octol1ttle 2026-05-05 18:00:06 +05:00
parent 4f58197edb
commit 1645f6510b
No known key found for this signature in database
GPG key ID: B77C34313AEE1FFF

View file

@ -75,7 +75,6 @@ class MacSparkleUpdater::Private {
SPUStandardUpdaterController* updaterController;
UpdaterObserver* updaterObserver;
UpdaterDelegate* updaterDelegate;
NSAutoreleasePool* autoReleasePool;
};
MacSparkleUpdater::MacSparkleUpdater() {
@ -83,7 +82,6 @@ MacSparkleUpdater::MacSparkleUpdater() {
// Enable Cocoa's memory management.
NSApplicationLoad();
priv->autoReleasePool = [[NSAutoreleasePool alloc] init];
// Delegate is used for setting/getting allowed update channels.
priv->updaterDelegate = [[UpdaterDelegate alloc] init];
@ -101,18 +99,20 @@ MacSparkleUpdater::MacSparkleUpdater() {
}
MacSparkleUpdater::~MacSparkleUpdater() {
@autoreleasepool {
[priv->updaterObserver removeObserver:priv->updaterObserver forKeyPath:@"updater.canCheckForUpdates"];
[priv->updaterController release];
}
[priv->updaterObserver release];
[priv->updaterController release];
[priv->updaterDelegate release];
[priv->autoReleasePool release];
delete priv;
}
void MacSparkleUpdater::checkForUpdates() {
@autoreleasepool {
[priv->updaterController checkForUpdates:nil];
}
}
bool MacSparkleUpdater::getAutomaticallyChecksForUpdates() {
return priv->updaterController.updater.automaticallyChecksForUpdates;
@ -123,6 +123,7 @@ double MacSparkleUpdater::getUpdateCheckInterval() {
}
QSet<QString> MacSparkleUpdater::getAllowedChannels() {
@autoreleasepool {
// Convert NSSet<NSString> -> QSet<QString>
__block QSet<QString> channels;
[priv->updaterDelegate.allowedChannels enumerateObjectsUsingBlock:^(NSString* channel, BOOL* stop) {
@ -130,6 +131,7 @@ QSet<QString> MacSparkleUpdater::getAllowedChannels() {
}];
return channels;
}
}
bool MacSparkleUpdater::getBetaAllowed() {
return getAllowedChannels().contains("beta");
@ -144,10 +146,13 @@ void MacSparkleUpdater::setUpdateCheckInterval(double seconds) {
}
void MacSparkleUpdater::clearAllowedChannels() {
@autoreleasepool {
priv->updaterDelegate.allowedChannels = [NSSet set];
}
}
void MacSparkleUpdater::setAllowedChannel(const QString& channel) {
@autoreleasepool {
if (channel.isEmpty()) {
clearAllowedChannels();
return;
@ -156,8 +161,10 @@ void MacSparkleUpdater::setAllowedChannel(const QString& channel) {
NSSet<NSString*>* nsChannels = [NSSet setWithObject:channel.toNSString()];
priv->updaterDelegate.allowedChannels = nsChannels;
}
}
void MacSparkleUpdater::setAllowedChannels(const QSet<QString>& channels) {
@autoreleasepool {
if (channels.isEmpty()) {
clearAllowedChannels();
return;
@ -173,6 +180,7 @@ void MacSparkleUpdater::setAllowedChannels(const QSet<QString>& channels) {
priv->updaterDelegate.allowedChannels = nsChannels;
}
}
void MacSparkleUpdater::setBetaAllowed(bool allowed) {
if (allowed) {