@thelacanians/vue-native-cli 0.4.14 → 0.6.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/dist/cli.js +789 -200
- package/native/android/VueNativeCore/src/main/kotlin/com/vuenative/core/Bridge/NativeBridge.kt +156 -5
- package/native/android/VueNativeCore/src/main/kotlin/com/vuenative/core/Components/Factories/VListFactory.kt +33 -13
- package/native/android/VueNativeCore/src/main/kotlin/com/vuenative/core/Components/Factories/VScrollViewFactory.kt +27 -6
- package/native/android/VueNativeCore/src/main/kotlin/com/vuenative/core/Components/Factories/VSliderFactory.kt +9 -2
- package/native/android/VueNativeCore/src/main/kotlin/com/vuenative/core/Components/Factories/VViewFactory.kt +178 -1
- package/native/android/VueNativeCore/src/main/kotlin/com/vuenative/core/Helpers/EventThrottle.kt +57 -0
- package/native/android/VueNativeCore/src/main/kotlin/com/vuenative/core/Modules/GeneratedModuleRegistry.kt +28 -0
- package/native/android/VueNativeCore/src/main/kotlin/com/vuenative/core/Modules/NativeModuleRegistry.kt +3 -0
- package/native/android/VueNativeCore/src/test/kotlin/com/vuenative/core/ComponentFactoryTest.kt +674 -0
- package/native/android/VueNativeCore/src/test/kotlin/com/vuenative/core/ErrorOverlayViewTest.kt +183 -0
- package/native/android/VueNativeCore/src/test/kotlin/com/vuenative/core/EventThrottleTest.kt +203 -0
- package/native/android/VueNativeCore/src/test/kotlin/com/vuenative/core/HotReloadManagerTest.kt +162 -0
- package/native/android/VueNativeCore/src/test/kotlin/com/vuenative/core/JSPolyfillsTest.kt +153 -0
- package/native/android/VueNativeCore/src/test/kotlin/com/vuenative/core/NativeBridgeTest.kt +6 -3
- package/native/android/VueNativeCore/src/test/kotlin/com/vuenative/core/NativeModuleTest.kt +475 -0
- package/native/android/gradle.properties +1 -0
- package/native/android/gradlew +1 -1
- package/native/ios/VueNativeCore/Package.swift +1 -1
- package/native/ios/VueNativeCore/Sources/VueNativeCore/Bridge/EventThrottle.swift +80 -0
- package/native/ios/VueNativeCore/Sources/VueNativeCore/Bridge/NativeBridge.swift +244 -112
- package/native/ios/VueNativeCore/Sources/VueNativeCore/Components/Factories/VListFactory.swift +19 -2
- package/native/ios/VueNativeCore/Sources/VueNativeCore/Components/Factories/VScrollViewFactory.swift +9 -4
- package/native/ios/VueNativeCore/Sources/VueNativeCore/Components/Factories/VSliderFactory.swift +8 -3
- package/native/ios/VueNativeCore/Sources/VueNativeCore/Components/Factories/VTextFactory.swift +43 -0
- package/native/ios/VueNativeCore/Sources/VueNativeCore/Components/Factories/VViewFactory.swift +116 -4
- package/native/ios/VueNativeCore/Sources/VueNativeCore/Helpers/GestureWrapper.swift +100 -0
- package/native/ios/VueNativeCore/Sources/VueNativeCore/Modules/GeneratedModuleRegistry.swift +28 -0
- package/native/ios/VueNativeCore/Sources/VueNativeCore/Modules/NativeModuleRegistry.swift +3 -0
- package/native/ios/VueNativeCore/Tests/VueNativeCoreTests/CertificatePinningTests.swift +190 -0
- package/native/ios/VueNativeCore/Tests/VueNativeCoreTests/ComponentFactoryTests.swift +585 -0
- package/native/ios/VueNativeCore/Tests/VueNativeCoreTests/EventThrottleTests.swift +161 -0
- package/native/ios/VueNativeCore/Tests/VueNativeCoreTests/HotReloadManagerTests.swift +88 -0
- package/native/ios/VueNativeCore/Tests/VueNativeCoreTests/JSPolyfillsTests.swift +319 -0
- package/native/ios/VueNativeCore/Tests/VueNativeCoreTests/NativeModuleTests.swift +400 -0
- package/native/macos/VueNativeMacOS/Package.swift +34 -0
- package/native/macos/VueNativeMacOS/Sources/VueNativeMacOS/Bridge/ErrorOverlayView.swift +112 -0
- package/native/macos/VueNativeMacOS/Sources/VueNativeMacOS/Bridge/EventThrottle.swift +58 -0
- package/native/macos/VueNativeMacOS/Sources/VueNativeMacOS/Bridge/HotReloadManager.swift +153 -0
- package/native/macos/VueNativeMacOS/Sources/VueNativeMacOS/Bridge/JSPolyfills.swift +696 -0
- package/native/macos/VueNativeMacOS/Sources/VueNativeMacOS/Bridge/JSRuntime.swift +347 -0
- package/native/macos/VueNativeMacOS/Sources/VueNativeMacOS/Bridge/NativeBridge.swift +877 -0
- package/native/macos/VueNativeMacOS/Sources/VueNativeMacOS/Bridge/VueNativeWindowController.swift +125 -0
- package/native/macos/VueNativeMacOS/Sources/VueNativeMacOS/Components/ComponentRegistry.swift +209 -0
- package/native/macos/VueNativeMacOS/Sources/VueNativeMacOS/Components/Factories/VActionSheetFactory.swift +155 -0
- package/native/macos/VueNativeMacOS/Sources/VueNativeMacOS/Components/Factories/VActivityIndicatorFactory.swift +85 -0
- package/native/macos/VueNativeMacOS/Sources/VueNativeMacOS/Components/Factories/VAlertDialogFactory.swift +132 -0
- package/native/macos/VueNativeMacOS/Sources/VueNativeMacOS/Components/Factories/VButtonFactory.swift +83 -0
- package/native/macos/VueNativeMacOS/Sources/VueNativeMacOS/Components/Factories/VCheckboxFactory.swift +108 -0
- package/native/macos/VueNativeMacOS/Sources/VueNativeMacOS/Components/Factories/VDropdownFactory.swift +155 -0
- package/native/macos/VueNativeMacOS/Sources/VueNativeMacOS/Components/Factories/VImageFactory.swift +270 -0
- package/native/macos/VueNativeMacOS/Sources/VueNativeMacOS/Components/Factories/VInputFactory.swift +257 -0
- package/native/macos/VueNativeMacOS/Sources/VueNativeMacOS/Components/Factories/VKeyboardAvoidingFactory.swift +22 -0
- package/native/macos/VueNativeMacOS/Sources/VueNativeMacOS/Components/Factories/VListFactory.swift +324 -0
- package/native/macos/VueNativeMacOS/Sources/VueNativeMacOS/Components/Factories/VModalFactory.swift +231 -0
- package/native/macos/VueNativeMacOS/Sources/VueNativeMacOS/Components/Factories/VOutlineViewFactory.swift +276 -0
- package/native/macos/VueNativeMacOS/Sources/VueNativeMacOS/Components/Factories/VPickerFactory.swift +134 -0
- package/native/macos/VueNativeMacOS/Sources/VueNativeMacOS/Components/Factories/VPressableFactory.swift +120 -0
- package/native/macos/VueNativeMacOS/Sources/VueNativeMacOS/Components/Factories/VProgressBarFactory.swift +71 -0
- package/native/macos/VueNativeMacOS/Sources/VueNativeMacOS/Components/Factories/VRadioFactory.swift +193 -0
- package/native/macos/VueNativeMacOS/Sources/VueNativeMacOS/Components/Factories/VRefreshControlFactory.swift +25 -0
- package/native/macos/VueNativeMacOS/Sources/VueNativeMacOS/Components/Factories/VSafeAreaFactory.swift +46 -0
- package/native/macos/VueNativeMacOS/Sources/VueNativeMacOS/Components/Factories/VScrollViewFactory.swift +190 -0
- package/native/macos/VueNativeMacOS/Sources/VueNativeMacOS/Components/Factories/VSectionListFactory.swift +374 -0
- package/native/macos/VueNativeMacOS/Sources/VueNativeMacOS/Components/Factories/VSegmentedControlFactory.swift +125 -0
- package/native/macos/VueNativeMacOS/Sources/VueNativeMacOS/Components/Factories/VSliderFactory.swift +131 -0
- package/native/macos/VueNativeMacOS/Sources/VueNativeMacOS/Components/Factories/VSplitViewFactory.swift +215 -0
- package/native/macos/VueNativeMacOS/Sources/VueNativeMacOS/Components/Factories/VStatusBarFactory.swift +25 -0
- package/native/macos/VueNativeMacOS/Sources/VueNativeMacOS/Components/Factories/VSwitchFactory.swift +92 -0
- package/native/macos/VueNativeMacOS/Sources/VueNativeMacOS/Components/Factories/VTextFactory.swift +336 -0
- package/native/macos/VueNativeMacOS/Sources/VueNativeMacOS/Components/Factories/VToolbarFactory.swift +212 -0
- package/native/macos/VueNativeMacOS/Sources/VueNativeMacOS/Components/Factories/VVideoFactory.swift +245 -0
- package/native/macos/VueNativeMacOS/Sources/VueNativeMacOS/Components/Factories/VViewFactory.swift +314 -0
- package/native/macos/VueNativeMacOS/Sources/VueNativeMacOS/Components/Factories/VWebViewFactory.swift +162 -0
- package/native/macos/VueNativeMacOS/Sources/VueNativeMacOS/Components/NativeComponentFactory.swift +54 -0
- package/native/macos/VueNativeMacOS/Sources/VueNativeMacOS/Helpers/ClickableView.swift +100 -0
- package/native/macos/VueNativeMacOS/Sources/VueNativeMacOS/Helpers/Extensions.swift +23 -0
- package/native/macos/VueNativeMacOS/Sources/VueNativeMacOS/Helpers/GestureWrapper.swift +183 -0
- package/native/macos/VueNativeMacOS/Sources/VueNativeMacOS/Helpers/NSColor+Hex.swift +78 -0
- package/native/macos/VueNativeMacOS/Sources/VueNativeMacOS/Layout/FlippedView.swift +19 -0
- package/native/macos/VueNativeMacOS/Sources/VueNativeMacOS/Layout/LayoutNode.swift +493 -0
- package/native/macos/VueNativeMacOS/Sources/VueNativeMacOS/Modules/AnimationModule.swift +354 -0
- package/native/macos/VueNativeMacOS/Sources/VueNativeMacOS/Modules/AppStateModule.swift +62 -0
- package/native/macos/VueNativeMacOS/Sources/VueNativeMacOS/Modules/BiometryModule.swift +60 -0
- package/native/macos/VueNativeMacOS/Sources/VueNativeMacOS/Modules/CameraModule.swift +167 -0
- package/native/macos/VueNativeMacOS/Sources/VueNativeMacOS/Modules/ClipboardModule.swift +34 -0
- package/native/macos/VueNativeMacOS/Sources/VueNativeMacOS/Modules/DeviceInfoModule.swift +49 -0
- package/native/macos/VueNativeMacOS/Sources/VueNativeMacOS/Modules/DragDropModule.swift +50 -0
- package/native/macos/VueNativeMacOS/Sources/VueNativeMacOS/Modules/FileDialogModule.swift +86 -0
- package/native/macos/VueNativeMacOS/Sources/VueNativeMacOS/Modules/HapticsModule.swift +42 -0
- package/native/macos/VueNativeMacOS/Sources/VueNativeMacOS/Modules/KeyboardModule.swift +28 -0
- package/native/macos/VueNativeMacOS/Sources/VueNativeMacOS/Modules/LinkingModule.swift +49 -0
- package/native/macos/VueNativeMacOS/Sources/VueNativeMacOS/Modules/MenuModule.swift +95 -0
- package/native/macos/VueNativeMacOS/Sources/VueNativeMacOS/Modules/NativeModuleRegistry.swift +63 -0
- package/native/macos/VueNativeMacOS/Sources/VueNativeMacOS/Modules/NotificationsModule.swift +112 -0
- package/native/macos/VueNativeMacOS/Sources/VueNativeMacOS/Modules/PermissionsModule.swift +149 -0
- package/native/macos/VueNativeMacOS/Sources/VueNativeMacOS/Modules/ShareModule.swift +37 -0
- package/native/macos/VueNativeMacOS/Sources/VueNativeMacOS/Modules/WindowModule.swift +71 -0
- package/native/macos/VueNativeMacOS/Sources/VueNativeMacOS/Resources/vue-native-placeholder.js +2 -0
- package/native/macos/VueNativeMacOS/Sources/VueNativeMacOS/Styling/StyleEngine.swift +885 -0
- package/native/macos/VueNativeMacOS/Tests/VueNativeMacOSTests/ComponentFactoryTests.swift +80 -0
- package/native/macos/VueNativeMacOS/Tests/VueNativeMacOSTests/VueNativeMacOSTests.swift +149 -0
- package/native/shared/VueNativeShared/AGENTS.md +129 -0
- package/native/shared/VueNativeShared/Package.swift +14 -0
- package/native/shared/VueNativeShared/Sources/VueNativeShared/CertificatePinning.swift +134 -0
- package/native/shared/VueNativeShared/Sources/VueNativeShared/EventThrottle.swift +78 -0
- package/native/shared/VueNativeShared/Sources/VueNativeShared/HotReloadManager.swift +162 -0
- package/native/shared/VueNativeShared/Sources/VueNativeShared/JSRuntime.swift +412 -0
- package/native/shared/VueNativeShared/Sources/VueNativeShared/Modules/AsyncStorageModule.swift +68 -0
- package/native/shared/VueNativeShared/Sources/VueNativeShared/Modules/AudioModule.swift +359 -0
- package/native/shared/VueNativeShared/Sources/VueNativeShared/Modules/DatabaseModule.swift +259 -0
- package/native/shared/VueNativeShared/Sources/VueNativeShared/Modules/FileSystemModule.swift +233 -0
- package/native/shared/VueNativeShared/Sources/VueNativeShared/Modules/GeolocationModule.swift +156 -0
- package/native/shared/VueNativeShared/Sources/VueNativeShared/Modules/NetworkModule.swift +59 -0
- package/native/shared/VueNativeShared/Sources/VueNativeShared/Modules/PerformanceModule.swift +113 -0
- package/native/shared/VueNativeShared/Sources/VueNativeShared/Modules/SecureStorageModule.swift +119 -0
- package/native/shared/VueNativeShared/Sources/VueNativeShared/Modules/WebSocketModule.swift +212 -0
- package/native/shared/VueNativeShared/Sources/VueNativeShared/NativeEventDispatcher.swift +6 -0
- package/native/shared/VueNativeShared/Sources/VueNativeShared/NativeModule.swift +26 -0
- package/native/shared/VueNativeShared/Sources/VueNativeShared/NativeModuleRegistry.swift +37 -0
- package/native/shared/VueNativeShared/Sources/VueNativeShared/SharedJSPolyfills.swift +673 -0
- package/native/shared/VueNativeShared/Tests/VueNativeSharedTests/VueNativeSharedTests.swift +44 -0
- package/package.json +8 -2
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import AVFoundation
|
|
2
|
+
import UserNotifications
|
|
3
|
+
import CoreLocation
|
|
4
|
+
import Contacts
|
|
5
|
+
import VueNativeShared
|
|
6
|
+
|
|
7
|
+
/// Native module for checking and requesting system permissions on macOS.
|
|
8
|
+
///
|
|
9
|
+
/// Methods:
|
|
10
|
+
/// - check(type: String) -> "granted"/"denied"/"undetermined"
|
|
11
|
+
/// - request(type: String) -> "granted"/"denied"
|
|
12
|
+
///
|
|
13
|
+
/// Supported permission types: "camera", "microphone", "notifications", "location", "contacts"
|
|
14
|
+
final class PermissionsModule: NativeModule {
|
|
15
|
+
let moduleName = "Permissions"
|
|
16
|
+
|
|
17
|
+
private lazy var locationManager = CLLocationManager()
|
|
18
|
+
|
|
19
|
+
func invoke(method: String, args: [Any], callback: @escaping (Any?, String?) -> Void) {
|
|
20
|
+
guard let permissionType = args.first as? String else {
|
|
21
|
+
callback(nil, "PermissionsModule: missing permission type argument")
|
|
22
|
+
return
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
switch method {
|
|
26
|
+
case "check":
|
|
27
|
+
checkPermission(type: permissionType, callback: callback)
|
|
28
|
+
|
|
29
|
+
case "request":
|
|
30
|
+
requestPermission(type: permissionType, callback: callback)
|
|
31
|
+
|
|
32
|
+
default:
|
|
33
|
+
callback(nil, "PermissionsModule: Unknown method '\(method)'")
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// MARK: - Check
|
|
38
|
+
|
|
39
|
+
private func checkPermission(type: String, callback: @escaping (Any?, String?) -> Void) {
|
|
40
|
+
switch type {
|
|
41
|
+
case "camera":
|
|
42
|
+
let status = AVCaptureDevice.authorizationStatus(for: .video)
|
|
43
|
+
callback(mapAVStatus(status), nil)
|
|
44
|
+
|
|
45
|
+
case "microphone":
|
|
46
|
+
let status = AVCaptureDevice.authorizationStatus(for: .audio)
|
|
47
|
+
callback(mapAVStatus(status), nil)
|
|
48
|
+
|
|
49
|
+
case "notifications":
|
|
50
|
+
UNUserNotificationCenter.current().getNotificationSettings { settings in
|
|
51
|
+
let result: String
|
|
52
|
+
switch settings.authorizationStatus {
|
|
53
|
+
case .authorized, .provisional, .ephemeral:
|
|
54
|
+
result = "granted"
|
|
55
|
+
case .denied:
|
|
56
|
+
result = "denied"
|
|
57
|
+
case .notDetermined:
|
|
58
|
+
result = "undetermined"
|
|
59
|
+
@unknown default:
|
|
60
|
+
result = "undetermined"
|
|
61
|
+
}
|
|
62
|
+
callback(result, nil)
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
case "location":
|
|
66
|
+
let status: CLAuthorizationStatus
|
|
67
|
+
status = locationManager.authorizationStatus
|
|
68
|
+
callback(mapCLStatus(status), nil)
|
|
69
|
+
|
|
70
|
+
case "contacts":
|
|
71
|
+
let status = CNContactStore.authorizationStatus(for: .contacts)
|
|
72
|
+
switch status {
|
|
73
|
+
case .authorized:
|
|
74
|
+
callback("granted", nil)
|
|
75
|
+
case .denied, .restricted:
|
|
76
|
+
callback("denied", nil)
|
|
77
|
+
case .notDetermined:
|
|
78
|
+
callback("undetermined", nil)
|
|
79
|
+
@unknown default:
|
|
80
|
+
callback("undetermined", nil)
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
default:
|
|
84
|
+
callback(nil, "PermissionsModule: Unsupported permission type '\(type)'")
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// MARK: - Request
|
|
89
|
+
|
|
90
|
+
private func requestPermission(type: String, callback: @escaping (Any?, String?) -> Void) {
|
|
91
|
+
switch type {
|
|
92
|
+
case "camera":
|
|
93
|
+
AVCaptureDevice.requestAccess(for: .video) { granted in
|
|
94
|
+
callback(granted ? "granted" : "denied", nil)
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
case "microphone":
|
|
98
|
+
AVCaptureDevice.requestAccess(for: .audio) { granted in
|
|
99
|
+
callback(granted ? "granted" : "denied", nil)
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
case "notifications":
|
|
103
|
+
UNUserNotificationCenter.current().requestAuthorization(
|
|
104
|
+
options: [.alert, .sound, .badge]
|
|
105
|
+
) { granted, _ in
|
|
106
|
+
callback(granted ? "granted" : "denied", nil)
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
case "location":
|
|
110
|
+
locationManager.requestWhenInUseAuthorization()
|
|
111
|
+
// CLLocationManager doesn't provide a completion handler.
|
|
112
|
+
// Return current status; JS side should re-check after a delay.
|
|
113
|
+
let status = locationManager.authorizationStatus
|
|
114
|
+
callback(mapCLStatus(status), nil)
|
|
115
|
+
|
|
116
|
+
case "contacts":
|
|
117
|
+
CNContactStore().requestAccess(for: .contacts) { granted, _ in
|
|
118
|
+
callback(granted ? "granted" : "denied", nil)
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
default:
|
|
122
|
+
callback(nil, "PermissionsModule: Unsupported permission type '\(type)'")
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
// MARK: - Helpers
|
|
127
|
+
|
|
128
|
+
private func mapAVStatus(_ status: AVAuthorizationStatus) -> String {
|
|
129
|
+
switch status {
|
|
130
|
+
case .authorized: return "granted"
|
|
131
|
+
case .denied, .restricted: return "denied"
|
|
132
|
+
case .notDetermined: return "undetermined"
|
|
133
|
+
@unknown default: return "undetermined"
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
private func mapCLStatus(_ status: CLAuthorizationStatus) -> String {
|
|
138
|
+
switch status {
|
|
139
|
+
case .authorizedAlways:
|
|
140
|
+
return "granted"
|
|
141
|
+
case .denied, .restricted:
|
|
142
|
+
return "denied"
|
|
143
|
+
case .notDetermined:
|
|
144
|
+
return "undetermined"
|
|
145
|
+
@unknown default:
|
|
146
|
+
return "undetermined"
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import AppKit
|
|
2
|
+
import VueNativeShared
|
|
3
|
+
|
|
4
|
+
/// Native module for sharing content on macOS via NSSharingServicePicker.
|
|
5
|
+
///
|
|
6
|
+
/// Methods:
|
|
7
|
+
/// - share({ message?: String, url?: String }) -> { action: String }
|
|
8
|
+
final class ShareModule: NativeModule {
|
|
9
|
+
var moduleName: String { "Share" }
|
|
10
|
+
|
|
11
|
+
func invoke(method: String, args: [Any], callback: @escaping (Any?, String?) -> Void) {
|
|
12
|
+
switch method {
|
|
13
|
+
case "share":
|
|
14
|
+
guard let content = args.first as? [String: Any] else {
|
|
15
|
+
callback(nil, "Invalid content")
|
|
16
|
+
return
|
|
17
|
+
}
|
|
18
|
+
var items: [Any] = []
|
|
19
|
+
if let message = content["message"] as? String { items.append(message) }
|
|
20
|
+
if let urlStr = content["url"] as? String, let u = URL(string: urlStr) { items.append(u) }
|
|
21
|
+
if items.isEmpty { callback(nil, "No shareable content"); return }
|
|
22
|
+
|
|
23
|
+
DispatchQueue.main.async {
|
|
24
|
+
let picker = NSSharingServicePicker(items: items)
|
|
25
|
+
if let window = NSApp.mainWindow, let view = window.contentView {
|
|
26
|
+
picker.show(relativeTo: view.bounds, of: view, preferredEdge: .minY)
|
|
27
|
+
}
|
|
28
|
+
callback(["action": "shared"], nil)
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
default:
|
|
32
|
+
callback(nil, "ShareModule: Unknown method '\(method)'")
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
func invokeSync(method: String, args: [Any]) -> Any? { nil }
|
|
37
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import AppKit
|
|
2
|
+
import VueNativeShared
|
|
3
|
+
|
|
4
|
+
/// macOS-only module for window management.
|
|
5
|
+
///
|
|
6
|
+
/// Methods:
|
|
7
|
+
/// - setTitle(title: String)
|
|
8
|
+
/// - setSize(width: Double, height: Double)
|
|
9
|
+
/// - center()
|
|
10
|
+
/// - minimize()
|
|
11
|
+
/// - toggleFullScreen()
|
|
12
|
+
/// - close()
|
|
13
|
+
/// - getInfo() -> { width, height, x, y, isFullScreen, isVisible, title }
|
|
14
|
+
final class WindowModule: NativeModule {
|
|
15
|
+
let moduleName = "Window"
|
|
16
|
+
|
|
17
|
+
func invoke(method: String, args: [Any], callback: @escaping (Any?, String?) -> Void) {
|
|
18
|
+
DispatchQueue.main.async {
|
|
19
|
+
switch method {
|
|
20
|
+
case "setTitle":
|
|
21
|
+
let title = args.first as? String ?? ""
|
|
22
|
+
NSApp.mainWindow?.title = title
|
|
23
|
+
callback(nil, nil)
|
|
24
|
+
|
|
25
|
+
case "setSize":
|
|
26
|
+
guard args.count >= 2,
|
|
27
|
+
let width = args[0] as? Double,
|
|
28
|
+
let height = args[1] as? Double else {
|
|
29
|
+
callback(nil, "Invalid args")
|
|
30
|
+
return
|
|
31
|
+
}
|
|
32
|
+
NSApp.mainWindow?.setContentSize(NSSize(width: width, height: height))
|
|
33
|
+
callback(nil, nil)
|
|
34
|
+
|
|
35
|
+
case "center":
|
|
36
|
+
NSApp.mainWindow?.center()
|
|
37
|
+
callback(nil, nil)
|
|
38
|
+
|
|
39
|
+
case "minimize":
|
|
40
|
+
NSApp.mainWindow?.miniaturize(nil)
|
|
41
|
+
callback(nil, nil)
|
|
42
|
+
|
|
43
|
+
case "toggleFullScreen":
|
|
44
|
+
NSApp.mainWindow?.toggleFullScreen(nil)
|
|
45
|
+
callback(nil, nil)
|
|
46
|
+
|
|
47
|
+
case "close":
|
|
48
|
+
NSApp.mainWindow?.close()
|
|
49
|
+
callback(nil, nil)
|
|
50
|
+
|
|
51
|
+
case "getInfo":
|
|
52
|
+
guard let window = NSApp.mainWindow else {
|
|
53
|
+
callback(nil, "No main window")
|
|
54
|
+
return
|
|
55
|
+
}
|
|
56
|
+
callback([
|
|
57
|
+
"width": window.frame.width,
|
|
58
|
+
"height": window.frame.height,
|
|
59
|
+
"x": window.frame.origin.x,
|
|
60
|
+
"y": window.frame.origin.y,
|
|
61
|
+
"isFullScreen": window.styleMask.contains(.fullScreen),
|
|
62
|
+
"isVisible": window.isVisible,
|
|
63
|
+
"title": window.title,
|
|
64
|
+
], nil)
|
|
65
|
+
|
|
66
|
+
default:
|
|
67
|
+
callback(nil, "WindowModule: Unknown method '\(method)'")
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|