From f1eeb8ed3bfca9404ae85320b299662a3d65cbcd Mon Sep 17 00:00:00 2001 From: Pranauv Muthuraman Date: Tue, 22 Sep 2026 18:31:09 -0700 Subject: [PATCH] Play the launch intro with its sound on every cold launch, not only during onboarding --- holmes/holmes/App/AppDelegate.swift | 7 ++- .../Views/Onboarding/LaunchIntroView.swift | 59 +++++++++++++++++++ 2 files changed, 65 insertions(+), 1 deletion(-) diff --git a/holmes/holmes/App/AppDelegate.swift b/holmes/holmes/App/AppDelegate.swift index 344132e..6e6e969 100644 --- a/holmes/holmes/App/AppDelegate.swift +++ b/holmes/holmes/App/AppDelegate.swift @@ -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 { diff --git a/holmes/holmes/Views/Onboarding/LaunchIntroView.swift b/holmes/holmes/Views/Onboarding/LaunchIntroView.swift index 46ae20e..c1e2f42 100644 --- a/holmes/holmes/Views/Onboarding/LaunchIntroView.swift +++ b/holmes/holmes/Views/Onboarding/LaunchIntroView.swift @@ -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? + + /// 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()