Skip to content

Commit

Permalink
- fix updater.sh for macOS Mojave (10.14)
Browse files Browse the repository at this point in the history
- fix notification that new version installed (not showing only if the new version is higher than previous one)

- small fix
  • Loading branch information
exelban committed Jul 9, 2020
1 parent 533770c commit 8296acb
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 39 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ prepare-dSYM:

clean:
rm -rf $(BUILD_PATH)
if [ -a $(PWD)/dSYM.zip ]; then rm $(PWD)/dSYM.zip; fi;
if [ -a $(PWD)/dSYMs.zip ]; then rm $(PWD)/dSYMs.zip; fi;
if [ -a $(PWD)/Stats.dmg ]; then rm $(PWD)/Stats.dmg; fi;

next-version:
Expand Down
4 changes: 2 additions & 2 deletions Stats.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1695,7 +1695,7 @@
"@executable_path/../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 10.14;
MARKETING_VERSION = 2.1.8;
MARKETING_VERSION = 2.1.9;
PRODUCT_BUNDLE_IDENTIFIER = eu.exelban.Stats;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
Expand Down Expand Up @@ -1727,7 +1727,7 @@
"@executable_path/../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 10.14;
MARKETING_VERSION = 2.1.8;
MARKETING_VERSION = 2.1.9;
PRODUCT_BUNDLE_IDENTIFIER = eu.exelban.Stats;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
Expand Down
18 changes: 10 additions & 8 deletions Stats/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -100,14 +100,16 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserNotificationCenterDele
return
}

let notification = NSUserNotification()
notification.identifier = UUID().uuidString
notification.title = "Successfully updated"
notification.subtitle = "Stats was updated to the latest version"
notification.soundName = NSUserNotificationDefaultSoundName
notification.hasActionButton = false

NSUserNotificationCenter.default.deliver(notification)
if IsNewestVersion(currentVersion: prevVersion, latestVersion: currentVersion) {
let notification = NSUserNotification()
notification.identifier = UUID().uuidString
notification.title = "Successfully updated"
notification.subtitle = "Stats was updated to the v\(currentVersion)"
notification.soundName = NSUserNotificationDefaultSoundName
notification.hasActionButton = false

NSUserNotificationCenter.default.deliver(notification)
}

os_log(.info, log: log, "Detected previous version %s. Current version (%s) set", prevVersion, currentVersion)
}
Expand Down
2 changes: 1 addition & 1 deletion Stats/Supporting Files/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<key>CFBundleShortVersionString</key>
<string>$(MARKETING_VERSION)</string>
<key>CFBundleVersion</key>
<string>11</string>
<string>14</string>
<key>Description</key>
<string>Simple macOS system monitor in your menu bar</string>
<key>LSApplicationCategoryType</key>
Expand Down
25 changes: 25 additions & 0 deletions StatsKit/extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -713,3 +713,28 @@ public func colorFromString(_ colorString: String) -> NSColor {
return NSColor.controlAccentColor
}
}

public func IsNewestVersion(currentVersion: String, latestVersion: String) -> Bool {
let currentNumber = currentVersion.replacingOccurrences(of: "v", with: "")
let latestNumber = latestVersion.replacingOccurrences(of: "v", with: "")

let currentArray = currentNumber.condenseWhitespace().split(separator: ".")
let latestArray = latestNumber.condenseWhitespace().split(separator: ".")

let current = Version(major: Int(currentArray[0]) ?? 0, minor: Int(currentArray[1]) ?? 0, patch: Int(currentArray[2]) ?? 0)
let latest = Version(major: Int(latestArray[0]) ?? 0, minor: Int(latestArray[1]) ?? 0, patch: Int(latestArray[2]) ?? 0)

if latest.major > current.major {
return true
}

if latest.minor > current.minor && latest.major >= current.major {
return true
}

if latest.patch > current.patch && latest.minor >= current.minor && latest.major >= current.major {
return true
}

return false
}
2 changes: 1 addition & 1 deletion StatsKit/updater.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ if [[ "$STEP" == "1" ]]; then
/usr/bin/hdiutil attach "$DMG_PATH" -mountpoint "$MOUNT_PATH" -noverify -nobrowse -noautoopen

cp $MOUNT_PATH/Stats.app/Contents/Resources/Scripts/updater.sh $TMPDIR/updater.sh
sh $TMPDIR/updater.sh --step 2 --app "$CURRENT_PATH" --dmg "$DMG_PATH" &
sh $TMPDIR/updater.sh --step 2 --app "$CURRENT_PATH" --dmg "$DMG_PATH" >/dev/null &

kill -9 $PID

Expand Down
27 changes: 1 addition & 26 deletions StatsKit/updater.swift
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public class macAppUpdater {

let downloadURL: String = result![1]
let lastVersion: String = result![0]
let newVersion: Bool = self.checkIfNewer(currentVersion: self.currentVersion, latestVersion: lastVersion)
let newVersion: Bool = IsNewestVersion(currentVersion: self.currentVersion, latestVersion: lastVersion)

completionHandler(version(current: self.currentVersion, latest: lastVersion, newest: newVersion, url: downloadURL), nil)
}
Expand Down Expand Up @@ -93,31 +93,6 @@ public class macAppUpdater {
task.resume()
}

private func checkIfNewer(currentVersion: String, latestVersion: String) -> Bool {
let currentNumber = currentVersion.replacingOccurrences(of: "v", with: "")
let latestNumber = latestVersion.replacingOccurrences(of: "v", with: "")

let currentArray = currentNumber.condenseWhitespace().split(separator: ".")
let latestArray = latestNumber.condenseWhitespace().split(separator: ".")

let current = Version(major: Int(currentArray[0]) ?? 0, minor: Int(currentArray[1]) ?? 0, patch: Int(currentArray[2]) ?? 0)
let latest = Version(major: Int(latestArray[0]) ?? 0, minor: Int(latestArray[1]) ?? 0, patch: Int(latestArray[2]) ?? 0)

if latest.major > current.major {
return true
}

if latest.minor > current.minor && latest.major >= current.major {
return true
}

if latest.patch > current.patch && latest.minor >= current.minor && latest.major >= current.major {
return true
}

return false
}

public func download(_ url: URL) {
let downloadTask = URLSession.shared.downloadTask(with: url) {
urlOrNil, responseOrNil, errorOrNil in
Expand Down

0 comments on commit 8296acb

Please sign in to comment.