mirror of
https://github.com/nicoverbruggen/phpmon.git
synced 2025-08-07 12:00:09 +02:00
✨ Check for updates
This commit is contained in:
@ -117,8 +117,8 @@
|
||||
C464ADAF275A7A69003FCD53 /* DomainListVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = C464ADAE275A7A69003FCD53 /* DomainListVC.swift */; };
|
||||
C464ADB0275A7A6A003FCD53 /* DomainListVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = C464ADAE275A7A69003FCD53 /* DomainListVC.swift */; };
|
||||
C464ADB2275A87CA003FCD53 /* DomainListCellProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = C464ADB1275A87CA003FCD53 /* DomainListCellProtocol.swift */; };
|
||||
C46E206D28299B3800D909D6 /* Updater.swift in Sources */ = {isa = PBXBuildFile; fileRef = C46E206C28299B3800D909D6 /* Updater.swift */; };
|
||||
C46E206E28299B3800D909D6 /* Updater.swift in Sources */ = {isa = PBXBuildFile; fileRef = C46E206C28299B3800D909D6 /* Updater.swift */; };
|
||||
C46E206D28299B3800D909D6 /* AppUpdateChecker.swift in Sources */ = {isa = PBXBuildFile; fileRef = C46E206C28299B3800D909D6 /* AppUpdateChecker.swift */; };
|
||||
C46E206E28299B3800D909D6 /* AppUpdateChecker.swift in Sources */ = {isa = PBXBuildFile; fileRef = C46E206C28299B3800D909D6 /* AppUpdateChecker.swift */; };
|
||||
C46FA23F246C358E00944F05 /* StringExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = C46FA23E246C358E00944F05 /* StringExtension.swift */; };
|
||||
C473319F2470923A009A0597 /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = C473319E2470923A009A0597 /* Localizable.strings */; };
|
||||
C47331A2247093B7009A0597 /* StatusMenu.swift in Sources */ = {isa = PBXBuildFile; fileRef = C47331A1247093B7009A0597 /* StatusMenu.swift */; };
|
||||
@ -339,7 +339,7 @@
|
||||
C464ADAB275A7A3F003FCD53 /* DomainListWC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DomainListWC.swift; sourceTree = "<group>"; };
|
||||
C464ADAE275A7A69003FCD53 /* DomainListVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DomainListVC.swift; sourceTree = "<group>"; };
|
||||
C464ADB1275A87CA003FCD53 /* DomainListCellProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DomainListCellProtocol.swift; sourceTree = "<group>"; };
|
||||
C46E206C28299B3800D909D6 /* Updater.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Updater.swift; sourceTree = "<group>"; };
|
||||
C46E206C28299B3800D909D6 /* AppUpdateChecker.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppUpdateChecker.swift; sourceTree = "<group>"; };
|
||||
C46FA23E246C358E00944F05 /* StringExtension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StringExtension.swift; sourceTree = "<group>"; };
|
||||
C473319E2470923A009A0597 /* Localizable.strings */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; path = Localizable.strings; sourceTree = "<group>"; };
|
||||
C47331A1247093B7009A0597 /* StatusMenu.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StatusMenu.swift; sourceTree = "<group>"; };
|
||||
@ -789,7 +789,7 @@
|
||||
C4B97B7A275CF20A003F3378 /* App+GlobalHotkey.swift */,
|
||||
C4EED88827A48778006D7272 /* InterAppHandler.swift */,
|
||||
C4D8016522B1584700C6DA1B /* Startup.swift */,
|
||||
C46E206C28299B3800D909D6 /* Updater.swift */,
|
||||
C46E206C28299B3800D909D6 /* AppUpdateChecker.swift */,
|
||||
);
|
||||
path = App;
|
||||
sourceTree = "<group>";
|
||||
@ -1182,7 +1182,7 @@
|
||||
C4811D2A22D70F9A00B5F6B3 /* MainMenu.swift in Sources */,
|
||||
C40C7F3027722E8D00DDDCDC /* Logger.swift in Sources */,
|
||||
C41CA5ED2774F8EE00A2C80E /* DomainListVC+Actions.swift in Sources */,
|
||||
C46E206D28299B3800D909D6 /* Updater.swift in Sources */,
|
||||
C46E206D28299B3800D909D6 /* AppUpdateChecker.swift in Sources */,
|
||||
C412E5FC25700D5300A1FB67 /* HomebrewPackage.swift in Sources */,
|
||||
C4D9ADBF277610E1007277F4 /* PhpSwitcher.swift in Sources */,
|
||||
C4068CAA27B0890D00544CD5 /* MenuBarIcons.swift in Sources */,
|
||||
@ -1351,7 +1351,7 @@
|
||||
C418898A275FE8CB001EF227 /* Filesystem.swift in Sources */,
|
||||
C4F780C625D80B75000DBC97 /* XibLoadable.swift in Sources */,
|
||||
C4EE55AA27708B9E001DF387 /* PMHeaderView.swift in Sources */,
|
||||
C46E206E28299B3800D909D6 /* Updater.swift in Sources */,
|
||||
C46E206E28299B3800D909D6 /* AppUpdateChecker.swift in Sources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
@ -1502,7 +1502,7 @@
|
||||
CODE_SIGN_IDENTITY = "Apple Development";
|
||||
CODE_SIGN_STYLE = Automatic;
|
||||
COMBINE_HIDPI_IMAGES = YES;
|
||||
CURRENT_PROJECT_VERSION = 775;
|
||||
CURRENT_PROJECT_VERSION = 780;
|
||||
DEBUG = YES;
|
||||
DEVELOPMENT_TEAM = 8M54J5J787;
|
||||
ENABLE_HARDENED_RUNTIME = YES;
|
||||
@ -1528,7 +1528,7 @@
|
||||
CODE_SIGN_IDENTITY = "Apple Development";
|
||||
CODE_SIGN_STYLE = Automatic;
|
||||
COMBINE_HIDPI_IMAGES = YES;
|
||||
CURRENT_PROJECT_VERSION = 775;
|
||||
CURRENT_PROJECT_VERSION = 780;
|
||||
DEBUG = NO;
|
||||
DEVELOPMENT_TEAM = 8M54J5J787;
|
||||
ENABLE_HARDENED_RUNTIME = YES;
|
||||
|
@ -9,15 +9,19 @@
|
||||
import Foundation
|
||||
import AppKit
|
||||
|
||||
class Updater {
|
||||
class AppUpdateChecker {
|
||||
|
||||
public static var enabled: Bool = {
|
||||
return Preferences.isEnabled(.automaticBackgroundUpdateCheck)
|
||||
}()
|
||||
|
||||
public static func checkForUpdates(background: Bool = true) {
|
||||
public static var isDev: Bool = {
|
||||
return App.version.contains("-dev")
|
||||
}()
|
||||
|
||||
public static func checkIfNewerVersionIsAvailable(automaticallyInitiated: Bool = true) {
|
||||
// Information about the status of a potential background update
|
||||
if background {
|
||||
if automaticallyInitiated {
|
||||
if !Preferences.isEnabled(.automaticBackgroundUpdateCheck) {
|
||||
Log.info("Automatic updates are disabled. No check will be performed.")
|
||||
return
|
||||
@ -34,9 +38,9 @@ class Updater {
|
||||
// We'll find out what the new version is by using `curl`
|
||||
var command = "curl -s"
|
||||
|
||||
if background {
|
||||
// If running as a background check, should only waste at most 2 secs of time
|
||||
command = "curl -s --max-time 2"
|
||||
if automaticallyInitiated {
|
||||
// If running as a background check, should only waste at most 3 secs of time
|
||||
command = "curl -s --max-time 3"
|
||||
}
|
||||
|
||||
let versionString = Shell.pipe(
|
||||
@ -47,38 +51,67 @@ class Updater {
|
||||
Log.err("We couldn't check for updates!")
|
||||
|
||||
// Only notify about connection issues if the request to check for updates was explicit
|
||||
if !background {
|
||||
if !automaticallyInitiated {
|
||||
notifyAboutConnectionIssue()
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
guard let current = VersionExtractor.from(App.shortVersion) else {
|
||||
guard let currentVersion = VersionExtractor.from(App.shortVersion) else {
|
||||
Log.err("We couldn't parse the current version number!")
|
||||
return
|
||||
}
|
||||
|
||||
switch onlineVersion.versionCompare(current) {
|
||||
handleVersionComparison(currentVersion, onlineVersion, automaticallyInitiated)
|
||||
}
|
||||
|
||||
private static func handleVersionComparison(
|
||||
_ currentVersion: String,
|
||||
_ onlineVersion: String,
|
||||
_ background: Bool
|
||||
) {
|
||||
switch onlineVersion.versionCompare(currentVersion) {
|
||||
case .orderedAscending:
|
||||
Log.info("You are running a newer version of PHP Monitor.")
|
||||
if !background {
|
||||
notifyVersionDoesNotNeedUpgrade()
|
||||
}
|
||||
case .orderedDescending:
|
||||
Log.info("There is a newer version (\(onlineVersion)) available!")
|
||||
notifyAboutNewerVersion(version: onlineVersion)
|
||||
case .orderedSame:
|
||||
Log.info("The installed version \(current) matches the latest release (\(onlineVersion)).")
|
||||
Log.info("The installed version \(currentVersion) matches the latest release (\(onlineVersion)).")
|
||||
if !background {
|
||||
notifyVersionDoesNotNeedUpgrade()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static func notifyVersionDoesNotNeedUpgrade() {
|
||||
DispatchQueue.main.async {
|
||||
BetterAlert().withInformation(
|
||||
title: "updater.alerts.is_latest_version.title\(isDev ? "_dev" : "")"
|
||||
.localized,
|
||||
subtitle: "updater.alerts.is_latest_version.subtitle\(isDev ? "_dev" : "")"
|
||||
.localized(App.shortVersion),
|
||||
description: ""
|
||||
)
|
||||
.withPrimary(text: "OK")
|
||||
.show()
|
||||
}
|
||||
}
|
||||
|
||||
private static func notifyAboutNewerVersion(version: String) {
|
||||
let dev = App.version.contains("-dev") ? "-dev" : ""
|
||||
let devSuffix = isDev ? "-dev" : ""
|
||||
let command = isDev ? "brew upgrade phpmon" : "brew upgrade phpmon-dev"
|
||||
|
||||
DispatchQueue.main.async {
|
||||
BetterAlert().withInformation(
|
||||
title: "updater.alerts.newer_version_available.title".localized(version),
|
||||
subtitle: "updater.alerts.newer_version_available.subtitle".localized,
|
||||
description: HomebrewDiagnostics.customCaskInstalled
|
||||
? "updater.installation_source.brew".localized
|
||||
? "updater.installation_source.brew".localized(command)
|
||||
: "updater.installation_source.direct".localized
|
||||
)
|
||||
.withPrimary(
|
||||
@ -86,11 +119,11 @@ class Updater {
|
||||
action: { vc in
|
||||
vc.close(with: .OK)
|
||||
NSWorkspace.shared.open(
|
||||
Constants.Urls.GitHubReleases.appendingPathComponent("/tag/v\(version)\(dev)")
|
||||
Constants.Urls.GitHubReleases.appendingPathComponent("/tag/v\(version)\(devSuffix)")
|
||||
)
|
||||
}
|
||||
)
|
||||
.withTertiary(text: "Close", action: { vc in
|
||||
.withTertiary(text: "Dismiss", action: { vc in
|
||||
vc.close(with: .OK)
|
||||
})
|
||||
.show()
|
@ -33,10 +33,19 @@ class HomebrewDiagnostics {
|
||||
It is possible to have the `shivammathur/php` tap installed, and for the core homebrew information to be outdated.
|
||||
This will then result in two different aliases claiming to point to the same formula (`php`).
|
||||
This will break all linking functionality in PHP Monitor, and the user needs to be informed of this.
|
||||
|
||||
|
||||
This check only needs to be performed if the `shivammathur/php` tap is active.
|
||||
*/
|
||||
public static func hasAliasConflict() -> Bool {
|
||||
public static func checkForCaskConflict() {
|
||||
if hasAliasConflict() {
|
||||
presentAlertAboutConflict()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
Check if the alias conflict as documented in `checkForCaskConflict` actually occurred.
|
||||
*/
|
||||
private static func hasAliasConflict() -> Bool {
|
||||
let tapAlias = Shell.pipe("\(Paths.brew) info shivammathur/php/php --json")
|
||||
|
||||
if tapAlias.contains("brew tap shivammathur/php") || tapAlias.contains("Error") {
|
||||
@ -75,10 +84,9 @@ class HomebrewDiagnostics {
|
||||
}
|
||||
|
||||
/**
|
||||
This method, unsurprisingly, is supposed to show a specific alert about this alias conflict
|
||||
with the `shivammathur/php` tap.
|
||||
Show this alert in case the tapped Cask does cause issues because of the conflict.
|
||||
*/
|
||||
public static func presentAlertAboutConflict() {
|
||||
private static func presentAlertAboutConflict() {
|
||||
DispatchQueue.main.async {
|
||||
BetterAlert()
|
||||
.withInformation(
|
||||
|
@ -47,9 +47,7 @@ extension MainMenu {
|
||||
PhpEnv.detectPhpVersions()
|
||||
|
||||
// Check for an alias conflict
|
||||
if HomebrewDiagnostics.hasAliasConflict() {
|
||||
HomebrewDiagnostics.presentAlertAboutConflict()
|
||||
}
|
||||
HomebrewDiagnostics.checkForCaskConflict()
|
||||
|
||||
updatePhpVersionInStatusBar()
|
||||
|
||||
@ -104,10 +102,11 @@ extension MainMenu {
|
||||
}
|
||||
|
||||
Stats.incrementSuccessfulLaunchCount()
|
||||
|
||||
Stats.evaluateSponsorMessageShouldBeDisplayed()
|
||||
|
||||
Updater.checkForUpdates()
|
||||
DispatchQueue.global(qos: .utility).async {
|
||||
AppUpdateChecker.checkIfNewerVersionIsAvailable()
|
||||
}
|
||||
|
||||
Log.info("PHP Monitor is ready to serve!")
|
||||
}
|
||||
|
@ -339,7 +339,7 @@ class MainMenu: NSObject, NSWindowDelegate, NSMenuDelegate, PhpSwitcherDelegate
|
||||
|
||||
@objc func checkForUpdates() {
|
||||
DispatchQueue.global(qos: .userInitiated).async {
|
||||
Updater.checkForUpdates(background: false)
|
||||
AppUpdateChecker.checkIfNewerVersionIsAvailable(automaticallyInitiated: false)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -380,12 +380,18 @@ You can do this by running `composer global update` in your terminal. After that
|
||||
// CHECK FOR UPDATES
|
||||
|
||||
"updater.alerts.newer_version_available.title" = "A newer version of PHP Monitor (v%@) is now available!";
|
||||
"updater.alerts.newer_version_available.subtitle" = "Keeping PHP Monitor up-to-date is highly recommended, since newer versions usually fix bugs and include fixes to support the latest versions of Valet and PHP. Sometimes, there's even cool new features!";
|
||||
"updater.alerts.newer_version_available.subtitle" = "Keeping PHP Monitor up-to-date is highly recommended, since newer versions usually fix bugs and include fixes to support the latest versions of Valet and PHP.";
|
||||
"updater.alerts.newer_version_available.description" = "PHP Monitor is supposed to be updated via Homebrew, so there is no built-in updater. This check is only meant to inform you of the existence of a new version, you do not need to upgrade.";
|
||||
"updater.installation_source.brew" = "You appear to have installed PHP Monitor via Homebrew (or have at least tapped the required Caskfile) so it is recommended that you upgrade via the terminal by running `brew upgrade phpmon`.";
|
||||
"updater.installation_source.brew" = "You appear to have installed PHP Monitor via Homebrew (or have at least tapped the required Caskfile) so it is recommended that you upgrade via the terminal by running `%@`.";
|
||||
"updater.installation_source.direct" = "You do not appear to have installed PHP Monitor via Homebrew, so you will need to visit GitHub to download the latest update.";
|
||||
"updater.alerts.buttons.release_notes" = "View Release Notes";
|
||||
|
||||
"updater.alerts.is_latest_version.title" = "PHP Monitor is up-to-date!";
|
||||
"updater.alerts.is_latest_version.subtitle" = "The currently installed version (v%@) is up-to-date.\nThere is no newer version available.";
|
||||
|
||||
"updater.alerts.is_latest_version.title_dev" = "PHP Monitor DEV is (probably) up-to-date!";
|
||||
"updater.alerts.is_latest_version.subtitle_dev" = "You appear to be running a development build. While no major newer version seems to be available, a newer dev build for the same version may be available, and it is recommended that you check if that is the case. Thanks for testing!";
|
||||
|
||||
"updater.alerts.cannot_check_for_update.title" = "PHP Monitor could not determine if a newer version is available.";
|
||||
"updater.alerts.cannot_check_for_update.subtitle" = "You might not be connected to the internet, are blocking traffic or GitHub is down and won't allow you to check for updates. If you keep seeing this message, you may want to manually check the releases page.";
|
||||
"updater.alerts.cannot_check_for_update.description" = "The currently installed version is: %@. You can go to the list of the latest releases (on GitHub) by clicking on the button on the left.";
|
||||
|
Reference in New Issue
Block a user