mirror of
https://github.com/nicoverbruggen/phpmon.git
synced 2025-12-22 11:30:07 +01:00
👌 Do not load identity asynchronously
This commit is contained in:
@@ -16,16 +16,12 @@ public class Paths {
|
|||||||
public static let shared = Paths()
|
public static let shared = Paths()
|
||||||
|
|
||||||
internal var baseDir: Paths.HomebrewDir
|
internal var baseDir: Paths.HomebrewDir
|
||||||
|
private var userName: String
|
||||||
private var userName: String! = nil
|
|
||||||
|
|
||||||
init() {
|
init() {
|
||||||
baseDir = App.architecture != "x86_64" ? .opt : .usr
|
baseDir = App.architecture != "x86_64" ? .opt : .usr
|
||||||
}
|
userName = identity()
|
||||||
|
Log.info("[ID] The current username is `\(userName)`.")
|
||||||
public func loadUser() async {
|
|
||||||
let output = await Shell.pipe("id -un").out
|
|
||||||
userName = String(output.split(separator: "\n")[0])
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public func detectBinaryPaths() {
|
public func detectBinaryPaths() {
|
||||||
|
|||||||
@@ -27,6 +27,30 @@ public func system(_ command: String) -> String {
|
|||||||
return output
|
return output
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Same as the `system` command, but does not return the output. */
|
||||||
public func system_quiet(_ command: String) {
|
public func system_quiet(_ command: String) {
|
||||||
_ = system(command)
|
_ = system(command)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
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)
|
||||||
|
}
|
||||||
|
|||||||
@@ -111,7 +111,6 @@ class AppDelegate: NSObject, NSApplicationDelegate, UNUserNotificationCenterDele
|
|||||||
// Make sure notifications will work
|
// Make sure notifications will work
|
||||||
setupNotifications()
|
setupNotifications()
|
||||||
Task { // Make sure the menu performs its initial checks
|
Task { // Make sure the menu performs its initial checks
|
||||||
await paths.loadUser()
|
|
||||||
await menu.startup()
|
await menu.startup()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user