Skip to content

Commit

Permalink
#26 added UI to manually trigger update
Browse files Browse the repository at this point in the history
  • Loading branch information
Ehlen, David committed Mar 7, 2019
1 parent 3c2ea90 commit b570664
Show file tree
Hide file tree
Showing 8 changed files with 87 additions and 12 deletions.
4 changes: 4 additions & 0 deletions Capture.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
0B3D7A70223109DD000F8C85 /* Path+Codable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0B3D7A67223109DD000F8C85 /* Path+Codable.swift */; };
0B3D7A71223109DD000F8C85 /* Path+StringConvertibles.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0B3D7A68223109DD000F8C85 /* Path+StringConvertibles.swift */; };
0B3D7A7422310A52000F8C85 /* PMKFoundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 0B3D7A7322310A52000F8C85 /* PMKFoundation.framework */; };
0B3D7A7622311676000F8C85 /* Alerts.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0B3D7A7522311676000F8C85 /* Alerts.swift */; };
0B4309A7221916C500766DB0 /* VideoPlayerViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0B4309A6221916C500766DB0 /* VideoPlayerViewController.swift */; };
0B4309A9221926C500766DB0 /* BundleExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0B4309A8221926C500766DB0 /* BundleExtension.swift */; };
0B4309AF22198FAA00766DB0 /* Preferences.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 0B4309AC22198FAA00766DB0 /* Preferences.storyboard */; };
Expand Down Expand Up @@ -109,6 +110,7 @@
0B3D7A67223109DD000F8C85 /* Path+Codable.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Path+Codable.swift"; sourceTree = "<group>"; };
0B3D7A68223109DD000F8C85 /* Path+StringConvertibles.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Path+StringConvertibles.swift"; sourceTree = "<group>"; };
0B3D7A7322310A52000F8C85 /* PMKFoundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = PMKFoundation.framework; path = Carthage/Build/Mac/PMKFoundation.framework; sourceTree = "<group>"; };
0B3D7A7522311676000F8C85 /* Alerts.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Alerts.swift; sourceTree = "<group>"; };
0B4309A6221916C500766DB0 /* VideoPlayerViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VideoPlayerViewController.swift; sourceTree = "<group>"; };
0B4309A8221926C500766DB0 /* BundleExtension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BundleExtension.swift; sourceTree = "<group>"; };
0B4309AC22198FAA00766DB0 /* Preferences.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; path = Preferences.storyboard; sourceTree = "<group>"; };
Expand Down Expand Up @@ -306,6 +308,7 @@
0BC83209221A085200FD8CF4 /* Utilities */ = {
isa = PBXGroup;
children = (
0B3D7A7522311676000F8C85 /* Alerts.swift */,
0B4309A8221926C500766DB0 /* BundleExtension.swift */,
0B64CD922218DA3F004F6321 /* DirectoryHandler.swift */,
0B64CD9B2218DE1B004F6321 /* Result.swift */,
Expand Down Expand Up @@ -551,6 +554,7 @@
0BE418BC221AF3B200B8E85D /* ContainerViewController.swift in Sources */,
0B581A2A222199EA006EF012 /* HotKeyService.swift in Sources */,
0B64CD972218DD5A004F6321 /* ConvertGif.swift in Sources */,
0B3D7A7622311676000F8C85 /* Alerts.swift in Sources */,
0B3276CA2219D9410028F007 /* UserDefaultsExtension.swift in Sources */,
0B3276D02219E6810028F007 /* GeneralPreferencesViewController.swift in Sources */,
0B3D7A5E223109CC000F8C85 /* Version+Comparable.swift in Sources */,
Expand Down
5 changes: 5 additions & 0 deletions Capture/AppUpdater/AppUpdater.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ import PMKFoundation
import Foundation
import PromiseKit

enum AppUpdaterError: Error {
case alreadyUpToDate
case failure(String)
}

public class AppUpdater {
var active = Promise()
#if !DEBUG
Expand Down
4 changes: 2 additions & 2 deletions Capture/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<string>0.9.1</string>
<key>CFBundleVersion</key>
<string>1</string>
<string>0.9.1</string>
<key>LSMinimumSystemVersion</key>
<string>$(MACOSX_DEPLOYMENT_TARGET)</string>
<key>NSHumanReadableCopyright</key>
Expand Down
10 changes: 10 additions & 0 deletions Capture/Preferences/View/GeneralPreferencesViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,16 @@ class GeneralPreferencesViewController: PreferencesViewController {
prepareHotKeys()
}

@IBAction func userRequestedAnExplicitUpdateCheck(_ sender: Any) {
let delegate = NSApplication.shared.delegate as? AppDelegate
delegate?.updater.check().catch(policy: .allErrors) { error in
if error.isCancelled {
showAlert(title: "alreadyUpToDateTitle".localized, message: ErrorMessageProvider.string(for: AppUpdaterError.alreadyUpToDate))
} else {
self.presentError(NSError.create(from: AppUpdaterError.failure(error.localizedDescription)))
}
}
}
}

// MARK: - Shortcut
Expand Down
52 changes: 43 additions & 9 deletions Capture/Preferences/View/Preferences.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@
<objects>
<viewController title="General" id="CbG-uA-UXG" customClass="GeneralPreferencesViewController" customModule="Capture" customModuleProvider="target" sceneMemberID="viewController">
<view key="view" id="4Ei-kU-JuY">
<rect key="frame" x="0.0" y="0.0" width="450" height="170"/>
<rect key="frame" x="0.0" y="0.0" width="450" height="256"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<pathControl focusRingType="none" verticalHuggingPriority="750" verticalCompressionResistancePriority="1000" allowsExpansionToolTips="YES" translatesAutoresizingMaskIntoConstraints="NO" id="xix-mN-5C6" customClass="PopUpButtonLikePathControl" customModule="Capture" customModuleProvider="target">
<rect key="frame" x="118" y="129" width="136" height="25"/>
<rect key="frame" x="118" y="215" width="136" height="25"/>
<pathCell key="cell" selectable="YES" editable="YES" focusRingType="none" alignment="left" pathStyle="popUp" id="fAZ-H5-ScI">
<font key="font" metaFont="system"/>
<url key="url" string="file:///Applications/"/>
Expand All @@ -77,60 +77,94 @@
</connections>
</pathControl>
<textField verticalHuggingPriority="750" horizontalCompressionResistancePriority="250" translatesAutoresizingMaskIntoConstraints="NO" id="btq-nd-DrW">
<rect key="frame" x="18" y="95" width="414" height="28"/>
<rect key="frame" x="18" y="181" width="414" height="28"/>
<textFieldCell key="cell" selectable="YES" title="Choose the directory the generated GIFs should be exported to. By default the GIF will be moved to your desktop." id="ePr-4A-nsB">
<font key="font" metaFont="smallSystem"/>
<color key="textColor" name="secondaryLabelColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="IDG-1b-v6d">
<rect key="frame" x="18" y="133" width="95" height="17"/>
<rect key="frame" x="18" y="219" width="95" height="17"/>
<textFieldCell key="cell" lineBreakMode="clipping" title="Export GIFs to:" id="312-bw-BIU">
<font key="font" metaFont="system"/>
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
<textField verticalHuggingPriority="750" horizontalCompressionResistancePriority="250" translatesAutoresizingMaskIntoConstraints="NO" id="Maz-20-LlC">
<rect key="frame" x="18" y="20" width="414" height="28"/>
<rect key="frame" x="18" y="97" width="414" height="28"/>
<textFieldCell key="cell" selectable="YES" title="Set a shortcut to quickly stop a recording. This shortcut will work globally as long as the application is running." id="EDg-3c-i1r">
<font key="font" metaFont="smallSystem"/>
<color key="textColor" name="secondaryLabelColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="UDU-Gc-nF1">
<rect key="frame" x="18" y="67" width="158" height="17"/>
<rect key="frame" x="18" y="144" width="158" height="17"/>
<textFieldCell key="cell" lineBreakMode="clipping" title="Stop Recording Shortcut:" id="oyp-PE-GmB">
<font key="font" metaFont="system"/>
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
<customView translatesAutoresizingMaskIntoConstraints="NO" id="K7Z-TW-8U8" customClass="RecordView" customModule="KeyHolder">
<rect key="frame" x="184" y="58" width="160" height="34"/>
<rect key="frame" x="184" y="135" width="160" height="34"/>
<constraints>
<constraint firstAttribute="width" constant="160" id="X15-zY-tJi"/>
<constraint firstAttribute="height" constant="34" id="jTh-0g-gT0"/>
</constraints>
</customView>
<button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="OBT-6X-HhQ">
<rect key="frame" x="195" y="51" width="154" height="32"/>
<buttonCell key="cell" type="push" title="Check for Updates" bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="4Nt-r1-RZz">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
<font key="font" metaFont="system"/>
</buttonCell>
<connections>
<action selector="userRequestedAnExplicitUpdateCheck:" target="CbG-uA-UXG" id="w3r-tC-xVF"/>
</connections>
</button>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="BYr-zV-DCp">
<rect key="frame" x="18" y="60" width="175" height="17"/>
<textFieldCell key="cell" lineBreakMode="clipping" title="Manually check for updates:" id="c2j-pE-j9t">
<font key="font" metaFont="system"/>
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
<textField verticalHuggingPriority="750" horizontalCompressionResistancePriority="250" translatesAutoresizingMaskIntoConstraints="NO" id="Y8G-g4-hdo">
<rect key="frame" x="18" y="20" width="414" height="28"/>
<textFieldCell key="cell" selectable="YES" title="The app will automatically try to update itself. However you can also try to trigger this update process manually." id="sPv-Hs-nk8">
<font key="font" metaFont="smallSystem"/>
<color key="textColor" name="secondaryLabelColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
</subviews>
<constraints>
<constraint firstAttribute="trailing" secondItem="btq-nd-DrW" secondAttribute="trailing" constant="20" id="078-OX-KBz"/>
<constraint firstItem="xix-mN-5C6" firstAttribute="leading" secondItem="IDG-1b-v6d" secondAttribute="trailing" constant="10" id="3UI-KT-DWK"/>
<constraint firstAttribute="trailing" secondItem="Maz-20-LlC" secondAttribute="trailing" constant="20" id="41h-OP-eMs"/>
<constraint firstAttribute="bottom" secondItem="Maz-20-LlC" secondAttribute="bottom" constant="20" id="7Vz-kA-FHc"/>
<constraint firstItem="K7Z-TW-8U8" firstAttribute="centerY" secondItem="UDU-Gc-nF1" secondAttribute="centerY" id="7fS-hS-Mf1"/>
<constraint firstItem="btq-nd-DrW" firstAttribute="leading" secondItem="IDG-1b-v6d" secondAttribute="leading" id="8Cv-GA-lj2"/>
<constraint firstItem="Y8G-g4-hdo" firstAttribute="leading" secondItem="4Ei-kU-JuY" secondAttribute="leading" constant="20" id="AgO-fd-4zk"/>
<constraint firstItem="BYr-zV-DCp" firstAttribute="top" secondItem="Maz-20-LlC" secondAttribute="bottom" constant="20" id="Bro-qe-PVH"/>
<constraint firstItem="Maz-20-LlC" firstAttribute="top" secondItem="K7Z-TW-8U8" secondAttribute="bottom" constant="10" id="DlR-2F-fjH"/>
<constraint firstItem="IDG-1b-v6d" firstAttribute="top" secondItem="4Ei-kU-JuY" secondAttribute="top" constant="20" id="Exg-sT-rCA"/>
<constraint firstItem="Y8G-g4-hdo" firstAttribute="top" secondItem="OBT-6X-HhQ" secondAttribute="bottom" constant="10" id="FL5-cX-QmI"/>
<constraint firstItem="OBT-6X-HhQ" firstAttribute="leading" secondItem="BYr-zV-DCp" secondAttribute="trailing" constant="10" id="OFT-n9-A8z"/>
<constraint firstItem="UDU-Gc-nF1" firstAttribute="leading" secondItem="IDG-1b-v6d" secondAttribute="leading" id="T6l-jB-xL5"/>
<constraint firstItem="xix-mN-5C6" firstAttribute="bottom" secondItem="IDG-1b-v6d" secondAttribute="bottom" id="TWm-Uv-LMv"/>
<constraint firstItem="OBT-6X-HhQ" firstAttribute="centerY" secondItem="BYr-zV-DCp" secondAttribute="centerY" id="UbV-3T-GOk"/>
<constraint firstItem="IDG-1b-v6d" firstAttribute="leading" secondItem="4Ei-kU-JuY" secondAttribute="leading" constant="20" id="YCS-ir-ksJ"/>
<constraint firstAttribute="trailing" secondItem="Y8G-g4-hdo" secondAttribute="trailing" constant="20" id="jKO-p2-7DV"/>
<constraint firstItem="BYr-zV-DCp" firstAttribute="leading" secondItem="IDG-1b-v6d" secondAttribute="leading" id="rOS-oM-6yR"/>
<constraint firstItem="Maz-20-LlC" firstAttribute="leading" secondItem="UDU-Gc-nF1" secondAttribute="leading" id="tgb-RF-1FF"/>
<constraint firstItem="btq-nd-DrW" firstAttribute="top" secondItem="IDG-1b-v6d" secondAttribute="bottom" constant="10" id="tkw-xm-Os6"/>
<constraint firstItem="K7Z-TW-8U8" firstAttribute="leading" secondItem="UDU-Gc-nF1" secondAttribute="trailing" constant="10" id="x8u-V1-rN7"/>
<constraint firstAttribute="bottom" secondItem="Y8G-g4-hdo" secondAttribute="bottom" constant="20" id="xJy-9L-5Fe"/>
<constraint firstItem="UDU-Gc-nF1" firstAttribute="top" secondItem="btq-nd-DrW" secondAttribute="bottom" constant="20" id="xX8-61-jeU"/>
</constraints>
</view>
<connections>
Expand All @@ -140,7 +174,7 @@
<customObject id="FvE-cN-eWk" userLabel="First Responder" customClass="NSResponder" sceneMemberID="firstResponder"/>
<userDefaultsController representsSharedInstance="YES" id="TAK-31-KNl"/>
</objects>
<point key="canvasLocation" x="550" y="243.5"/>
<point key="canvasLocation" x="550" y="328.5"/>
</scene>
</scenes>
<resources>
Expand Down
9 changes: 9 additions & 0 deletions Capture/Utilities/Alerts.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import AppKit

func showAlert(title: String, message: String) {
let alert = NSAlert.init()
alert.messageText = title
alert.informativeText = message
alert.addButton(withTitle: "OK")
alert.runModal()
}
11 changes: 11 additions & 0 deletions Capture/Utilities/Error/ErrorMessageProvider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ struct ErrorMessageProvider {
return string(for: error)
} else if let error = error as? VideoPlayerError {
return string(for: error)
} else if let error = error as? AppUpdaterError {
return string(for: error)
}
return error.localizedDescription
}
Expand Down Expand Up @@ -36,4 +38,13 @@ struct ErrorMessageProvider {
return "exportFailed".localized
}
}

private static func string(for error: AppUpdaterError) -> String {
switch error {
case .alreadyUpToDate:
return "alreadyUpToDate".localized
case .failure(let message):
return String(format: "updateFailed".localized, message)
}
}
}
4 changes: 3 additions & 1 deletion Capture/en.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,6 @@
"noCurrentItem" = "The video player does not know which video file to export. Therefore the operation failed.";
"missingFile" = "The video file could not be found and therefore the export failed. Please try again with a different recording.";
"exportFailed" = "The GIF export failed. Please try again with a different recording.";

"alreadyUpToDate" = "Capture is already up to date. Thank you for using Capture ❤️";
"updateFailed" = "Checking for an update failed: %@";
"alreadyUpToDateTitle" = "Already up to date!";

0 comments on commit b570664

Please sign in to comment.