mirror of
https://github.com/sparkle-project/Sparkle
synced 2026-11-26 04:57:54 +00:00
Add external releasenote support to popup titlebar user driver
This commit is contained in:
1 parent
6dddbcc353
commit
d8ce7cb48b
3 files changed
+75
-17
No files matched your search
@@ -7,12 +7,12 @@
|
||||
//
|
||||
|
||||
#import <Cocoa/Cocoa.h>
|
||||
#import "SPUStatusCompletionResults.h"
|
||||
|
||||
@class SUAppcastItem;
|
||||
#import <Sparkle/Sparkle.h>
|
||||
|
||||
@interface SUInstallUpdateViewController : NSViewController
|
||||
|
||||
- (instancetype)initWithAppcastItem:(SUAppcastItem *)appcastItem skippable:(BOOL)skippable reply:(void (^)(SPUUpdateAlertChoice))reply;
|
||||
|
||||
- (void)showReleaseNotesWithDownloadData:(SPUDownloadData *)downloadData;
|
||||
|
||||
@end
|
||||
@@ -7,13 +7,13 @@
|
||||
//
|
||||
|
||||
#import "SUInstallUpdateViewController.h"
|
||||
#import "SUAppcastItem.h"
|
||||
|
||||
@interface SUInstallUpdateViewController ()
|
||||
|
||||
@property (nonatomic) IBOutlet NSButton *skipUpdatesButton;
|
||||
@property (nonatomic) IBOutlet NSTextView *textView;
|
||||
@property (nonatomic, readonly) SUAppcastItem *appcastItem;
|
||||
@property (nonatomic, nullable) NSAttributedString *preloadedReleaseNotes;
|
||||
@property (nonatomic, copy) void (^reply)(SPUUpdateAlertChoice);
|
||||
@property (nonatomic, readonly) BOOL skippable;
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
|
||||
@synthesize skipUpdatesButton = _skipUpdatesButton;
|
||||
@synthesize textView = _textView;
|
||||
@synthesize preloadedReleaseNotes = _preloadedReleaseNotes;
|
||||
@synthesize appcastItem = _appcastItem;
|
||||
@synthesize reply = _reply;
|
||||
@synthesize skippable = _skippable;
|
||||
@@ -47,16 +48,64 @@
|
||||
[[self.textView enclosingScrollView] setDrawsBackground:NO];
|
||||
[self.textView setDrawsBackground:NO];
|
||||
|
||||
if (self.appcastItem.releaseNotesURL == nil) {
|
||||
if (self.preloadedReleaseNotes != nil) {
|
||||
[self displayReleaseNotes:self.preloadedReleaseNotes];
|
||||
self.preloadedReleaseNotes = nil;
|
||||
} else 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];
|
||||
[self displayReleaseNotes:attributedString];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
- (void)displayReleaseNotes:(NSAttributedString *)releaseNotes
|
||||
{
|
||||
if (self.textView == nil) {
|
||||
self.preloadedReleaseNotes = releaseNotes;
|
||||
} else {
|
||||
[self.textView.textStorage setAttributedString:releaseNotes];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)displayHTMLReleaseNotes:(NSData *)releaseNotes
|
||||
{
|
||||
NSAttributedString *attributedString = [[NSAttributedString alloc] initWithHTML:releaseNotes documentAttributes:NULL];
|
||||
[self displayReleaseNotes:attributedString];
|
||||
}
|
||||
|
||||
- (void)displayPlainTextReleaseNotes:(NSData *)releaseNotes encoding:(NSStringEncoding)encoding
|
||||
{
|
||||
NSString *string = [[NSString alloc] initWithData:releaseNotes encoding:encoding];
|
||||
NSAttributedString *attributedString = [[NSAttributedString alloc] initWithString:string attributes:nil];
|
||||
[self displayReleaseNotes:attributedString];
|
||||
}
|
||||
|
||||
- (void)showReleaseNotesWithDownloadData:(SPUDownloadData *)downloadData
|
||||
{
|
||||
// Partially copied from SPUCommandLineUserDriver
|
||||
// Not all user drivers need this kind of implementation (eg: see SPUStandardUserDriver)
|
||||
// Also I'm not extremely confident about the correctness of this code so I don't want to export it publicly
|
||||
if (downloadData.MIMEType != nil && [downloadData.MIMEType isEqualToString:@"text/plain"]) {
|
||||
NSStringEncoding encoding;
|
||||
if (downloadData.textEncodingName == nil) {
|
||||
encoding = NSUTF8StringEncoding;
|
||||
} else {
|
||||
CFStringEncoding cfEncoding = CFStringConvertIANACharSetNameToEncoding((CFStringRef)downloadData.textEncodingName);
|
||||
if (cfEncoding != kCFStringEncodingInvalidId) {
|
||||
encoding = CFStringConvertEncodingToNSStringEncoding(cfEncoding);
|
||||
} else {
|
||||
encoding = NSUTF8StringEncoding;
|
||||
}
|
||||
}
|
||||
[self displayPlainTextReleaseNotes:downloadData.data encoding:encoding];
|
||||
} else {
|
||||
[self displayHTMLReleaseNotes:downloadData.data];
|
||||
}
|
||||
}
|
||||
|
||||
- (IBAction)installUpdate:(id)__unused sender
|
||||
{
|
||||
if (self.reply != nil) {
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
|
||||
@property (nonatomic, readonly) NSBundle *hostBundle;
|
||||
@property (nonatomic, readonly) NSWindow *window;
|
||||
@property (nonatomic, nullable) SUInstallUpdateViewController *installUpdateViewController;
|
||||
@property (nonatomic, readonly) SPUUserDriverCoreComponent *coreComponent;
|
||||
@property (nonatomic, readonly) SPUUserDriverUIComponent *uiComponent;
|
||||
@property (nonatomic) NSTitlebarAccessoryViewController *accessoryViewController;
|
||||
@@ -28,6 +29,7 @@
|
||||
|
||||
@synthesize hostBundle = _hostBundle;
|
||||
@synthesize window = _window;
|
||||
@synthesize installUpdateViewController = _installUpdateViewController;
|
||||
@synthesize coreComponent = _coreComponent;
|
||||
@synthesize uiComponent = _uiComponent;
|
||||
@synthesize accessoryViewController = _accessoryViewController;
|
||||
@@ -134,16 +136,23 @@
|
||||
NSPopover *popover = [[NSPopover alloc] init];
|
||||
popover.behavior = NSPopoverBehaviorTransient;
|
||||
|
||||
[self addUpdateButtonWithTitle:@"Update Available" action:^(NSButton *button) {
|
||||
if (popover.contentViewController == nil) {
|
||||
popover.contentViewController = [[SUInstallUpdateViewController alloc] initWithAppcastItem:appcastItem skippable:skippable reply:^(SPUUpdateAlertChoice choice) {
|
||||
reply(choice);
|
||||
|
||||
[popover close];
|
||||
button.enabled = NO;
|
||||
}];
|
||||
}
|
||||
__weak SUPopUpTitlebarUserDriver *weakSelf = self;
|
||||
__block NSButton *actionButton = nil;
|
||||
|
||||
SUInstallUpdateViewController *viewController = [[SUInstallUpdateViewController alloc] initWithAppcastItem:appcastItem skippable:skippable reply:^(SPUUpdateAlertChoice choice) {
|
||||
reply(choice);
|
||||
|
||||
[popover close];
|
||||
actionButton.enabled = NO;
|
||||
|
||||
weakSelf.installUpdateViewController = nil;
|
||||
}];
|
||||
|
||||
self.installUpdateViewController = viewController;
|
||||
|
||||
[self addUpdateButtonWithTitle:@"Update Available" action:^(NSButton *button) {
|
||||
actionButton = button;
|
||||
popover.contentViewController = viewController;
|
||||
[popover showRelativeToRect:button.bounds ofView:button preferredEdge:NSMaxYEdge];
|
||||
}];
|
||||
}
|
||||
@@ -180,9 +189,9 @@
|
||||
});
|
||||
}
|
||||
|
||||
- (void)showUpdateReleaseNotesWithDownloadData:(SPUDownloadData *)__unused downloadData
|
||||
- (void)showUpdateReleaseNotesWithDownloadData:(SPUDownloadData *)downloadData
|
||||
{
|
||||
// todo: this should really be implemented
|
||||
[self.installUpdateViewController showReleaseNotesWithDownloadData:downloadData];
|
||||
}
|
||||
|
||||
- (void)showUpdateReleaseNotesFailedToDownloadWithError:(NSError *)__unused error
|
||||
|
||||
Reference in new issue
Block a user