1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import SwiftUI
@main
struct OldFellaApp: App {
@State private var model: AppModel
private let defaults: UserDefaults
init() {
AppFont.registerBundledFonts()
let arguments = ProcessInfo.processInfo.arguments
let isUITesting = arguments.contains("-ui-testing")
if isUITesting {
let suite = "com.oldfella.app.ui-tests"
let testDefaults = UserDefaults(suiteName: suite)!
if !arguments.contains("-ui-testing-preserve-defaults") {
testDefaults.removePersistentDomain(forName: suite)
}
if arguments.contains("-ui-testing-start-custom-feed") {
let feed = CustomFeed(
id: "at://did:plc:demo/app.bsky.feed.generator/nature", name: "Nature", avatarURL: nil)
testDefaults.set(try? JSONEncoder().encode(feed), forKey: "oldsky.defaultFeed.demo")
}
if arguments.contains("-ui-testing-three-loading-columns") {
let feed = CustomFeed(
id: "at://did:plc:demo/app.bsky.feed.generator/nature", name: "Nature", avatarURL: nil)
testDefaults.set(3, forKey: "padVisibleColumnCount")
testDefaults.set(
try? JSONEncoder().encode([PadColumn.following, .notifications, PadColumn(feed: feed)]),
forKey: "oldsky.padColumns.demo")
}
defaults = testDefaults
} else {
defaults = .standard
}
let requiresAuthFactor = arguments.contains("-ui-testing-auth-factor")
let threadResponseDelay: UInt64 = arguments.contains("-ui-testing-thread-delay") ? 3_000_000_000 : 0
let service: any BlueskyService =
isUITesting
? MockBlueskyService(
requiresAuthFactorToken: requiresAuthFactor,
restoresAccount: arguments.contains("-ui-testing-signed-in"),
threadResponseDelayNanoseconds: threadResponseDelay,
authorFeedResponseDelayNanoseconds: arguments.contains("-ui-testing-profile-feed-delay")
? 12_000_000_000 : 0,
draftDefaults: defaults
)
: ATProtoBlueskyService()
_model = State(initialValue: AppModel(
service: service, feedDefaults: defaults, signedInAvatar: isUITesting ? nil : SignedInAvatarStore()
))
}
var body: some Scene {
WindowGroup {
RootView()
.appDefaultFont()
.defaultAppStorage(defaults)
.tint(AppPalette.accent)
.progressViewStyle(AppProgressViewStyle())
.preferredColorScheme(ProcessInfo.processInfo.arguments.contains("-ui-testing-dark") ? .dark : nil)
.environment(model)
.overlay(alignment: .topTrailing) { ViewUpdateMetricsPanel() }
}
}
}