Skip to content

Commit 8a145a4

Browse files
committed
Update AppGraph
1 parent c5be89b commit 8a145a4

File tree

6 files changed

+119
-28
lines changed

6 files changed

+119
-28
lines changed
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
//
2+
// AppGraph.swift
3+
// OpenSwiftUI
4+
//
5+
// Created by Kyle on 2023/9/22.
6+
// Lastest Version: iOS 15.5
7+
// Status: WIP
8+
// ID: A363922CEBDF47986D9772B903C8737A
9+
10+
#if canImport(Darwin)
11+
import Darwin
12+
#elseif canImport(Glibc)
13+
import Glibc
14+
#elseif os(WASI)
15+
import WASILibc
16+
#endif
17+
18+
final class AppGraph: GraphHost {
19+
static var shared: AppGraph? = nil
20+
static var delegateBox: AnyFallbackDelegateBox? = nil
21+
22+
private struct LaunchProfileOptions: OptionSet {
23+
let rawValue: Int32
24+
25+
static var enable: LaunchProfileOptions { .init(rawValue: 1 << 1) }
26+
}
27+
28+
private lazy var launchProfileOptions: LaunchProfileOptions = {
29+
let env = getenv("SWIFTUI_PROFILE_LAUNCH")
30+
if let env {
31+
return .init(rawValue: atoi(env))
32+
} else {
33+
return []
34+
}
35+
}()
36+
37+
var didCollectLaunchProfile: Bool = false
38+
39+
init(app _: some App) {}
40+
41+
func extendedLaunchTestName() -> String? { nil }
42+
43+
func startProfilingIfNecessary() {
44+
guard !didCollectLaunchProfile else {
45+
return
46+
}
47+
48+
if launchProfileOptions.contains(.enable) {
49+
// AGGraphStartProfiling
50+
}
51+
}
52+
53+
func stopProfilingIfNecessary() {
54+
guard !didCollectLaunchProfile else {
55+
return
56+
}
57+
didCollectLaunchProfile = true
58+
59+
if launchProfileOptions.contains(.enable) {
60+
// AGGraphStopProfiling
61+
}
62+
63+
if launchProfileOptions.rawValue != 0 {
64+
// AGGraphArchiveJSON
65+
}
66+
}
67+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
//
2+
// FinishLaunchTestAction.swift
3+
// OpenSwiftUI
4+
//
5+
// Created by Kyle on 2024/2/25.
6+
// Lastest Version: iOS 15.5
7+
// Status: Complete
8+
9+
#if os(iOS)
10+
import UIKit
11+
#elseif os(macOS)
12+
import AppKit
13+
#endif
14+
15+
struct FinishLaunchTestAction {
16+
func callAsFunction() {
17+
AppGraph.shared?.stopProfilingIfNecessary()
18+
#if os(iOS)
19+
UIApplication.shared.finishedTest(UIApplication.shared._launchTestName())
20+
#else
21+
fatalError("Unimplemented for other platform")
22+
#endif
23+
}
24+
}
25+
26+
extension EnvironmentValues {
27+
var finishLaunchTest: FinishLaunchTestAction {
28+
FinishLaunchTestAction()
29+
}
30+
}

Sources/OpenSwiftUI/AppStructure/AppOrganization/TODO/AppGraph.swift

Lines changed: 0 additions & 21 deletions
This file was deleted.

Sources/OpenSwiftUI/AppStructure/AppOrganization/TODO/FallbackDelegateBox.swift

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
// Lastest Version: iOS 15.5
77
// Status: WIP
88

9-
#if canImport(Darwin)
109
import Foundation
1110
#if OPENSWIFTUI_OPENCOMBINE
1211
import OpenCombine
@@ -39,6 +38,10 @@ class FallbackDelegateBox<Delegate: NSObject>: AnyFallbackDelegateBox {
3938
}
4039

4140
override var delegate: NSObject? {
41+
// FIXME: error: constructing an object of class type 'Delegate' with a metatype value must use a 'required' initializer
42+
#if !canImport(Darwin)
43+
return nil
44+
#else
4245
switch storage {
4346
case let .type(type):
4447
let delegate = type.init()
@@ -47,6 +50,6 @@ class FallbackDelegateBox<Delegate: NSObject>: AnyFallbackDelegateBox {
4750
case let .instance(delegate):
4851
return delegate
4952
}
53+
#endif
5054
}
5155
}
52-
#endif

Sources/OpenSwiftUI/Test/_PerformanceTest.swift

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,24 +35,30 @@ extension _BenchmarkHost {
3535
public func _started(test: _PerformanceTest) {
3636
#if os(iOS)
3737
UIApplication.shared.startedTest(test.name)
38+
#elseif os(macOS)
39+
NSApplication.shared.startedTest(test.name)
3840
#else
39-
fatalError("TODO")
41+
fatalError("Unimplemented for other platform")
4042
#endif
4143
}
4244

4345
public func _finished(test: _PerformanceTest) {
4446
#if os(iOS)
4547
UIApplication.shared.finishedTest(test.name)
48+
#elseif os(macOS)
49+
NSApplication.shared.finishedTest(test.name)
4650
#else
47-
fatalError("TODO")
51+
fatalError("Unimplemented for other platform")
4852
#endif
4953
}
5054

5155
public func _failed(test: _PerformanceTest) {
5256
#if os(iOS)
5357
UIApplication.shared.failedTest(test.name, withFailure: nil)
58+
#elseif os(macOS)
59+
NSApplication.shared.failedTest(test.name, withFailure: nil)
5460
#else
55-
fatalError("TODO")
61+
fatalError("Unimplemented for other platform")
5662
#endif
5763
}
5864
}

Sources/OpenSwiftUIShims/include/OpenSwiftUI_SPI.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,15 @@
1414
- (void)startedTest:(nullable NSString *)name;
1515
- (void)finishedTest:(nullable NSString *)name;
1616
- (void)failedTest:(nullable NSString *)name withFailure:(nullable NSError*)failure;
17+
- (nullable NSString *)_launchTestName;
18+
@end
19+
#elif __has_include(<AppKit/AppKit.h>)
20+
#import <AppKit/AppKit.h>
21+
@interface NSApplication (OpenSwiftUI_SPI)
22+
- (void)startedTest:(nullable NSString *)name;
23+
- (void)finishedTest:(nullable NSString *)name;
24+
- (void)failedTest:(nullable NSString *)name withFailure:(nullable NSError*)failure;
1725
@end
18-
#else
19-
2026
#endif
2127

2228
#endif /* OpenSwiftUI_SPI_h */

0 commit comments

Comments
 (0)