diff options
| -rw-r--r-- | DWA140Menu/Base.lproj/Main.storyboard | 12 | ||||
| -rw-r--r-- | DWA140Menu/DWA140Menu.entitlements | 2 | ||||
| -rw-r--r-- | DWA140Menu/Info.plist | 2 | ||||
| -rw-r--r-- | DWA140Menu/ViewController.swift | 31 |
4 files changed, 45 insertions, 2 deletions
diff --git a/DWA140Menu/Base.lproj/Main.storyboard b/DWA140Menu/Base.lproj/Main.storyboard index c98ce56..f945d9a 100644 --- a/DWA140Menu/Base.lproj/Main.storyboard +++ b/DWA140Menu/Base.lproj/Main.storyboard @@ -834,6 +834,17 @@ <action selector="sourceButtonPressed:" target="9wW-Ed-Ez8" id="m07-Ts-gmm"/> </connections> </button> + <button verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="bx2-GW-e8o"> + <rect key="frame" x="233" y="91" width="169" height="21"/> + <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/> + <buttonCell key="cell" type="squareTextured" title="Up to date" bezelStyle="texturedSquare" alignment="right" imageScaling="proportionallyDown" inset="2" id="j7a-Sp-hFl"> + <behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/> + <font key="font" metaFont="systemLight" size="17"/> + </buttonCell> + <connections> + <action selector="updatePressed:" target="9wW-Ed-Ez8" id="qRC-zS-7UM"/> + </connections> + </button> </subviews> <constraints> <constraint firstItem="a54-Wx-Jxc" firstAttribute="leading" secondItem="Eft-IA-k07" secondAttribute="leading" constant="126" id="5TX-7M-4y3"/> @@ -870,6 +881,7 @@ <outlet property="awesomeSubtitle" destination="zkt-Ir-J68" id="STq-QI-Ka4"/> <outlet property="loginButton" destination="lJe-dq-rJi" id="RTZ-Zk-gMz"/> <outlet property="loginSubtitle" destination="C1E-Lz-oIr" id="QAS-Ig-kEB"/> + <outlet property="versionCheckLabel" destination="bx2-GW-e8o" id="XUm-Jo-ZV5"/> <outlet property="versionLabel" destination="a54-Wx-Jxc" id="c7J-BT-Ita"/> </connections> </viewController> diff --git a/DWA140Menu/DWA140Menu.entitlements b/DWA140Menu/DWA140Menu.entitlements index 18aff0c..625af03 100644 --- a/DWA140Menu/DWA140Menu.entitlements +++ b/DWA140Menu/DWA140Menu.entitlements @@ -6,5 +6,7 @@ <true/> <key>com.apple.security.files.user-selected.read-only</key> <true/> + <key>com.apple.security.network.client</key> + <true/> </dict> </plist> diff --git a/DWA140Menu/Info.plist b/DWA140Menu/Info.plist index d682a29..055ee5d 100644 --- a/DWA140Menu/Info.plist +++ b/DWA140Menu/Info.plist @@ -17,7 +17,7 @@ <key>CFBundlePackageType</key> <string>APPL</string> <key>CFBundleShortVersionString</key> - <string>1.0.2</string> + <string>1.1</string> <key>CFBundleVersion</key> <string>1</string> <key>LSApplicationCategoryType</key> diff --git a/DWA140Menu/ViewController.swift b/DWA140Menu/ViewController.swift index 16968a0..416fb1c 100644 --- a/DWA140Menu/ViewController.swift +++ b/DWA140Menu/ViewController.swift @@ -14,14 +14,23 @@ class ViewController: NSViewController { @IBOutlet weak var loginButton: NSButton! @IBOutlet weak var awesomeSubtitle: NSTextField! @IBOutlet weak var loginSubtitle: NSTextField! + @IBOutlet weak var versionCheckLabel: NSButton! let defaults : UserDefaults = .standard let delegate = NSApplication.shared.delegate as! AppDelegate var loginLaunch = UserDefaults.standard.bool(forKey: "loginLaunch") + let appVersion = (Bundle.main.infoDictionary!["CFBundleShortVersionString"] as? String)! + let style = NSMutableParagraphStyle() + override func viewDidAppear() { + style.alignment = .right + if checkForUpdate() == "Update available" { + versionCheckLabel.stringValue = checkForUpdate() + versionCheckLabel.attributedTitle = NSAttributedString(string: "Update available", attributes: [ NSAttributedString.Key.foregroundColor : #colorLiteral(red: 0, green: 0.4784313725, blue: 1, alpha: 1), NSAttributedString.Key.paragraphStyle : style ]) + } loginButton.state = loginLaunch ? .on : .off - versionLabel.stringValue = "Version " + (Bundle.main.infoDictionary!["CFBundleShortVersionString"] as? String)! + versionLabel.stringValue = "Version " + appVersion if loginLaunch { loginSubtitle.stringValue = "This application will launch when you login." } @@ -38,6 +47,26 @@ class ViewController: NSViewController { } } + func checkForUpdate() -> String { + var Update: String? = nil + if let url = URL(string: "https://raw.githubusercontent.com/FivePixels/dwa140shortcut/master/version.txt") { + Update = try? String(contentsOf: url, encoding: String.Encoding(rawValue: String.Encoding.utf8.rawValue)) + } + let result = Update?.dropLast(1) + if Update == nil { + return "?" + } else if result!.compare(appVersion, options: .numeric, range: nil, locale: .current) == .orderedDescending { + return "Update available" + } else { + return "Up to date" + } + } + + @IBAction func updatePressed(_ sender: NSButton) { + if checkForUpdate() == "Update available" { + NSWorkspace.shared.open(URL(string: "https://github.com/fivepixels/dwa140shortcut/releases")!) + } + } @IBAction func loginButtonPressed(_ sender: NSButton) { toggleLoginLaunch() if loginLaunch { |
