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
import Foundation
import SwiftUI
/// True when code is running inside an Xcode preview canvas.
/// Use to skip network calls that would block or slow down previews.
var isPreview: Bool {
ProcessInfo.processInfo.environment["XCODE_RUNNING_FOR_PREVIEWS"] == "1"
}
// MARK: - Preview Modifiers
extension XRPCClient {
/// Shared preview client — avoids repeating `XRPCClient(baseURL: AuthManager.serverURL)`.
static var preview: XRPCClient {
XRPCClient(baseURL: AuthManager.serverURL)
}
}
extension View {
/// Applies the standard Grain preview styling: dark mode + accent color.
/// Use on every #Preview so the canvas matches the real app.
func grainPreview() -> some View {
preferredColorScheme(.dark)
.tint(Color.accentColor)
}
/// Injects the standard Grain environment objects required by most previews.
func previewEnvironments() -> some View {
environment(Router())
.environment(AuthManager())
.environment(StoryStatusCache())
.environment(ViewedStoryStorage())
.environment(LabelDefinitionsCache())
.environment(GalleryUploadCenter())
}
}