mirror of
https://github.com/nicoverbruggen/phpmon.git
synced 2026-03-30 08:20:09 +02:00
🐛 Prevent timeout message from showing incorrectly
This commit is contained in:
@@ -18,6 +18,16 @@ struct Constants {
|
||||
*/
|
||||
static let MinimumRecommendedValetVersion = "2.16.2"
|
||||
|
||||
/**
|
||||
The amount of seconds that is considered the threshold for
|
||||
PHP Monitor to mark any given launch as a "slow" launch.
|
||||
|
||||
If the startup procedure was slow (or hangs), this message should
|
||||
be displayed. This is based on an appropriate launch time on a
|
||||
basic M1 Apple chip, with some margin for slower Intel chips.
|
||||
*/
|
||||
static let SlowBootThresholdInterval: TimeInterval = 30.0
|
||||
|
||||
/**
|
||||
PHP Monitor supplies a hardcoded list of PHP packages in its own
|
||||
PHP Version Manager.
|
||||
|
||||
32
phpmon/Domain/App/Startup+Timers.swift
Normal file
32
phpmon/Domain/App/Startup+Timers.swift
Normal file
@@ -0,0 +1,32 @@
|
||||
//
|
||||
// Startup+Timers.swift
|
||||
// PHP Monitor
|
||||
//
|
||||
// Created by Nico Verbruggen on 23/07/2025.
|
||||
// Copyright © 2025 Nico Verbruggen. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
extension Startup {
|
||||
@MainActor static var startupTimer: Timer?
|
||||
@MainActor static var launchTime: Date?
|
||||
|
||||
@MainActor func startTimeoutTimer() {
|
||||
Self.launchTime = Date()
|
||||
Self.startupTimer = Timer.scheduledTimer(
|
||||
timeInterval: Constants.SlowBootThresholdInterval, target: self,
|
||||
selector: #selector(startupTimeout), userInfo: nil, repeats: false
|
||||
)
|
||||
}
|
||||
|
||||
@MainActor static func invalidateTimeoutTimer() {
|
||||
let elapsedTime = Date().timeIntervalSince(Self.launchTime!)
|
||||
let printableTime = String(format: "%.2f", elapsedTime)
|
||||
|
||||
Log.info("PHP Monitor launched quickly enough!")
|
||||
Log.info("PHP Monitor boot time: \(printableTime) sec")
|
||||
Self.startupTimer?.invalidate()
|
||||
Self.startupTimer = nil
|
||||
}
|
||||
}
|
||||
@@ -10,21 +10,6 @@ import AppKit
|
||||
import NVAlert
|
||||
|
||||
class Startup {
|
||||
|
||||
@MainActor static var startupTimer: Timer?
|
||||
|
||||
@MainActor func startTimeoutTimer() {
|
||||
Self.startupTimer = Timer.scheduledTimer(
|
||||
timeInterval: 30.0, target: self, selector: #selector(startupTimeout),
|
||||
userInfo: nil, repeats: false
|
||||
)
|
||||
}
|
||||
|
||||
@MainActor static func invalidateTimeoutTimer() {
|
||||
Self.startupTimer?.invalidate()
|
||||
Self.startupTimer = nil
|
||||
}
|
||||
|
||||
/**
|
||||
Checks the user's environment and checks if PHP Monitor can be used properly.
|
||||
This checks if PHP is installed, Valet is running, the appropriate permissions are set, and more.
|
||||
|
||||
@@ -103,12 +103,6 @@ extension MainMenu {
|
||||
// Find out which services are active
|
||||
Log.info("The services manager knows about \(ServicesManager.shared.services.count) services.")
|
||||
|
||||
// Post-launch stats and update check, but only if not running tests
|
||||
await performPostLaunchActions()
|
||||
|
||||
// Check if the linked version has changed between launches of phpmon
|
||||
PhpGuard().compareToLastGlobalVersion()
|
||||
|
||||
// We are ready!
|
||||
PhpEnvironments.shared.isBusy = false
|
||||
|
||||
@@ -120,6 +114,9 @@ extension MainMenu {
|
||||
|
||||
// Check if we upgraded from a previous version
|
||||
AppUpdater.checkIfUpdateWasPerformed()
|
||||
|
||||
// Post-launch stats and update check, but only if not running tests
|
||||
await performPostLaunchActions()
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -127,18 +124,24 @@ extension MainMenu {
|
||||
(This code is skipped when running SwiftUI previews.)
|
||||
*/
|
||||
private func performPostLaunchActions() async {
|
||||
if !isRunningSwiftUIPreview {
|
||||
Stats.incrementSuccessfulLaunchCount()
|
||||
Stats.evaluateSponsorMessageShouldBeDisplayed()
|
||||
if isRunningSwiftUIPreview {
|
||||
return
|
||||
}
|
||||
|
||||
if Stats.successfulLaunchCount == 1 {
|
||||
Log.info("Should present the first launch screen!")
|
||||
Task { @MainActor in
|
||||
OnboardingWindowController.show()
|
||||
}
|
||||
} else {
|
||||
await AppUpdater().checkForUpdates(userInitiated: false)
|
||||
Stats.incrementSuccessfulLaunchCount()
|
||||
Stats.evaluateSponsorMessageShouldBeDisplayed()
|
||||
|
||||
if Stats.successfulLaunchCount == 1 {
|
||||
Log.info("Should present the first launch screen!")
|
||||
Task { @MainActor in
|
||||
OnboardingWindowController.show()
|
||||
}
|
||||
} else {
|
||||
// Check for updates
|
||||
await AppUpdater().checkForUpdates(userInitiated: false)
|
||||
|
||||
// Check if the linked version has changed between launches of phpmon
|
||||
await PhpGuard().compareToLastGlobalVersion()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ class PhpGuard {
|
||||
Log.info("The currently linked version of PHP is: \(linked.version.short).")
|
||||
}
|
||||
|
||||
public func compareToLastGlobalVersion() {
|
||||
public func compareToLastGlobalVersion() async {
|
||||
guard let currentVersion else {
|
||||
return
|
||||
}
|
||||
@@ -34,6 +34,7 @@ class PhpGuard {
|
||||
Stats.persistCurrentGlobalPhpVersion(version: currentVersion)
|
||||
return Log.warn("PHP Guard is saving the currently linked PHP version (first time only).")
|
||||
}
|
||||
|
||||
Log.info("Previously, the globally linked PHP version was: \(previousVersion).")
|
||||
|
||||
if previousVersion == currentVersion {
|
||||
|
||||
Reference in New Issue
Block a user