1
0
mirror of https://github.com/nicoverbruggen/phpmon.git synced 2025-11-07 13:20:05 +01:00

Notify about installed update

This commit is contained in:
2023-02-02 19:46:07 +01:00
parent 0bb3e5c173
commit b182218cad
4 changed files with 35 additions and 6 deletions

View File

@@ -41,21 +41,30 @@ class RealFileSystem: FileSystemProtocol {
} }
func getShallowContentsOfDirectory(_ path: String) throws -> [String] { func getShallowContentsOfDirectory(_ path: String) throws -> [String] {
return try FileManager.default.contentsOfDirectory(atPath: path) return try FileManager.default.contentsOfDirectory(
atPath: path.replacingTildeWithHomeDirectory
)
} }
func getDestinationOfSymlink(_ path: String) throws -> String { func getDestinationOfSymlink(_ path: String) throws -> String {
return try FileManager.default.destinationOfSymbolicLink(atPath: path) return try FileManager.default.destinationOfSymbolicLink(
atPath: path.replacingTildeWithHomeDirectory
)
} }
// MARK: - Move & Delete Files // MARK: - Move & Delete Files
func move(from path: String, to newPath: String) throws { func move(from path: String, to newPath: String) throws {
try FileManager.default.moveItem(atPath: path, toPath: newPath) try FileManager.default.moveItem(
atPath: path.replacingTildeWithHomeDirectory,
toPath: newPath.replacingTildeWithHomeDirectory
)
} }
func remove(_ path: String) throws { func remove(_ path: String) throws {
try FileManager.default.removeItem(atPath: path) try FileManager.default.removeItem(
atPath: path.replacingTildeWithHomeDirectory
)
} }
// MARK: FS Attributes // MARK: FS Attributes

View File

@@ -10,8 +10,8 @@ import UserNotifications
class LocalNotification { class LocalNotification {
@MainActor public static func send(title: String, subtitle: String, preference: PreferenceName) { @MainActor public static func send(title: String, subtitle: String, preference: PreferenceName?) {
if !Preferences.isEnabled(preference) { if preference != nil && !Preferences.isEnabled(preference!) {
return return
} }

View File

@@ -120,6 +120,9 @@ extension MainMenu {
// We are ready! // We are ready!
Log.info("PHP Monitor is ready to serve!") Log.info("PHP Monitor is ready to serve!")
// Check if we upgraded just now
self.checkIfUpgradeWasPerformed()
} }
/** /**
@@ -188,4 +191,18 @@ extension MainMenu {
Log.info("Detected applications: \(appNames)") Log.info("Detected applications: \(appNames)")
} }
private func checkIfUpgradeWasPerformed() {
if FileSystem.fileExists("~/.config/phpmon/updater/upgrade.success") {
// Send a notification about the update
Task { @MainActor in
LocalNotification.send(
title: "notification.phpmon_updated.title".localized,
subtitle: "notification.phpmon_updated.desc".localized(App.shortVersion),
preference: nil
)
try! FileSystem.remove("~/.config/phpmon/updater/upgrade.success")
}
}
}
} }

View File

@@ -358,6 +358,9 @@ This has no effect on other terminals, only for the particular terminal session
"notification.preset_reverted_title" = "Preset reverted"; "notification.preset_reverted_title" = "Preset reverted";
"notification.preset_reverted_desc" = "The last preset you applied has been undone. Your previous configuration is now active."; "notification.preset_reverted_desc" = "The last preset you applied has been undone. Your previous configuration is now active.";
"notification.phpmon_updated.title" = "PHP Monitor has been updated!";
"notification.phpmon_updated.desc" = "You are now running PHP Monitor v%@.";
// Composer Update // Composer Update
"alert.composer_missing.title" = "Composer not found!"; "alert.composer_missing.title" = "Composer not found!";
"alert.composer_missing.subtitle" = "PHP Monitor could not find Composer. Make sure that Composer is installed and try again."; "alert.composer_missing.subtitle" = "PHP Monitor could not find Composer. Make sure that Composer is installed and try again.";