From 94df551b4b7a7f8b7258379903559d7b6c875466 Mon Sep 17 00:00:00 2001 From: Nico Verbruggen Date: Fri, 3 Jun 2022 23:52:40 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=91=8C=20Show=20alert=20with=20what=20wil?= =?UTF-8?q?l=20be=20rolled=20back?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- phpmon/Domain/Menu/MainMenu+Actions.swift | 20 ++++++++++++++++- phpmon/Domain/Presets/Preset.swift | 26 +++++++++++++++++++++++ 2 files changed, 45 insertions(+), 1 deletion(-) diff --git a/phpmon/Domain/Menu/MainMenu+Actions.swift b/phpmon/Domain/Menu/MainMenu+Actions.swift index ad95113..3a8194c 100644 --- a/phpmon/Domain/Menu/MainMenu+Actions.swift +++ b/phpmon/Domain/Menu/MainMenu+Actions.swift @@ -145,7 +145,7 @@ extension MainMenu { } } - @objc func rollbackPreset() { + private func performRollback() { asyncExecution { PresetHelper.rollbackPreset?.apply() PresetHelper.rollbackPreset = nil @@ -153,6 +153,24 @@ extension MainMenu { } } + @objc func rollbackPreset() { + guard let preset = PresetHelper.rollbackPreset else { + return + } + + BetterAlert().withInformation( + title: "alert.revert_description.title".localized, + subtitle: "alert.revert_description.subtitle".localized( + preset.textDescription + ) + ) + .withPrimary(text: "alert.revert_description.ok".localized, action: { _ in + self.performRollback() + }) + .withSecondary(text: "alert.revert_description.cancel".localized) + .show() + } + @objc func togglePreset(sender: PresetMenuItem) { asyncExecution { sender.preset?.apply() diff --git a/phpmon/Domain/Presets/Preset.swift b/phpmon/Domain/Presets/Preset.swift index 8fad54e..a92629f 100644 --- a/phpmon/Domain/Presets/Preset.swift +++ b/phpmon/Domain/Presets/Preset.swift @@ -21,6 +21,32 @@ struct Preset: Codable { configuration = "configuration" } + var textDescription: String { + var text = "" + + if self.version != nil { + text += "Switches to PHP \(self.version!).\n" + } + + if !self.extensions.isEmpty { + text += "\nApplies the following extensions:\n" + } + + for (ext, extValue) in self.extensions { + text += "• \(ext): \(extValue ? "enabled" : "disabled") \n" + } + + if !self.configuration.isEmpty { + text += "\nApplies the following configuration values:\n" + } + + for (key, value) in self.configuration { + text += "• \(key)=\(value ?? "(empty)") \n" + } + + return text + } + // MARK: Applying /**