mirror of
https://github.com/Louis-CFM/coucou.git
synced 2026-12-07 07:32:35 +09:00
A first launch opens the onboarding window under the notch after Mochi's greeting: Mochi sleeps in a drawn notch, wakes, falls into the window with a bounce, follows the pointer, asks what to call you (empty means « toi », and Mochi says so), then the four editor Mochis drop onto the stage and Mochi flies back up into the notch; Coucou opens. - OnboardingCenter: first launch detection (existing users never see it), resume once if it was left halfway, the window, closing opens Coucou - OnboardingView + OnboardingStage: one canvas for Mochi and the troupe (gravity, bounces, walking, cheer, the flight home), the typed sentence, progress dots, Skip - Settings › App: See the onboarding again - resolveUserFirstName() prefers the name given to Mochi - 16 strings in 16 languages Claude-Session: https://claude.ai/code/session_01LJm3SRL9k3gBPaVtfPhwcT Co-authored-by: Claude <noreply@anthropic.com>
39 lines
1.7 KiB
Swift
39 lines
1.7 KiB
Swift
import Foundation
|
|
|
|
/// The name you gave Mochi in the onboarding; otherwise the first name of the macOS account holder, or nil when the account name is not something
|
|
/// you would greet someone by. "Théodore Riant" gives "Théodore"; a login handle like
|
|
/// "theodoreriant" or "t.riant2" gives nil, because "Hey theodoreriant!" reads worse than
|
|
/// a greeting with no name at all.
|
|
func resolveUserFirstName() -> String? {
|
|
// the name you gave Mochi (the onboarding) comes first
|
|
if let given = UserDefaults.standard.string(forKey: "coucouUserName")?.trimmingCharacters(in: .whitespacesAndNewlines),
|
|
!given.isEmpty {
|
|
return given
|
|
}
|
|
let fullName = NSFullUserName().trimmingCharacters(in: .whitespacesAndNewlines)
|
|
guard !fullName.isEmpty, fullName.count <= maxUserFullNameLength else { return nil }
|
|
guard !looksLikeLoginHandle(fullName) else { return nil }
|
|
|
|
guard let first = fullName.split(separator: " ").first.map(String.init),
|
|
!first.isEmpty,
|
|
first.allSatisfy(isNamePart) else { return nil }
|
|
return first
|
|
}
|
|
|
|
/// NSFullUserName() falls back to the short account name when the full name is unset, so a
|
|
/// single lowercase word, or one carrying digits or separators, is treated as a handle.
|
|
private func looksLikeLoginHandle(_ name: String) -> Bool {
|
|
guard !name.contains(" ") else { return false }
|
|
return name == name.lowercased() || name.contains(where: isHandleMarker)
|
|
}
|
|
|
|
private func isHandleMarker(_ character: Character) -> Bool {
|
|
character.isNumber || "._-@".contains(character)
|
|
}
|
|
|
|
private func isNamePart(_ character: Character) -> Bool {
|
|
character.isLetter || character == "'" || character == "-"
|
|
}
|
|
|
|
private let maxUserFullNameLength = 32
|