mirror of
https://github.com/nicoverbruggen/phpmon.git
synced 2025-08-07 12:00:09 +02:00
✨ Load persisted revert & allow revert
This also moves the location of the .phpmon.conf.json file to a new location: ~/.config/phpmon/config.json.
This commit is contained in:
@ -123,6 +123,8 @@
|
||||
C44CCD4A27AFF3BC00CE40E5 /* MainMenu+Async.swift in Sources */ = {isa = PBXBuildFile; fileRef = C44CCD4827AFF3B700CE40E5 /* MainMenu+Async.swift */; };
|
||||
C44F868E2835BD8D005C353A /* phpmon-config.json in Resources */ = {isa = PBXBuildFile; fileRef = C44F868D2835BD8D005C353A /* phpmon-config.json */; };
|
||||
C459B4BD27F6093700E9B4B4 /* nginx-proxy.test in Resources */ = {isa = PBXBuildFile; fileRef = C459B4BC27F6093700E9B4B4 /* nginx-proxy.test */; };
|
||||
C463E380284930EE00422731 /* PresetHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = C463E37F284930EE00422731 /* PresetHelper.swift */; };
|
||||
C463E381284930EE00422731 /* PresetHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = C463E37F284930EE00422731 /* PresetHelper.swift */; };
|
||||
C464ADAC275A7A3F003FCD53 /* DomainListWC.swift in Sources */ = {isa = PBXBuildFile; fileRef = C464ADAB275A7A3F003FCD53 /* DomainListWC.swift */; };
|
||||
C464ADAD275A7A3F003FCD53 /* DomainListWC.swift in Sources */ = {isa = PBXBuildFile; fileRef = C464ADAB275A7A3F003FCD53 /* DomainListWC.swift */; };
|
||||
C464ADAF275A7A69003FCD53 /* DomainListVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = C464ADAE275A7A69003FCD53 /* DomainListVC.swift */; };
|
||||
@ -360,6 +362,7 @@
|
||||
C44CCD4827AFF3B700CE40E5 /* MainMenu+Async.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "MainMenu+Async.swift"; sourceTree = "<group>"; };
|
||||
C44F868D2835BD8D005C353A /* phpmon-config.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = "phpmon-config.json"; sourceTree = "<group>"; };
|
||||
C459B4BC27F6093700E9B4B4 /* nginx-proxy.test */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = "nginx-proxy.test"; sourceTree = "<group>"; };
|
||||
C463E37F284930EE00422731 /* PresetHelper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PresetHelper.swift; sourceTree = "<group>"; };
|
||||
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>"; };
|
||||
@ -561,6 +564,7 @@
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
C40C5C9B2846A40600E28255 /* Preset.swift */,
|
||||
C463E37F284930EE00422731 /* PresetHelper.swift */,
|
||||
);
|
||||
path = Presets;
|
||||
sourceTree = "<group>";
|
||||
@ -1216,6 +1220,7 @@
|
||||
C41E871A2763D42300161EE0 /* DomainListVC+ContextMenu.swift in Sources */,
|
||||
C48D0CA325CC992000CC7490 /* StatsView.swift in Sources */,
|
||||
C40C7F2827721FF600DDDCDC /* ActivePhpInstallation+Checks.swift in Sources */,
|
||||
C463E380284930EE00422731 /* PresetHelper.swift in Sources */,
|
||||
C4EE55A927708B9E001DF387 /* PMHeaderView.swift in Sources */,
|
||||
C41C02A927E61A65009F26CB /* ValetSite+Fake.swift in Sources */,
|
||||
C4C0E8DF27F88AEB002D32A9 /* FakeSiteScanner.swift in Sources */,
|
||||
@ -1347,6 +1352,7 @@
|
||||
C4C0E8E327F88B13002D32A9 /* ValetSiteScanner.swift in Sources */,
|
||||
C4CCBA6D275C567B008C7055 /* PMWindowController.swift in Sources */,
|
||||
C4B5635F276AB09000F12CCB /* VersionExtractor.swift in Sources */,
|
||||
C463E381284930EE00422731 /* PresetHelper.swift in Sources */,
|
||||
C46FA98C2822F08F00D78807 /* PhpConfigurationTest.swift in Sources */,
|
||||
C4BF90C127C57C220054E78C /* MainMenu+FixMyValet.swift in Sources */,
|
||||
C4C0E8EB27F88B80002D32A9 /* ValetProxy+Fake.swift in Sources */,
|
||||
|
@ -309,7 +309,7 @@ All of these apps should just be detected correctly, no matter their location on
|
||||
|
||||
To see which files are checked to determine availability, see [this file](./phpmon/Domain/Helpers/Application.swift).
|
||||
|
||||
You can add your own apps by creating and editing a `~/.phpmon.conf.json` file, with the following entry:
|
||||
You can add your own apps by creating and editing a `~/.config/phpmon/config.json` file, with the following entry:
|
||||
|
||||
<pre>
|
||||
{
|
||||
|
@ -145,6 +145,14 @@ extension MainMenu {
|
||||
}
|
||||
}
|
||||
|
||||
@objc func rollbackPreset() {
|
||||
asyncExecution {
|
||||
PresetHelper.rollbackPreset?.apply()
|
||||
PresetHelper.rollbackPreset = nil
|
||||
MainMenu.shared.rebuild()
|
||||
}
|
||||
}
|
||||
|
||||
@objc func togglePreset(sender: PresetMenuItem) {
|
||||
asyncExecution {
|
||||
sender.preset?.apply()
|
||||
|
@ -62,22 +62,10 @@ extension MainMenu {
|
||||
App.shared.handlePhpConfigWatcher()
|
||||
|
||||
// Detect applications (preset + custom)
|
||||
Log.info("Detecting applications...")
|
||||
App.shared.detectedApplications = Application.detectPresetApplications()
|
||||
self.loadApps()
|
||||
|
||||
let customApps = Preferences.custom.scanApps.map { appName in
|
||||
return Application(appName, .user_supplied)
|
||||
}.filter { app in
|
||||
return app.isInstalled()
|
||||
}
|
||||
|
||||
App.shared.detectedApplications.append(contentsOf: customApps)
|
||||
|
||||
let appNames = App.shared.detectedApplications.map { app in
|
||||
return app.name
|
||||
}
|
||||
|
||||
Log.info("Detected applications: \(appNames)")
|
||||
// Load the rollback preset
|
||||
PresetHelper.loadRollbackPresetFromFile()
|
||||
|
||||
// Load the global hotkey
|
||||
App.shared.loadGlobalHotkey()
|
||||
@ -133,4 +121,23 @@ extension MainMenu {
|
||||
Task { await startup() }
|
||||
}
|
||||
}
|
||||
|
||||
private func loadApps() {
|
||||
Log.info("Detecting applications...")
|
||||
App.shared.detectedApplications = Application.detectPresetApplications()
|
||||
|
||||
let customApps = Preferences.custom.scanApps.map { appName in
|
||||
return Application(appName, .user_supplied)
|
||||
}.filter { app in
|
||||
return app.isInstalled()
|
||||
}
|
||||
|
||||
App.shared.detectedApplications.append(contentsOf: customApps)
|
||||
|
||||
let appNames = App.shared.detectedApplications.map { app in
|
||||
return app.name
|
||||
}
|
||||
|
||||
Log.info("Detected applications: \(appNames)")
|
||||
}
|
||||
}
|
||||
|
@ -103,8 +103,11 @@ extension StatusMenu {
|
||||
presetsMenu.addItem(NSMenuItem.separator())
|
||||
presetsMenu.addItem(NSMenuItem(
|
||||
title: "Revert to Previous Configuration...",
|
||||
action: #selector(MainMenu.restartDnsMasq), keyEquivalent: "")
|
||||
)
|
||||
action: PresetHelper.rollbackPreset != nil
|
||||
? #selector(MainMenu.rollbackPreset)
|
||||
: nil,
|
||||
keyEquivalent: ""
|
||||
))
|
||||
presetsMenu.addItem(NSMenuItem.separator())
|
||||
presetsMenu.addItem(NSMenuItem(
|
||||
title: "\(Preferences.custom.presets.count) profiles loaded from configuration file",
|
||||
|
@ -173,12 +173,12 @@ class Preferences {
|
||||
// MARK: - Custom Preferences
|
||||
|
||||
private func loadCustomPreferences() {
|
||||
let url = URL(fileURLWithPath: "/Users/\(Paths.whoami)/.phpmon.conf.json")
|
||||
let url = URL(fileURLWithPath: "/Users/\(Paths.whoami)/.config/phpmon/config.json")
|
||||
if Filesystem.fileExists(url.path) {
|
||||
Log.info("A custom .phpmon.conf.json file was found. Attempting to parse...")
|
||||
Log.info("A custom ~/.config/phpmon/config.json file was found. Attempting to parse...")
|
||||
loadCustomPreferencesFile(url)
|
||||
} else {
|
||||
Log.info("There was no .phpmon.conf.json file to be loaded.")
|
||||
Log.info("There was no /.config/phpmon/config.json file to be loaded.")
|
||||
}
|
||||
}
|
||||
|
||||
@ -189,10 +189,10 @@ class Preferences {
|
||||
from: try! String(contentsOf: url, encoding: .utf8).data(using: .utf8)!
|
||||
)
|
||||
|
||||
Log.info("The .phpmon.conf.json file was successfully parsed.")
|
||||
Log.info("The ~/.config/phpmon/config.json file was successfully parsed.")
|
||||
Log.info("There are \(customPreferences.presets.count) custom presets.")
|
||||
} catch {
|
||||
Log.warn("The .phpmon.conf.json file seems to be missing or malformed.")
|
||||
Log.warn("The ~/.config/phpmon/config.json file seems to be missing or malformed.")
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -51,6 +51,10 @@ struct Preset: Codable {
|
||||
}
|
||||
}
|
||||
|
||||
// Reload what rollback file exists
|
||||
PresetHelper.loadRollbackPresetFromFile()
|
||||
|
||||
// Restart PHP FPM process (also reloads menu, which will show the preset rollback)
|
||||
Actions.restartPhpFpm()
|
||||
}
|
||||
}
|
||||
|
37
phpmon/Domain/Presets/PresetHelper.swift
Normal file
37
phpmon/Domain/Presets/PresetHelper.swift
Normal file
@ -0,0 +1,37 @@
|
||||
//
|
||||
// PresetHelper.swift
|
||||
// PHP Monitor
|
||||
//
|
||||
// Created by Nico Verbruggen on 02/06/2022.
|
||||
// Copyright © 2022 Nico Verbruggen. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
class PresetHelper {
|
||||
|
||||
static var rollbackPreset: Preset?
|
||||
|
||||
// MARK: - Reloading Configuration
|
||||
|
||||
public static func loadRollbackPresetFromFile() {
|
||||
guard let revert = try? String(
|
||||
contentsOfFile: "/Users/\(Paths.whoami)/.config/phpmon/preset_revert.json",
|
||||
encoding: .utf8
|
||||
) else {
|
||||
PresetHelper.rollbackPreset = nil
|
||||
return
|
||||
}
|
||||
|
||||
guard let preset = try? JSONDecoder().decode(
|
||||
Preset.self,
|
||||
from: revert.data(using: .utf8)!
|
||||
) else {
|
||||
PresetHelper.rollbackPreset = nil
|
||||
return
|
||||
}
|
||||
|
||||
PresetHelper.rollbackPreset = preset
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user