Skip to content

Commit

Permalink
🚀 Version 6.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
nicoverbruggen committed Oct 27, 2023
2 parents d5888c1 + 91bc347 commit 20d19f2
Show file tree
Hide file tree
Showing 43 changed files with 597 additions and 348 deletions.
98 changes: 65 additions & 33 deletions PHP Monitor.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions phpmon/Common/Core/Paths.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public class Paths {

internal var baseDir: Paths.HomebrewDir
private var userName: String
private var preferredShell: String

init() {
// Assume the default directory is correct
Expand All @@ -31,9 +32,11 @@ public class Paths {
}

userName = identity()
preferredShell = preferred_shell()

if !isRunningSwiftUIPreview {
Log.info("The current username is `\(userName)`.")
Log.info("The user's shell is `\(preferredShell)`.")
}
}

Expand Down Expand Up @@ -104,6 +107,10 @@ public class Paths {
+ (App.identifier.contains(".dev") ? "phpmon-dev" : "phpmon")
}

public static var shell: String {
return shared.preferredShell
}

// MARK: - Flexible Binaries
// (these can be in multiple locations, so we scan common places because)
// (PHP Monitor will not use the user's own PATH)
Expand Down
2 changes: 1 addition & 1 deletion phpmon/Common/Helpers/PMWindowController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class PMWindowController: NSWindowController, NSWindowDelegate {

extension NSWindowController {

public func positionWindowInTopLeftCorner(offsetY: CGFloat = 0, offsetX: CGFloat = 0) {
public func positionWindowInTopRightCorner(offsetY: CGFloat = 0, offsetX: CGFloat = 0) {
guard let frame = NSScreen.main?.frame else { return }
guard let window = self.window else { return }

Expand Down
8 changes: 8 additions & 0 deletions phpmon/Common/Helpers/System.swift
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,11 @@ public func identity() -> String {

return output.trimmingCharacters(in: .whitespacesAndNewlines)
}

/**
Retrieves the user's preferred shell.
*/
public func preferred_shell() -> String {
return system("dscl . -read ~/ UserShell | sed 's/UserShell: //'")
.trimmingCharacters(in: .whitespacesAndNewlines)
}
24 changes: 21 additions & 3 deletions phpmon/Common/PHP/PHP Version/PhpHelper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,10 @@ class PhpHelper {
let path = URL(fileURLWithPath: "\(Paths.optPath)/php@\(version)/bin")
.resolvingSymlinksInPath().path

// The contents of the script!
let script = script(path, keyPhrase, version, dotless)
// Check if the user uses Fish
let script = Paths.shell.contains("/fish")
? fishScript(path, keyPhrase, version, dotless)
: zshScript(path, keyPhrase, version, dotless)

Task { @MainActor in
try FileSystem.writeAtomicallyToFile(destination, content: script)
Expand Down Expand Up @@ -78,7 +80,7 @@ class PhpHelper {
}
}

private static func script(
private static func zshScript(
_ path: String,
_ keyPhrase: String,
_ version: String,
Expand All @@ -96,6 +98,22 @@ class PhpHelper {
"""
}

private static func fishScript(
_ path: String,
_ keyPhrase: String,
_ version: String,
_ dotless: String
) -> String {
return """
#!\(Paths.binPath)/fish
# \(keyPhrase)
# It reflects the location of PHP \(version)'s binaries on your system.
# Usage: . pm\(dotless)
echo "PHP Monitor has enabled this terminal to use PHP \(version)."; \\
set -x PATH \(path) $PATH
"""
}

private static func createSymlink(_ dotless: String) async {
let source = "\(Paths.homePath)/.config/phpmon/bin/pm\(dotless)"
let destination = "/usr/local/bin/pm\(dotless)"
Expand Down
9 changes: 8 additions & 1 deletion phpmon/Common/PHP/PhpConfigurationFile.swift
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,9 @@ class PhpConfigurationFile: CreatedFromFile {
return nil
}

enum ReplacementErrors: Error {
public enum ReplacementErrors: Error {
case missingKey
case missingFile
}

/**
Expand All @@ -95,10 +96,16 @@ class PhpConfigurationFile: CreatedFromFile {
// Replace the specific line
self.lines[item.lineIndex] = components.joined(separator: "=")

// Ensure the watchers aren't tripped up by config changes
ConfigWatchManager.ignoresModificationsToConfigValues = true

// Finally, join the string and save the file atomatically again
try self.lines.joined(separator: "\n")
.write(toFile: self.filePath, atomically: true, encoding: .utf8)

// Ensure watcher behaviour is reverted
ConfigWatchManager.ignoresModificationsToConfigValues = false

// Reload the original file
self.reload()
}
Expand Down
1 change: 1 addition & 0 deletions phpmon/Common/Testables/TestableConfiguration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public struct TestableConfiguration: Codable {
private var primaryPhpVersion: VersionNumber?
private var secondaryPhpVersions: [VersionNumber] = []

// swiftlint:disable function_body_length
mutating func addPhpVersion(_ version: VersionNumber, primary: Bool) {
if primary {
if primaryPhpVersion != nil {
Expand Down
6 changes: 4 additions & 2 deletions phpmon/Domain/App/App+GlobalHotkey.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,10 @@ extension App {
}

hotkey.keyDownHandler = {
MainMenu.shared.statusItem.button?.performClick(nil)
NSApplication.shared.activate(ignoringOtherApps: true)
Task { @MainActor in
MainMenu.shared.statusItem.button?.performClick(nil)
NSApplication.shared.activate(ignoringOtherApps: true)
}
}
}

Expand Down
18 changes: 11 additions & 7 deletions phpmon/Domain/App/App.swift
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,13 @@ class App {
/** The window controller of the onboarding window. */
var onboardingWindowController: OnboardingWindowController?

/** The window controller of the config manager window. */
var phpConfigManagerWindowController: PhpConfigManagerWindowController?

/** The window controller of the warnings window. */
var phpDoctorWindowController: PhpDoctorWindowController?

/** The window controller of the warnings window. */
/** The window controller of the PHP version manager window. */
var phpVersionManagerWindowController: PhpVersionManagerWindowController?

/** List of detected (installed) applications that PHP Monitor can work with. */
Expand All @@ -86,9 +89,6 @@ class App {
/** The warning manager, responsible for keeping track of warnings. */
var warnings = WarningManager.shared

/** The filesystem watchers, responsible for keeping track of changes to the PHP installation. */
var watchers: [FSNotifier.Kind: FSNotifier] = [:]

/** Timer that will periodically reload info about the user's PHP installation. */
var timer: Timer?

Expand Down Expand Up @@ -117,8 +117,12 @@ class App {

// MARK: - App Watchers

/**
The `PhpConfigWatcher` is responsible for watching the `.ini` files and the `.conf.d` folder.
/** Individual filesystem watchers, which are, i.e. responsible for watching the Homebrew folders. */
var watchers: [String: FSNotifier] = [:]

/**
The `ConfigWatchManager` is responsible for watching the `.ini` files and the `.conf.d` folder.
This manager object can immediately start or stop all watchers (or pause them) all at once.
*/
var watcher: PhpConfigWatcher!
var watchManager: ConfigWatchManager!
}
Loading

0 comments on commit 20d19f2

Please sign in to comment.