@webspatial/platform-visionos 0.0.2 → 0.0.3-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -14,6 +14,25 @@ class SpatialWindowContainer: SpatialObject {
|
|
|
14
14
|
|
|
15
15
|
// Resources that will be destroyed when this window group is removed
|
|
16
16
|
private var childResources = [String: SpatialObject]()
|
|
17
|
+
public func addChildResource(_ spatialObject: SpatialObject) {
|
|
18
|
+
childResources[spatialObject.id] = spatialObject
|
|
19
|
+
spatialObject
|
|
20
|
+
.on(
|
|
21
|
+
event: SpatialObject.Events.BeforeDestroyed.rawValue,
|
|
22
|
+
listener: onSptatialObjectDestroyed
|
|
23
|
+
)
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
private func onSptatialObjectDestroyed(_ object: Any, _ data: Any) {
|
|
27
|
+
let spatialObject = object as! SpatialObject
|
|
28
|
+
spatialObject
|
|
29
|
+
.off(
|
|
30
|
+
event: SpatialObject.Events.BeforeDestroyed.rawValue,
|
|
31
|
+
listener: onSptatialObjectDestroyed
|
|
32
|
+
)
|
|
33
|
+
childResources.removeValue(forKey: spatialObject.id)
|
|
34
|
+
}
|
|
35
|
+
|
|
17
36
|
public var childContainers = [String: SpatialWindowContainer]()
|
|
18
37
|
|
|
19
38
|
var wgd: WindowContainerData
|
|
@@ -128,8 +128,8 @@ class CommandManager {
|
|
|
128
128
|
}
|
|
129
129
|
|
|
130
130
|
private func setComponent(target: SpatialWindowComponent, info: CommandInfo) {
|
|
131
|
-
if let component =
|
|
132
|
-
let entity =
|
|
131
|
+
if let component = SpatialObject.get(info.resourceID) as? SpatialComponent,
|
|
132
|
+
let entity = SpatialObject.get(info.entityID) as? SpatialEntity
|
|
133
133
|
{
|
|
134
134
|
entity.addComponent(component)
|
|
135
135
|
} else {
|
|
@@ -147,6 +147,15 @@ class CommandManager {
|
|
|
147
147
|
}
|
|
148
148
|
}
|
|
149
149
|
|
|
150
|
+
private static func setParentResourceDependencies(object: SpatialObject, info: CommandInfo) {
|
|
151
|
+
if let parentWindowComponent = SpatialObject.get(info.resourceID) as? SpatialWindowComponent {
|
|
152
|
+
parentWindowComponent.addChildSpatialObject(object)
|
|
153
|
+
}
|
|
154
|
+
if let parentWindowContainer = SpatialWindowContainer.getSpatialWindowContainer(info.windowContainerID) {
|
|
155
|
+
parentWindowContainer.addChildResource(object)
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
|
|
150
159
|
private func createResource(target: SpatialWindowComponent, info: CommandInfo) {
|
|
151
160
|
let data = info.cmd.data!
|
|
152
161
|
if let type = data.type {
|
|
@@ -165,9 +174,11 @@ class CommandManager {
|
|
|
165
174
|
case "PhysicallyBasedMaterial":
|
|
166
175
|
sr = SpatialPhysicallyBasedMaterial(PhysicallyBasedMaterial())
|
|
167
176
|
case "SpatialWebView":
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
177
|
+
if let parentWindowContainer = SpatialWindowContainer.getSpatialWindowContainer(info.windowContainerID) {
|
|
178
|
+
sr = SpatialWindowComponent(parentWindowContainerID: parentWindowContainer.id)
|
|
179
|
+
let spatialWindowComponent = sr as! SpatialWindowComponent
|
|
180
|
+
spatialWindowComponent.parentWebviewID = target.id
|
|
181
|
+
}
|
|
171
182
|
case "SpatialView":
|
|
172
183
|
sr = SpatialViewComponent()
|
|
173
184
|
case "Model3DComponent":
|
|
@@ -206,8 +217,8 @@ class CommandManager {
|
|
|
206
217
|
|
|
207
218
|
Task.detached { @MainActor in
|
|
208
219
|
// Update state on main thread
|
|
220
|
+
CommandManager.setParentResourceDependencies(object: spatialModelComponent, info: info)
|
|
209
221
|
target.completeEvent(requestID: info.requestID, data: "{createdID: '" + spatialModelComponent.id + "'}")
|
|
210
|
-
target.addChildSpatialObject(spatialModelComponent)
|
|
211
222
|
logger.debug("Model load success!")
|
|
212
223
|
}
|
|
213
224
|
} catch {
|
|
@@ -224,8 +235,8 @@ class CommandManager {
|
|
|
224
235
|
default: logger.warning("failed to create sr of type \(type)")
|
|
225
236
|
}
|
|
226
237
|
if let srObject = sr {
|
|
238
|
+
CommandManager.setParentResourceDependencies(object: srObject, info: info)
|
|
227
239
|
target.completeEvent(requestID: info.requestID, data: "{createdID: '" + srObject.id + "'}")
|
|
228
|
-
target.addChildSpatialObject(srObject)
|
|
229
240
|
} else {
|
|
230
241
|
logger.warning("failed to create sr of type: \(type)")
|
|
231
242
|
}
|
|
@@ -11,15 +11,19 @@ let logger = Logger()
|
|
|
11
11
|
|
|
12
12
|
// To load a local path, remove http:// eg. "static-web/"
|
|
13
13
|
let nativeAPIVersion = "0.0.1"
|
|
14
|
+
// start URL
|
|
15
|
+
let startURL = pwaManager.start_url
|
|
14
16
|
|
|
15
17
|
// detect when app properties like defaultSize change so we can avoid race condition of setting default values and then opening window container
|
|
16
18
|
var sceneStateChangedCB: ((Any) -> Void) = { _ in
|
|
17
19
|
}
|
|
18
20
|
|
|
21
|
+
// TODO: we need to get rid of rootWGD and rootWC to cleanup memory and better handle close/reopen
|
|
22
|
+
weak var rootWC: SpatialWindowComponent?
|
|
23
|
+
|
|
19
24
|
@main
|
|
20
25
|
struct web_spatialApp: App {
|
|
21
26
|
@UIApplicationDelegateAdaptor(AppDelegate.self) var appDelegate
|
|
22
|
-
@State var root: SpatialWindowComponent? = nil
|
|
23
27
|
@State var rootWGD: SpatialWindowContainer
|
|
24
28
|
@State var initialLaunch = true
|
|
25
29
|
|
|
@@ -28,7 +32,7 @@ struct web_spatialApp: App {
|
|
|
28
32
|
@Environment(\.scenePhase) private var scenePhase
|
|
29
33
|
|
|
30
34
|
init() {
|
|
31
|
-
logger.debug("WebSpatial App Started --------")
|
|
35
|
+
logger.debug("WebSpatial App Started -------- rootURL: " + startURL)
|
|
32
36
|
|
|
33
37
|
// init global logger
|
|
34
38
|
Logger.initLogger()
|
|
@@ -48,7 +52,7 @@ struct web_spatialApp: App {
|
|
|
48
52
|
// There seems to be a bug in WKWebView where it needs to be initialized after the app has loaded so we do this here instead of init()
|
|
49
53
|
// https://forums.developer.apple.com/forums/thread/61432
|
|
50
54
|
func initAppOnViewMount() {
|
|
51
|
-
if
|
|
55
|
+
if rootWC == nil {
|
|
52
56
|
let fileUrl = getFileUrl()
|
|
53
57
|
|
|
54
58
|
// Create a default entity with webview resource
|
|
@@ -58,7 +62,9 @@ struct web_spatialApp: App {
|
|
|
58
62
|
rootEntity.addComponent(windowComponent)
|
|
59
63
|
rootEntity.setParentWindowContainer(wg: rootWGD)
|
|
60
64
|
|
|
61
|
-
|
|
65
|
+
rootWGD.addChildResource(windowComponent)
|
|
66
|
+
rootWGD.addChildResource(rootEntity)
|
|
67
|
+
rootWC = windowComponent
|
|
62
68
|
}
|
|
63
69
|
}
|
|
64
70
|
|
|
@@ -72,14 +78,16 @@ struct web_spatialApp: App {
|
|
|
72
78
|
if windowData.windowContainerID == SpatialWindowContainer.getRootID() {
|
|
73
79
|
VStack {}.onAppear { initAppOnViewMount() }
|
|
74
80
|
|
|
75
|
-
PlainWindowContainerView().environment(rootWGD).background(Color.clear.opacity(0))
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
81
|
+
PlainWindowContainerView().environment(rootWGD).background(Color.clear.opacity(0))
|
|
82
|
+
// TODO: Universal link is currently broken
|
|
83
|
+
// .onOpenURL { myURL in
|
|
84
|
+
// initAppOnViewMount()
|
|
85
|
+
// let urlToLoad = pwaManager.checkInDeeplink(url: myURL.absoluteString)
|
|
86
|
+
//
|
|
87
|
+
// if let url = URL(string: urlToLoad) {
|
|
88
|
+
// // root!.navigateToURL(url: url)
|
|
89
|
+
// }
|
|
90
|
+
// }
|
|
83
91
|
} else {
|
|
84
92
|
let wg = SpatialWindowContainer.getOrCreateSpatialWindowContainer(
|
|
85
93
|
windowData.windowContainerID, windowData
|