From b182218cadb67f856020c44365e32df719aad05e Mon Sep 17 00:00:00 2001 From: Nico Verbruggen Date: Thu, 2 Feb 2023 19:46:07 +0100 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Notify=20about=20installed=20update?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- phpmon/Common/Filesystem/RealFileSystem.swift | 17 +++++++++++++---- phpmon/Common/Helpers/LocalNotification.swift | 4 ++-- phpmon/Domain/Menu/MainMenu+Startup.swift | 17 +++++++++++++++++ phpmon/Localizable.strings | 3 +++ 4 files changed, 35 insertions(+), 6 deletions(-) diff --git a/phpmon/Common/Filesystem/RealFileSystem.swift b/phpmon/Common/Filesystem/RealFileSystem.swift index e7b87f3..67cfa91 100644 --- a/phpmon/Common/Filesystem/RealFileSystem.swift +++ b/phpmon/Common/Filesystem/RealFileSystem.swift @@ -41,21 +41,30 @@ class RealFileSystem: FileSystemProtocol { } 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 { - return try FileManager.default.destinationOfSymbolicLink(atPath: path) + return try FileManager.default.destinationOfSymbolicLink( + atPath: path.replacingTildeWithHomeDirectory + ) } // MARK: - Move & Delete Files 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 { - try FileManager.default.removeItem(atPath: path) + try FileManager.default.removeItem( + atPath: path.replacingTildeWithHomeDirectory + ) } // MARK: — FS Attributes diff --git a/phpmon/Common/Helpers/LocalNotification.swift b/phpmon/Common/Helpers/LocalNotification.swift index 6e4f7bc..eb8de9a 100644 --- a/phpmon/Common/Helpers/LocalNotification.swift +++ b/phpmon/Common/Helpers/LocalNotification.swift @@ -10,8 +10,8 @@ import UserNotifications class LocalNotification { - @MainActor public static func send(title: String, subtitle: String, preference: PreferenceName) { - if !Preferences.isEnabled(preference) { + @MainActor public static func send(title: String, subtitle: String, preference: PreferenceName?) { + if preference != nil && !Preferences.isEnabled(preference!) { return } diff --git a/phpmon/Domain/Menu/MainMenu+Startup.swift b/phpmon/Domain/Menu/MainMenu+Startup.swift index 97cb19c..73d2d4d 100644 --- a/phpmon/Domain/Menu/MainMenu+Startup.swift +++ b/phpmon/Domain/Menu/MainMenu+Startup.swift @@ -120,6 +120,9 @@ extension MainMenu { // We are ready! 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)") } + + 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") + } + } + } } diff --git a/phpmon/Localizable.strings b/phpmon/Localizable.strings index f59c9b4..6c052e4 100644 --- a/phpmon/Localizable.strings +++ b/phpmon/Localizable.strings @@ -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_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 "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.";