Skip to content

Commit

Permalink
Delegate can now control how version numbers are formatted/displayed …
Browse files Browse the repository at this point in the history
…to the user, so we can e.g. exclude build numbers or whatever makes sense for a particular application.
  • Loading branch information
Uli Kusterer committed Dec 8, 2009
1 parent cee669c commit a453afa
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 2 deletions.
5 changes: 5 additions & 0 deletions SUUIBasedUpdateDriver.m
Expand Up @@ -20,6 +20,11 @@ - (void)didFindValidUpdate
updateAlert = [[SUUpdateAlert alloc] initWithAppcastItem:updateItem host:host];
[updateAlert setDelegate:self];

id<SUVersionDisplay> versDisp = nil;
if ([[updater delegate] respondsToSelector:@selector(versionDisplayerForUpdater:)])
versDisp = [[updater delegate] versionDisplayerForUpdater: updater];
[updateAlert setVersionDisplayer: versDisp];

if ([[updater delegate] respondsToSelector:@selector(updater:didFindValidUpdate:)])
[[updater delegate] updater:updater didFindValidUpdate:updateItem];

Expand Down
5 changes: 5 additions & 0 deletions SUUpdateAlert.h
Expand Up @@ -10,6 +10,8 @@
#define SUUPDATEALERT_H

#import "SUWindowController.h"
#import "SUVersionDisplayProtocol.h"


typedef enum
{
Expand All @@ -24,6 +26,7 @@ typedef enum
SUAppcastItem *updateItem;
SUHost *host;
id delegate;
id<SUVersionDisplay> versionDisplayer;

IBOutlet WebView *releaseNotesView;
IBOutlet NSTextField *description;
Expand All @@ -39,6 +42,8 @@ typedef enum
- (IBAction)skipThisVersion:sender;
- (IBAction)remindMeLater:sender;

- (void)setVersionDisplayer: (id<SUVersionDisplay>)disp;

@end

@interface NSObject (SUUpdateAlertDelegate)
Expand Down
9 changes: 8 additions & 1 deletion SUUpdateAlert.m
Expand Up @@ -48,6 +48,11 @@ - (void)dealloc
[super dealloc];
}

- (void)setVersionDisplayer: (id<SUVersionDisplay>)disp
{
versionDisplayer = disp;
}

- (void)endWithSelection:(SUUpdateAlertChoice)choice
{
[releaseNotesView stopLoading:self];
Expand Down Expand Up @@ -233,11 +238,13 @@ - (NSString *)descriptionText
NSString *updateItemVersion = [updateItem displayVersionString];
NSString *hostVersion = [host displayVersion];
// Display more info if the version strings are the same; useful for betas.
if ([updateItemVersion isEqualToString:hostVersion])
if( !versionDisplayer && [updateItemVersion isEqualToString:hostVersion] )
{
updateItemVersion = [updateItemVersion stringByAppendingFormat:@" (%@)", [updateItem versionString]];
hostVersion = [hostVersion stringByAppendingFormat:@" (%@)", [host version]];
}
else
[versionDisplayer formatVersion: &updateItemVersion andVersion: &hostVersion];
return [NSString stringWithFormat:SULocalizedString(@"%@ %@ is now available--you have %@. Would you like to download it now?", nil), [host name], updateItemVersion, hostVersion];
}

Expand Down
33 changes: 32 additions & 1 deletion SUUpdater.h
Expand Up @@ -9,10 +9,27 @@
#ifndef SUUPDATER_H
#define SUUPDATER_H

// -----------------------------------------------------------------------------
// Headers:
// -----------------------------------------------------------------------------

#import "SUVersionComparisonProtocol.h"
#import "SUVersionDisplayProtocol.h"


// -----------------------------------------------------------------------------
// Forwards:
// -----------------------------------------------------------------------------

@class SUUpdateDriver, SUAppcastItem, SUHost, SUAppcast;
@interface SUUpdater : NSObject {


// -----------------------------------------------------------------------------
// SUUpdater:
// -----------------------------------------------------------------------------

@interface SUUpdater : NSObject
{
NSTimer *checkTimer;
SUUpdateDriver *driver;

Expand Down Expand Up @@ -73,6 +90,11 @@

@end


// -----------------------------------------------------------------------------
// SUUpdater Delegate:
// -----------------------------------------------------------------------------

@interface NSObject (SUUpdaterDelegateInformalProtocol)

// Use this to keep Sparkle from popping up e.g. while your setup assistant is showing:
Expand Down Expand Up @@ -119,11 +141,20 @@
// If you don't implement this method or return nil, the standard version comparator will be used.
- (id <SUVersionComparison>)versionComparatorForUpdater:(SUUpdater *)updater;

// This method allows you to provide a custom version comparator.
// If you don't implement this method or return nil, the standard version comparator will be used.
- (id <SUVersionDisplay>)versionDisplayerForUpdater:(SUUpdater *)updater;

// Returns the path which is used to relaunch the client after the update is installed. By default, the path of the host bundle.
- (NSString *)pathToRelaunchForUpdater:(SUUpdater *)updater;

@end


// -----------------------------------------------------------------------------
// Constants:
// -----------------------------------------------------------------------------

// Define some minimum intervals to avoid DOS-like checking attacks. These are in seconds.
#ifdef DEBUG && 0
#define SU_MIN_CHECK_INTERVAL 60
Expand Down
27 changes: 27 additions & 0 deletions SUVersionDisplayProtocol.h
@@ -0,0 +1,27 @@
//
// SUVersionDisplayProtocol.h
// EyeTV
//
// Created by Uli Kusterer on 08.12.09.
// Copyright 2009 Elgato Systems GmbH. All rights reserved.
//

#import <Cocoa/Cocoa.h>


/*!
@protocol
@abstract Implement this protocol to apply special formatting to the two
version numbers.
*/
@protocol SUVersionDisplay

/*!
@method
@abstract An abstract method to format two version strings.
@discussion You get both so you can display important distinguishing
information, but leave out unnecessary/confusing parts.
*/
-(void) formatVersion: (NSString**)inOutVersionA andVersion: (NSString**)inOutVersionB;

@end

0 comments on commit a453afa

Please sign in to comment.