Skip to content

Commit

Permalink
Enable auto-update for my fork
Browse files Browse the repository at this point in the history
Removed the concept of release channels because I just have one.
  • Loading branch information
douglashill committed Dec 22, 2018
1 parent 77583ad commit 14e87ad
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 90 deletions.
1 change: 0 additions & 1 deletion GitUp/Application/AppDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
@property(nonatomic, strong) IBOutlet NSWindow* preferencesWindow;
@property(nonatomic, weak) IBOutlet NSToolbar* preferencesToolbar;
@property(nonatomic, weak) IBOutlet NSTabView* preferencesTabView;
@property(nonatomic, weak) IBOutlet NSPopUpButton* channelPopUpButton;

@property(nonatomic, strong) IBOutlet NSWindow* cloneWindow;
@property(nonatomic, weak) IBOutlet NSTextField* cloneURLTextField;
Expand Down
47 changes: 5 additions & 42 deletions GitUp/Application/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@
#import "Common.h"
#import "ToolProtocol.h"

#define OFFICIAL 0
#define OFFICIAL_RELEASE !DEBUG && OFFICIAL

#define __ENABLE_SUDDEN_TERMINATION__ 1

#define kNotificationUserInfoKey_Action @"action" // NSString
Expand Down Expand Up @@ -98,7 +95,6 @@ + (void)initialize {
GICommitMessageViewUserDefaultsKey_ContinuousSpellChecking : @(YES),
GICommitMessageViewUserDefaultsKey_SmartInsertDelete : @(YES),
GIUserDefaultKey_FontSize : @(GIDefaultFontSize),
kUserDefaultsKey_ReleaseChannel : kReleaseChannel_Stable,
kUserDefaultsKey_CheckInterval : @(15 * 60),
kUserDefaultsKey_FirstLaunch : @(YES),
kUserDefaultsKey_DiffWhitespaceMode : @(kGCLiveRepositoryDiffWhitespaceMode_Normal),
Expand Down Expand Up @@ -267,26 +263,9 @@ - (void)awakeFromNib {
_preferencesToolbar.selectedItemIdentifier = kPreferencePaneIdentifier_General;
[self selectPreferencePane:nil];

[_channelPopUpButton.menu removeAllItems];
for (NSString* string in @[ kReleaseChannel_Stable, kReleaseChannel_Continuous ]) {
NSMenuItem* item = [[NSMenuItem alloc] initWithTitle:NSLocalizedString(string, nil) action:NULL keyEquivalent:@""];
item.representedObject = string;
[_channelPopUpButton.menu addItem:item];
}

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(_willShowRecentPopUpMenu:) name:NSPopUpButtonWillPopUpNotification object:_recentPopUpButton];
}

- (void)_updatePreferencePanel {
NSString* channel = [[NSUserDefaults standardUserDefaults] stringForKey:kUserDefaultsKey_ReleaseChannel];
for (NSMenuItem* item in _channelPopUpButton.menu.itemArray) {
if ([item.representedObject isEqualToString:channel]) {
[_channelPopUpButton selectItem:item];
break;
}
}
}

