Open History to see the last commit
1import AppKit
2import SpriteKit
3
4@MainActor
5private final class WelcomeExplorerScene: SKScene {
6 private let explorer = ExplorerRig()
7 private var previousTime: TimeInterval?
8 override init(size: CGSize) {
9 super.init(size: size)
10 backgroundColor = .clear
11 let floor = SKShapeNode(rect: .init(x: 5, y: 20, width: 110, height: 12), cornerRadius: 2)
12 floor.fillColor = NotebookTheme.leather.withAlphaComponent(0.045); floor.strokeColor = .clear; floor.zPosition = -20; addChild(floor)
13 let edge = CGMutablePath(); edge.move(to: .init(x: 5, y: 32)); edge.addLine(to: .init(x: 115, y: 32))
14 let floorEdge = SKShapeNode(path: edge); floorEdge.strokeColor = NotebookTheme.leather.withAlphaComponent(0.3); floorEdge.lineWidth = 1; floorEdge.zPosition = -19; addChild(floorEdge)
15 explorer.position = .init(x: 60, y: 32)
16 explorer.setScale(1.35)
17 addChild(explorer)
18 // The illustrated ledge occludes the drop shadow just like a real window.
19 explorer.setShadowOcclusion(windows: [.init(x: -100, y: -100, width: 320, height: 132)], from: self)
20 }
21 required init?(coder: NSCoder) { fatalError("Use init(size:)") }
22 override func update(_ currentTime: TimeInterval) {
23 explorer.render(delta: previousTime.map { min(0.1, max(0, currentTime - $0)) } ?? 0)
24 previousTime = currentTime
25 }
26}
27
28enum ExplorerControls {
29 @MainActor static var rows: [[String]] { [
30 [GlobalShortcutAction.ask.display, "Ask Jerry, from any app"], [GlobalShortcutAction.control.display, "Take or release control"],
31 ["Arrows / WASD", "Move, climb or swing; Up grabs a hold"],
32 ["Shift", "Run or climb faster"], ["Space", "Jump"], ["↓", "Step off an edge and parachute"],
33 ["Hold G + arrows", "Aim the grappling hook; release G to fire"],
34 ["Hold C", "Crouch"], ["Option + C", "Crouch and reach lower"],
35 ["E", "Click at Jerry’s hand, including on ropes"],
36 ["Return", "Ask Jerry"], ["Esc", "Return to your previous app"]
37 ] }
38 @MainActor static var groups: [(String, [[String]])] { [
39 ("From any app", [rows[1], rows[0]]),
40 ("Movement", [rows[2], rows[4], rows[3], rows[5], rows[7], rows[11]]),
41 ("Tools & tasks", [rows[6], rows[8], rows[9], rows[10]])
42 ] }
43}
44
45/// A short, permission-free introduction. The full reference lives in Settings.
46@MainActor
47final class WelcomeController: NSWindowController, NSWindowDelegate {
48 var onIdleChanged: ((Bool) -> Void)?
49 var onTakeControl: (() -> Void)?
50 var onSetupAI: (() -> Void)?
51 var onClose: (() -> Void)?
52 private let illustration = SKView()
53 private var controlShortcutLabel: NSTextField!
54 private var askShortcutLabel: NSTextField!
55 init() {
56 let window = NotebookWindow(contentRect: .init(x: 0, y: 0, width: 560, height: 450), styleMask: [.titled, .closable, .miniaturizable, .fullSizeContentView], backing: .buffered, defer: false)
57 window.title = "Welcome to Jerry"; window.titlebarAppearsTransparent = true
58 window.isReleasedWhenClosed = false
59 super.init(window: window); window.delegate = self; window.center()
60 let root = NotebookTheme.install(on: window, title: "Welcome", showsCaption: false)
61 let content = NSStackView(); content.orientation = .vertical; content.alignment = .leading; content.spacing = 16
62 content.translatesAutoresizingMaskIntoConstraints = false; root.addSubview(content)
63 NSLayoutConstraint.activate([content.leadingAnchor.constraint(equalTo: root.leadingAnchor, constant: 32), content.trailingAnchor.constraint(equalTo: root.trailingAnchor, constant: -32), content.topAnchor.constraint(equalTo: root.topAnchor, constant: 18)])
64 let header = NSStackView(); header.spacing = 20; header.alignment = .centerY
65 illustration.allowsTransparency = true; illustration.preferredFramesPerSecond = 30; illustration.setAccessibilityElement(false)
66 illustration.presentScene(WelcomeExplorerScene(size: .init(width: 120, height: 148)))
67 illustration.widthAnchor.constraint(equalToConstant: 120).isActive = true; illustration.heightAnchor.constraint(equalToConstant: 148).isActive = true
68 let intro = NSStackView(); intro.orientation = .vertical; intro.alignment = .leading; intro.spacing = 9
69 intro.addArrangedSubview(text("Meet Jerry.", size: 30, weight: .semibold, serif: true))
70 intro.addArrangedSubview(text("Your personal\ndesktop explorer.", size: 15))
71 header.addArrangedSubview(illustration); header.addArrangedSubview(intro); content.addArrangedSubview(header)
72 content.addArrangedSubview(text("Take control and turn your desktop into an adventure, or give Jerry a mission. He keeps a journal along the way.", size: 13))
73 let shortcuts = NSStackView(); shortcuts.orientation = .vertical; shortcuts.alignment = .leading; shortcuts.spacing = 9
74 controlShortcutLabel = text("", size: 12, weight: .medium); askShortcutLabel = text("", size: 12, weight: .medium)
75 shortcuts.addArrangedSubview(controlShortcutLabel); shortcuts.addArrangedSubview(askShortcutLabel)
76 let playHint = text("In control: arrows move · Space jumps · Esc returns.", size: 11); playHint.textColor = NotebookTheme.faded
77 shortcuts.addArrangedSubview(playHint)
78 content.addArrangedSubview(shortcuts)
79 let note = text("Between expeditions, he explores your windows looking for patterned socks. Drag him aside whenever he’s in the way.", size: 12); note.textColor = NotebookTheme.faded; content.addArrangedSubview(note)
80 let actions = NSStackView(); actions.spacing = 10
81 let setup = NSButton(title: "Set up AI…", target: self, action: #selector(setupAI)); setup.isBordered = false; setup.contentTintColor = NotebookTheme.faded
82 let github = NSButton(title: "GitHub ↗", target: self, action: #selector(openGitHub)); github.isBordered = false; github.contentTintColor = NotebookTheme.faded
83 let spacer = NSView(); spacer.setContentHuggingPriority(.defaultLow, for: .horizontal)
84 let control = NSButton(title: "Try Controls", target: self, action: #selector(takeControl)); control.bezelStyle = .rounded
85 let start = NSButton(title: "Let’s Go", target: self, action: #selector(startExploring)); start.bezelStyle = .rounded; start.keyEquivalent = "\r"
86 NotebookTheme.style(control); NotebookTheme.style(start, primary: true)
87 [setup, github, spacer, control, start].forEach { actions.addArrangedSubview($0) }
88 content.addArrangedSubview(actions)
89 for view in [header, shortcuts, actions] { view.widthAnchor.constraint(equalTo: content.widthAnchor).isActive = true }
90 }
91 required init?(coder: NSCoder) { fatalError("Use init()") }
92 private func text(_ value: String, size: CGFloat, weight: NSFont.Weight = .regular, serif: Bool = false) -> NSTextField {
93 let label = NSTextField(wrappingLabelWithString: value)
94 label.font = NotebookTheme.font(size, weight: weight, italic: serif)
95 label.textColor = NotebookTheme.ink
96 label.setContentCompressionResistancePriority(.required, for: .vertical)
97 label.preferredMaxLayoutWidth = 476
98 return label
99 }
100 func open(idleExploration: Bool) {
101 controlShortcutLabel.stringValue = GlobalShortcutAction.control.display + " Take control"
102 askShortcutLabel.stringValue = GlobalShortcutAction.ask.display + " Give Jerry a mission"
103 illustration.isPaused = false; NSApp.activate(ignoringOtherApps: true); window?.makeKeyAndOrderFront(nil) }
104 @objc private func openGitHub() { NSWorkspace.shared.open(URL(string: "https://github.com/samwillis/jerry")!) }
105 @objc private func startExploring() { onIdleChanged?(true); close() }
106 @objc private func takeControl() { close(); onTakeControl?() }
107 @objc private func setupAI() { close(); onSetupAI?() }
108 func windowWillClose(_ notification: Notification) { illustration.isPaused = true; onClose?() }
109}