Skip to content

Truly independent web browser

UI/Qt: Add a debug action that shows the update dialog

Jelle Raaijmakers4d233bfaad0b
diff --git a/UI/Qt/Application.cpp b/UI/Qt/Application.cpp
index 75f41b83520..33d2f763d89 100644
--- a/UI/Qt/Application.cpp
+++ b/UI/Qt/Application.cpp
@@ -536,6 +536,13 @@ public:
software_updater->check_for_updates();
});
m_help_menu->addAction(check_for_updates_action);
+
+ auto* show_update_dialog_action = make_action("Show Update Dialog for Latest Version");
+ QObject::connect(show_update_dialog_action, &QAction::triggered, this, [software_updater]() {
+ software_updater->show_update_dialog_for_latest_version();
+ });
+ m_debug_menu->addSeparator();
+ m_debug_menu->addAction(show_update_dialog_action);
}
#endif
}
diff --git a/UI/Qt/SoftwareUpdaterMac.h b/UI/Qt/SoftwareUpdaterMac.h
index cc53f24f8eb..a3d6056e15b 100644
--- a/UI/Qt/SoftwareUpdaterMac.h
+++ b/UI/Qt/SoftwareUpdaterMac.h
@@ -28,6 +28,7 @@ public:
~SoftwareUpdater();
void check_for_updates();
+ void show_update_dialog_for_latest_version();
private:
explicit SoftwareUpdater(NonnullOwnPtr<Detail::SparkleUpdater>);
diff --git a/UI/Qt/SoftwareUpdaterMac.mm b/UI/Qt/SoftwareUpdaterMac.mm
index e0844353161..de5d0a93e3a 100644
--- a/UI/Qt/SoftwareUpdaterMac.mm
+++ b/UI/Qt/SoftwareUpdaterMac.mm
@@ -8,6 +8,52 @@
#import <Sparkle/Sparkle.h>
+// While it offers the latest version as an update, the running version counts as older than itself, so that Sparkle
+// offers to install the newest version of the appcast even when it is the one running. Sparkle's installer refuses
+// only downgrades, so installing it again goes through. Sparkle tells versions that look the same apart by their build
+// numbers, which are the same as well, so the versions show as they are.
+@interface LadybirdUpdaterDelegate : NSObject <SPUUpdaterDelegate, SPUStandardUserDriverDelegate, SUVersionComparison, SUVersionDisplay>
+
+@property (atomic) BOOL offersLatestVersion;
+
+@end
+
+@implementation LadybirdUpdaterDelegate
+
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wdeprecated-implementations"
+- (id<SUVersionComparison>)versionComparatorForUpdater:(SPUUpdater*)updater
+{
+ return self.offersLatestVersion ? self : nil;
+}
+#pragma clang diagnostic pop
+
+// NB: Sparkle may call this off the main thread.
+- (NSComparisonResult)compareVersion:(NSString*)versionA toVersion:(NSString*)versionB
+{
+ auto result = [[SUStandardVersionComparator defaultComparator] compareVersion:versionA toVersion:versionB];
+ if (result == NSOrderedSame && [versionA isEqualToString:NSBundle.mainBundle.infoDictionary[@"CFBundleVersion"]])
+ return NSOrderedAscending;
+ return result;
+}
+
+- (id<SUVersionDisplay>)standardUserDriverRequestsVersionDisplayer
+{
+ return self.offersLatestVersion ? self : nil;
+}
+
+- (NSString*)formatUpdateDisplayVersionFromUpdate:(SUAppcastItem*)update andBundleDisplayVersion:(NSString* __autoreleasing*)inOutBundleDisplayVersion withBundleVersion:(NSString*)bundleVersion
+{
+ return update.displayVersionString;
+}
+
+- (void)updater:(SPUUpdater*)updater didFinishUpdateCycleForUpdateCheck:(SPUUpdateCheck)updateCheck error:(NSError*)error
+{
+ self.offersLatestVersion = NO;
+}
+
+@end
+
namespace Ladybird {
namespace Detail {
@@ -15,6 +61,8 @@ namespace Detail {
struct SparkleUpdater {
AK_ALLOC_WITH_KMALLOC;
+ // NB: Sparkle holds its delegate weakly.
+ LadybirdUpdaterDelegate* delegate { nil };
SPUStandardUpdaterController* controller { nil };
};
@@ -25,7 +73,8 @@ struct SparkleUpdater {
NonnullOwnPtr<SoftwareUpdater> SoftwareUpdater::create()
{
auto sparkle = make<Detail::SparkleUpdater>();
- sparkle->controller = [[SPUStandardUpdaterController alloc] initWithStartingUpdater:YES updaterDelegate:nil userDriverDelegate:nil];
+ sparkle->delegate = [[LadybirdUpdaterDelegate alloc] init];
+ sparkle->controller = [[SPUStandardUpdaterController alloc] initWithStartingUpdater:YES updaterDelegate:sparkle->delegate userDriverDelegate:sparkle->delegate];
return adopt_own(*new SoftwareUpdater(move(sparkle)));
}
@@ -41,4 +90,10 @@ void SoftwareUpdater::check_for_updates()
[m_sparkle->controller checkForUpdates:nil];
}
+void SoftwareUpdater::show_update_dialog_for_latest_version()
+{
+ m_sparkle->delegate.offersLatestVersion = YES;
+ [m_sparkle->controller checkForUpdates:nil];
+}
+
}