catalyst-core 0.0.3-canary.9 → 0.1.0-beta.2
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/README.md +4 -5
- package/bin/catalyst.js +28 -15
- package/changelog.md +139 -30
- package/dist/native/androidProject/app/build.gradle.kts +125 -15
- package/dist/native/androidProject/app/proguard-rules.pro +85 -14
- package/dist/native/androidProject/app/src/debug/res/xml/network_security_config.xml +8 -0
- package/dist/native/androidProject/app/src/main/AndroidManifest.xml +10 -3
- package/dist/native/androidProject/app/src/main/java/io/yourname/androidproject/BridgeMessageValidator.kt +552 -0
- package/dist/native/androidProject/app/src/main/java/io/yourname/androidproject/CatalystConstants.kt +109 -0
- package/dist/native/androidProject/app/src/main/java/io/yourname/androidproject/CustomWebview.kt +605 -124
- package/dist/native/androidProject/app/src/main/java/io/yourname/androidproject/MainActivity.kt +405 -47
- package/dist/native/androidProject/app/src/main/java/io/yourname/androidproject/MetricsMonitor.kt +341 -0
- package/dist/native/androidProject/app/src/main/java/io/yourname/androidproject/NativeBridge.kt +954 -71
- package/dist/native/androidProject/app/src/main/java/io/yourname/androidproject/SplashActivity.kt +111 -0
- package/dist/native/androidProject/app/src/main/java/io/yourname/androidproject/URLWhitelistManager.kt +231 -0
- package/dist/native/androidProject/app/src/main/java/io/yourname/androidproject/Utils.kt +49 -55
- package/dist/native/androidProject/app/src/main/java/io/yourname/androidproject/WebCacheManager.kt +81 -8
- package/dist/native/androidProject/app/src/main/java/io/yourname/androidproject/design/DesignTokens.kt +307 -0
- package/dist/native/androidProject/app/src/main/java/io/yourname/androidproject/security/EmulatorDetector.kt +203 -0
- package/dist/native/androidProject/app/src/main/java/io/yourname/androidproject/security/FridaDetector.kt +187 -0
- package/dist/native/androidProject/app/src/main/java/io/yourname/androidproject/security/SecurityAlertHandler.kt +170 -0
- package/dist/native/androidProject/app/src/main/java/io/yourname/androidproject/security/SecurityAlertUI.kt +366 -0
- package/dist/native/androidProject/app/src/main/java/io/yourname/androidproject/security/SecurityBottomSheet.kt +138 -0
- package/dist/native/androidProject/app/src/main/java/io/yourname/androidproject/security/SecurityCheckManager.kt +511 -0
- package/dist/native/androidProject/app/src/main/java/io/yourname/androidproject/security/SecurityCheckScheduler.kt +68 -0
- package/dist/native/androidProject/app/src/main/java/io/yourname/androidproject/utils/BridgeUtils.kt +47 -11
- package/dist/native/androidProject/app/src/main/java/io/yourname/androidproject/utils/DeviceInfoUtils.kt +38 -13
- package/dist/native/androidProject/app/src/main/java/io/yourname/androidproject/utils/DownloadUtils.kt +36 -14
- package/dist/native/androidProject/app/src/main/java/io/yourname/androidproject/utils/FileUtils.kt +3 -2
- package/dist/native/androidProject/app/src/main/java/io/yourname/androidproject/utils/FrameworkServerUtils.kt +57 -8
- package/dist/native/androidProject/app/src/main/java/io/yourname/androidproject/utils/IntentUtils.kt +31 -6
- package/dist/native/androidProject/app/src/main/java/io/yourname/androidproject/utils/KeyboardUtil.kt +82 -0
- package/dist/native/androidProject/app/src/main/java/io/yourname/androidproject/utils/NetworkUtils.kt +105 -0
- package/dist/native/androidProject/app/src/main/java/io/yourname/androidproject/utils/NotificationConstants.kt +28 -0
- package/dist/native/androidProject/app/src/main/java/io/yourname/androidproject/utils/NotificationUtils.kt +639 -0
- package/dist/native/androidProject/app/src/main/java/io/yourname/androidproject/utils/SafeAreaUtils.kt +62 -0
- package/dist/native/androidProject/app/src/main/res/drawable/splashscreen_fallback.png +0 -0
- package/dist/native/androidProject/app/src/main/res/layout/activity_main.xml +1 -0
- package/dist/native/androidProject/app/src/main/res/layout/activity_splash.xml +20 -0
- package/dist/native/androidProject/app/src/main/res/values/themes.xml +23 -0
- package/dist/native/androidProject/app/src/main/res/values-night/themes.xml +11 -0
- package/dist/native/androidProject/app/src/main/res/xml/network_security_config.xml +12 -0
- package/dist/native/androidProject/app/src/noFcm/java/io/yourname/androidproject/utils/NotificationManager.kt +166 -0
- package/dist/native/androidProject/app/src/noFcm/java/io/yourname/androidproject/utils/PushNotificationUtils.kt +94 -0
- package/dist/native/androidProject/app/src/test/java/io/yourname/androidproject/BridgeMessageValidatorTest.kt +267 -0
- package/dist/native/androidProject/app/src/test/java/io/yourname/androidproject/BridgeUtilsTest.kt +286 -0
- package/dist/native/androidProject/app/src/test/java/io/yourname/androidproject/CameraUtilsTest.kt +296 -0
- package/dist/native/androidProject/app/src/test/java/io/yourname/androidproject/ConfigMappingTest.kt +594 -0
- package/dist/native/androidProject/app/src/test/java/io/yourname/androidproject/CustomWebviewTest.kt +466 -0
- package/dist/native/androidProject/app/src/test/java/io/yourname/androidproject/DeviceInfoUtilsTest.kt +187 -0
- package/dist/native/androidProject/app/src/test/java/io/yourname/androidproject/FileUtilsTest.kt +304 -0
- package/dist/native/androidProject/app/src/test/java/io/yourname/androidproject/NativeBridgeTest.kt +424 -0
- package/dist/native/androidProject/app/src/test/java/io/yourname/androidproject/NotificationUtilsTest.kt +469 -0
- package/dist/native/androidProject/app/src/test/java/io/yourname/androidproject/SecurityBridgeTest.kt +199 -0
- package/dist/native/androidProject/app/src/test/java/io/yourname/androidproject/URLWhitelistManagerTest.kt +462 -0
- package/dist/native/androidProject/app/src/test/java/io/yourname/androidproject/WebCacheManagerTest.kt +391 -0
- package/dist/native/androidProject/app/src/withFcm/java/io/yourname/androidproject/utils/NotificationManager.kt +224 -0
- package/dist/native/androidProject/app/src/withFcm/java/io/yourname/androidproject/utils/PushNotificationUtils.kt +399 -0
- package/dist/native/androidProject/build.gradle.kts +6 -0
- package/dist/native/androidProject/gradle/libs.versions.toml +8 -2
- package/dist/native/androidSetup.js +4 -3
- package/dist/native/assets/catalyst.png +0 -0
- package/dist/native/bridge/WebBridge.js +16 -3
- package/dist/native/bridge/constants/NativeInterfaces.js +28 -10
- package/dist/native/bridge/errors.js +1 -1
- package/dist/native/bridge/hooks.js +76 -16
- package/dist/native/bridge/safeArea.js +5 -0
- package/dist/native/bridge/standardizedHooks.js +23 -5
- package/dist/native/bridge/useBaseHook.js +7 -9
- package/dist/native/bridge/utils/CameraUtils.js +58 -0
- package/dist/native/bridge/utils/FileObjectConverter.js +40 -0
- package/dist/native/bridge/utils/NativeBridge.js +57 -8
- package/dist/native/buildAppAndroid.js +115 -43
- package/dist/native/buildAppIos.js +291 -26
- package/dist/native/iosnativeWebView/Configurations/Debug.xcconfig +21 -0
- package/dist/native/iosnativeWebView/Configurations/Release.xcconfig +24 -0
- package/dist/native/iosnativeWebView/Configurations/Shared.xcconfig +50 -0
- package/dist/native/iosnativeWebView/Package.resolved +32 -0
- package/dist/native/iosnativeWebView/Package.swift +37 -0
- package/dist/native/iosnativeWebView/Sources/CatalystNotifications/LocalNotificationHandler.swift +293 -0
- package/dist/native/iosnativeWebView/Sources/CatalystNotifications/NotificationManager.swift +299 -0
- package/dist/native/iosnativeWebView/Sources/CatalystNotifications/PushNotificationHandler.swift +199 -0
- package/dist/native/iosnativeWebView/Sources/Core/Constants/CatalystConstants.swift +125 -0
- package/dist/native/iosnativeWebView/Sources/Core/Constants/ConfigConstants.swift +70 -0
- package/dist/native/iosnativeWebView/Sources/Core/Notifications/NotificationModels.swift +156 -0
- package/dist/native/iosnativeWebView/Sources/Core/Protocols/NotificationHandlerProtocol.swift +35 -0
- package/dist/native/iosnativeWebView/Sources/Core/Utils/BootTimingUtility.swift +26 -0
- package/dist/native/iosnativeWebView/{iosnativeWebView → Sources/Core/Utils}/CacheManager.swift +69 -36
- package/dist/native/iosnativeWebView/Sources/Core/Utils/CameraTransportUtils.swift +363 -0
- package/dist/native/iosnativeWebView/Sources/Core/Utils/DeviceInfoUtils.swift +67 -0
- package/dist/native/iosnativeWebView/Sources/Core/Utils/FilePickerHandler.swift +1053 -0
- package/dist/native/iosnativeWebView/Sources/Core/Utils/FrameworkServerUtils.swift +901 -0
- package/dist/native/iosnativeWebView/{iosnativeWebView → Sources/Core/Utils}/ImageHandler.swift +206 -20
- package/dist/native/iosnativeWebView/Sources/Core/Utils/NetworkMonitor.swift +112 -0
- package/dist/native/iosnativeWebView/Sources/Core/Utils/NotificationHandlerProvider.swift +20 -0
- package/dist/native/iosnativeWebView/Sources/Core/Utils/NullNotificationHandler.swift +85 -0
- package/dist/native/iosnativeWebView/{iosnativeWebView → Sources/Core/Utils}/ResourceURLProtocol.swift +60 -25
- package/dist/native/iosnativeWebView/Sources/Core/Utils/SafeAreaUtils.swift +132 -0
- package/dist/native/iosnativeWebView/Sources/Core/Utils/ScreenSecureManager.swift +131 -0
- package/dist/native/iosnativeWebView/Sources/Core/Utils/URLWhitelistManager.swift +224 -0
- package/dist/native/iosnativeWebView/Sources/Core/Utils/WebKitConfig.swift +43 -0
- package/dist/native/iosnativeWebView/Sources/Core/WebView/BridgeCommandHandler.swift +991 -0
- package/dist/native/iosnativeWebView/Sources/Core/WebView/BridgeDelegateHandler.swift +166 -0
- package/dist/native/iosnativeWebView/Sources/Core/WebView/BridgeFileHandler.swift +340 -0
- package/dist/native/iosnativeWebView/Sources/Core/WebView/BridgeJavaScriptInterface.swift +149 -0
- package/dist/native/iosnativeWebView/Sources/Core/WebView/BridgeMessageValidator.swift +611 -0
- package/dist/native/iosnativeWebView/Sources/Core/WebView/NativeBridge.swift +334 -0
- package/dist/native/iosnativeWebView/Sources/Core/WebView/SplashView.swift +95 -0
- package/dist/native/iosnativeWebView/Sources/Core/WebView/SplashViewModel.swift +86 -0
- package/dist/native/iosnativeWebView/Sources/Core/WebView/WebView.swift +181 -0
- package/dist/native/iosnativeWebView/Sources/Core/WebView/WebViewModel.swift +182 -0
- package/dist/native/iosnativeWebView/Sources/Core/WebView/WebViewNavigationDelegate.swift +395 -0
- package/dist/native/iosnativeWebView/iosnativeWebView/AppDelegate.swift +84 -0
- package/dist/native/iosnativeWebView/iosnativeWebView/Assets.xcassets/AccentColor.colorset/Contents.json +8 -8
- package/dist/native/iosnativeWebView/iosnativeWebView/Assets.xcassets/AppIcon.appiconset/Contents.json +10 -10
- package/dist/native/iosnativeWebView/iosnativeWebView/Assets.xcassets/Contents.json +4 -4
- package/dist/native/iosnativeWebView/iosnativeWebView/ContentView.swift +65 -10
- package/dist/native/iosnativeWebView/iosnativeWebView/Info-Release.plist +21 -0
- package/dist/native/iosnativeWebView/iosnativeWebView/Info.plist +13 -0
- package/dist/native/iosnativeWebView/iosnativeWebView/Preview Content/Preview Assets.xcassets/Contents.json +4 -4
- package/dist/native/iosnativeWebView/iosnativeWebView/iosnativeWebView.entitlements +12 -0
- package/dist/native/iosnativeWebView/iosnativeWebView/iosnativeWebViewApp.swift +80 -0
- package/dist/native/iosnativeWebView/iosnativeWebView/localhost.p12 +0 -0
- package/dist/native/iosnativeWebView/iosnativeWebView.xcodeproj/project.pbxproj +118 -100
- package/dist/native/iosnativeWebView/iosnativeWebView.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved +69 -0
- package/dist/native/iosnativeWebView/iosnativeWebView.xcodeproj/xcshareddata/xcschemes/iosnativeWebView.xcscheme +9 -4
- package/dist/native/iosnativeWebView/iosnativeWebView.xctestplan +47 -0
- package/dist/native/iosnativeWebView/iosnativeWebViewTests/BootTimingUtilityTests.swift +236 -0
- package/dist/native/iosnativeWebView/iosnativeWebViewTests/BridgeCommandHandlerSecurityTests.swift +212 -0
- package/dist/native/iosnativeWebView/iosnativeWebViewTests/BridgeMessageValidatorTests.swift +418 -0
- package/dist/native/iosnativeWebView/iosnativeWebViewTests/CacheManagerTests.swift +390 -0
- package/dist/native/iosnativeWebView/iosnativeWebViewTests/ConfigMappingTests.swift +299 -0
- package/dist/native/iosnativeWebView/iosnativeWebViewTests/FilePickerHandlerTests.swift +383 -0
- package/dist/native/iosnativeWebView/iosnativeWebViewTests/FrameworkServerUtilsTests.swift +391 -0
- package/dist/native/iosnativeWebView/iosnativeWebViewTests/NativeBridgeTests.swift +581 -0
- package/dist/native/iosnativeWebView/iosnativeWebViewTests/NotificationHandlerTests.swift +430 -0
- package/dist/native/iosnativeWebView/iosnativeWebViewTests/ScreenSecureManagerTests.swift +121 -0
- package/dist/native/iosnativeWebView/iosnativeWebViewTests/URLWhitelistManagerTests.swift +367 -0
- package/dist/native/iosnativeWebView/iosnativeWebViewTests/WebViewTests.swift +440 -0
- package/dist/native/renameAndroidProject.js +80 -70
- package/dist/native/setupEmulatorIos.js +22 -5
- package/dist/native/setupServer.js +11 -10
- package/dist/native/terminalProgress.js +10 -10
- package/dist/native/utils.js +4 -5
- package/dist/otel.js +4 -0
- package/dist/scripts/build.js +2 -2
- package/dist/scripts/devBuild.js +2 -2
- package/dist/scripts/loadEnvironmentVariables.js +3 -1
- package/dist/scripts/scriptUtils.js +2 -2
- package/dist/sentry.js +4 -1
- package/dist/server/renderer/document/Body.js +4 -4
- package/dist/server/renderer/handler.js +7 -5
- package/dist/webpack/development.client.babel.js +1 -1
- package/mcp_v2/conversion-tasks.json +326 -0
- package/mcp_v2/knowledge-base.json +1068 -0
- package/mcp_v2/lib/helpers.js +165 -0
- package/mcp_v2/mcp.js +563 -0
- package/mcp_v2/package.json +13 -0
- package/mcp_v2/schema.sql +88 -0
- package/mcp_v2/setup.js +278 -0
- package/mcp_v2/tools/build.js +686 -0
- package/mcp_v2/tools/config.js +453 -0
- package/mcp_v2/tools/conversion.js +799 -0
- package/mcp_v2/tools/debug.js +113 -0
- package/mcp_v2/tools/knowledge.js +219 -0
- package/mcp_v2/tools/sync.js +23 -0
- package/mcp_v2/tools/tasks.js +945 -0
- package/package.json +11 -15
- package/dist/native/androidProject/.idea/.name +0 -1
- package/dist/native/androidProject/.idea/AndroidProjectSystem.xml +0 -6
- package/dist/native/androidProject/.idea/compiler.xml +0 -6
- package/dist/native/androidProject/.idea/deploymentTargetSelector.xml +0 -10
- package/dist/native/androidProject/.idea/gradle.xml +0 -18
- package/dist/native/androidProject/.idea/migrations.xml +0 -10
- package/dist/native/androidProject/.idea/misc.xml +0 -10
- package/dist/native/androidProject/.idea/runConfigurations.xml +0 -17
- package/dist/native/androidProject/.idea/vcs.xml +0 -6
- package/dist/native/iosnativeWebView/iosnativeWebView/NativeBridge.swift +0 -217
- package/dist/native/iosnativeWebView/iosnativeWebView/WebView.swift +0 -96
- package/dist/native/iosnativeWebView/iosnativeWebView/WebViewModel.swift +0 -47
- package/dist/native/iosnativeWebView/iosnativeWebView/WebViewNavigationDelegate.swift +0 -140
- package/license +0 -10
package/dist/native/iosnativeWebView/{iosnativeWebView → Sources/Core/Utils}/CacheManager.swift
RENAMED
|
@@ -3,8 +3,8 @@ import os
|
|
|
3
3
|
|
|
4
4
|
private let logger = Logger(subsystem: Bundle.main.bundleIdentifier ?? "com.app", category: "CacheManager")
|
|
5
5
|
|
|
6
|
-
class CacheManager {
|
|
7
|
-
static let shared = CacheManager()
|
|
6
|
+
public final class CacheManager {
|
|
7
|
+
public static let shared = CacheManager()
|
|
8
8
|
private let queue = DispatchQueue(label: "com.app.cachemanager", attributes: .concurrent)
|
|
9
9
|
|
|
10
10
|
enum CacheState {
|
|
@@ -14,15 +14,16 @@ class CacheManager {
|
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
private struct CachePolicy {
|
|
17
|
-
static let freshWindow: TimeInterval =
|
|
18
|
-
static let staleWindow: TimeInterval =
|
|
17
|
+
static let freshWindow: TimeInterval = CatalystConstants.Cache.freshWindow
|
|
18
|
+
static let staleWindow: TimeInterval = CatalystConstants.Cache.staleWindow
|
|
19
19
|
}
|
|
20
|
-
|
|
21
|
-
private let memoryCapacity =
|
|
22
|
-
private let diskCapacity =
|
|
20
|
+
|
|
21
|
+
private let memoryCapacity = CatalystConstants.Cache.memoryCapacity
|
|
22
|
+
private let diskCapacity = CatalystConstants.Cache.diskCapacity
|
|
23
23
|
private let session: URLSession
|
|
24
24
|
private var resourceCache: [String: CachedResource] = [:]
|
|
25
25
|
private let cacheDirectory: URL
|
|
26
|
+
private let compiledCachePatterns: [NSRegularExpression]
|
|
26
27
|
|
|
27
28
|
private struct CachedResource: Codable {
|
|
28
29
|
let data: Data
|
|
@@ -42,19 +43,34 @@ class CacheManager {
|
|
|
42
43
|
}
|
|
43
44
|
|
|
44
45
|
private init() {
|
|
46
|
+
let initStart = CFAbsoluteTimeGetCurrent()
|
|
47
|
+
|
|
45
48
|
let baseDirectory = FileManager.default.urls(
|
|
46
49
|
for: .cachesDirectory,
|
|
47
50
|
in: .userDomainMask
|
|
48
51
|
)[0]
|
|
49
|
-
|
|
52
|
+
|
|
50
53
|
self.cacheDirectory = baseDirectory.appendingPathComponent("WebCache", isDirectory: true)
|
|
51
|
-
|
|
54
|
+
|
|
52
55
|
try? FileManager.default.createDirectory(
|
|
53
56
|
at: cacheDirectory,
|
|
54
57
|
withIntermediateDirectories: true,
|
|
55
58
|
attributes: nil
|
|
56
59
|
)
|
|
57
|
-
|
|
60
|
+
|
|
61
|
+
// Pre-compile regex patterns for better performance
|
|
62
|
+
self.compiledCachePatterns = ConfigConstants.cachePattern.compactMap { pattern in
|
|
63
|
+
do {
|
|
64
|
+
return try NSRegularExpression(
|
|
65
|
+
pattern: pattern.replacingOccurrences(of: "*", with: ".*"),
|
|
66
|
+
options: .caseInsensitive
|
|
67
|
+
)
|
|
68
|
+
} catch {
|
|
69
|
+
logger.error("Failed to compile cache pattern '\(pattern)': \(error)")
|
|
70
|
+
return nil
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
58
74
|
let configuration = URLSessionConfiguration.default
|
|
59
75
|
configuration.requestCachePolicy = .returnCacheDataElseLoad
|
|
60
76
|
configuration.urlCache = URLCache(
|
|
@@ -62,14 +78,18 @@ class CacheManager {
|
|
|
62
78
|
diskCapacity: diskCapacity,
|
|
63
79
|
directory: cacheDirectory
|
|
64
80
|
)
|
|
65
|
-
|
|
81
|
+
|
|
66
82
|
session = URLSession(configuration: configuration)
|
|
67
|
-
|
|
68
|
-
|
|
83
|
+
|
|
84
|
+
let initTime = (CFAbsoluteTimeGetCurrent() - initStart) * 1000
|
|
85
|
+
logWithTimestamp("💾 Cache initialized at: \(self.cacheDirectory.path) (took \(String(format: "%.2f", initTime))ms)")
|
|
86
|
+
|
|
69
87
|
loadCacheFromDisk()
|
|
70
88
|
}
|
|
71
89
|
|
|
72
90
|
private func loadCacheFromDisk() {
|
|
91
|
+
let loadStart = CFAbsoluteTimeGetCurrent()
|
|
92
|
+
|
|
73
93
|
queue.async {
|
|
74
94
|
do {
|
|
75
95
|
let fileManager = FileManager.default
|
|
@@ -77,7 +97,7 @@ class CacheManager {
|
|
|
77
97
|
at: self.cacheDirectory,
|
|
78
98
|
includingPropertiesForKeys: nil
|
|
79
99
|
).filter { $0.pathExtension == "cache" }
|
|
80
|
-
|
|
100
|
+
|
|
81
101
|
for file in files {
|
|
82
102
|
do {
|
|
83
103
|
let data = try Data(contentsOf: file)
|
|
@@ -88,8 +108,9 @@ class CacheManager {
|
|
|
88
108
|
logger.error("Failed to load cached file: \(error.localizedDescription)")
|
|
89
109
|
}
|
|
90
110
|
}
|
|
91
|
-
|
|
92
|
-
|
|
111
|
+
|
|
112
|
+
let loadTime = (CFAbsoluteTimeGetCurrent() - loadStart) * 1000
|
|
113
|
+
logWithTimestamp("📂 Loaded \(self.resourceCache.count) resources from disk cache (took \(String(format: "%.2f", loadTime))ms)")
|
|
93
114
|
} catch {
|
|
94
115
|
logger.error("Failed to load cache from disk: \(error.localizedDescription)")
|
|
95
116
|
}
|
|
@@ -107,20 +128,17 @@ class CacheManager {
|
|
|
107
128
|
}
|
|
108
129
|
|
|
109
130
|
func shouldCacheURL(_ url: URL) -> Bool {
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
return false
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
let range = NSRange(urlString.startIndex..., in: urlString)
|
|
121
|
-
return regex.firstMatch(in: urlString, options: [], range: range) != nil
|
|
131
|
+
let urlString = url.absoluteString
|
|
132
|
+
|
|
133
|
+
// Use pre-compiled regex patterns for better performance
|
|
134
|
+
for regex in compiledCachePatterns {
|
|
135
|
+
let range = NSRange(urlString.startIndex..., in: urlString)
|
|
136
|
+
if regex.firstMatch(in: urlString, options: [], range: range) != nil {
|
|
137
|
+
return true
|
|
122
138
|
}
|
|
123
139
|
}
|
|
140
|
+
|
|
141
|
+
return false
|
|
124
142
|
}
|
|
125
143
|
|
|
126
144
|
private func getCacheState(for timestamp: Date) -> CacheState {
|
|
@@ -136,15 +154,16 @@ class CacheManager {
|
|
|
136
154
|
}
|
|
137
155
|
|
|
138
156
|
func getCachedResource(for request: URLRequest) async -> (Data?, CacheState, String?) {
|
|
157
|
+
let manager = self
|
|
139
158
|
return await withCheckedContinuation { continuation in
|
|
140
|
-
queue.async {
|
|
159
|
+
manager.queue.async {
|
|
141
160
|
guard let urlString = request.url?.absoluteString else {
|
|
142
161
|
continuation.resume(returning: (nil, .expired, nil))
|
|
143
162
|
return
|
|
144
163
|
}
|
|
145
164
|
|
|
146
|
-
if let cachedResource =
|
|
147
|
-
let state =
|
|
165
|
+
if let cachedResource = manager.resourceCache[urlString] {
|
|
166
|
+
let state = manager.getCacheState(for: cachedResource.timestamp)
|
|
148
167
|
|
|
149
168
|
switch state {
|
|
150
169
|
case .fresh:
|
|
@@ -154,7 +173,7 @@ class CacheManager {
|
|
|
154
173
|
case .stale:
|
|
155
174
|
logger.info("🟡 Stale cache hit for: \(urlString)")
|
|
156
175
|
Task {
|
|
157
|
-
await
|
|
176
|
+
await manager.revalidateResource(request: request)
|
|
158
177
|
}
|
|
159
178
|
continuation.resume(returning: (cachedResource.data, .stale, cachedResource.mimeType))
|
|
160
179
|
|
|
@@ -246,10 +265,24 @@ class CacheManager {
|
|
|
246
265
|
}
|
|
247
266
|
|
|
248
267
|
func getCacheStatistics() -> (memoryUsed: Int, diskUsed: Int) {
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
268
|
+
let memoryUsed = session.configuration.urlCache?.currentMemoryUsage ?? 0
|
|
269
|
+
|
|
270
|
+
// Sum size of all custom .cache files written to disk (separate from URLCache internals)
|
|
271
|
+
var diskUsed = 0
|
|
272
|
+
if let files = try? FileManager.default.contentsOfDirectory(
|
|
273
|
+
at: cacheDirectory,
|
|
274
|
+
includingPropertiesForKeys: [.fileSizeKey]
|
|
275
|
+
) {
|
|
276
|
+
diskUsed = files.reduce(0) { total, url in
|
|
277
|
+
let size = (try? url.resourceValues(forKeys: [.fileSizeKey]))?.fileSize ?? 0
|
|
278
|
+
return total + size
|
|
279
|
+
}
|
|
253
280
|
}
|
|
281
|
+
|
|
282
|
+
return (memoryUsed, diskUsed)
|
|
254
283
|
}
|
|
255
284
|
}
|
|
285
|
+
|
|
286
|
+
// Serialized access via a private queue keeps mutations thread-safe even when
|
|
287
|
+
// CacheManager is shared across actors.
|
|
288
|
+
extension CacheManager: @unchecked Sendable {}
|
|
@@ -0,0 +1,363 @@
|
|
|
1
|
+
//
|
|
2
|
+
// CameraTransportUtils.swift
|
|
3
|
+
// iosnativeWebView
|
|
4
|
+
//
|
|
5
|
+
// Camera tri-transport architecture for iOS
|
|
6
|
+
// Handles file size-based routing and processing similar to Android's FileSizeRouterUtils
|
|
7
|
+
//
|
|
8
|
+
|
|
9
|
+
import Foundation
|
|
10
|
+
import UIKit
|
|
11
|
+
import os
|
|
12
|
+
|
|
13
|
+
private let logger = Logger(subsystem: Bundle.main.bundleIdentifier ?? "com.app", category: "CameraTransportUtils")
|
|
14
|
+
|
|
15
|
+
// MARK: - Transport Types
|
|
16
|
+
|
|
17
|
+
enum TransportType: String, CaseIterable {
|
|
18
|
+
case base64 = "BASE64"
|
|
19
|
+
case fileUrl = "FILE_URL"
|
|
20
|
+
case frameworkServer = "FRAMEWORK_SERVER"
|
|
21
|
+
|
|
22
|
+
var name: String {
|
|
23
|
+
return self.rawValue
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// MARK: - Transport Decision
|
|
28
|
+
|
|
29
|
+
struct TransportDecision {
|
|
30
|
+
let transportType: TransportType
|
|
31
|
+
let reason: String
|
|
32
|
+
let fileSize: Int64
|
|
33
|
+
let filePath: String
|
|
34
|
+
let fileName: String
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// MARK: - Processing Result
|
|
38
|
+
|
|
39
|
+
struct CameraProcessingResult {
|
|
40
|
+
let success: Bool
|
|
41
|
+
let fileName: String
|
|
42
|
+
let fileSrc: String?
|
|
43
|
+
let filePath: String?
|
|
44
|
+
let fileSize: Int64
|
|
45
|
+
let mimeType: String
|
|
46
|
+
let transportUsed: TransportType
|
|
47
|
+
let error: String?
|
|
48
|
+
|
|
49
|
+
static func failure(error: String) -> CameraProcessingResult {
|
|
50
|
+
return CameraProcessingResult(
|
|
51
|
+
success: false,
|
|
52
|
+
fileName: "",
|
|
53
|
+
fileSrc: nil,
|
|
54
|
+
filePath: nil,
|
|
55
|
+
fileSize: 0,
|
|
56
|
+
mimeType: "",
|
|
57
|
+
transportUsed: .base64,
|
|
58
|
+
error: error
|
|
59
|
+
)
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
static func success(
|
|
63
|
+
fileName: String,
|
|
64
|
+
fileSrc: String?,
|
|
65
|
+
filePath: String?,
|
|
66
|
+
fileSize: Int64,
|
|
67
|
+
mimeType: String,
|
|
68
|
+
transportUsed: TransportType
|
|
69
|
+
) -> CameraProcessingResult {
|
|
70
|
+
return CameraProcessingResult(
|
|
71
|
+
success: true,
|
|
72
|
+
fileName: fileName,
|
|
73
|
+
fileSrc: fileSrc,
|
|
74
|
+
filePath: filePath,
|
|
75
|
+
fileSize: fileSize,
|
|
76
|
+
mimeType: mimeType,
|
|
77
|
+
transportUsed: transportUsed,
|
|
78
|
+
error: nil
|
|
79
|
+
)
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// MARK: - Camera Transport Router
|
|
84
|
+
|
|
85
|
+
class CameraTransportUtils {
|
|
86
|
+
|
|
87
|
+
// Size thresholds from unified configuration
|
|
88
|
+
static let BASE64_SIZE_LIMIT: Int64 = CatalystConstants.FileTransport.base64SizeLimit
|
|
89
|
+
static let FRAMEWORK_SERVER_SIZE_LIMIT: Int64 = CatalystConstants.FileTransport.frameworkServerSizeLimit
|
|
90
|
+
|
|
91
|
+
// MARK: - Transport Decision Logic
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Determine the best transport method based on file size
|
|
95
|
+
* Matches Android's FileSizeRouterUtils.determineTransport() logic
|
|
96
|
+
*/
|
|
97
|
+
static func determineTransport(for fileURL: URL) -> TransportDecision {
|
|
98
|
+
let fileName = fileURL.lastPathComponent
|
|
99
|
+
let filePath = fileURL.path
|
|
100
|
+
|
|
101
|
+
do {
|
|
102
|
+
let fileAttributes = try FileManager.default.attributesOfItem(atPath: filePath)
|
|
103
|
+
let fileSize = fileAttributes[.size] as? Int64 ?? 0
|
|
104
|
+
|
|
105
|
+
logger.debug("Determining transport for file: \(fileName) (size: \(formatFileSize(fileSize)))")
|
|
106
|
+
|
|
107
|
+
// Size-based routing logic exactly matching Android FileSizeRouterUtils
|
|
108
|
+
if fileSize <= BASE64_SIZE_LIMIT {
|
|
109
|
+
return TransportDecision(
|
|
110
|
+
transportType: .base64,
|
|
111
|
+
reason: "File size (\(formatFileSize(fileSize))) is within bridge base64 limit (\(formatFileSize(BASE64_SIZE_LIMIT)))",
|
|
112
|
+
fileSize: fileSize,
|
|
113
|
+
filePath: filePath,
|
|
114
|
+
fileName: fileName
|
|
115
|
+
)
|
|
116
|
+
} else if fileSize <= FRAMEWORK_SERVER_SIZE_LIMIT {
|
|
117
|
+
return TransportDecision(
|
|
118
|
+
transportType: .frameworkServer,
|
|
119
|
+
reason: "File size (\(formatFileSize(fileSize))) exceeds bridge limit, using framework server (limit: \(formatFileSize(FRAMEWORK_SERVER_SIZE_LIMIT)))",
|
|
120
|
+
fileSize: fileSize,
|
|
121
|
+
filePath: filePath,
|
|
122
|
+
fileName: fileName
|
|
123
|
+
)
|
|
124
|
+
} else {
|
|
125
|
+
// File too large - matches Android UNSUPPORTED behavior
|
|
126
|
+
return TransportDecision(
|
|
127
|
+
transportType: .frameworkServer,
|
|
128
|
+
reason: "File size (\(formatFileSize(fileSize))) exceeds maximum supported size, will attempt framework server as fallback",
|
|
129
|
+
fileSize: fileSize,
|
|
130
|
+
filePath: filePath,
|
|
131
|
+
fileName: fileName
|
|
132
|
+
)
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
} catch {
|
|
136
|
+
logger.error("Error getting file attributes: \(error.localizedDescription)")
|
|
137
|
+
// Fallback decision
|
|
138
|
+
return TransportDecision(
|
|
139
|
+
transportType: .base64,
|
|
140
|
+
reason: "Error determining file size, defaulting to base64: \(error.localizedDescription)",
|
|
141
|
+
fileSize: 0,
|
|
142
|
+
filePath: filePath,
|
|
143
|
+
fileName: fileName
|
|
144
|
+
)
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
// MARK: - File Processing
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* Process file using the determined transport method
|
|
152
|
+
* Matches Android's FileSizeRouterUtils.processFile() functionality
|
|
153
|
+
*/
|
|
154
|
+
static func processFile(decision: TransportDecision, options: [String: Any] = [:]) -> CameraProcessingResult {
|
|
155
|
+
logger.info("Processing file with transport: \(decision.transportType.name) - \(decision.reason)")
|
|
156
|
+
|
|
157
|
+
let fileURL = URL(fileURLWithPath: decision.filePath)
|
|
158
|
+
let mimeType = getMimeType(for: fileURL)
|
|
159
|
+
|
|
160
|
+
switch decision.transportType {
|
|
161
|
+
case .base64:
|
|
162
|
+
return processWithBase64(fileURL: fileURL, decision: decision, mimeType: mimeType, options: options)
|
|
163
|
+
|
|
164
|
+
case .frameworkServer:
|
|
165
|
+
return processWithFrameworkServer(fileURL: fileURL, decision: decision, mimeType: mimeType, options: options)
|
|
166
|
+
|
|
167
|
+
case .fileUrl:
|
|
168
|
+
// Legacy support - redirect to framework server for consistency
|
|
169
|
+
logger.warning("fileUrl transport type deprecated, using framework server")
|
|
170
|
+
return processWithFrameworkServer(fileURL: fileURL, decision: decision, mimeType: mimeType, options: options)
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
// MARK: - Base64 Processing
|
|
175
|
+
|
|
176
|
+
private static func processWithBase64(fileURL: URL, decision: TransportDecision, mimeType: String, options: [String: Any]) -> CameraProcessingResult {
|
|
177
|
+
do {
|
|
178
|
+
let imageData = try Data(contentsOf: fileURL)
|
|
179
|
+
|
|
180
|
+
// Apply quality compression if specified
|
|
181
|
+
let processedData = applyQualityCompression(data: imageData, options: options, mimeType: mimeType)
|
|
182
|
+
let base64String = processedData.base64EncodedString()
|
|
183
|
+
let dataUri = "data:\(mimeType);base64,\(base64String)"
|
|
184
|
+
|
|
185
|
+
logger.debug("Successfully processed file with base64 transport")
|
|
186
|
+
|
|
187
|
+
return CameraProcessingResult.success(
|
|
188
|
+
fileName: decision.fileName,
|
|
189
|
+
fileSrc: dataUri,
|
|
190
|
+
filePath: decision.filePath,
|
|
191
|
+
fileSize: Int64(processedData.count),
|
|
192
|
+
mimeType: mimeType,
|
|
193
|
+
transportUsed: .base64
|
|
194
|
+
)
|
|
195
|
+
|
|
196
|
+
} catch {
|
|
197
|
+
logger.error("Base64 processing failed: \(error.localizedDescription)")
|
|
198
|
+
return CameraProcessingResult.failure(error: "Base64 encoding failed: \(error.localizedDescription)")
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
// MARK: - File URL Processing
|
|
203
|
+
|
|
204
|
+
private static func processWithFileUrl(fileURL: URL, decision: TransportDecision, mimeType: String, options: [String: Any]) -> CameraProcessingResult {
|
|
205
|
+
do {
|
|
206
|
+
// Create accessible file URL for WebView
|
|
207
|
+
let accessibleURL = try createAccessibleFileUrl(from: fileURL, options: options)
|
|
208
|
+
|
|
209
|
+
logger.debug("Successfully processed file with file URL transport")
|
|
210
|
+
|
|
211
|
+
return CameraProcessingResult.success(
|
|
212
|
+
fileName: decision.fileName,
|
|
213
|
+
fileSrc: accessibleURL.absoluteString,
|
|
214
|
+
filePath: accessibleURL.path,
|
|
215
|
+
fileSize: decision.fileSize,
|
|
216
|
+
mimeType: mimeType,
|
|
217
|
+
transportUsed: .fileUrl
|
|
218
|
+
)
|
|
219
|
+
|
|
220
|
+
} catch {
|
|
221
|
+
logger.error("File URL processing failed: \(error.localizedDescription)")
|
|
222
|
+
return CameraProcessingResult.failure(error: "File URL processing failed: \(error.localizedDescription)")
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
// MARK: - Framework Server Processing
|
|
227
|
+
|
|
228
|
+
private static func processWithFrameworkServer(fileURL: URL, decision: TransportDecision, mimeType: String, options: [String: Any]) -> CameraProcessingResult {
|
|
229
|
+
logger.info("Processing file with framework server transport")
|
|
230
|
+
|
|
231
|
+
let frameworkServer = FrameworkServerUtils.shared
|
|
232
|
+
|
|
233
|
+
// Ensure framework server is running
|
|
234
|
+
if !frameworkServer.isRunning() {
|
|
235
|
+
logger.info("Framework server not running, starting server...")
|
|
236
|
+
if !frameworkServer.startServer() {
|
|
237
|
+
logger.error("Failed to start framework server, falling back to file URL")
|
|
238
|
+
return fallbackToFileUrlProcessing(fileURL: fileURL, decision: decision, mimeType: mimeType, options: options)
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
// Copy file to server cache and get serving URL
|
|
243
|
+
guard let serverUrl = frameworkServer.copyAndServeFile(
|
|
244
|
+
originalFile: fileURL,
|
|
245
|
+
fileName: decision.fileName,
|
|
246
|
+
mimeType: mimeType
|
|
247
|
+
) else {
|
|
248
|
+
logger.error("Failed to add file to framework server, falling back to file URL")
|
|
249
|
+
return fallbackToFileUrlProcessing(fileURL: fileURL, decision: decision, mimeType: mimeType, options: options)
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
logger.debug("Successfully processed file with framework server: \(serverUrl)")
|
|
253
|
+
|
|
254
|
+
return CameraProcessingResult.success(
|
|
255
|
+
fileName: decision.fileName,
|
|
256
|
+
fileSrc: serverUrl,
|
|
257
|
+
filePath: fileURL.path,
|
|
258
|
+
fileSize: decision.fileSize,
|
|
259
|
+
mimeType: mimeType,
|
|
260
|
+
transportUsed: .frameworkServer
|
|
261
|
+
)
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
// MARK: - Fallback Processing
|
|
265
|
+
|
|
266
|
+
private static func fallbackToFileUrlProcessing(fileURL: URL, decision: TransportDecision, mimeType: String, options: [String: Any]) -> CameraProcessingResult {
|
|
267
|
+
do {
|
|
268
|
+
// Create accessible file URL for WebView (iOS file:// URL with proper permissions)
|
|
269
|
+
let accessibleURL = try createAccessibleFileUrl(from: fileURL, options: options)
|
|
270
|
+
|
|
271
|
+
logger.debug("Successfully processed file with file URL fallback")
|
|
272
|
+
|
|
273
|
+
return CameraProcessingResult.success(
|
|
274
|
+
fileName: decision.fileName,
|
|
275
|
+
fileSrc: accessibleURL.absoluteString,
|
|
276
|
+
filePath: accessibleURL.path,
|
|
277
|
+
fileSize: decision.fileSize,
|
|
278
|
+
mimeType: mimeType,
|
|
279
|
+
transportUsed: .fileUrl
|
|
280
|
+
)
|
|
281
|
+
|
|
282
|
+
} catch {
|
|
283
|
+
logger.error("File URL fallback failed: \(error.localizedDescription)")
|
|
284
|
+
return CameraProcessingResult.failure(error: "Framework server and file URL fallback both failed: \(error.localizedDescription)")
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
// MARK: - Helper Methods
|
|
289
|
+
|
|
290
|
+
/**
|
|
291
|
+
* Apply quality compression based on options
|
|
292
|
+
*/
|
|
293
|
+
private static func applyQualityCompression(data: Data, options: [String: Any], mimeType: String) -> Data {
|
|
294
|
+
// Only apply compression for JPEG images
|
|
295
|
+
guard mimeType.contains("jpeg") || mimeType.contains("jpg"),
|
|
296
|
+
let image = UIImage(data: data) else {
|
|
297
|
+
return data
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
// Determine compression quality using unified constants
|
|
301
|
+
let quality: CGFloat
|
|
302
|
+
if let qualityString = options["quality"] as? String {
|
|
303
|
+
switch qualityString.lowercased() {
|
|
304
|
+
case "high":
|
|
305
|
+
quality = CatalystConstants.ImageProcessing.Quality.high
|
|
306
|
+
case "low":
|
|
307
|
+
quality = CatalystConstants.ImageProcessing.Quality.low
|
|
308
|
+
case "medium":
|
|
309
|
+
quality = CatalystConstants.ImageProcessing.Quality.medium
|
|
310
|
+
default:
|
|
311
|
+
quality = CatalystConstants.ImageProcessing.defaultQuality
|
|
312
|
+
}
|
|
313
|
+
} else {
|
|
314
|
+
quality = CatalystConstants.ImageProcessing.defaultQuality
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
if let compressedData = image.jpegData(compressionQuality: quality) {
|
|
318
|
+
logger.debug("Applied JPEG compression with quality: \(quality)")
|
|
319
|
+
return compressedData
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
return data
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
/**
|
|
326
|
+
* Create accessible file URL for WebView consumption
|
|
327
|
+
*/
|
|
328
|
+
private static func createAccessibleFileUrl(from fileURL: URL, options: [String: Any]) throws -> URL {
|
|
329
|
+
// For iOS, we'll use the file URL directly
|
|
330
|
+
// In production, this might involve copying to a web-accessible directory
|
|
331
|
+
return fileURL
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
/**
|
|
335
|
+
* Get MIME type for file
|
|
336
|
+
*/
|
|
337
|
+
private static func getMimeType(for fileURL: URL) -> String {
|
|
338
|
+
let pathExtension = fileURL.pathExtension.lowercased()
|
|
339
|
+
|
|
340
|
+
switch pathExtension {
|
|
341
|
+
case "jpg", "jpeg":
|
|
342
|
+
return "image/jpeg"
|
|
343
|
+
case "png":
|
|
344
|
+
return "image/png"
|
|
345
|
+
case "gif":
|
|
346
|
+
return "image/gif"
|
|
347
|
+
case "webp":
|
|
348
|
+
return "image/webp"
|
|
349
|
+
default:
|
|
350
|
+
return "image/jpeg" // Default for camera images
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
/**
|
|
355
|
+
* Format file size for logging
|
|
356
|
+
*/
|
|
357
|
+
static func formatFileSize(_ bytes: Int64) -> String {
|
|
358
|
+
let formatter = ByteCountFormatter()
|
|
359
|
+
formatter.allowedUnits = [.useKB, .useMB, .useGB]
|
|
360
|
+
formatter.countStyle = .file
|
|
361
|
+
return formatter.string(fromByteCount: bytes)
|
|
362
|
+
}
|
|
363
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
//
|
|
2
|
+
// DeviceInfoUtils.swift
|
|
3
|
+
// iosnativeWebView
|
|
4
|
+
//
|
|
5
|
+
// Created by Catalyst Core
|
|
6
|
+
//
|
|
7
|
+
|
|
8
|
+
import Foundation
|
|
9
|
+
import UIKit
|
|
10
|
+
import os
|
|
11
|
+
|
|
12
|
+
private let logger = Logger(subsystem: Bundle.main.bundleIdentifier ?? "com.app", category: "DeviceInfoUtils")
|
|
13
|
+
|
|
14
|
+
/// Utility class for retrieving device information
|
|
15
|
+
/// Provides device model, manufacturer, platform, screen dimensions, and OS version
|
|
16
|
+
class DeviceInfoUtils {
|
|
17
|
+
|
|
18
|
+
/// Get comprehensive device information
|
|
19
|
+
/// - Returns: Dictionary containing device information or error details
|
|
20
|
+
static func getDeviceInfo() -> [String: Any] {
|
|
21
|
+
logger.debug("Fetching device information")
|
|
22
|
+
|
|
23
|
+
let device = UIDevice.current
|
|
24
|
+
let screen = UIScreen.main
|
|
25
|
+
|
|
26
|
+
// Basic device information
|
|
27
|
+
var deviceInfo: [String: Any] = [
|
|
28
|
+
"model": device.model,
|
|
29
|
+
"manufacturer": "Apple",
|
|
30
|
+
"platform": "ios",
|
|
31
|
+
"systemVersion": device.systemVersion,
|
|
32
|
+
// Screen dimensions in actual pixels
|
|
33
|
+
"screenWidth": Int(screen.bounds.width * screen.scale),
|
|
34
|
+
"screenHeight": Int(screen.bounds.height * screen.scale),
|
|
35
|
+
"screenDensity": screen.scale
|
|
36
|
+
]
|
|
37
|
+
|
|
38
|
+
deviceInfo["appInfo"] = ConfigConstants.appInfo
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
logger.debug("Device info retrieved successfully: \(deviceInfo.description)")
|
|
42
|
+
return deviceInfo
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/// Get device model name
|
|
46
|
+
/// - Returns: Device model string (e.g., "iPhone", "iPad")
|
|
47
|
+
static func getDeviceModel() -> String {
|
|
48
|
+
return UIDevice.current.model
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/// Get iOS system version
|
|
52
|
+
/// - Returns: System version string (e.g., "17.0")
|
|
53
|
+
static func getSystemVersion() -> String {
|
|
54
|
+
return UIDevice.current.systemVersion
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/// Get screen dimensions
|
|
58
|
+
/// - Returns: Tuple containing width, height, and scale factor
|
|
59
|
+
static func getScreenDimensions() -> (width: Int, height: Int, scale: CGFloat) {
|
|
60
|
+
let screen = UIScreen.main
|
|
61
|
+
let width = Int(screen.bounds.width * screen.scale)
|
|
62
|
+
let height = Int(screen.bounds.height * screen.scale)
|
|
63
|
+
let scale = screen.scale
|
|
64
|
+
|
|
65
|
+
return (width: width, height: height, scale: scale)
|
|
66
|
+
}
|
|
67
|
+
}
|