Repository Public
1// Author: Simon-Pierre Boucher — contact@spboucher.ai2// File: App/DevTour.swift3// Description: Development variant only: walks through every screen of the app and saves a picture of its own window for each (visual checks without capturing the screen, and a smoke test that no screen crashes). The menu bar Command Center is rendered in a window of its own for its picture.4#if SPD_DEV5import AppKit6import SPDriveCore7import SwiftUI89@MainActor10enum DevTour {11 static func snapshot(_ name: String, into dir: URL, window: NSWindow? = nil) {12 let windows = NSApp.windows.filter { $0.isVisible && $0.contentView != nil && !($0.className.contains("StatusBar")) }13 // the sheet when there is one, otherwise the main window14 guard let main = window ?? windows.first(where: { $0.canBecomeMain }) else { return }15 let target = main.attachedSheet ?? main16 guard let view = target.contentView?.superview ?? target.contentView, let rep = view.bitmapImageRepForCachingDisplay(in: view.bounds) else { return }17 view.cacheDisplay(in: view.bounds, to: rep)18 try? rep.representation(using: .png, properties: [:])?.write(to: dir.appendingPathComponent("\(name).png"))19 }20 static func run(_ model: AppModel, into dir: URL) async {21 try? FileManager.default.removeItem(at: dir)22 try? FileManager.default.createDirectory(at: dir, withIntermediateDirectories: true)23 let nav = model.nav24 func pause(_ s: Double) async { try? await Task.sleep(nanoseconds: UInt64(s * 1e9)) }25 func step(_ name: String, wait: Double = 0.9, _ setup: () -> Void) async { setup(); await pause(wait); snapshot(name, into: dir) }26 func sheet(_ name: String, _ kind: SheetKind) async { nav.sheet = kind; await pause(1.6); snapshot(name, into: dir); nav.sheet = nil; await pause(0.7) }27 await pause(2.5)28 let root = model.rootID ?? ""29 let top = model.children(of: root)30 let atelier = top.first { $0.name == "Atelier" } ?? top.first { $0.isFolder }31 let photos = atelier.flatMap { a in model.children(of: a.id).first { $0.name.hasPrefix("Photos") } }32 let client = (atelier.flatMap { a in model.children(of: a.id).first { $0.name.hasPrefix("Dossiers") } }).flatMap { d in model.children(of: d.id).first }33 let docs = client.map { model.children(of: $0.id) } ?? []34 let file = docs.first { !$0.isFolder && $0.versionCount > 1 } ?? docs.first { !$0.isFolder }35 await step("01-drive-list") { nav.section = .drive; nav.folderID = nil; model.settings.gridView = false }36 await step("02-folder-list") { nav.go(to: client?.id); if let file { nav.selection = [file.id] } }37 await step("03-inspector", wait: 1.6) { nav.showInspector = true }38 await step("04-rename-inline") { nav.showInspector = false; nav.renamingID = file?.id }39 await step("05-grid-thumbnails", wait: 2.2) { nav.renamingID = nil; model.settings.gridView = true; nav.go(to: photos?.id); nav.selection = Set(model.children(of: photos?.id ?? "").prefix(1).map(\.id)) }40 await step("06-grid-inspector", wait: 1.6) { nav.showInspector = true }41 await step("07-grid-folders") { nav.showInspector = false; nav.go(to: client?.id) }42 await step("08-palette") { nav.showPalette = true }43 nav.showPalette = false; await pause(0.4)44 await step("09-search") { model.settings.gridView = false; nav.go(to: nil); nav.searchText = "plan" }45 await step("10-search-empty") { nav.searchText = "introuvable-xyz" }46 await step("11-search-filter") { nav.searchText = ""; nav.filter.category = .image }47 await step("12-recent") { nav.filter = LocalSearch(); nav.section = .recent }48 await step("13-favorites") { nav.section = .favorites }49 await step("14-offline") { nav.section = .offline }50 await step("15-shared", wait: 1.5) { nav.section = .shared }51 await step("16-portals", wait: 1.5) { nav.section = .portals }52 await step("17-transfers", wait: 1.2) { nav.section = .transfers }53 await step("18-conflicts") { nav.section = .conflicts }54 await step("19-trash") { nav.section = .trash }55 await step("20-storage", wait: 1.5) { nav.section = .storage }56 nav.section = .drive; nav.go(to: client?.id); await pause(0.5)57 if let file {58 await sheet("21-sheet-share", .share(file)); await sheet("22-sheet-versions", .versions(file)); await sheet("23-sheet-move", .move([file]))59 }60 if let atelier { await sheet("24-sheet-portal", .portal(folder: atelier)) }61 await sheet("25-sheet-newfolder", .newFolder(parent: root))62 // SP Drive 2.0 screens (only what the connected server offers)63 if model.has(.contentSearch) { await step("30-search-content", wait: 2.2) { nav.section = .drive; nav.go(to: nil); nav.searchText = "couleur" }; nav.searchText = "" }64 if model.has(.semantic) { await step("31-search-semantic", wait: 2.5) { nav.searchText = "choix de typographie"; nav.searchSemantic = true }; nav.searchSemantic = false; nav.searchText = "" }65 if model.isAvailable(.collections) { await step("32-collection", wait: 1.6) { nav.collectionID = model.collections.first?.id; nav.section = .collections }; await sheet("33-sheet-collection-rule", .collection(model.collections.first)) }66 if model.isAvailable(.sharedWithMe) { await step("34-shared-with-me", wait: 1.5) { nav.section = .sharedWithMe } }67 if model.isAvailable(.activity) { await step("35-activity", wait: 1.6) { nav.section = .activity } }68 if model.has(.storage) { await step("36-storage-center", wait: 2.5) { nav.section = .storage } }69 if model.isAvailable(.admin) { await step("37-admin", wait: 1.8) { nav.section = .admin } }70 nav.section = .drive; nav.go(to: client?.id); await pause(0.5)71 if let file, model.has(.ai) { nav.sheet = .ask(file); await pause(1.8); snapshot("38-sheet-ask", into: dir); nav.sheet = nil; await pause(0.7) }72 if let atelier, model.has(.collab) { await sheet("39-sheet-members", .members(atelier)) }73 if let c = model.conflicts.first(where: \.isOpen) { nav.sheet = .conflict(c); await pause(3.0); snapshot("26-sheet-conflict", into: dir); nav.sheet = nil; await pause(0.7) }74 // the Command Center, in a plain window (the status item's own popover cannot be opened from code)75 let host = NSWindow(contentRect: NSRect(x: 0, y: 0, width: 348, height: 10), styleMask: [.titled], backing: .buffered, defer: false)76 host.isReleasedWhenClosed = false77 host.contentView = NSHostingView(rootView: MenuBarView().environment(model).background(SPDTheme.surfaceRaised))78 host.setContentSize(host.contentView?.fittingSize ?? NSSize(width: 348, height: 480))79 if let m = NSApp.windows.first(where: { $0.isVisible && $0.canBecomeMain }) { host.setFrameOrigin(NSPoint(x: m.frame.minX + 40, y: m.frame.minY + 40)) }80 host.orderFront(nil); await pause(1.2)81 snapshot("27-menubar-command-center", into: dir, window: host)82 host.orderOut(nil)83 try? "done".write(to: dir.appendingPathComponent("done.txt"), atomically: true, encoding: .utf8)84 }85}86#endif87