mirror of
https://github.com/nicoverbruggen/phpmon.git
synced 2025-08-07 03:50:08 +02:00
👌 Do not load identity asynchronously
This commit is contained in:
@ -16,16 +16,12 @@ public class Paths {
|
||||
public static let shared = Paths()
|
||||
|
||||
internal var baseDir: Paths.HomebrewDir
|
||||
|
||||
private var userName: String! = nil
|
||||
private var userName: String
|
||||
|
||||
init() {
|
||||
baseDir = App.architecture != "x86_64" ? .opt : .usr
|
||||
}
|
||||
|
||||
public func loadUser() async {
|
||||
let output = await Shell.pipe("id -un").out
|
||||
userName = String(output.split(separator: "\n")[0])
|
||||
userName = identity()
|
||||
Log.info("[ID] The current username is `\(userName)`.")
|
||||
}
|
||||
|
||||
public func detectBinaryPaths() {
|
||||
|
@ -28,9 +28,7 @@ public func system(_ command: String) -> String {
|
||||
}
|
||||
|
||||
/**
|
||||
Run a simple blocking Shell command on the user's own system.
|
||||
This variation does not return the output.
|
||||
Avoid using this method in favor of the fakeable Shell class unless needed for express system operations.
|
||||
Same as the `system` command, but does not return the output.
|
||||
*/
|
||||
public func system_quiet(_ command: String) {
|
||||
let task = Process()
|
||||
@ -44,3 +42,26 @@ public func system_quiet(_ command: String) {
|
||||
_ = pipe.fileHandleForReading.readDataToEndOfFile()
|
||||
return
|
||||
}
|
||||
|
||||
/**
|
||||
Retrieves the username for the currently signed in user via `/usr/bin/id`.
|
||||
This cannot fail or the application will crash.
|
||||
*/
|
||||
public func identity() -> String {
|
||||
let task = Process()
|
||||
task.launchPath = "/usr/bin/id"
|
||||
task.arguments = ["-un"]
|
||||
|
||||
let pipe = Pipe()
|
||||
task.standardOutput = pipe
|
||||
task.launch()
|
||||
|
||||
guard let output = String(
|
||||
data: pipe.fileHandleForReading.readDataToEndOfFile(),
|
||||
encoding: String.Encoding.utf8
|
||||
) else {
|
||||
fatalError("Could not retrieve username via `id -un`!")
|
||||
}
|
||||
|
||||
return output.trimmingCharacters(in: .whitespacesAndNewlines)
|
||||
}
|
||||
|
@ -119,7 +119,6 @@ class AppDelegate: NSObject, NSApplicationDelegate, UNUserNotificationCenterDele
|
||||
// self.watchHomebrewBinFolder()
|
||||
|
||||
Task { // Make sure the menu performs its initial checks
|
||||
await paths.loadUser()
|
||||
await menu.startup()
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user