- (void)_showNotificationWithTitle:(NSString*)title action:(SEL)action message:(NSString*)message {
NSUserNotification* notification = [[NSUserNotification alloc] init];
if (action) {
Expand Down Expand Up @@ -324,7 +303,7 @@ - (void)applicationWillFinishLaunching:(NSNotification*)notification {
}

- (void)applicationDidFinishLaunching:(NSNotification*)notification {
#if OFFICIAL_RELEASE
#if !DEBUG
// Initialize Sparkle and check for update immediately
if (![[NSUserDefaults standardUserDefaults] boolForKey:kUserDefaultsKey_DisableSparkle]) {
_updater = [SUUpdater sharedUpdater];
Expand Down Expand Up @@ -469,17 +448,6 @@ - (IBAction)openDocument:(id)sender {
[[NSDocumentController sharedDocumentController] openDocument:sender];
}

- (IBAction)changeReleaseChannel:(id)sender {
NSString* oldChannel = [[NSUserDefaults standardUserDefaults] stringForKey:kUserDefaultsKey_ReleaseChannel];
NSString* newChannel = _channelPopUpButton.selectedItem.representedObject;
if (![newChannel isEqualToString:oldChannel]) {
[[NSUserDefaults standardUserDefaults] setObject:newChannel forKey:kUserDefaultsKey_ReleaseChannel];

_manualCheck = NO;
[_updater checkForUpdatesInBackground];
}
}

- (IBAction)viewWiki:(id)sender {
[[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:kURL_Wiki]];
}
Expand Down Expand Up @@ -507,7 +475,6 @@ - (IBAction)showAboutPanel:(id)sender {
}

- (IBAction)showPreferences:(id)sender {
[self _updatePreferencePanel];
[_preferencesWindow makeKeyAndOrderFront:nil];
}

Expand Down Expand Up @@ -722,13 +689,11 @@ - (void)repository:(GCRepository*)repository didFinishTransferWithURL:(NSURL*)ur
#pragma mark - SUUpdaterDelegate

- (NSString*)feedURLStringForUpdater:(SUUpdater*)updater {
NSString* channel = [[NSUserDefaults standardUserDefaults] stringForKey:kUserDefaultsKey_ReleaseChannel];
return [NSString stringWithFormat:kURL_AppCast, channel];
return kURL_AppCast;
}

- (void)updater:(SUUpdater*)updater didFindValidUpdate:(SUAppcastItem*)item {
NSString* channel = [[NSUserDefaults standardUserDefaults] stringForKey:kUserDefaultsKey_ReleaseChannel];
XLOG_INFO(@"Did find app update on channel “%@” for version %@", channel, item.versionString);
XLOG_INFO(@"Did find app update for version %@", item.versionString);
if (_manualCheck) {
let alert = [[NSAlert alloc] init];
alert.messageText = NSLocalizedString(@"A GitUp update is available!", nil);
Expand All @@ -740,8 +705,7 @@ - (void)updater:(SUUpdater*)updater didFindValidUpdate:(SUAppcastItem*)item {
}

- (void)updaterDidNotFindUpdate:(SUUpdater*)updater {
NSString* channel = [[NSUserDefaults standardUserDefaults] stringForKey:kUserDefaultsKey_ReleaseChannel];
XLOG_VERBOSE(@"App is up-to-date at version %@ on channel '%@'", [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleVersion"], channel);
XLOG_VERBOSE(@"App is up-to-date at version %@", [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleVersion"]);
if (_manualCheck) {
let alert = [[NSAlert alloc] init];
alert.messageText = NSLocalizedString(@"GitUp is already up-to-date!", nil);
Expand All @@ -752,9 +716,8 @@ - (void)updaterDidNotFindUpdate:(SUUpdater*)updater {
}

- (void)updater:(SUUpdater*)updater didAbortWithError:(NSError*)error {
NSString* channel = [[NSUserDefaults standardUserDefaults] stringForKey:kUserDefaultsKey_ReleaseChannel];
if (![error.domain isEqualToString:SUSparkleErrorDomain] || (error.code != SUNoUpdateError)) {
XLOG_ERROR(@"App update on channel “%@aborted: %@", channel, error);
XLOG_ERROR(@"App update aborted: %@", error);
}
}

Expand Down
6 changes: 1 addition & 5 deletions GitUp/Application/Common.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,9 @@

#define MAKE_ERROR(message) [NSError errorWithDomain:@"App" code:-1 userInfo:@{NSLocalizedDescriptionKey : message}]

#define kReleaseChannel_Stable @"stable"
#define kReleaseChannel_Continuous @"continuous"

#define kUserDefaultsKey_FirstLaunch @"FirstLaunch" // BOOL
#define kUserDefaultsKey_SkipInstallCLT @"SkipInstallCLT" // BOOL
#define kUserDefaultsKey_LastVersion @"LastVersion" // NSUInteger
#define kUserDefaultsKey_ReleaseChannel @"ReleaseChannel" // NSString
#define kUserDefaultsKey_CheckInterval @"CheckInterval" // NSInteger
#define kUserDefaultsKey_SimpleCommit @"SimpleCommit" // BOOL
#define kUserDefaultsKey_DisableSparkle @"DisableSparkle" // BOOL
Expand All @@ -32,7 +28,7 @@
#define kRepositoryUserInfoKey_MainWindowFrame @"MainWindowFrame" // NSString
#define kRepositoryUserInfoKey_IndexDiffs @"IndexDiffs" // BOOL

#define kURL_AppCast @"https://s3-us-west-2.amazonaws.com/gitup-builds/%@/appcast.xml"
#define kURL_AppCast @"https://douglashill.s3.amazonaws.com/GitUp-appcast.xml"

#define kURL_Issues @"https://github.com/douglashill/GitUp/issues"
#define kURL_Wiki @"https://github.com/git-up/GitUp/wiki"
Expand Down
39 changes: 1 addition & 38 deletions GitUp/Application/en.lproj/MainMenu.xib
Original file line number Diff line number Diff line change
Expand Up @@ -275,38 +275,11 @@ You must close and reopen any opened repositories in GitUp after changing this s
</subviews>
</view>
</tabViewItem>
<tabViewItem label="{500, 262}" identifier="advanced" id="Qdl-lQ-O4q">
<tabViewItem label="{500, 182}" identifier="advanced" id="Qdl-lQ-O4q">
<view key="view" id="8CG-H0-Xhk">
<rect key="frame" x="0.0" y="0.0" width="500" height="400"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<popUpButton verticalHuggingPriority="750" id="7N4-S9-iWL">
<rect key="frame" x="136" y="192" width="200" height="26"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<popUpButtonCell key="cell" type="push" title="&lt;RELEASE CHANNEL&gt;" bezelStyle="rounded" alignment="left" lineBreakMode="truncatingTail" state="on" borderStyle="borderAndBezel" imageScaling="proportionallyDown" inset="2" autoenablesItems="NO" selectedItem="xdx-IX-FK6" id="Sdr-Ep-kPW">
<behavior key="behavior" lightByBackground="YES" lightByGray="YES"/>
<font key="font" metaFont="menu"/>
<menu key="menu" autoenablesItems="NO" id="0Z3-9j-kDN">
<items>
<menuItem title="&lt;RELEASE CHANNEL&gt;" state="on" id="xdx-IX-FK6">
<modifierMask key="keyEquivalentModifierMask"/>
</menuItem>
</items>
</menu>
</popUpButtonCell>
<connections>
<action selector="changeReleaseChannel:" target="Voe-Tx-rLC" id="qGn-WN-qQh"/>
</connections>
</popUpButton>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" id="mi3-Eg-51i">
<rect key="frame" x="12" y="198" width="120" height="17"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" allowsUndo="NO" sendsActionOnEndEditing="YES" alignment="right" title="Release Channel:" id="M0A-b6-dhN">
<font key="font" metaFont="system"/>
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" id="b9G-MU-MDn">
<rect key="frame" x="12" y="295" width="120" height="17"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
Expand All @@ -316,15 +289,6 @@ You must close and reopen any opened repositories in GitUp after changing this s
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
<textField verticalHuggingPriority="750" horizontalCompressionResistancePriority="250" id="PtA-hG-Qmn">
<rect key="frame" x="137" y="154" width="345" height="34"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<textFieldCell key="cell" controlSize="small" sendsActionOnEndEditing="YES" alignment="left" title="The &quot;Continuous&quot; release channel installs builds directly from GitUp Continuous Integration. Use at your own risk!" id="qB2-E4-Yuu">
<font key="font" metaFont="smallSystem"/>
<color key="textColor" name="secondaryLabelColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" id="w2N-io-xkS">
<rect key="frame" x="137" y="295" width="130" height="17"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
Expand Down Expand Up @@ -485,7 +449,6 @@ You must close and reopen any opened repositories in GitUp after changing this s
<outlet property="authenticationPasswordTextField" destination="Uio-D2-Dnt" id="nNT-Jn-Q9Y"/>
<outlet property="authenticationURLTextField" destination="fBP-U8-T31" id="JUd-Sw-FSA"/>
<outlet property="authenticationWindow" destination="mcM-YD-UN9" id="ZkH-zK-43f"/>
<outlet property="channelPopUpButton" destination="7N4-S9-iWL" id="Ols-8n-NyQ"/>
<outlet property="cloneRecursiveButton" destination="V3d-LG-L26" id="iSp-hX-Jc0"/>
<outlet property="cloneURLTextField" destination="KgY-GJ-dY0" id="qXq-61-cKm"/>
<outlet property="cloneWindow" destination="6SP-eN-0Kv" id="Bd8-7b-vpr"/>
Expand Down
49 changes: 49 additions & 0 deletions dh-build-and-upload.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#!/bin/sh -ex

PRODUCT_NAME="GitUp"
APPCAST_NAME="GitUp-appcast.xml"

MAX_VERSION=`git tag -l "dh*" | sed 's/dh//g' | sort -nr | head -n 1`
VERSION=$((MAX_VERSION + 1))

##### Archive and export app

rm -rf "build"
pushd "GitUp"
xcodebuild archive -scheme "Application" -archivePath "../build/$PRODUCT_NAME.xcarchive" "BUNDLE_VERSION=$VERSION"
xcodebuild -exportArchive -exportOptionsPlist "Export-Options.plist" -archivePath "../build/$PRODUCT_NAME.xcarchive" -exportPath "../build/$PRODUCT_NAME"
popd

##### Upload to S3 and update Appcast

FULL_PRODUCT_NAME="$PRODUCT_NAME.app"
PRODUCT_PATH="`pwd`/build/$PRODUCT_NAME/$FULL_PRODUCT_NAME" # Must be absolute path
INFO_PLIST_PATH="$PRODUCT_PATH/Contents/Info.plist"
VERSION_ID=`defaults read "$INFO_PLIST_PATH" "CFBundleVersion"`
VERSION_STRING=`defaults read "$INFO_PLIST_PATH" "CFBundleShortVersionString"`
MIN_OS=`defaults read "$INFO_PLIST_PATH" "LSMinimumSystemVersion"`

ARCHIVE_NAME="$PRODUCT_NAME.zip"
BACKUP_ARCHIVE_NAME="$PRODUCT_NAME-$VERSION_ID.zip"
APPCAST_URL="https://douglashill.s3.amazonaws.com/$APPCAST_NAME"
ARCHIVE_URL="https://douglashill.s3.amazonaws.com/$ARCHIVE_NAME"
BACKUP_ARCHIVE_URL="https://douglashill.s3.amazonaws.com/$BACKUP_ARCHIVE_NAME"

ARCHIVE_PATH="build/$ARCHIVE_NAME"
APPCAST_PATH="GitUp/SparkleAppcast.xml"

ditto -c -k --keepParent "$PRODUCT_PATH" "$ARCHIVE_PATH"

ARCHIVE_SIZE=`stat -f "%z" "$ARCHIVE_PATH"`

EDITED_APPCAST_PATH="build/appcast.xml"
perl -p -e "s|__APPCAST_TITLE__|$PRODUCT_NAME|g;s|__APPCAST_URL__|$APPCAST_URL|g;s|__VERSION_ID__|$VERSION_ID|g;s|__VERSION_STRING__|$VERSION_STRING|g;s|__ARCHIVE_URL__|$ARCHIVE_URL|g;s|__ARCHIVE_SIZE__|$ARCHIVE_SIZE|g;s|__MIN_OS__|$MIN_OS|g" "$APPCAST_PATH" > "$EDITED_APPCAST_PATH"

aws s3 cp "$ARCHIVE_PATH" "s3://douglashill/$BACKUP_ARCHIVE_NAME" --acl public-read
aws s3 cp "s3://douglashill/$BACKUP_ARCHIVE_NAME" "s3://douglashill/$ARCHIVE_NAME" --acl public-read
aws s3 cp "$EDITED_APPCAST_PATH" "s3://douglashill/$APPCAST_NAME" --acl public-read

##### Tag build

git tag -f "dh$VERSION"
git push -f origin "dh$VERSION"
4 changes: 0 additions & 4 deletions dh-build.sh → dh-build-only.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,3 @@ pushd "GitUp"
xcodebuild archive -scheme "Application" -archivePath "../build/$PRODUCT_NAME.xcarchive" "BUNDLE_VERSION=$VERSION"
xcodebuild -exportArchive -exportOptionsPlist "Export-Options.plist" -archivePath "../build/$PRODUCT_NAME.xcarchive" -exportPath "../build/$PRODUCT_NAME"
popd

##### Tag build

git tag -f "dh$VERSION"

0 comments on commit 14e87ad

Please sign in to comment.