forked from OpenSwiftUIProject/OpenSwiftUI
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bump watchOS target and update App related (OpenSwiftUIProject#40)
* Bump watchOS target and fix available issue * Update AppGraph * Update OpenGraph to add profile support * Add GraphDelegate and update App related
- Loading branch information
Showing
14 changed files
with
179 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
Sources/OpenSwiftUI/AppStructure/AppOrganization/Graph/AppGraph.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
// | ||
// AppGraph.swift | ||
// OpenSwiftUI | ||
// | ||
// Created by Kyle on 2023/9/22. | ||
// Lastest Version: iOS 15.5 | ||
// Status: WIP | ||
// ID: A363922CEBDF47986D9772B903C8737A | ||
|
||
#if canImport(Darwin) | ||
import Darwin | ||
#elseif canImport(Glibc) | ||
import Glibc | ||
#elseif os(WASI) | ||
import WASILibc | ||
#endif | ||
internal import OpenGraphShims | ||
|
||
final class AppGraph: GraphHost { | ||
static var shared: AppGraph? = nil | ||
static var delegateBox: AnyFallbackDelegateBox? = nil | ||
|
||
private struct LaunchProfileOptions: OptionSet { | ||
let rawValue: Int32 | ||
static var profile: LaunchProfileOptions { .init(rawValue: 1 << 1) } | ||
} | ||
|
||
private lazy var launchProfileOptions: LaunchProfileOptions = { | ||
let env = getenv("OPENSWIFTUI_PROFILE_LAUNCH") | ||
if let env { | ||
return .init(rawValue: atoi(env)) | ||
} else { | ||
return [] | ||
} | ||
}() | ||
|
||
var didCollectLaunchProfile: Bool = false | ||
|
||
// TODO | ||
init(app: some App) { | ||
let data = GraphHost.Data() | ||
super.init(data: data) | ||
} | ||
|
||
// MARK: - Override Methods | ||
|
||
// MARK: - Profile related | ||
|
||
func extendedLaunchTestName() -> String? { nil } | ||
|
||
func startProfilingIfNecessary() { | ||
guard !didCollectLaunchProfile else { | ||
return | ||
} | ||
if launchProfileOptions.contains(.profile) { | ||
OGGraph.startProfiling() | ||
} | ||
} | ||
|
||
func stopProfilingIfNecessary() { | ||
guard !didCollectLaunchProfile else { | ||
return | ||
} | ||
didCollectLaunchProfile = true | ||
if launchProfileOptions.contains(.profile) { | ||
OGGraph.stopProfiling() | ||
} | ||
if !launchProfileOptions.isEmpty { | ||
// /tmp/graph.ag-gzon | ||
OGGraph.archiveJSON(name: nil) | ||
} | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
Sources/OpenSwiftUI/AppStructure/AppOrganization/Profile/FinishLaunchTestAction.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// | ||
// FinishLaunchTestAction.swift | ||
// OpenSwiftUI | ||
// | ||
// Created by Kyle on 2024/2/25. | ||
// Lastest Version: iOS 15.5 | ||
// Status: Complete | ||
|
||
#if os(iOS) | ||
import UIKit | ||
#elseif os(macOS) | ||
import AppKit | ||
#endif | ||
|
||
struct FinishLaunchTestAction { | ||
func callAsFunction() { | ||
AppGraph.shared?.stopProfilingIfNecessary() | ||
#if os(iOS) | ||
UIApplication.shared.finishedTest(UIApplication.shared._launchTestName()) | ||
#else | ||
fatalError("Unimplemented for other platform") | ||
#endif | ||
} | ||
} | ||
|
||
extension EnvironmentValues { | ||
var finishLaunchTest: FinishLaunchTestAction { | ||
FinishLaunchTestAction() | ||
} | ||
} |
22 changes: 0 additions & 22 deletions
22
Sources/OpenSwiftUI/AppStructure/AppOrganization/TODO/AppGraph.swift
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// | ||
// GraphDelegate.swift | ||
// OpenSwiftUI | ||
// | ||
// Created by Kyle on 2024/2/26. | ||
// Lastest Version: iOS 15.5 | ||
// Status: Complete | ||
|
||
protocol GraphDelegate: AnyObject { | ||
func updateGraph<V>(body: (GraphHost) -> V) -> V | ||
func graphDidChange() | ||
func preferencesDidChange() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters