Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Sources/Auth/HostAccountFlow.swift
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ final class HostAccountFlow: AccountFlow, AccountSignInFlow {
coordinator.isAuthenticated
}

var isRestoringSession: Bool {
coordinator.isRestoringSession
}

var isPresentingSignIn: Bool {
browserSignIn.isPresentingSignIn
}
Expand Down
18 changes: 15 additions & 3 deletions Sources/Auth/StackAccountAvatarView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,21 @@ struct StackAccountAvatarView: View {
let displayName: String
let email: String
let size: CGFloat
var loadingSystemName: String? = nil

var body: some View {
Group {
if let avatarURL {
AsyncImage(url: avatarURL) { phase in
if let image = phase.image {
image.resizable().scaledToFill()
} else if phase.error == nil, let loadingSystemName {
CmuxSystemSymbolImage(
systemName: loadingSystemName,
pointSize: size,
weight: .regular
)
.foregroundStyle(Color(nsColor: .secondaryLabelColor))
} else {
fallback
}
Expand All @@ -30,22 +38,26 @@ struct StackAccountAvatarView: View {

private var fallback: some View {
ZStack {
Circle().fill(Color.accentColor.opacity(0.18))
Circle().fill(fallbackForegroundColor.opacity(0.18))
if let initial {
Text(verbatim: initial)
.cmuxFont(size: max(8, size * 0.4), weight: .semibold)
.foregroundStyle(Color.accentColor)
.foregroundStyle(fallbackForegroundColor)
} else {
CmuxSystemSymbolImage(
systemName: "person.fill",
pointSize: max(8, size * 0.45),
weight: .medium
)
.foregroundStyle(Color.accentColor)
.foregroundStyle(fallbackForegroundColor)
}
}
}

private var fallbackForegroundColor: Color {
loadingSystemName == nil ? Color.accentColor : Color(nsColor: .secondaryLabelColor)
}

private var initial: String? {
let trimmedName = displayName.trimmingCharacters(in: .whitespacesAndNewlines)
let source = trimmedName.isEmpty ? email : trimmedName
Expand Down
21 changes: 15 additions & 6 deletions Sources/VerticalTabsSidebar+EmptyAreasAndFooter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,10 @@ struct SidebarAccountButtonPresentation: Equatable {

static func resolve(
isSignedIn: Bool,
prefersProfileIcon: Bool
prefersProfileIcon: Bool,
isRestoringSession: Bool = false
) -> SidebarAccountButtonPresentation {
if isSignedIn, !prefersProfileIcon {
if isSignedIn, !prefersProfileIcon, !isRestoringSession {
return SidebarAccountButtonPresentation(
visual: .profilePicture,
size: SidebarFooterButtonMetrics.profilePictureSize
Expand Down Expand Up @@ -257,10 +258,14 @@ struct SidebarAccountMenuButton: View {
#endif
}

private func presentation(isSignedIn: Bool) -> SidebarAccountButtonPresentation {
private func presentation(
isSignedIn: Bool,
isRestoringSession: Bool
) -> SidebarAccountButtonPresentation {
let presentation = SidebarAccountButtonPresentation.resolve(
isSignedIn: isSignedIn,
prefersProfileIcon: prefersProfileIcon
prefersProfileIcon: prefersProfileIcon,
isRestoringSession: isRestoringSession
)
#if DEBUG
if !presentation.showsProfilePicture {
Expand All @@ -277,7 +282,10 @@ struct SidebarAccountMenuButton: View {
let identity = accountFlow?.currentIdentity
let isSignedIn = identity != nil
let buttonTitle = isSignedIn ? title : signInTitle
let presentation = presentation(isSignedIn: isSignedIn)
let presentation = presentation(
isSignedIn: isSignedIn,
isRestoringSession: accountFlow?.isRestoringSession == true
)
Button {
if isSignedIn {
isPopoverPresented.toggle()
Expand Down Expand Up @@ -422,7 +430,8 @@ struct SidebarAccountAvatar: View {
avatarURL: avatarURL,
displayName: displayName,
email: email,
size: size
size: size,
loadingSystemName: signedOutSystemName
)
} else {
SidebarFooterCircularIcon(
Expand Down
6 changes: 6 additions & 0 deletions cmuxTests/WorkspaceContentViewVisibilityTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,11 @@ final class WorkspaceContentViewVisibilityTests {
isSignedIn: false,
prefersProfileIcon: false
)
let restoringSignedInIcon = SidebarAccountButtonPresentation.resolve(
isSignedIn: true,
prefersProfileIcon: false,
isRestoringSession: true
)

#expect(picture.visual == .profilePicture)
#expect(picture.size == SidebarFooterButtonMetrics.accountAndHelpVisualSize)
Expand All @@ -474,6 +479,7 @@ final class WorkspaceContentViewVisibilityTests {
)
#expect(toggledIcon.size == SidebarFooterButtonMetrics.accountAndHelpVisualSize)
#expect(signedOutIcon == toggledIcon)
#expect(restoringSignedInIcon == toggledIcon)
#expect(
SidebarFooterButtonMetrics.profilePictureSize
== SidebarFooterButtonMetrics.helpIconSize
Expand Down