mirror of
https://github.com/sparkle-project/Sparkle
synced 2026-11-27 05:04:27 +00:00
Add methods onto user driver show showing linked release notes
These release notes are downloaded while showing that the new update is found
This commit is contained in:
1 parent
95416e4f65
commit
1446acf519
11 files changed
+117
-15
No files matched your search
Vendored
+18
@@ -116,6 +116,9 @@
|
||||
|
||||
- (void)setUpFocusForActiveUpdateAlert
|
||||
{
|
||||
// Make sure the window is loaded in any case
|
||||
[self.activeUpdateAlert window];
|
||||
|
||||
// If the app is a menubar app or the like, we need to focus it first and alter the
|
||||
// update prompt to behave like a normal window. Otherwise if the window were hidden
|
||||
// there may be no way for the application to be activated to make it visible again.
|
||||
@@ -158,6 +161,21 @@
|
||||
});
|
||||
}
|
||||
|
||||
- (void)showUpdateReleaseNotes:(NSData *)releaseNotes
|
||||
{
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
[self.activeUpdateAlert showReleaseNotes:releaseNotes];
|
||||
});
|
||||
}
|
||||
|
||||
- (void)showUpdateReleaseNotesFailedToDownloadWithError:(NSError *)error
|
||||
{
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
NSLog(@"Failed to download release notes with error: %@", error);
|
||||
[self.activeUpdateAlert showReleaseNotesFailedToDownload];
|
||||
});
|
||||
}
|
||||
|
||||
#pragma mark Install & Relaunch Update
|
||||
|
||||
- (void)showReadyToInstallAndRelaunch:(void (^)(SUInstallUpdateStatus))installUpdateHandler
|
||||
|
||||
Vendored
+14
@@ -14,6 +14,7 @@
|
||||
#import "SUUpdaterDelegate.h"
|
||||
#import "SUAppcastItem.h"
|
||||
#import "SUErrors.h"
|
||||
#import "SUURLDownload.h"
|
||||
|
||||
#ifdef _APPKITDEFINES_H
|
||||
#error This is a "core" class and should NOT import AppKit
|
||||
@@ -84,6 +85,19 @@
|
||||
[self updateAlertFinishedForUpdateItem:updateItem withChoice:choice];
|
||||
});
|
||||
}];
|
||||
|
||||
if (updateItem.releaseNotesURL != nil) {
|
||||
NSURLRequest *request = [NSURLRequest requestWithURL:updateItem.releaseNotesURL cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:30];
|
||||
|
||||
id <SUUserDriver> userDriver = self.userDriver;
|
||||
SUDownloadURLWithRequest(request, ^(NSData * _Nullable data, NSError * _Nullable error) {
|
||||
if (data != nil) {
|
||||
[userDriver showUpdateReleaseNotes:(NSData * _Nonnull)data];
|
||||
} else {
|
||||
[userDriver showUpdateReleaseNotesFailedToDownloadWithError:(NSError * _Nonnull)error];
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
- (void)updateAlertFinishedForUpdateItem:(SUAppcastItem *)updateItem withChoice:(SUUpdateAlertChoice)choice
|
||||
|
||||
Vendored
+1
-1
@@ -10,7 +10,7 @@
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
// From the completion block, either data or error can be nil (or both can be nil if an unknown error occured)
|
||||
// From the completion block, either data or error can be nil, but not both
|
||||
// The completion block returns on the main queue
|
||||
void SUDownloadURLWithRequest(NSURLRequest * request, void (^completionBlock)(NSData * _Nullable data, NSError * _Nullable error));
|
||||
|
||||
|
||||
Vendored
+2
-1
@@ -10,6 +10,7 @@
|
||||
#import "SUXPCServiceInfo.h"
|
||||
#import "SUAppcastDownloader.h"
|
||||
#import "SUAppcastDownloaderProtocol.h"
|
||||
#import "SUErrors.h"
|
||||
|
||||
void SUDownloadURLWithRequest(NSURLRequest * request, void (^completionBlock)(NSData * _Nullable, NSError * _Nullable))
|
||||
{
|
||||
@@ -35,7 +36,7 @@ void SUDownloadURLWithRequest(NSURLRequest * request, void (^completionBlock)(NS
|
||||
connection.invalidationHandler = ^{
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
if (!retrievedDownloadResult) {
|
||||
completionBlock(nil, nil);
|
||||
completionBlock(nil, [NSError errorWithDomain:SUSparkleErrorDomain code:SUDownloadError userInfo:nil]);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
Vendored
+3
@@ -22,6 +22,9 @@
|
||||
|
||||
- (instancetype)initWithAppcastItem:(SUAppcastItem *)item host:(SUHost *)aHost versionDisplayer:(id <SUVersionDisplay>)aVersionDisplayer allowsAutomaticUpdates:(BOOL)allowsAutomaticUpdates alreadyDownloaded:(BOOL)alreadyDownloaded completionBlock:(void (^)(SUUpdateAlertChoice))block;
|
||||
|
||||
- (void)showReleaseNotes:(NSData *)releaseNotes;
|
||||
- (void)showReleaseNotesFailedToDownload;
|
||||
|
||||
- (IBAction)installUpdate:sender;
|
||||
- (IBAction)skipThisVersion:sender;
|
||||
- (IBAction)remindMeLater:sender;
|
||||
|
||||
Vendored
+25
-9
@@ -143,7 +143,7 @@
|
||||
// "-apple-system-font" is a reference to the system UI font on OS X. "-apple-system" is the new recommended token, but for backward compatibility we can't use it.
|
||||
prefs.standardFontFamily = @"-apple-system-font";
|
||||
prefs.defaultFontSize = (int)[NSFont systemFontSize];
|
||||
|
||||
|
||||
// Stick a nice big spinner in the middle of the web view until the page is loaded.
|
||||
NSRect frame = [[self.releaseNotesView superview] frame];
|
||||
self.releaseNotesSpinner = [[NSProgressIndicator alloc] initWithFrame:NSMakeRect(NSMidX(frame) - 16, NSMidY(frame) - 16, 32, 32)];
|
||||
@@ -151,18 +151,34 @@
|
||||
[self.releaseNotesSpinner startAnimation:self];
|
||||
self.webViewFinishedLoading = NO;
|
||||
[[self.releaseNotesView superview] addSubview:self.releaseNotesSpinner];
|
||||
|
||||
// If there's a release notes URL, load it; otherwise, just stick the contents of the description into the web view.
|
||||
if ([self.updateItem releaseNotesURL])
|
||||
{
|
||||
[[self.releaseNotesView mainFrame] loadRequest:[NSURLRequest requestWithURL:[self.updateItem releaseNotesURL] cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:30]];
|
||||
}
|
||||
else
|
||||
|
||||
// If there's no release notes URL, just stick the contents of the description into the web view
|
||||
// Otherwise we'll wait until the client wants us to show release notes
|
||||
if (self.updateItem.releaseNotesURL == nil)
|
||||
{
|
||||
[[self.releaseNotesView mainFrame] loadHTMLString:[self.updateItem itemDescription] baseURL:nil];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)showReleaseNotes:(NSData *)releaseNotes
|
||||
{
|
||||
if (!self.webViewFinishedLoading) {
|
||||
[[self.releaseNotesView mainFrame] loadData:releaseNotes MIMEType:@"text/html" textEncodingName:@"utf-8" baseURL:nil];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)showReleaseNotesFailedToDownload
|
||||
{
|
||||
[self stopReleaseNotesSpinner];
|
||||
self.webViewFinishedLoading = YES;
|
||||
}
|
||||
|
||||
- (void)stopReleaseNotesSpinner
|
||||
{
|
||||
[self.releaseNotesSpinner stopAnimation:self];
|
||||
[self.releaseNotesSpinner setHidden:YES];
|
||||
}
|
||||
|
||||
- (BOOL)showsReleaseNotes
|
||||
{
|
||||
NSNumber *shouldShowReleaseNotes = [self.host objectForInfoDictionaryKey:SUShowReleaseNotesKey];
|
||||
@@ -287,8 +303,8 @@
|
||||
- (void)webView:(WebView *)sender didFinishLoadForFrame:frame
|
||||
{
|
||||
if ([frame parentFrame] == nil) {
|
||||
[self stopReleaseNotesSpinner];
|
||||
self.webViewFinishedLoading = YES;
|
||||
[self.releaseNotesSpinner setHidden:YES];
|
||||
[sender display]; // necessary to prevent weird scroll bar artifacting
|
||||
}
|
||||
}
|
||||
|
||||
Vendored
+26
@@ -137,6 +137,32 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
*/
|
||||
- (void)showUpdateFoundWithAppcastItem:(SUAppcastItem *)appcastItem allowsAutomaticUpdates:(BOOL)allowsAutomaticUpdates alreadyDownloaded:(BOOL)alreadyDownloaded reply:(void (^)(SUUpdateAlertChoice))reply;
|
||||
|
||||
/*!
|
||||
* Show the user the release notes for the new update
|
||||
*
|
||||
* Display the release notes to the user. This will be called after showing the new update.
|
||||
* This is only applicable if the release notes are linked from the appcast, and are not directly embedded inside of the appcast file.
|
||||
* That is, this may be invoked if the releaseNotesURL from the appcast item is non-nil.
|
||||
*
|
||||
* @param releaseNotes The data for the release notes that was downloaded from the new update's appcast.
|
||||
*
|
||||
* This can be called from any thread
|
||||
*/
|
||||
- (void)showUpdateReleaseNotes:(NSData *)releaseNotes;
|
||||
|
||||
/*!
|
||||
* Show the user that the new update's release notes could not be downloaded
|
||||
*
|
||||
* This will be called after showing the new update.
|
||||
* This is only applicable if the release notes are linked from the appcast, and are not directly embedded inside of the appcast file.
|
||||
* That is, this may be invoked if the releaseNotesURL from the appcast item is non-nil.
|
||||
*
|
||||
* @param error The error associated with why the new update's release notes could not be downloaded.
|
||||
*
|
||||
* This can be called from any thread
|
||||
*/
|
||||
- (void)showUpdateReleaseNotesFailedToDownloadWithError:(NSError *)error;
|
||||
|
||||
/*!
|
||||
* Show the user a new update was not found
|
||||
*
|
||||
|
||||
@@ -47,10 +47,14 @@
|
||||
[[self.textView enclosingScrollView] setDrawsBackground:NO];
|
||||
[self.textView setDrawsBackground:NO];
|
||||
|
||||
NSString *descriptionHTML = self.appcastItem.itemDescription;
|
||||
NSData *htmlData = [descriptionHTML dataUsingEncoding:NSUTF8StringEncoding];
|
||||
NSAttributedString *attributedString = [[NSAttributedString alloc] initWithHTML:htmlData documentAttributes:NULL];
|
||||
[self.textView.textStorage setAttributedString:attributedString];
|
||||
if (self.appcastItem.releaseNotesURL == nil) {
|
||||
NSString *descriptionHTML = self.appcastItem.itemDescription;
|
||||
if (descriptionHTML == nil) {
|
||||
NSData *htmlData = [descriptionHTML dataUsingEncoding:NSUTF8StringEncoding];
|
||||
NSAttributedString *attributedString = [[NSAttributedString alloc] initWithHTML:htmlData documentAttributes:NULL];
|
||||
[self.textView.textStorage setAttributedString:attributedString];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
- (IBAction)installUpdate:(id)__unused sender
|
||||
|
||||
@@ -186,6 +186,14 @@
|
||||
});
|
||||
}
|
||||
|
||||
- (void)showUpdateReleaseNotes:(NSData *)__unused releaseNotes
|
||||
{
|
||||
}
|
||||
|
||||
- (void)showUpdateReleaseNotesFailedToDownloadWithError:(NSError *)__unused error
|
||||
{
|
||||
}
|
||||
|
||||
#pragma mark Install & Relaunch Update
|
||||
|
||||
- (void)showReadyToInstallAndRelaunch:(void (^)(SUInstallUpdateStatus))installUpdateHandler
|
||||
|
||||
@@ -35,6 +35,10 @@
|
||||
|
||||
- (void)showUpdateFoundWithAppcastItem:(SUAppcastItem *)__unused appcastItem allowsAutomaticUpdates:(BOOL)__unused allowsAutomaticUpdates alreadyDownloaded:(BOOL)__unused alreadyDownloaded reply:(void (^)(SUUpdateAlertChoice))__unused reply {}
|
||||
|
||||
- (void)showUpdateReleaseNotes:(NSData *)__unused releaseNotes {}
|
||||
|
||||
- (void)showUpdateReleaseNotesFailedToDownloadWithError:(NSError *)__unused error {}
|
||||
|
||||
- (void)showUpdateNotFoundWithAcknowledgement:(void (^)(void))__unused acknowledgement {}
|
||||
|
||||
- (void)showUpdaterError:(NSError *)__unused error acknowledgement:(void (^)(void))__unused acknowledgement {}
|
||||
|
||||
@@ -129,6 +129,14 @@
|
||||
});
|
||||
}
|
||||
|
||||
- (void)showUpdateReleaseNotes:(NSData *)__unused releaseNotes
|
||||
{
|
||||
}
|
||||
|
||||
- (void)showUpdateReleaseNotesFailedToDownloadWithError:(NSError *)__unused error
|
||||
{
|
||||
}
|
||||
|
||||
- (void)showUpdateNotFoundWithAcknowledgement:(void (^)(void))__unused acknowledgement
|
||||
{
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
|
||||
Reference in new issue
Block a user