Skip to content
Closed
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
149 changes: 102 additions & 47 deletions apps/desktop/Sources/StimDesktop/Design/TutorialAnchors.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import StimKit
import SwiftUI

enum TutorialAnchorID: Hashable {
case sidebarRow, buildSection, cacheBadge, deviceTile, viewerControl, logsTab, agentActions, replay, archivedFilter
case sidebarRow, deviceTile, viewerControl, logsTab, archivedFilter
}

struct TutorialAnchorKey: Hashable {
Expand All @@ -23,30 +23,18 @@ struct TutorialHint {
var selectedPath: String?
var showMe: () -> Void

var anchor: TutorialAnchorID? {
var target: (anchor: TutorialAnchorID, callout: String)? {
switch step {
case "sidebar": return .sidebarRow
case "build": return .buildSection
case "rebuild": return .cacheBadge
case "device": return .deviceTile
case "logs", "refresh": return .logsTab
case "agent": return .agentActions
case "finish", "done": return .archivedFilter
case "sidebar": return (.sidebarRow, "Select the tutorial workspace")
case "device": return (.deviceTile, "Open the live view, then tap Log an error.")
case "logs", "refresh": return (.logsTab, "Open Logs")
case "finish", "done": return (.archivedFilter, "Find the run in Archived")
default: return nil
}
}

var callout: String {
switch step {
case "sidebar": return "Select the tutorial workspace"
case "build": return "Follow the iOS build"
case "rebuild": return "See the cache outcome in build details"
case "device": return "Open the live view, then tap Log an error."
case "logs", "refresh": return "Open Logs"
case "agent": return "Watch Agent actions and Replay"
case "finish", "done": return "Find the run in Archived"
default: return "Follow the tutorial workspace"
}
var offersShowMe: Bool {
["sidebar", "build", "rebuild", "device", "logs", "refresh", "agent", "finish", "done"].contains(step ?? "")
}
}

Expand Down Expand Up @@ -80,38 +68,24 @@ private struct TutorialHighlights: ViewModifier {
func body(content: Content) -> some View {
content.overlayPreferenceValue(TutorialAnchorPreference.self) { anchors in
GeometryReader { geometry in
if let hint, let id = hint.anchor {
if let hint {
let spec = hint.target
let match =
anchors.first {
$0.key.id == id && ($0.key.workspace == nil || $0.key.workspace == hint.path)
} ?? anchors.first {
hint.step == "rebuild" && $0.key.id == .buildSection && $0.key.workspace == hint.path
} ?? anchors.first {
hint.step == "device" && $0.key.id == .viewerControl
$0.key.id == spec?.anchor && ($0.key.workspace == nil || $0.key.workspace == hint.path)
}
?? anchors.first {
hint.step == "agent" && $0.key.id == .replay
hint.step == "device" && $0.key.id == .viewerControl
}
if let match, hint.path == hint.selectedPath || id == .sidebarRow || id == .archivedFilter,
geometry[match.value].intersects(CGRect(origin: .zero, size: geometry.size))
{
let rect = geometry[match.value]
RoundedRectangle(cornerRadius: Radius.control)
.stroke(Palette.accent, lineWidth: 2)
.frame(width: rect.width + 6, height: rect.height + 6)
.position(x: rect.midX, y: rect.midY)
.allowsHitTesting(false)
Text(hint.callout).font(.stim(.footnote, weight: .semibold))
.foregroundStyle(Palette.text)
.padding(.horizontal, Space.md).padding(.vertical, Space.sm)
.background(RoundedRectangle(cornerRadius: Radius.control).fill(Palette.surface))
.fixedSize(horizontal: true, vertical: false)
.position(
x: max(140, min(geometry.size.width - 140, rect.midX)),
y: rect.maxY + 38 < geometry.size.height ? rect.maxY + 22 : max(20, rect.minY - 22)
)
.allowsHitTesting(false)
} else if showFallback, hint.path != nil, hint.path != hint.selectedPath {
let rect = match.map { geometry[$0.value] }
let onPage = hint.path == hint.selectedPath || spec?.anchor == .sidebarRow || spec?.anchor == .archivedFilter
let target = rect.flatMap { onPage && $0.intersects(CGRect(origin: .zero, size: geometry.size)) ? $0 : nil }
if let spec {
TutorialGlow(
rect: target, bounds: geometry.size, callout: spec.callout,
restartKey: "\(hint.step ?? "")|\(hint.selectedPath ?? "")")
}
if target == nil, showFallback, hint.offersShowMe, hint.path != nil, hint.path != hint.selectedPath {
Button("Show Me", action: hint.showMe)
.buttonStyle(.stim(.secondary))
.accessibilityLabel("Show the tutorial workspace")
Expand All @@ -123,3 +97,84 @@ private struct TutorialHighlights: ViewModifier {
}
}
}

private struct TutorialGlow: View {
static let visibleSeconds = 4.0
static let fadeSeconds = 0.6
static let pulsePeriod = 1.4
static let reshowAfterAbsence = 1.0

var rect: CGRect?
var bounds: CGSize
var callout: String
var restartKey: String
@Environment(\.accessibilityReduceMotion) private var reduceMotion
@State private var alive = false
@State private var faded = false
@State private var present = false
@State private var absentSince: Date?
@State private var epoch = 0

var body: some View {
Group {
if alive, let rect {
TimelineView(reduceMotion ? .animation(minimumInterval: 3600) : .animation) { context in
let phase = reduceMotion ? 0 : (sin(context.date.timeIntervalSinceReferenceDate * 2 * .pi / Self.pulsePeriod) + 1) / 2
glow(rect, phase: phase)
}
.opacity(faded ? 0 : 1)
.allowsHitTesting(false)
.accessibilityHidden(true)
}
}
.onChange(of: rect == nil, initial: true) { _, absent in
present = !absent
if absent {
absentSince = Date()
} else {
if let absentSince, Date().timeIntervalSince(absentSince) > Self.reshowAfterAbsence { epoch += 1 }
absentSince = nil
}
}
.task(id: "\(restartKey)|\(epoch)") {
alive = false
faded = false
while !present {
try? await Task.sleep(for: .milliseconds(100))
if Task.isCancelled { return }
}
alive = true
try? await Task.sleep(for: .seconds(Self.visibleSeconds))
if Task.isCancelled { return }
withAnimation(.easeOut(duration: Self.fadeSeconds)) { faded = true }
try? await Task.sleep(for: .seconds(Self.fadeSeconds))
if !Task.isCancelled { alive = false }
}
}

private func glow(_ rect: CGRect, phase: Double) -> some View {
let size = CGSize(width: rect.width + 6, height: rect.height + 6)
let aboveY = rect.minY - 18
return ZStack {
RoundedRectangle(cornerRadius: Radius.control + 3)
.stroke(Palette.accent.opacity(0.45 + 0.25 * phase), lineWidth: 4 + 2 * phase)
.blur(radius: 6 + 2 * phase)
.frame(width: size.width, height: size.height)
.position(x: rect.midX, y: rect.midY)
RoundedRectangle(cornerRadius: Radius.control + 3)
.strokeBorder(Palette.accent.opacity(0.4), lineWidth: 1)
.frame(width: size.width, height: size.height)
.position(x: rect.midX, y: rect.midY)
Text(callout).font(.stim(.footnote, weight: .semibold))
.foregroundStyle(Palette.onPrimary)
.padding(.horizontal, Space.md).padding(.vertical, Space.xs)
.background(Capsule().fill(Palette.accent))
.shadow(color: Palette.accent.opacity(0.4), radius: 6)
.fixedSize(horizontal: true, vertical: false)
.position(
x: max(140, min(bounds.width - 140, rect.midX)),
y: aboveY >= 14 ? aboveY : min(rect.maxY + 18, bounds.height - 14)
)
}
}
}
1 change: 0 additions & 1 deletion apps/desktop/Sources/StimDesktop/Views/BuildSection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,6 @@ struct BuildOutcomeBadge: View {
var body: some View {
if let label = build.outcomeLabel {
Pill(label, tone: build.outcome == "hit" ? .success : .warning, size: .small)
.tutorialAnchor(.cacheBadge)
}
}
}
Expand Down
3 changes: 0 additions & 3 deletions apps/desktop/Sources/StimDesktop/Views/BuildSheet.swift
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ struct BuildSheet: View {
cli: cli, env: app, run: run, archive: archive, logsExpired: logsExpired, readsServer: readsServer,
dismiss: { dismiss() }
)
.tutorialAnchor(.buildSection, workspace: app.path)
.id(page == nil ? run.id : "\(app.path)|\(run.id)")
.padding(Space.xxl)
if archive == nil, run.running == nil, run.id == runs.first?.id { nextBuild }
Expand All @@ -103,7 +102,6 @@ struct BuildSheet: View {
.frame(maxWidth: .infinity, maxHeight: .infinity)
}
}
.tutorialHighlights(showFallback: false)
.font(.stim(.callout))
.background(Palette.background)
.frame(minWidth: 980, idealWidth: 980, minHeight: 720, idealHeight: 720)
Expand Down Expand Up @@ -342,7 +340,6 @@ private struct BuildRunDetail: View {
tone: run.running?.cacheLookupOutcome == "hit" || run.last?.cacheHit == .local || run.last?.cacheHit == .remote
? .success : .warning
)
.tutorialAnchor(.cacheBadge, workspace: env.path)
}
if let reason = run.missReason { MissReasonView(reason: reason) }
if let note = run.running?.recheckNote { Text(note).foregroundStyle(Palette.tertiary) }
Expand Down
1 change: 0 additions & 1 deletion apps/desktop/Sources/StimDesktop/Views/DeviceViewer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,6 @@ struct DeviceViewer: View {
close()
}
)
.tutorialAnchor(.agentActions, workspace: env.path)
.frame(width: Self.actionsWidth)
.background(Palette.sidebar)
}
Expand Down
1 change: 0 additions & 1 deletion apps/desktop/Sources/StimDesktop/Views/ReplayViews.swift
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,6 @@ struct ReplayBar: View {
.buttonStyle(.stim())
.fixedSize()
.help(isLive ? "Pause on the current frame" : playing ? "Pause" : "Play the recording")
.tutorialAnchor(.replay)
.accessibilityLabel(showsPause ? "Pause" : "Play")
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,6 @@ struct WorkspaceDetail: View {
}
.environmentObject(actions)
.environmentObject(checks)
.environment(\.tutorialHint, tutorialHint)
}
.confirmationDialog(
"Delete \(archive?.title ?? "archive") (\(archive?.removedLabel(now: fixtureDate ?? Date()) ?? ""))?",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ struct WorkspaceHeaderLine: View {
gitWorkspace: page?.apps[0].path,
openBuild: openBuild)
}
.tutorialAnchor(.buildSection, workspace: env.path)
Spacer(minLength: Space.md)
if apps.contains(where: \.replayOff) {
Pill("Replay off")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ struct Inspector: View {
cli: cli, env: env, openLogs: openLogs, openBuild: openBuild, readOnly: archive != nil,
totals: archive?.buildTotalsLine
)
.tutorialAnchor(.buildSection, workspace: env.path)
.id(env.path)
}

Expand Down
Loading