@webspatial/platform-visionos 0.1.11 → 0.1.14
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 +1 -1
- package/web-spatial/libs/SpatialWindowComponent.swift +14 -0
- package/web-spatial/libs/Utils/CommandManager.swift +14 -4
- package/web-spatial/libs/Utils/version.swift +25 -0
- package/web-spatial/libs/webView/backend/NativeWebView.swift +21 -31
- package/web-spatial/web_spatialApp.swift +6 -2
- package/web-spatial.xcodeproj/project.pbxproj +4 -0
package/package.json
CHANGED
|
@@ -227,6 +227,20 @@ class SpatialWindowComponent: SpatialComponent {
|
|
|
227
227
|
webViewNative!.initialLoad()
|
|
228
228
|
}
|
|
229
229
|
|
|
230
|
+
/// Remove webview window.name
|
|
231
|
+
///
|
|
232
|
+
/// The expectation is that when the app is reopened, the root page should not have a window.name. However, under the current scene mechanism, if the last closed scene had set a window.name, it will still exist the next time the app is opened.
|
|
233
|
+
///
|
|
234
|
+
/// Currently, window.name is only deleted when non-main scenes are closed along with the destruction of the WebView.
|
|
235
|
+
///
|
|
236
|
+
/// the root page should always have a blank name
|
|
237
|
+
|
|
238
|
+
func removeWebviewName(completion: (() -> Void)? = nil) {
|
|
239
|
+
webViewNative?.webViewHolder.appleWebView?.evaluateJavaScript("window.name = '';") { _, _ in
|
|
240
|
+
completion?()
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
|
|
230
244
|
func isScrollEnabled() -> Bool {
|
|
231
245
|
return webViewNative!.webViewHolder.appleWebView!.scrollView.isScrollEnabled
|
|
232
246
|
}
|
|
@@ -492,14 +492,14 @@ class CommandManager {
|
|
|
492
492
|
}
|
|
493
493
|
|
|
494
494
|
if let backgroundMaterial: BackgroundMaterial = data.update?.style?.backgroundMaterial {
|
|
495
|
-
if
|
|
496
|
-
|
|
495
|
+
if spatialWindowComponent.isLoading {
|
|
496
|
+
spatialWindowComponent.loadingStyles.backgroundMaterial = backgroundMaterial
|
|
497
497
|
}
|
|
498
498
|
spatialWindowComponent.backgroundMaterial = backgroundMaterial
|
|
499
499
|
}
|
|
500
500
|
if let cornerRadius: CornerRadius = data.update?.style?.cornerRadius {
|
|
501
|
-
if
|
|
502
|
-
|
|
501
|
+
if spatialWindowComponent.isLoading {
|
|
502
|
+
spatialWindowComponent.loadingStyles.cornerRadius = cornerRadius
|
|
503
503
|
}
|
|
504
504
|
spatialWindowComponent.cornerRadius = cornerRadius
|
|
505
505
|
}
|
|
@@ -617,6 +617,15 @@ class CommandManager {
|
|
|
617
617
|
WindowContainerMgr.Instance.updateWindowContainerPlainDefaultValues(cfg)
|
|
618
618
|
return
|
|
619
619
|
}
|
|
620
|
+
|
|
621
|
+
if let shouldClose = data.update?.close,
|
|
622
|
+
let wg = SpatialWindowContainer.getSpatialWindowContainer(target.readWindowContainerID(id: info.windowContainerID))
|
|
623
|
+
{
|
|
624
|
+
if shouldClose {
|
|
625
|
+
wg.destroy()
|
|
626
|
+
}
|
|
627
|
+
}
|
|
628
|
+
|
|
620
629
|
target.completeEvent(requestID: info.requestID)
|
|
621
630
|
}
|
|
622
631
|
|
|
@@ -726,6 +735,7 @@ struct JSResourceData: Codable {
|
|
|
726
735
|
var windowID: String?
|
|
727
736
|
var style: JSEntityStyle?
|
|
728
737
|
var nextOpenSettings: JSNextOpen?
|
|
738
|
+
var close: Bool?
|
|
729
739
|
var getBoundingBox: Bool?
|
|
730
740
|
var zIndex: Double?
|
|
731
741
|
var visible: Bool?
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import Foundation
|
|
2
|
+
|
|
3
|
+
struct PackageJSON: Codable {
|
|
4
|
+
let version: String
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
func getPackageVersion() -> String {
|
|
8
|
+
let currentFileURL = URL(fileURLWithPath: #file) // path of version
|
|
9
|
+
let currentDirectoryURL = currentFileURL.deletingLastPathComponent()
|
|
10
|
+
|
|
11
|
+
let packageJSONURL = currentDirectoryURL
|
|
12
|
+
.deletingLastPathComponent()
|
|
13
|
+
.deletingLastPathComponent()
|
|
14
|
+
.deletingLastPathComponent() // .. project root
|
|
15
|
+
.appendingPathComponent("package.json")
|
|
16
|
+
|
|
17
|
+
do {
|
|
18
|
+
// read file
|
|
19
|
+
let data = try Data(contentsOf: packageJSONURL)
|
|
20
|
+
let package = try JSONDecoder().decode(PackageJSON.self, from: data)
|
|
21
|
+
return package.version
|
|
22
|
+
} catch {
|
|
23
|
+
fatalError("⚠️ Error reading package.json at \(packageJSONURL.path): \(error)")
|
|
24
|
+
}
|
|
25
|
+
}
|
|
@@ -56,33 +56,6 @@ class Coordinator: NSObject, WKNavigationDelegate, WKScriptMessageHandler, WKUID
|
|
|
56
56
|
dataTask.resume()
|
|
57
57
|
return
|
|
58
58
|
}
|
|
59
|
-
|
|
60
|
-
var styleJsonString: String? = URLComponents(string: url!.absoluteString)?.queryItems?.first(where: { $0.name == "style" })?.value
|
|
61
|
-
|
|
62
|
-
do {
|
|
63
|
-
if styleJsonString?.contains("?") != nil {
|
|
64
|
-
// remove invalid query string
|
|
65
|
-
// before "{\"glassEffect\":true,\"cornerRadius\":50}?uniqueURL=0.0010192470591506853"
|
|
66
|
-
// after "{\"glassEffect\":true,\"cornerRadius\":50}"
|
|
67
|
-
styleJsonString = styleJsonString?
|
|
68
|
-
.components(separatedBy: "?").first
|
|
69
|
-
}
|
|
70
|
-
let styleToSet = try decoder.decode(PreloadStyleSettings.self, from: styleJsonString!.data(using: .utf8)!)
|
|
71
|
-
|
|
72
|
-
webviewGetEarlyStyleData.send(WebviewEarlyStyle(webview: webView, style: styleToSet))
|
|
73
|
-
} catch {
|
|
74
|
-
logger.warning("Style url parse failure " + error.localizedDescription)
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
// Respond with empty css file
|
|
78
|
-
let response = ".ignoreThis{}".data(using: .utf8)
|
|
79
|
-
let mimeType = "text/css"
|
|
80
|
-
let headers = ["Content-Type": mimeType, "Cache-Control": "no-cache"]
|
|
81
|
-
let resp = HTTPURLResponse(url: url!, statusCode: 200, httpVersion: "1.1", headerFields: headers)
|
|
82
|
-
|
|
83
|
-
urlSchemeTask.didReceive(resp!)
|
|
84
|
-
urlSchemeTask.didReceive(response!)
|
|
85
|
-
urlSchemeTask.didFinish()
|
|
86
59
|
}
|
|
87
60
|
|
|
88
61
|
func webView(_ webView: WKWebView, stop urlSchemeTask: any WKURLSchemeTask) {}
|
|
@@ -120,6 +93,27 @@ class Coordinator: NSObject, WKNavigationDelegate, WKScriptMessageHandler, WKUID
|
|
|
120
93
|
decisionHandler(.cancel)
|
|
121
94
|
return
|
|
122
95
|
}
|
|
96
|
+
if let url = navigationAction.request.url,
|
|
97
|
+
url.absoluteString.starts(with: "forcestyle://")
|
|
98
|
+
{
|
|
99
|
+
var styleJsonString: String? = URLComponents(string: url.absoluteString)?.queryItems?.first(where: { $0.name == "style" })?.value
|
|
100
|
+
do {
|
|
101
|
+
if styleJsonString?.contains("?") != nil {
|
|
102
|
+
// remove invalid query string
|
|
103
|
+
// before "{\"glassEffect\":true,\"cornerRadius\":50}?uniqueURL=0.0010192470591506853"
|
|
104
|
+
// after "{\"glassEffect\":true,\"cornerRadius\":50}"
|
|
105
|
+
styleJsonString = styleJsonString?
|
|
106
|
+
.components(separatedBy: "?").first
|
|
107
|
+
}
|
|
108
|
+
let styleToSet = try decoder.decode(PreloadStyleSettings.self, from: styleJsonString!.data(using: .utf8)!)
|
|
109
|
+
|
|
110
|
+
webviewGetEarlyStyleData.send(WebviewEarlyStyle(webview: webView, style: styleToSet))
|
|
111
|
+
} catch {
|
|
112
|
+
logger.warning("Style url parse failure " + error.localizedDescription)
|
|
113
|
+
}
|
|
114
|
+
decisionHandler(.cancel)
|
|
115
|
+
return
|
|
116
|
+
}
|
|
123
117
|
var resource = navigationAction.request.url!.absoluteString
|
|
124
118
|
if pwaManager.isLocal {
|
|
125
119
|
resource = pwaManager.getLocalResourceURL(url: resource)
|
|
@@ -244,10 +238,6 @@ struct WebViewNative: UIViewRepresentable {
|
|
|
244
238
|
myConfig.userContentController = userContentController
|
|
245
239
|
myConfig.preferences.javaScriptCanOpenWindowsAutomatically = true
|
|
246
240
|
myConfig.preferences.setValue(true, forKey: "allowFileAccessFromFileURLs")
|
|
247
|
-
|
|
248
|
-
if myConfig.urlSchemeHandler(forURLScheme: "forceStyle") == nil {
|
|
249
|
-
myConfig.setURLSchemeHandler(webViewHolder.webViewCoordinator, forURLScheme: "forceStyle")
|
|
250
|
-
}
|
|
251
241
|
if myConfig.urlSchemeHandler(forURLScheme: "file") == nil {
|
|
252
242
|
myConfig.setURLSchemeHandler(webViewHolder.webViewCoordinator, forURLScheme: "file")
|
|
253
243
|
}
|
|
@@ -10,7 +10,8 @@ import SwiftUI
|
|
|
10
10
|
let logger = Logger()
|
|
11
11
|
|
|
12
12
|
// To load a local path, remove http:// eg. "static-web/"
|
|
13
|
-
let nativeAPIVersion =
|
|
13
|
+
let nativeAPIVersion = getPackageVersion()
|
|
14
|
+
|
|
14
15
|
// start URL
|
|
15
16
|
let startURL = pwaManager.start_url
|
|
16
17
|
|
|
@@ -97,7 +98,10 @@ struct web_spatialApp: App {
|
|
|
97
98
|
}.first?.value
|
|
98
99
|
|
|
99
100
|
if let wv = rootEntity?.getComponent(SpatialWindowComponent.self) {
|
|
100
|
-
|
|
101
|
+
// remove the webview's name to behave like new opened root scene
|
|
102
|
+
wv.removeWebviewName {
|
|
103
|
+
wv.navigateToURL(url: fileUrl)
|
|
104
|
+
}
|
|
101
105
|
}
|
|
102
106
|
// reset to mainScene size
|
|
103
107
|
wgm.setToMainSceneCfg()
|
|
@@ -30,6 +30,7 @@
|
|
|
30
30
|
2BC261222D38F1DA00BCA977 /* NavView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2BC261202D38F1DA00BCA977 /* NavView.swift */; };
|
|
31
31
|
2BC9A2212D1E829B00912170 /* HideViewModifier.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2BC9A2202D1E829B00912170 /* HideViewModifier.swift */; };
|
|
32
32
|
2BD510562D54A30D0001E5E6 /* SceneManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2BD510552D54A2FF0001E5E6 /* SceneManager.swift */; };
|
|
33
|
+
2BD5880E2DB1237F00C0E13B /* version.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2BD5880D2DB1236000C0E13B /* version.swift */; };
|
|
33
34
|
2BDBED5F2D3F885A0065443F /* SpatialModel3DComponent.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2BDBED5E2D3F885A0065443F /* SpatialModel3DComponent.swift */; };
|
|
34
35
|
2BDBED632D3FE8EC0065443F /* SpatialModel3DView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2BDBED622D3FE8EA0065443F /* SpatialModel3DView.swift */; };
|
|
35
36
|
2BDBF9B62C4ED9F600D269D7 /* static-web in Resources */ = {isa = PBXBuildFile; fileRef = 2BDBF9B52C4ED9F600D269D7 /* static-web */; };
|
|
@@ -83,6 +84,7 @@
|
|
|
83
84
|
2BC261202D38F1DA00BCA977 /* NavView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NavView.swift; sourceTree = "<group>"; };
|
|
84
85
|
2BC9A2202D1E829B00912170 /* HideViewModifier.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HideViewModifier.swift; sourceTree = "<group>"; };
|
|
85
86
|
2BD510552D54A2FF0001E5E6 /* SceneManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SceneManager.swift; sourceTree = "<group>"; };
|
|
87
|
+
2BD5880D2DB1236000C0E13B /* version.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = version.swift; sourceTree = "<group>"; };
|
|
86
88
|
2BDBED5E2D3F885A0065443F /* SpatialModel3DComponent.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SpatialModel3DComponent.swift; sourceTree = "<group>"; };
|
|
87
89
|
2BDBED622D3FE8EA0065443F /* SpatialModel3DView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SpatialModel3DView.swift; sourceTree = "<group>"; };
|
|
88
90
|
2BDBF9B52C4ED9F600D269D7 /* static-web */ = {isa = PBXFileReference; lastKnownFileType = folder; path = "static-web"; sourceTree = "<group>"; };
|
|
@@ -121,6 +123,7 @@
|
|
|
121
123
|
2B0B1C0E2C494E4100E644F9 /* Utils */ = {
|
|
122
124
|
isa = PBXGroup;
|
|
123
125
|
children = (
|
|
126
|
+
2BD5880D2DB1236000C0E13B /* version.swift */,
|
|
124
127
|
2BD510552D54A2FF0001E5E6 /* SceneManager.swift */,
|
|
125
128
|
2B0B43092CBE21540003CEF3 /* CommandManager.swift */,
|
|
126
129
|
2B0B1C0F2C494E5400E644F9 /* Logger.swift */,
|
|
@@ -384,6 +387,7 @@
|
|
|
384
387
|
2BDBED5F2D3F885A0065443F /* SpatialModel3DComponent.swift in Sources */,
|
|
385
388
|
2B2F1D6B2BEBFAAA006897EE /* web_spatialApp.swift in Sources */,
|
|
386
389
|
2B0B1C102C494E5400E644F9 /* Logger.swift in Sources */,
|
|
390
|
+
2BD5880E2DB1237F00C0E13B /* version.swift in Sources */,
|
|
387
391
|
2B37E8E12D002C4D0096749A /* MaterialWithBorderCornerModifier.swift in Sources */,
|
|
388
392
|
2BC261222D38F1DA00BCA977 /* NavView.swift in Sources */,
|
|
389
393
|
2BAC1BE22CDC49040022E29B /* SpatialViewUI.swift in Sources */,
|