mirror of
https://github.com/nicoverbruggen/phpmon.git
synced 2025-08-07 12:00:09 +02:00
🏗 WIP: Check for updates
This commit is contained in:
@ -56,13 +56,23 @@ struct Constants {
|
||||
static let DonationPayment = URL(
|
||||
string: "https://nicoverbruggen.be/sponsor#pay-now"
|
||||
)!
|
||||
|
||||
static let DonationPage = URL(
|
||||
string: "https://nicoverbruggen.be/sponsor"
|
||||
)!
|
||||
|
||||
static let FrequentlyAskedQuestions = URL(
|
||||
string: "https://github.com/nicoverbruggen/phpmon#%EF%B8%8F-faq--troubleshooting"
|
||||
)!
|
||||
|
||||
static let StableBuildCaskFile = URL(
|
||||
string: "https://raw.githubusercontent.com/nicoverbruggen/homebrew-cask/master/Casks/phpmon.rb"
|
||||
)!
|
||||
|
||||
static let DevBuildCaskFile = URL(
|
||||
string: "https://raw.githubusercontent.com/nicoverbruggen/homebrew-cask/master/Casks/phpmon-dev.rb"
|
||||
)!
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -21,6 +21,12 @@ class App {
|
||||
return "\(version) (\(build))"
|
||||
}
|
||||
|
||||
/** Retrieve the version number from the main info dictionary, Info.plist, but without the build number. */
|
||||
static var shortVersion: String {
|
||||
let version = Bundle.main.infoDictionary?["CFBundleShortVersionString"] as! String
|
||||
return "\(version)"
|
||||
}
|
||||
|
||||
static var architecture: String {
|
||||
var systeminfo = utsname()
|
||||
uname(&systeminfo)
|
||||
|
@ -337,6 +337,37 @@ class MainMenu: NSObject, NSWindowDelegate, NSMenuDelegate, PhpSwitcherDelegate
|
||||
NSApplication.shared.terminate(nil)
|
||||
}
|
||||
|
||||
@objc func checkForUpdates() {
|
||||
DispatchQueue.global(qos: .userInitiated).async {
|
||||
let caskFile = App.version.contains("-dev")
|
||||
? Constants.Urls.DevBuildCaskFile.absoluteString
|
||||
: Constants.Urls.StableBuildCaskFile.absoluteString
|
||||
|
||||
let versionString = Shell.pipe(
|
||||
"curl -s '\(caskFile)' | grep version"
|
||||
)
|
||||
|
||||
guard let onlineVersion = VersionExtractor.from(versionString) else {
|
||||
Log.err("We couldn't check for updates!")
|
||||
return
|
||||
}
|
||||
|
||||
guard let current = VersionExtractor.from(App.shortVersion) else {
|
||||
Log.err("We couldn't parse the current version number!")
|
||||
return
|
||||
}
|
||||
|
||||
switch onlineVersion.versionCompare(current) {
|
||||
case .orderedAscending:
|
||||
Log.info("You are running a newer version of PHP Monitor.")
|
||||
case .orderedDescending:
|
||||
Log.info("There is a newer version (\(onlineVersion)) available!")
|
||||
case .orderedSame:
|
||||
Log.info("The installed version matches the latest release (\(current)).")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Menu Delegate
|
||||
|
||||
func menuWillOpen(_ menu: NSMenu) {
|
||||
|
@ -74,15 +74,16 @@ class StatusMenu: NSMenu {
|
||||
}
|
||||
|
||||
func addCoreMenuItems() {
|
||||
self.addItem(
|
||||
NSMenuItem(title: "mi_preferences".localized, action: #selector(MainMenu.openPrefs), keyEquivalent: ",")
|
||||
)
|
||||
self.addItem(
|
||||
NSMenuItem(title: "mi_about".localized, action: #selector(MainMenu.openAbout), keyEquivalent: "")
|
||||
)
|
||||
self.addItem(
|
||||
NSMenuItem(title: "mi_quit".localized, action: #selector(MainMenu.terminateApp), keyEquivalent: "q")
|
||||
)
|
||||
self.addItem(NSMenuItem.separator())
|
||||
self.addItem(NSMenuItem(title: "mi_preferences".localized,
|
||||
action: #selector(MainMenu.openPrefs), keyEquivalent: ","))
|
||||
self.addItem(NSMenuItem(title: "mi_check_for_updates".localized,
|
||||
action: #selector(MainMenu.checkForUpdates), keyEquivalent: ""))
|
||||
self.addItem(NSMenuItem.separator())
|
||||
self.addItem(NSMenuItem(title: "mi_about".localized,
|
||||
action: #selector(MainMenu.openAbout), keyEquivalent: ""))
|
||||
self.addItem(NSMenuItem(title: "mi_quit".localized,
|
||||
action: #selector(MainMenu.terminateApp), keyEquivalent: "q"))
|
||||
}
|
||||
|
||||
// MARK: Remaining Menu Items
|
||||
|
@ -10,6 +10,22 @@
|
||||
<string>https://github.com/nicoverbruggen/phpmon</string>
|
||||
<key>Connections</key>
|
||||
<array>
|
||||
<dict>
|
||||
<key>IsIncoming</key>
|
||||
<false/>
|
||||
<key>Host</key>
|
||||
<string>raw.githubusercontent.com</string>
|
||||
<key>NetworkProtocol</key>
|
||||
<string>TCP</string>
|
||||
<key>Port</key>
|
||||
<string>80, 443</string>
|
||||
<key>Relevance</key>
|
||||
<string>Essential</string>
|
||||
<key>Purpose</key>
|
||||
<string>PHP Monitor connects to GitHub to check the Cask file to determine what the latest release of PHP Monitor is.</string>
|
||||
<key>DenyConsequences</key>
|
||||
<string>If you deny this connection, PHP Monitor will not be able to search for updates. If you don't want this check to happen, you can disable automatic updates in the Preferences menu instead.</string>
|
||||
</dict>
|
||||
<dict>
|
||||
<key>IsIncoming</key>
|
||||
<false/>
|
||||
|
@ -59,6 +59,7 @@
|
||||
|
||||
"mi_preferences" = "Preferences...";
|
||||
"mi_donate" = "Donate...";
|
||||
"mi_check_for_updates" = "Check for Updates...";
|
||||
"mi_quit" = "Quit PHP Monitor";
|
||||
"mi_about" = "About PHP Monitor";
|
||||
|
||||
|
Reference in New Issue
Block a user