Skip to content

Commit ae9c7d5

Browse files
committed
Username simplification
Reading the username now uses much simpler API as pointed out to me in the community
1 parent c3b3a3e commit ae9c7d5

2 files changed

Lines changed: 1 addition & 50 deletions

File tree

src/Support/AppDelegate.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -542,7 +542,6 @@ class AppDelegate: NSObject, NSApplicationDelegate, ObservableObject {
542542

543543
Task {
544544
await self.userinfo.getCurrentUserRecord()
545-
await self.userinfo.getUserFullName()
546545
}
547546

548547
// Post Distributed Notification to trigger script for custom info items
@@ -563,7 +562,6 @@ class AppDelegate: NSObject, NSApplicationDelegate, ObservableObject {
563562
self.computerinfo.kernelBootTime()
564563
Task {
565564
await self.userinfo.getCurrentUserRecord()
566-
await self.userinfo.getUserFullName()
567565
await self.computerinfo.getSerialNumber()
568566
}
569567
self.computerinfo.getStorage()

src/Support/UserInfo.swift

Lines changed: 1 addition & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class UserInfo: ObservableObject {
3939
@Published var networkUnavailable: Bool = false
4040

4141
// Full name of macOS user account
42-
@Published var fullName: String = ""
42+
var fullName: String = NSFullUserName()
4343

4444
// Array of detected Kerberos Realms
4545
var realmsArray: [String] = []
@@ -443,53 +443,6 @@ class UserInfo: ObservableObject {
443443
logger.debug("Pasword Expiry Limit did not change, no need to reload StatusBarItem")
444444
}
445445
}
446-
447-
// MARK: - Function to get the user record and full name
448-
func getUserFullName() {
449-
450-
// Skip if user's full name is already available
451-
guard fullName.isEmpty else {
452-
return
453-
}
454-
455-
DispatchQueue.global().async { [self] in
456-
do {
457-
let node = try ODNode.init(session: session, type: UInt32(kODNodeTypeAuthentication))
458-
// let node = try ODNode.init(session: session, type: UInt32(kODNodeTypeLocalNodes))
459-
let query = try ODQuery.init(node: node, forRecordTypes: kODRecordTypeUsers, attribute: kODAttributeTypeRecordName, matchType: UInt32(kODMatchEqualTo), queryValues: currentConsoleUserName, returnAttributes: kODAttributeTypeNativeOnly, maximumResults: 0)
460-
records = try query.resultsAllowingPartial(false) as! [ODRecord]
461-
} catch {
462-
logger.error("Unable to get local user account ODRecords")
463-
}
464-
}
465-
466-
// We may have gotten multiple ODRecords that match username,
467-
// So make sure it also matches the UID.
468-
469-
// Perform on background thread
470-
DispatchQueue.global().async { [self] in
471-
472-
for case let record in records {
473-
let attribute = "dsAttrTypeStandard:UniqueID"
474-
if let odUid = try? String(describing: record.values(forAttribute: attribute)[0]) {
475-
if ( odUid == uid) {
476-
477-
do {
478-
let fullNameArray = try record.values(forAttribute: kODAttributeTypeFullName) as? [String]
479-
DispatchQueue.main.async {
480-
self.fullName = fullNameArray?.first ?? ""
481-
self.logger.debug("Full name is: \(self.fullName, privacy: .public)")
482-
}
483-
} catch {
484-
logger.error("Error while getting user's full name")
485-
logger.error("\(error.localizedDescription)")
486-
}
487-
488-
}
489-
}
490-
}
491-
}
492-
}
493446

494447
// MARK: - Expirimental function to change the local Mac password
495448
func changePassword() {

0 commit comments

Comments
 (0)