1 #include "sparkleupdater.h"
3 #import <SUAppcastItem.h>
5 #import <SUUpdaterDelegate.h>
7 @interface SparkleDelegate : NSObject <SUUpdaterDelegate> {
11 @implementation SparkleDelegate {
15 - (void)setUpdater:(Updater *)v {
19 - (void)updater:(SUUpdater *)updater didFindValidUpdate:(SUAppcastItem *)item {
20 qDebug() << item.versionString;
22 u->setVersion(QString::fromNSString(item.displayVersionString));
23 u->setStatus(Updater::Status::UpdateAvailable);
24 // [updater installUpdatesIfAvailable];
27 - (void)updaterDidNotFindUpdate:(SUUpdater *)updater {
29 u->setStatus(Updater::Status::UpToDate);
32 - (void)updater:(SUUpdater *)updater
33 willDownloadUpdate:(SUAppcastItem *)item
34 withRequest:(NSMutableURLRequest *)request {
35 qDebug() << item.versionString << request;
37 u->setStatus(Updater::Status::DownloadingUpdate);
40 - (void)updater:(SUUpdater *)updater didDownloadUpdate:(SUAppcastItem *)item {
41 qDebug() << item.versionString;
43 u->setStatus(Updater::Status::UpdateDownloaded);
46 - (void)userDidCancelDownload:(SUUpdater *)updater {
48 u->setStatus(Updater::Status::UpdateAvailable);
51 - (void)updater:(SUUpdater *)updater
52 failedToDownloadUpdate:(SUAppcastItem *)item
53 error:(NSError *)error {
55 u->setStatus(Updater::Status::UpdateDownloadFailed);
58 - (void)updater:(SUUpdater *)updater
59 willInstallUpdateOnQuit:(SUAppcastItem *)item
60 immediateInstallationInvocation:(NSInvocation *)invocation {
62 qDebug() << u->getImmediateInstallAndRelaunch();
63 if (u->getImmediateInstallAndRelaunch()) [invocation invoke];
66 - (void)updater:(SUUpdater *)updater willInstallUpdate:(SUAppcastItem *)item {
67 qDebug() << item.versionString;
70 - (void)updaterWillRelaunchApplication:(SUUpdater *)updater {
74 - (void)updater:(SUUpdater *)updater didAbortWithError:(NSError *)error {
82 SparkleUpdater::SparkleUpdater() {
83 SparkleDelegate *delegate = [[SparkleDelegate alloc] init];
84 [delegate setUpdater:this];
85 [[SUUpdater sharedUpdater] setDelegate:delegate];
86 [SUUpdater sharedUpdater].automaticallyChecksForUpdates = YES;
87 [SUUpdater sharedUpdater].automaticallyDownloadsUpdates = YES;
90 bool SparkleUpdater::getAutomaticDownload() const {
91 return [SUUpdater sharedUpdater].automaticallyDownloadsUpdates;
94 void SparkleUpdater::setAutomaticDownload(bool value) {
95 [SUUpdater sharedUpdater].automaticallyDownloadsUpdates = value;
98 void SparkleUpdater::checkAndShowUI() {
99 [[SUUpdater sharedUpdater] checkForUpdates:nil];
102 void SparkleUpdater::checkAndMaybeShowUI() {
103 [[SUUpdater sharedUpdater] checkForUpdatesInBackground];
106 void SparkleUpdater::checkWithoutUI() {
107 [[SUUpdater sharedUpdater] checkForUpdateInformation];
110 void SparkleUpdater::update() {
111 [[SUUpdater sharedUpdater] installUpdatesIfAvailable];
114 } // namespace updater