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() {
|
||||
|
@ -27,6 +27,30 @@ public func system(_ command: String) -> String {
|
||||
return output
|
||||
}
|
||||
|
||||
/** Same as the `system` command, but does not return the output. */
|
||||
public func system_quiet(_ command: String) {
|
||||
_ = 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
|
||||
setupNotifications()
|
||||
Task { // Make sure the menu performs its initial checks
|
||||
await paths.loadUser()
|
||||
await menu.startup()
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user