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
7 changes: 6 additions & 1 deletion holmes/holmes/App/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,16 @@ class AppDelegate: NSObject, NSApplicationDelegate {

@MainActor
private func handleAuthAndLaunch() async {
// Every cold launch opens with the brand intro. The first run plays it
// inside onboarding; later launches play it on its own while the
// session restores, and the app starts once it ends.
let hasCompletedOnboarding = UserDefaults.standard.bool(forKey: "hasCompletedOnboarding")
let intro = hasCompletedOnboarding ? Task { await LaunchIntroWindowController.shared.play() } : nil
// Holmes requires an account. The SDK keeps the session between
// launches, so this only asks when no valid session exists.
let signedIn = await AuthService.shared.restoreSession()
await intro?.value
observeSignOut()
let hasCompletedOnboarding = UserDefaults.standard.bool(forKey: "hasCompletedOnboarding")
if !hasCompletedOnboarding {
showOnboarding(requiresSignIn: !signedIn)
} else if signedIn {
Expand Down
59 changes: 59 additions & 0 deletions holmes/holmes/Views/Onboarding/LaunchIntroView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,65 @@ struct LaunchIntroView: NSViewRepresentable {
}
}

// MARK: - Launch intro window
// Returning launches have no onboarding window to play the intro over, so it
// plays on its own in a borderless, transparent window centered on the screen.
// The first run still plays it inside onboarding. Reduce Motion skips it.
@MainActor
final class LaunchIntroWindowController {
static let shared = LaunchIntroWindowController()

private var window: NSWindow?
private var continuation: CheckedContinuation<Void, Never>?

/// Returns once the intro ends or is clicked away.
func play() async {
guard window == nil, !NSWorkspace.shared.accessibilityDisplayShouldReduceMotion else { return }
await withCheckedContinuation { continuation in
self.continuation = continuation
show()
}
}

private func show() {
let root = LaunchIntroView(onFinish: { [weak self] in self?.finish() })
.overlay {
// Click anywhere to skip.
Color.clear
.contentShape(Rectangle())
.onTapGesture { [weak self] in self?.finish() }
}

// The clip is 16:9 with a transparent background.
let window = NSWindow(
contentRect: NSRect(x: 0, y: 0, width: 800, height: 450),
styleMask: [.borderless],
backing: .buffered,
defer: false
)
window.isOpaque = false
window.backgroundColor = .clear
window.hasShadow = false
window.level = .floating
window.isReleasedWhenClosed = false
window.contentView = NSHostingView(rootView: root)
window.center()
window.orderFrontRegardless()
self.window = window
NSApp.activate(ignoringOtherApps: true)
}

private func finish() {
guard let continuation else { return }
self.continuation = nil
window?.orderOut(nil)
// Dropping the hosting view dismantles the player, which stops playback.
window?.contentView = nil
window = nil
continuation.resume()
}
}

final class PlayerLayerView: NSView {
let playerLayer = AVPlayerLayer()

Expand Down
Loading