Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump watchOS target and update App related #40

Merged
merged 4 commits into from
Feb 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"location" : "https://github.com/OpenSwiftUIProject/OpenGraph",
"state" : {
"branch" : "main",
"revision" : "6133e9f737077b5c75ff33dee1c2c969cb5d91b4"
"revision" : "45bd9b86eb917e1bd56ead3ef51ca82beca94a70"
}
},
{
Expand Down
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ let package = Package(
.macOS(.v10_15),
.macCatalyst(.v13),
.tvOS(.v13),
.watchOS(.v6),
.watchOS(.v7), // WKApplicationMain is available for watchOS 7.0+
.visionOS(.v1),
],
products: [
Expand Down
2 changes: 0 additions & 2 deletions Sources/OpenSwiftUI/AppStructure/AppOrganization/App.swift
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@
/// }
/// }
///
@available(watchOS 7.0, *)
public protocol App {
/// The type of scene representing the content of the app.
///
Expand Down Expand Up @@ -108,7 +107,6 @@ public protocol App {
init()
}

@available(watchOS 7.0, *)
extension App {
/// Initializes and runs the app.
///
Expand Down
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)
}
}
}
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()
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
// Lastest Version: iOS 15.5
// Status: WIP

#if canImport(Darwin)
import Foundation
#if OPENSWIFTUI_OPENCOMBINE
import OpenCombine
Expand Down Expand Up @@ -39,6 +38,10 @@ class FallbackDelegateBox<Delegate: NSObject>: AnyFallbackDelegateBox {
}

override var delegate: NSObject? {
// FIXME: error: constructing an object of class type 'Delegate' with a metatype value must use a 'required' initializer
#if !canImport(Darwin)
return nil
#else
switch storage {
case let .type(type):
let delegate = type.init()
Expand All @@ -47,6 +50,6 @@ class FallbackDelegateBox<Delegate: NSObject>: AnyFallbackDelegateBox {
case let .instance(delegate):
return delegate
}
#endif
}
}
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,14 @@ private final class OpenSwiftUIApplication: NSApplication {
import Foundation
#endif

@available(watchOS 7.0, *)
func runApp(_ app: some App) -> Never {
#if canImport(Darwin)
let graph = AppGraph(app: app)
graph.startProfilingIfNecessary()
// graph.instantiate()
graph.instantiate()
AppGraph.shared = graph
#endif
KitRendererCommon()
}

@available(watchOS 7.0, *)
private func KitRendererCommon() -> Never {
let argc = CommandLine.argc
let argv = CommandLine.unsafeArgv
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
// Lastest Version: iOS 15.5
// Status: Complete

@available(iOS 13.0, macOS 10.15, tvOS 13.0, watchOS 6.0, *)
@frozen public struct EventModifiers: OptionSet {
public let rawValue: Int
public init(rawValue: Int) {
Expand Down
13 changes: 13 additions & 0 deletions Sources/OpenSwiftUI/Internal/Graph/GraphDelegate.swift
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()
}
43 changes: 38 additions & 5 deletions Sources/OpenSwiftUI/Internal/Graph/GraphHost.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,50 @@
internal import OpenGraphShims

class GraphHost {

// var data: Data
// var isInstantiated: Swift.Bool
var data: Data
var isInstantiated: Bool
// var hostPreferenceValues: OptionalAttribute<PreferenceList>
// var lastHostPreferencesSeed: VersionSeed
// var pendingTransactions: [SwiftUI.(AsyncTransaction in _30C09FF16BC95EC5173809B57186CAC3)]
// var pendingTransactions: [AsyncTransaction]
// var inTransaction: Bool
// var continuations: [() -> ()]
// var mayDeferUpdate: Bool
// var removedState: RemovedState

// FIXME
static var isUpdating = false

// private static let shared = OGGraphCreate()

// MARK: - non final methods

// private static let shared = OGGraphCreate()
init(data: Data) {
self.data = data
isInstantiated = false
// TODO
}

func invalidate() {
// TODO
}

var graphDelegate: GraphDelegate? { nil }
var parentHost: GraphHost? { nil }
func instantiateOutputs() {}
func uninstantiateOutputs() {}
func timeDidChange() {}
func isHiddenForReuseDidChange() {}

// MARK: - final methods

final func instantiate() {
guard !isInstantiated else {
return
}
graphDelegate?.updateGraph { _ in }
instantiateOutputs()
isInstantiated = true
}
}

// MARK: - GraphHost.Data
Expand All @@ -40,6 +69,10 @@ extension GraphHost {
@Attribute
var transaction: Transaction
var inputs: _GraphInputs

init() {
fatalError("TODO")
}
}
}

Expand Down
12 changes: 9 additions & 3 deletions Sources/OpenSwiftUI/Test/_PerformanceTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,24 +35,30 @@ extension _BenchmarkHost {
public func _started(test: _PerformanceTest) {
#if os(iOS)
UIApplication.shared.startedTest(test.name)
#elseif os(macOS)
NSApplication.shared.startedTest(test.name)
#else
fatalError("TODO")
fatalError("Unimplemented for other platform")
#endif
}

public func _finished(test: _PerformanceTest) {
#if os(iOS)
UIApplication.shared.finishedTest(test.name)
#elseif os(macOS)
NSApplication.shared.finishedTest(test.name)
#else
fatalError("TODO")
fatalError("Unimplemented for other platform")
#endif
}

public func _failed(test: _PerformanceTest) {
#if os(iOS)
UIApplication.shared.failedTest(test.name, withFailure: nil)
#elseif os(macOS)
NSApplication.shared.failedTest(test.name, withFailure: nil)
#else
fatalError("TODO")
fatalError("Unimplemented for other platform")
#endif
}
}
1 change: 0 additions & 1 deletion Sources/OpenSwiftUI/Views/View/Extension/View_Font.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ extension View {
}
}

@available(iOS 13.0, *)
extension View {
@inline(__always)
func defaultFont(_ font: Font?) -> some View {
Expand Down
10 changes: 8 additions & 2 deletions Sources/OpenSwiftUIShims/include/OpenSwiftUI_SPI.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,15 @@
- (void)startedTest:(nullable NSString *)name;
- (void)finishedTest:(nullable NSString *)name;
- (void)failedTest:(nullable NSString *)name withFailure:(nullable NSError*)failure;
- (nullable NSString *)_launchTestName;
@end
#elif __has_include(<AppKit/AppKit.h>)
#import <AppKit/AppKit.h>
@interface NSApplication (OpenSwiftUI_SPI)
- (void)startedTest:(nullable NSString *)name;
- (void)finishedTest:(nullable NSString *)name;
- (void)failedTest:(nullable NSString *)name withFailure:(nullable NSError*)failure;
@end
#else

#endif

#endif /* OpenSwiftUI_SPI_h */
Loading