Add custom user driver in the test app

This commit is contained in:
Zorg committed 2016-03-05 12:59:11 -05:00
1 parent 30cb984341
commit 5dca54d904
12 files changed
+700 -80

No files matched your search

+22 -2
View File
@@ -184,6 +184,10 @@
725F977C1C8A896F00265BE4 /* SUUserDriverCoreComponent.m in Sources */ = {isa = PBXBuildFile; fileRef = 725F977A1C8A896F00265BE4 /* SUUserDriverCoreComponent.m */; };
725F977F1C8A93D700265BE4 /* SUUserDriverUIComponent.h in Headers */ = {isa = PBXBuildFile; fileRef = 725F977D1C8A93D700265BE4 /* SUUserDriverUIComponent.h */; };
725F97801C8A93D700265BE4 /* SUUserDriverUIComponent.m in Sources */ = {isa = PBXBuildFile; fileRef = 725F977E1C8A93D700265BE4 /* SUUserDriverUIComponent.m */; };
725F97841C8AA90000265BE4 /* SUPopUpTitlebarUserDriver.m in Sources */ = {isa = PBXBuildFile; fileRef = 725F97831C8AA90000265BE4 /* SUPopUpTitlebarUserDriver.m */; };
725F97A51C8B304D00265BE4 /* SUInstallUpdateViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 725F97A31C8B304D00265BE4 /* SUInstallUpdateViewController.m */; };
725F97A61C8B304D00265BE4 /* SUInstallUpdateViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 725F97A41C8B304D00265BE4 /* SUInstallUpdateViewController.xib */; };
725F97A81C8B42D700265BE4 /* SUStandardUserDriverProtocol.h in Headers */ = {isa = PBXBuildFile; fileRef = 725F97A71C8B42D700265BE4 /* SUStandardUserDriverProtocol.h */; settings = {ATTRIBUTES = (Public, ); }; };
7268AC631AD634C200C3E0C1 /* SUBinaryDeltaCreate.m in Sources */ = {isa = PBXBuildFile; fileRef = 7268AC621AD634C200C3E0C1 /* SUBinaryDeltaCreate.m */; };
726DF88E1C84277600188804 /* SUStatusCompletionResults.h in Headers */ = {isa = PBXBuildFile; fileRef = 726DF88D1C84277500188804 /* SUStatusCompletionResults.h */; settings = {ATTRIBUTES = (Public, ); }; };
726E4A0E1C86881600C57C6A /* SUStandardUserDriverUIDelegate.h in Headers */ = {isa = PBXBuildFile; fileRef = 726E4A0D1C86881600C57C6A /* SUStandardUserDriverUIDelegate.h */; settings = {ATTRIBUTES = (Public, ); }; };
@@ -676,6 +680,12 @@
725F977A1C8A896F00265BE4 /* SUUserDriverCoreComponent.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SUUserDriverCoreComponent.m; sourceTree = "<group>"; };
725F977D1C8A93D700265BE4 /* SUUserDriverUIComponent.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SUUserDriverUIComponent.h; sourceTree = "<group>"; };
725F977E1C8A93D700265BE4 /* SUUserDriverUIComponent.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SUUserDriverUIComponent.m; sourceTree = "<group>"; };
725F97821C8AA90000265BE4 /* SUPopUpTitlebarUserDriver.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SUPopUpTitlebarUserDriver.h; sourceTree = "<group>"; };
725F97831C8AA90000265BE4 /* SUPopUpTitlebarUserDriver.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SUPopUpTitlebarUserDriver.m; sourceTree = "<group>"; };
725F97A21C8B304D00265BE4 /* SUInstallUpdateViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SUInstallUpdateViewController.h; sourceTree = "<group>"; };
725F97A31C8B304D00265BE4 /* SUInstallUpdateViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SUInstallUpdateViewController.m; sourceTree = "<group>"; };
725F97A41C8B304D00265BE4 /* SUInstallUpdateViewController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = SUInstallUpdateViewController.xib; sourceTree = "<group>"; };
725F97A71C8B42D700265BE4 /* SUStandardUserDriverProtocol.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SUStandardUserDriverProtocol.h; sourceTree = "<group>"; };
7268AC621AD634C200C3E0C1 /* SUBinaryDeltaCreate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SUBinaryDeltaCreate.m; sourceTree = "<group>"; };
7268AC641AD634E400C3E0C1 /* SUBinaryDeltaCreate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SUBinaryDeltaCreate.h; sourceTree = "<group>"; };
726B2B5D1C645FC900388755 /* UI Tests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "UI Tests.xctest"; sourceTree = BUILT_PRODUCTS_DIR; };
@@ -1138,6 +1148,11 @@
726E4A311C87E0C700C57C6A /* SURemoteUpdateSettingsWindowController.h */,
726E4A321C87E0C700C57C6A /* SURemoteUpdateSettingsWindowController.m */,
726E4A331C87E0C700C57C6A /* SURemoteUpdateSettingsWindowController.xib */,
725F97821C8AA90000265BE4 /* SUPopUpTitlebarUserDriver.h */,
725F97831C8AA90000265BE4 /* SUPopUpTitlebarUserDriver.m */,
725F97A21C8B304D00265BE4 /* SUInstallUpdateViewController.h */,
725F97A31C8B304D00265BE4 /* SUInstallUpdateViewController.m */,
725F97A41C8B304D00265BE4 /* SUInstallUpdateViewController.xib */,
72E45CFD1B641D0D005C701A /* test_app_only_dsa_priv_dont_ever_do_this_for_real.pem */,
14732BBF1960F0AC00593899 /* test_app_only_dsa_pub.pem */,
61B5F90409C4CEE200B25A18 /* TestApplication-Info.plist */,
@@ -1161,6 +1176,8 @@
isa = PBXGroup;
children = (
725CB9561C7120410064365A /* SUUserDriver.h */,
725F97791C8A896F00265BE4 /* SUUserDriverCoreComponent.h */,
725F977A1C8A896F00265BE4 /* SUUserDriverCoreComponent.m */,
726DF88D1C84277500188804 /* SUStatusCompletionResults.h */,
61B93B250DD0FDD300DCD2F8 /* SUAutomaticUpdateDriver.h */,
61B93B260DD0FDD300DCD2F8 /* SUAutomaticUpdateDriver.m */,
@@ -1200,10 +1217,9 @@
726E4A361C89116000C57C6A /* SUStandardUserDriverDelegate.h */,
726E4A0D1C86881600C57C6A /* SUStandardUserDriverUIDelegate.h */,
726E4A0F1C86B5A200C57C6A /* SUStandardUserDriverRemoteDelegate.h */,
725F97A71C8B42D700265BE4 /* SUStandardUserDriverProtocol.h */,
725CB9581C7121830064365A /* SUStandardUserDriver.h */,
725CB9591C7121830064365A /* SUStandardUserDriver.m */,
725F97791C8A896F00265BE4 /* SUUserDriverCoreComponent.h */,
725F977A1C8A896F00265BE4 /* SUUserDriverCoreComponent.m */,
725F977D1C8A93D700265BE4 /* SUUserDriverUIComponent.h */,
725F977E1C8A93D700265BE4 /* SUUserDriverUIComponent.m */,
);
@@ -1279,6 +1295,7 @@
files = (
726E4A371C89116000C57C6A /* SUStandardUserDriverDelegate.h in Headers */,
726E4A0E1C86881600C57C6A /* SUStandardUserDriverUIDelegate.h in Headers */,
725F97A81C8B42D700265BE4 /* SUStandardUserDriverProtocol.h in Headers */,
726E4A101C86B5A200C57C6A /* SUStandardUserDriverRemoteDelegate.h in Headers */,
725CB95A1C7121830064365A /* SUStandardUserDriver.h in Headers */,
725CB9571C7120410064365A /* SUUserDriver.h in Headers */,
@@ -1640,6 +1657,7 @@
buildActionMask = 2147483647;
files = (
726E4A351C87E0C700C57C6A /* SURemoteUpdateSettingsWindowController.xib in Resources */,
725F97A61C8B304D00265BE4 /* SUInstallUpdateViewController.xib in Resources */,
1420DF50196247F900203BB0 /* Images.xcassets in Resources */,
61B5F92E09C4CFD800B25A18 /* InfoPlist.strings in Resources */,
61B5F92F09C4CFD800B25A18 /* MainMenu.xib in Resources */,
@@ -1813,8 +1831,10 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
725F97841C8AA90000265BE4 /* SUPopUpTitlebarUserDriver.m in Sources */,
726E4A2B1C87D56200C57C6A /* SUTestWebServer.m in Sources */,
726E4A341C87E0C700C57C6A /* SURemoteUpdateSettingsWindowController.m in Sources */,
725F97A51C8B304D00265BE4 /* SUInstallUpdateViewController.m in Sources */,
61B5F93009C4CFDC00B25A18 /* main.m in Sources */,
726F2CEB1BC9C733001971A4 /* SUConstants.m in Sources */,
72E45CF31B640CDD005C701A /* SUTestApplicationDelegate.m in Sources */,
+2 -2
View File
@@ -11,7 +11,7 @@
NS_ASSUME_NONNULL_BEGIN
@class SUUpdater;
@class SUStandardUserDriver;
@protocol SUStandardUserDriver;
/*!
A controller class that instantiates a SUUpdater and allows binding UI to it.
@@ -43,7 +43,7 @@ NS_ASSUME_NONNULL_BEGIN
/*!
Accessible property for the updater's user driver.
*/
@property (nonatomic, readonly) SUStandardUserDriver *userDriver;
@property (nonatomic, readonly) id <SUStandardUserDriver> userDriver;
/*!
Explicitly checks for updates and displays a progress dialog while doing so.
+5 -3
View File
@@ -19,7 +19,7 @@ static NSString *const SUUpdaterDefaultsObservationContext = @"SUUpdaterDefaults
@interface SUStandardUpdaterController ()
@property (nonatomic) SUUpdater *updater;
@property (nonatomic) SUStandardUserDriver *userDriver;
@property (nonatomic) id <SUStandardUserDriver> userDriver;
@end
@@ -35,8 +35,10 @@ static NSString *const SUUpdaterDefaultsObservationContext = @"SUUpdaterDefaults
[self registerAsObserver];
NSBundle *hostBundle = [NSBundle mainBundle];
_userDriver = [[SUStandardUserDriver alloc] initWithHostBundle:hostBundle delegate:nil];
_updater = [[SUUpdater alloc] initWithHostBundle:hostBundle userDriver:_userDriver delegate:nil];
id <SUUserDriver, SUStandardUserDriver> userDriver = [[SUStandardUserDriver alloc] initWithHostBundle:hostBundle delegate:nil];
_updater = [[SUUpdater alloc] initWithHostBundle:hostBundle userDriver:userDriver delegate:nil];
_userDriver = userDriver;
}
return self;
}
+2 -70
View File
@@ -8,6 +8,7 @@
#import <Cocoa/Cocoa.h>
#import "SUUserDriver.h"
#import "SUStandardUserDriverProtocol.h"
NS_ASSUME_NONNULL_BEGIN
@@ -16,7 +17,7 @@ NS_ASSUME_NONNULL_BEGIN
/*!
Sparkle's standard built-in user driver for updater interactions
*/
@interface SUStandardUserDriver : NSObject <SUUserDriver>
@interface SUStandardUserDriver : NSObject <SUUserDriver, SUStandardUserDriver>
/*!
Initializes a Sparkle's standard user driver for user update interactions
@@ -26,75 +27,6 @@ NS_ASSUME_NONNULL_BEGIN
*/
- (instancetype)initWithHostBundle:(NSBundle *)hostBundle delegate:(_Nullable id <SUStandardUserDriverDelegate>)delegate;
/*!
Readable and writable property for this user driver's delegate
*/
@property (nonatomic, weak, nullable) id <SUStandardUserDriverDelegate> delegate;
/*!
Indicates whether or not an update is in progress as far as the user's perspective is concerned
A typical application may rely on this property for its check for updates menu item validation
*/
@property (nonatomic, readonly, getter=isUpdateInProgress) BOOL updateInProgress;
/*!
Indicates whether or not a currently pending update check will be initiated in the future
This may be useful for deciding if the user driver should be invalidated, when the connection to the updater
has been interrupted.
*/
@property (nonatomic, readonly) BOOL willInitiateNextUpdateCheck;
/*!
Indicates whether or not Sparkle's updater has been idling on update checks; i.e, if automatic update checks
had been disabled the last time the updater checked.
This may be useful for deciding if a connection needs to be immediately resumed or re-created if it has been interrupted.
See also -willInitiateNextUpdateCheck
*/
@property (nonatomic, readonly) BOOL idlesOnUpdateChecks;
/*!
Send a signal to the user driver that the user application should terminate.
This should only be invoked if the user driver's delegate says it's responsible for signaling application termination,
and this should only be called from NSApplicationDelegate's applicationShouldTerminate: method.
This is particularly useful when the user driver and updater live in separate processes, and the updater
wants to install an automatic update on termination. If the updater is in a separate process, that means
we may have to defer application termination a bit until the updater is ready to launch its auto updater.
@return The NSApplication termination reply. Use this as a return value to NSApplicationDelegate's applicationShouldTerminate:
*/
- (NSApplicationTerminateReply)sendApplicationTerminationSignal;
/*!
Terminate the current application after sending a termination signal
This should only be invoked by the user driver's delegate if the -sendApplicationTerminationSignal message has been sent prior.
For this user driver's delegate, invoking this is appropriate when the application's termination has been delayed, and the connection
to the updater has been invalidated or interrupted -- in which case the updater can no longer tell the user driver when to finish terminating.
This implementation will be dispatched on the main queue.
Note this is also a part of the SUUserDriver protocol that this class implements
*/
- (void)terminateApplication;
/*!
Invalidate the current update installation
This stops all behavior for the current update installation. It avoids making any calls or replies to Sparkle's updater.
Note this does not change the idle state of update checks (i.e, -idlesOnUpdateChecks), but it will invalidate any pending update checks.
One may want to check if there is a pending update check (i.e, -willInitiateNextUpdateCheck) before making this call to decide if the
user driver should be invalidated or not
This is appropriate to call when the connection to the updater has been interrupted or invalidated. Note this class is still re-usable
in the case that the connection should be later resumed.
*/
- (void)invalidate;
@end
NS_ASSUME_NONNULL_END
+89
View File
@@ -0,0 +1,89 @@
//
// SUStandardUserDriverProtocol.h
// Sparkle
//
// Created by Mayur Pawashe on 3/5/16.
// Copyright © 2016 Sparkle Project. All rights reserved.
//
#import <Foundation/Foundation.h>
@protocol SUStandardUserDriverDelegate;
/*!
Protocol for Sparkle's standard built-in user driver for updater interactions.
Other user drivers may wish to implement this protocol.
*/
@protocol SUStandardUserDriver <NSObject>
/*!
Readable and writable property for this user driver's delegate
*/
@property (nonatomic, weak, nullable) id <SUStandardUserDriverDelegate> delegate;
/*!
Indicates whether or not an update is in progress as far as the user's perspective is concerned
A typical application may rely on this property for its check for updates menu item validation
*/
@property (nonatomic, readonly, getter=isUpdateInProgress) BOOL updateInProgress;
/*!
Indicates whether or not a currently pending update check will be initiated in the future
This may be useful for deciding if the user driver should be invalidated, when the connection to the updater
has been interrupted.
*/
@property (nonatomic, readonly) BOOL willInitiateNextUpdateCheck;
/*!
Indicates whether or not Sparkle's updater has been idling on update checks; i.e, if automatic update checks
had been disabled the last time the updater checked.
This may be useful for deciding if a connection needs to be immediately resumed or re-created if it has been interrupted.
See also -willInitiateNextUpdateCheck
*/
@property (nonatomic, readonly) BOOL idlesOnUpdateChecks;
/*!
Send a signal to the user driver that the user application should terminate.
This should only be invoked if the user driver's delegate says it's responsible for signaling application termination,
and this should only be called from NSApplicationDelegate's applicationShouldTerminate: method.
This is particularly useful when the user driver and updater live in separate processes, and the updater
wants to install an automatic update on termination. If the updater is in a separate process, that means
we may have to defer application termination a bit until the updater is ready to launch its auto updater.
@return The NSApplication termination reply. Use this as a return value to NSApplicationDelegate's applicationShouldTerminate:
*/
- (NSApplicationTerminateReply)sendApplicationTerminationSignal;
/*!
Terminate the current application after sending a termination signal
This should only be invoked by the user driver's delegate if the -sendApplicationTerminationSignal message has been sent prior.
For this user driver's delegate, invoking this is appropriate when the application's termination has been delayed, and the connection
to the updater has been invalidated or interrupted -- in which case the updater can no longer tell the user driver when to finish terminating.
This implementation will be dispatched on the main queue.
Note this is also a part of the SUUserDriver protocol that this class implements
*/
- (void)terminateApplication;
/*!
Invalidate the current update installation
This stops all behavior for the current update installation. It avoids making any calls or replies to Sparkle's updater.
Note this does not change the idle state of update checks (i.e, -idlesOnUpdateChecks), but it will invalidate any pending update checks.
One may want to check if there is a pending update check (i.e, -willInitiateNextUpdateCheck) before making this call to decide if the
user driver should be invalidated or not
This is appropriate to call when the connection to the updater has been interrupted or invalidated. Note this class is still re-usable
in the case that the connection should be later resumed.
*/
- (void)invalidate;
@end
@@ -0,0 +1,18 @@
//
// SUInstallUpdateViewController.h
// Sparkle
//
// Created by Mayur Pawashe on 3/5/16.
// Copyright © 2016 Sparkle Project. All rights reserved.
//
#import <Cocoa/Cocoa.h>
#import "SUStatusCompletionResults.h"
@class SUAppcastItem;
@interface SUInstallUpdateViewController : NSViewController
- (instancetype)initWithAppcastItem:(SUAppcastItem *)appcastItem reply:(void (^)(SUUpdateAlertChoice))reply;
@end
@@ -0,0 +1,73 @@
//
// SUInstallUpdateViewController.m
// Sparkle
//
// Created by Mayur Pawashe on 3/5/16.
// Copyright © 2016 Sparkle Project. All rights reserved.
//
#import "SUInstallUpdateViewController.h"
#import "SUAppcastItem.h"
@interface SUInstallUpdateViewController ()
@property (nonatomic) IBOutlet NSTextView *textView;
@property (nonatomic, readonly) SUAppcastItem *appcastItem;
@property (nonatomic, copy) void (^reply)(SUUpdateAlertChoice);
@end
@implementation SUInstallUpdateViewController
@synthesize textView = _textView;
@synthesize appcastItem = _appcastItem;
@synthesize reply = _reply;
- (instancetype)initWithAppcastItem:(SUAppcastItem *)appcastItem reply:(void (^)(SUUpdateAlertChoice))reply
{
self = [super initWithNibName:@"SUInstallUpdateViewController" bundle:nil];
if (self != nil) {
_appcastItem = appcastItem;
self.reply = reply;
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
[[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];
}
- (IBAction)installUpdate:(id)__unused sender
{
if (self.reply != nil) {
self.reply(SUInstallUpdateChoice);
self.reply = nil;
}
}
- (IBAction)installUpdateLater:(id)__unused sender
{
if (self.reply != nil) {
self.reply(SUInstallLaterChoice);
self.reply = nil;
}
}
- (IBAction)skipUpdate:(id)__unused sender
{
if (self.reply != nil) {
self.reply(SUSkipThisVersionChoice);
self.reply = nil;
}
}
@end
@@ -0,0 +1,88 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="9532" systemVersion="15D21" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
<dependencies>
<deployment identifier="macosx"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="9532"/>
</dependencies>
<objects>
<customObject id="-2" userLabel="File's Owner" customClass="SUInstallUpdateViewController">
<connections>
<outlet property="textView" destination="hvq-rZ-gUG" id="U5Y-SK-7E5"/>
<outlet property="view" destination="Hz6-mo-xeY" id="0bl-1N-x8E"/>
</connections>
</customObject>
<customObject id="-1" userLabel="First Responder" customClass="FirstResponder"/>
<customObject id="-3" userLabel="Application" customClass="NSObject"/>
<customView id="Hz6-mo-xeY">
<rect key="frame" x="0.0" y="0.0" width="370" height="182"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<subviews>
<button verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="JaG-xU-cSv">
<rect key="frame" x="128" y="6" width="114" height="32"/>
<buttonCell key="cell" type="push" title="Install Later" bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="vGh-C9-cmI">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
<font key="font" metaFont="system"/>
<string key="keyEquivalent" base64-UTF8="YES">
Gw
</string>
</buttonCell>
<connections>
<action selector="installUpdateLater:" target="-2" id="49e-4G-Ofu"/>
</connections>
</button>
<button verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="GnO-99-FrA">
<rect key="frame" x="14" y="6" width="114" height="32"/>
<buttonCell key="cell" type="push" title="Skip Update" bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="Q9S-re-mYe">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
<font key="font" metaFont="system"/>
</buttonCell>
<connections>
<action selector="skipUpdate:" target="-2" id="VsN-ie-9xR"/>
</connections>
</button>
<scrollView fixedFrame="YES" horizontalLineScroll="10" horizontalPageScroll="10" verticalLineScroll="10" verticalPageScroll="10" hasHorizontalScroller="NO" usesPredominantAxisScrolling="NO" translatesAutoresizingMaskIntoConstraints="NO" id="3Cj-JW-f43">
<rect key="frame" x="0.0" y="46" width="370" height="136"/>
<clipView key="contentView" ambiguous="YES" id="CIT-u4-hRg">
<rect key="frame" x="1" y="1" width="368" height="134"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<textView ambiguous="YES" editable="NO" importsGraphics="NO" findStyle="panel" verticallyResizable="YES" allowsNonContiguousLayout="YES" id="hvq-rZ-gUG">
<rect key="frame" x="0.0" y="0.0" width="368" height="134"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<size key="minSize" width="368" height="134"/>
<size key="maxSize" width="463" height="10000000"/>
<color key="insertionPointColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
<size key="minSize" width="368" height="134"/>
<size key="maxSize" width="463" height="10000000"/>
</textView>
</subviews>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
</clipView>
<scroller key="horizontalScroller" hidden="YES" verticalHuggingPriority="750" doubleValue="1" horizontal="YES" id="t2X-nw-Cy5">
<rect key="frame" x="-100" y="-100" width="87" height="18"/>
<autoresizingMask key="autoresizingMask"/>
</scroller>
<scroller key="verticalScroller" verticalHuggingPriority="750" horizontal="NO" id="dth-jh-Csr">
<rect key="frame" x="353" y="1" width="16" height="134"/>
<autoresizingMask key="autoresizingMask"/>
</scroller>
</scrollView>
<button verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="cYY-dW-0o8">
<rect key="frame" x="242" y="6" width="114" height="32"/>
<buttonCell key="cell" type="push" title="Install Update" bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="AoI-0t-LLU">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
<font key="font" metaFont="system"/>
<string key="keyEquivalent" base64-UTF8="YES">
DQ
</string>
</buttonCell>
<connections>
<action selector="installUpdate:" target="-2" id="G8I-20-OHo"/>
</connections>
</button>
</subviews>
<point key="canvasLocation" x="174" y="251"/>
</customView>
</objects>
</document>
@@ -0,0 +1,18 @@
//
// SUPopUpTitlebarUserDriver.h
// Sparkle
//
// Created by Mayur Pawashe on 3/5/16.
// Copyright © 2016 Sparkle Project. All rights reserved.
//
#import <Foundation/Foundation.h>
#import <Sparkle/Sparkle.h>
@protocol SUStandardUserDriver;
@interface SUPopUpTitlebarUserDriver : NSObject <SUUserDriver, SUStandardUserDriver>
- (instancetype)initWithWindow:(NSWindow *)window delegate:(id<SUStandardUserDriverDelegate>)delegate;
@end
+376
View File
@@ -0,0 +1,376 @@
//
// SUPopUpTitlebarUserDriver.m
// Sparkle
//
// Created by Mayur Pawashe on 3/5/16.
// Copyright © 2016 Sparkle Project. All rights reserved.
//
#import "SUPopUpTitlebarUserDriver.h"
#import "SUStandardUserDriverDelegate.h"
#import "SUUserDriverCoreComponent.h"
#import "SUUserDriverUIComponent.h"
#import "SUUserDriverCoreComponent.h"
#import "SUUserDriverUIComponent.h"
#import "SUInstallUpdateViewController.h"
@interface SUPopUpTitlebarUserDriver()
@property (nonatomic, readonly) NSWindow *window;
@property (nonatomic, readonly) SUUserDriverCoreComponent *coreComponent;
@property (nonatomic, readonly) SUUserDriverUIComponent *uiComponent;
@property (nonatomic) NSTitlebarAccessoryViewController *accessoryViewController;
@property (nonatomic) BOOL addedAccessory;
@property (nonatomic) NSButton *updateButton;
@property (nonatomic, copy) void (^updateButtonAction)(NSButton *);
@property (nonatomic) NSUInteger expectedContentLength;
@property (nonatomic) NSUInteger contentLengthDownloaded;
@end
@implementation SUPopUpTitlebarUserDriver
@synthesize delegate = _delegate;
@synthesize window = _window;
@synthesize coreComponent = _coreComponent;
@synthesize uiComponent = _uiComponent;
@synthesize accessoryViewController = _accessoryViewController;
@synthesize addedAccessory = _addedAccessory;
@synthesize updateButton = _updateButton;
@synthesize updateButtonAction = _updateButtonAction;
@synthesize expectedContentLength = _expectedContentLength;
@synthesize contentLengthDownloaded = _contentLengthDownloaded;
- (instancetype)initWithWindow:(NSWindow *)window delegate:(id<SUStandardUserDriverDelegate>)delegate
{
self = [super init];
if (self != nil) {
_window = window;
_delegate = delegate;
_coreComponent = [[SUUserDriverCoreComponent alloc] initWithUserDriver:self delegate:delegate];
_uiComponent = [[SUUserDriverUIComponent alloc] initWithUserDriver:self delegate:delegate];
}
return self;
}
- (void)addUpdateButtonWithTitle:(NSString *)title
{
[self addUpdateButtonWithTitle:title action:nil];
}
- (void)addUpdateButtonWithTitle:(NSString *)title action:(void (^)(NSButton *button))action
{
if (self.updateButton == nil) {
NSButton *updateButton = [[NSButton alloc] initWithFrame:NSMakeRect(0, 0, 160, 100)];
updateButton.title = title;
updateButton.bezelStyle = NSRecessedBezelStyle;
self.updateButton = updateButton;
} else {
self.updateButton.title = title;
}
if (action != nil) {
self.updateButton.target = self;
self.updateButton.action = @selector(updateButtonAction:);
self.updateButtonAction = action;
self.updateButton.enabled = YES;
} else {
self.updateButton.enabled = NO;
self.updateButton.target = nil;
self.updateButtonAction = nil;
}
if (self.accessoryViewController == nil) {
self.accessoryViewController = [[NSTitlebarAccessoryViewController alloc] init];
self.accessoryViewController.layoutAttribute = NSLayoutAttributeRight;
self.accessoryViewController.view = self.updateButton;
}
if (!self.addedAccessory) {
[self.window addTitlebarAccessoryViewController:self.accessoryViewController];
self.addedAccessory = YES;
}
}
- (void)updateButtonAction:(NSButton *)sender
{
if (self.updateButtonAction != nil) {
self.updateButtonAction(sender);
}
}
- (void)removeUpdateButton
{
[self.accessoryViewController removeFromParentViewController];
self.addedAccessory = NO;
self.updateButtonAction = nil;
}
#pragma mark Is Update Busy?
- (void)idleOnUpdateChecks:(BOOL)shouldIdleOnUpdateChecks
{
dispatch_async(dispatch_get_main_queue(), ^{
[self.coreComponent idleOnUpdateChecks:shouldIdleOnUpdateChecks];
});
}
- (BOOL)idlesOnUpdateChecks
{
return self.coreComponent.idlesOnUpdateChecks;
}
- (void)showUpdateInProgress:(BOOL)isUpdateInProgress
{
dispatch_async(dispatch_get_main_queue(), ^{
[self.coreComponent showUpdateInProgress:isUpdateInProgress];
});
}
- (BOOL)isUpdateInProgress
{
return self.coreComponent.updateInProgress;
}
#pragma mark Check Updates Timer
- (BOOL)willInitiateNextUpdateCheck
{
return [self.coreComponent willInitiateNextUpdateCheck];
}
- (void)startUpdateCheckTimerWithNextTimeInterval:(NSTimeInterval)timeInterval reply:(void (^)(SUUpdateCheckTimerStatus))reply
{
dispatch_async(dispatch_get_main_queue(), ^{
[self.coreComponent startUpdateCheckTimerWithNextTimeInterval:timeInterval reply:reply];
});
}
- (void)invalidateUpdateCheckTimer
{
dispatch_async(dispatch_get_main_queue(), ^{
[self.coreComponent invalidateUpdateCheckTimer];
});
}
#pragma mark Update Permission
- (void)requestUpdatePermissionWithSystemProfile:(NSArray *)__unused systemProfile reply:(void (^)(SUUpdatePermissionPromptResult *))reply
{
// Just make a decision..
dispatch_async(dispatch_get_main_queue(), ^{
reply([SUUpdatePermissionPromptResult updatePermissionPromptResultWithChoice:SUAutomaticallyCheck shouldSendProfile:NO]);
});
}
#pragma mark Update Found
- (void)showUpdateWithAppcastItem:(SUAppcastItem *)appcastItem reply:(void (^)(SUUpdateAlertChoice))reply
{
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 reply:^(SUUpdateAlertChoice choice) {
reply(choice);
[popover close];
button.enabled = NO;
}];
}
[popover showRelativeToRect:button.bounds ofView:button preferredEdge:NSMaxYEdge];
}];
}
- (void)showUpdateFoundWithAppcastItem:(SUAppcastItem *)appcastItem allowsAutomaticUpdates:(BOOL)__unused allowsAutomaticUpdates reply:(void (^)(SUUpdateAlertChoice))reply
{
dispatch_async(dispatch_get_main_queue(), ^{
[self showUpdateWithAppcastItem:appcastItem reply:reply];
});
}
- (void)showAutomaticUpdateFoundWithAppcastItem:(SUAppcastItem *)appcastItem reply:(void (^)(SUUpdateAlertChoice))reply
{
dispatch_async(dispatch_get_main_queue(), ^{
[self showUpdateWithAppcastItem:appcastItem reply:reply];
});
}
#pragma mark Install & Relaunch Update
- (void)showExtractionFinishedAndReadyToInstallAndRelaunch:(void (^)(SUInstallUpdateStatus))installUpdateHandler
{
dispatch_async(dispatch_get_main_queue(), ^{
[self.coreComponent registerInstallUpdateHandler:installUpdateHandler];
[self addUpdateButtonWithTitle:@"Install & Relaunch" action:^(NSButton *__unused button) {
installUpdateHandler(SUInstallAndRelaunchUpdateNow);
}];
});
}
#pragma mark Check for Updates
- (void)showUserInitiatedUpdateCheckWithCompletion:(void (^)(SUUserInitiatedCheckStatus))updateCheckStatusCompletion
{
dispatch_async(dispatch_get_main_queue(), ^{
[self.coreComponent registerUpdateCheckStatusHandler:updateCheckStatusCompletion];
[self addUpdateButtonWithTitle:@"Checking for Updates…"];
});
}
- (void)dismissUserInitiatedUpdateCheck
{
dispatch_async(dispatch_get_main_queue(), ^{
[self.coreComponent completeUpdateCheckStatus];
[self removeUpdateButton];
});
}
#pragma mark Update Errors
- (void)showUpdaterError:(NSError *)error
{
dispatch_async(dispatch_get_main_queue(), ^{
[self addUpdateButtonWithTitle:@"Update Failed"];
NSLog(@"Error: %@", error);
});
}
- (void)showUpdateNotFound
{
dispatch_async(dispatch_get_main_queue(), ^{
[self addUpdateButtonWithTitle:@"No Update Found"];
});
}
#pragma mark Download & Install Updates
- (void)showDownloadInitiatedWithCompletion:(void (^)(SUDownloadUpdateStatus))downloadUpdateStatusCompletion
{
dispatch_async(dispatch_get_main_queue(), ^{
[self.coreComponent registerDownloadStatusHandler:downloadUpdateStatusCompletion];
});
}
- (void)showDownloadDidReceiveResponse:(NSURLResponse *)response
{
dispatch_async(dispatch_get_main_queue(), ^{
[self addUpdateButtonWithTitle:@"Downloading…"];
self.contentLengthDownloaded = 0;
self.expectedContentLength = (NSUInteger)response.expectedContentLength;
if (self.expectedContentLength == 0) {
// don't divide by zero ever
self.expectedContentLength = 1;
}
});
}
- (void)showDownloadDidReceiveDataOfLength:(NSUInteger)length
{
dispatch_async(dispatch_get_main_queue(), ^{
self.contentLengthDownloaded += length;
double progress = (double)self.contentLengthDownloaded / self.expectedContentLength;
[self addUpdateButtonWithTitle:[NSString stringWithFormat:@"Downloading (%d%%)", (int)progress] action:nil];
});
}
- (void)showDownloadFinishedAndStartedExtractingUpdate
{
dispatch_async(dispatch_get_main_queue(), ^{
[self.coreComponent completeDownloadStatus];
[self addUpdateButtonWithTitle:@"Extracting…"];
});
}
- (void)showExtractionReceivedProgress:(double)progress
{
dispatch_async(dispatch_get_main_queue(), ^{
[self addUpdateButtonWithTitle:[NSString stringWithFormat:@"Extracting (%d%%)…", (int)(progress * 100)]];
});
}
- (void)showInstallingUpdate
{
dispatch_async(dispatch_get_main_queue(), ^{
[self addUpdateButtonWithTitle:@"Installing…"];
});
}
#pragma mark Application Death
- (void)registerApplicationTermination:(void (^)(SUApplicationTerminationStatus))applicationTerminationHandler
{
dispatch_async(dispatch_get_main_queue(), ^{
[self.uiComponent registerApplicationTermination:applicationTerminationHandler];
});
}
- (void)unregisterApplicationTermination
{
dispatch_async(dispatch_get_main_queue(), ^{
[self.uiComponent unregisterApplicationTermination];
});
}
- (NSApplicationTerminateReply)sendApplicationTerminationSignal
{
return [self.uiComponent sendApplicationTerminationSignal];
}
- (void)terminateApplication
{
dispatch_async(dispatch_get_main_queue(), ^{
[self.uiComponent terminateApplication];
});
}
#pragma mark System Death
- (void)registerSystemPowerOff:(void (^)(SUSystemPowerOffStatus))systemPowerOffHandler
{
dispatch_async(dispatch_get_main_queue(), ^{
[self.uiComponent registerSystemPowerOff:systemPowerOffHandler];
});
}
- (void)unregisterSystemPowerOff
{
dispatch_async(dispatch_get_main_queue(), ^{
[self.uiComponent unregisterSystemPowerOff];
});
}
#pragma mark Aborting Everything
- (void)_dismissUpdateInstallation
{
// Make sure everything we call here does not dispatch async to main queue
// because we are already on the main queue (and I've been bitten in the past by this before)
[self.coreComponent dismissUpdateInstallation];
[self.uiComponent dismissUpdateInstallation];
[self removeUpdateButton];
}
- (void)dismissUpdateInstallation
{
dispatch_async(dispatch_get_main_queue(), ^{
[self _dismissUpdateInstallation];
});
}
- (void)invalidate
{
[self.coreComponent invalidate];
[self.uiComponent invalidate];
[self _dismissUpdateInstallation];
}
@end
@@ -8,11 +8,12 @@
#import "SURemoteUpdateSettingsWindowController.h"
#import "TestAppHelperProtocol.h"
#import "SUPopUpTitlebarUserDriver.h"
@interface SURemoteUpdateSettingsWindowController ()
@property (nonatomic) NSXPCConnection *connection;
@property (nonatomic) SUStandardUserDriver *userDriver;
@property (nonatomic) id<SUStandardUserDriver> userDriver;
@property (nonatomic) BOOL isTerminating;
@@ -54,7 +55,10 @@
self.connection = [[NSXPCConnection alloc] initWithServiceName:@"org.sparkle-project.TestAppHelper"];
self.connection.exportedInterface = [NSXPCInterface interfaceWithProtocol:@protocol(SUUserDriver)];
self.userDriver = [[SUStandardUserDriver alloc] initWithHostBundle:[NSBundle mainBundle] delegate:self];
self.userDriver = [[SUPopUpTitlebarUserDriver alloc] initWithWindow:self.window delegate:self];
//self.userDriver = [[SUStandardUserDriver alloc] initWithHostBundle:[NSBundle mainBundle] delegate:self];
self.connection.exportedObject = self.userDriver;
self.connection.remoteObjectInterface = [NSXPCInterface interfaceWithProtocol:@protocol(TestAppHelperProtocol)];
@@ -16,7 +16,7 @@
</customObject>
<customObject id="-1" userLabel="First Responder" customClass="FirstResponder"/>
<customObject id="-3" userLabel="Application" customClass="NSObject"/>
<window title="Options" allowsToolTipsWhenApplicationIsInactive="NO" autorecalculatesKeyViewLoop="NO" releasedWhenClosed="NO" visibleAtLaunch="NO" animationBehavior="default" id="XEo-7J-oab" userLabel="Options Window">
<window allowsToolTipsWhenApplicationIsInactive="NO" autorecalculatesKeyViewLoop="NO" releasedWhenClosed="NO" visibleAtLaunch="NO" animationBehavior="default" id="XEo-7J-oab" userLabel="Options Window">
<windowStyleMask key="styleMask" titled="YES" closable="YES" miniaturizable="YES"/>
<windowPositionMask key="initialPositionMask" leftStrut="YES" rightStrut="YES"/>
<rect key="contentRect" x="543" y="572" width="314" height="149"/>