vxrn 2.15.0 → 2.15.1
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/exports/prebuild.mjs +37 -0
- package/dist/exports/prebuild.mjs.map +1 -1
- package/dist/exports/prebuild.native.js +55 -0
- package/dist/exports/prebuild.native.js.map +1 -1
- package/dist/exports/prebuildWithoutExpo.mjs +197 -12
- package/dist/exports/prebuildWithoutExpo.mjs.map +1 -1
- package/dist/exports/prebuildWithoutExpo.native.js +197 -10
- package/dist/exports/prebuildWithoutExpo.native.js.map +1 -1
- package/package.json +13 -13
- package/src/exports/prebuild.ts +30 -0
- package/src/exports/prebuildWithoutExpo.test.ts +74 -2
- package/src/exports/prebuildWithoutExpo.ts +204 -12
- package/types/exports/prebuild.d.ts.map +1 -1
- package/types/exports/prebuildWithoutExpo.d.ts.map +1 -1
|
@@ -250,6 +250,9 @@ function swiftShortcutPhrase(value) {
|
|
|
250
250
|
function renderIosAppIntentsSwift(actions) {
|
|
251
251
|
var types = actions.map(function(action, index) {
|
|
252
252
|
var summaryTitle = swiftLiteral(action.title).slice(1, -1);
|
|
253
|
+
var description = action.description === void 0 ? "" : `
|
|
254
|
+
static let description = IntentDescription(${swiftLiteral(action.description)})`;
|
|
255
|
+
var openAppWhenRun = action.openAppWhenRun === true ? "\n static let openAppWhenRun: Bool = true" : "";
|
|
253
256
|
var text = action.textParameterTitle === void 0 ? "" : `
|
|
254
257
|
@Parameter(title: ${swiftLiteral(action.textParameterTitle)}) var text: String
|
|
255
258
|
|
|
@@ -258,20 +261,22 @@ function renderIosAppIntentsSwift(actions) {
|
|
|
258
261
|
}
|
|
259
262
|
`;
|
|
260
263
|
return `struct OneAppIntent${index}: AppIntent {
|
|
261
|
-
static let title: LocalizedStringResource = ${swiftLiteral(action.title)}
|
|
264
|
+
static let title: LocalizedStringResource = ${swiftLiteral(action.title)}${description}${openAppWhenRun}
|
|
262
265
|
${text}
|
|
263
|
-
func perform() async throws -> some IntentResult & ReturnsValue<String> {
|
|
266
|
+
func perform() async throws -> some IntentResult & ReturnsValue<String> & ProvidesDialog {
|
|
264
267
|
let result = try await oneAppIntentsRun(${swiftLiteral(action.id)}, ${text ? "text" : "nil"})
|
|
265
|
-
return .result(value: result)
|
|
268
|
+
return .result(value: result, dialog: IntentDialog(stringLiteral: result))
|
|
266
269
|
}
|
|
267
270
|
}`;
|
|
268
271
|
});
|
|
269
272
|
var shortcuts = actions.map(function(action, index) {
|
|
273
|
+
var _action_shortcutPhrases, _action_systemImageName;
|
|
274
|
+
var phrases = Array.from(/* @__PURE__ */ new Set([action.shortcutPhrase, ...(_action_shortcutPhrases = action.shortcutPhrases) !== null && _action_shortcutPhrases !== void 0 ? _action_shortcutPhrases : []])).map(swiftShortcutPhrase);
|
|
270
275
|
return ` AppShortcut(
|
|
271
276
|
intent: OneAppIntent${index}(),
|
|
272
|
-
phrases: [${
|
|
277
|
+
phrases: [${phrases.join(", ")}],
|
|
273
278
|
shortTitle: ${swiftLiteral(action.title)},
|
|
274
|
-
systemImageName: "bolt.fill"
|
|
279
|
+
systemImageName: ${swiftLiteral((_action_systemImageName = action.systemImageName) !== null && _action_systemImageName !== void 0 ? _action_systemImageName : "bolt.fill")}
|
|
275
280
|
)`;
|
|
276
281
|
}).join("\n");
|
|
277
282
|
return `import AppIntents
|
|
@@ -664,6 +669,7 @@ function generateIosAppIntents(dest, platform, app) {
|
|
|
664
669
|
writeFileSync(path.join(dest, app.name, "OneAppIntents.swift"), renderIosAppIntentsSwift(app.ios.appIntents.actions));
|
|
665
670
|
}
|
|
666
671
|
function generateIosWidgets(dest, app) {
|
|
672
|
+
var _widgets_families;
|
|
667
673
|
var _app_ios, _app_ios1;
|
|
668
674
|
var widgets = (_app_ios = app.ios) === null || _app_ios === void 0 ? void 0 : _app_ios.widgets;
|
|
669
675
|
if (!widgets) return;
|
|
@@ -691,6 +697,9 @@ function generateIosWidgets(dest, app) {
|
|
|
691
697
|
<key>NSExtension</key><dict><key>NSExtensionPointIdentifier</key><string>com.apple.widgetkit-extension</string></dict>
|
|
692
698
|
</dict></plist>
|
|
693
699
|
`);
|
|
700
|
+
var supportedFamilies = ((_widgets_families = widgets.families) !== null && _widgets_families !== void 0 ? _widgets_families : ["systemSmall", "systemMedium"]).map(function(family) {
|
|
701
|
+
return `.${family}`;
|
|
702
|
+
}).join(", ");
|
|
694
703
|
writeFileSync(path.join(appDir, "OneWidgetContract.swift"), `import Foundation
|
|
695
704
|
import ActivityKit
|
|
696
705
|
|
|
@@ -698,6 +707,7 @@ enum OneWidgetContract {
|
|
|
698
707
|
static let appGroup = ${JSON.stringify(widgets.appGroup)}
|
|
699
708
|
static let kind = ${JSON.stringify(widgets.kind)}
|
|
700
709
|
static let dataKey = "one.widget.data"
|
|
710
|
+
static let actionKeyPrefix = "one.widget.action."
|
|
701
711
|
|
|
702
712
|
struct Data: Codable {
|
|
703
713
|
let title: String
|
|
@@ -706,6 +716,13 @@ enum OneWidgetContract {
|
|
|
706
716
|
let layout: String?
|
|
707
717
|
}
|
|
708
718
|
|
|
719
|
+
struct Action: Codable {
|
|
720
|
+
let id: String
|
|
721
|
+
let action: String
|
|
722
|
+
let value: String?
|
|
723
|
+
let timestampMs: Double
|
|
724
|
+
}
|
|
725
|
+
|
|
709
726
|
struct Attributes: ActivityAttributes {
|
|
710
727
|
struct ContentState: Codable, Hashable {
|
|
711
728
|
let status: String
|
|
@@ -719,6 +736,7 @@ enum OneWidgetContract {
|
|
|
719
736
|
writeFileSync(path.join(extensionDir, "OneWidget.swift"), `import SwiftUI
|
|
720
737
|
import WidgetKit
|
|
721
738
|
import ActivityKit
|
|
739
|
+
import AppIntents
|
|
722
740
|
|
|
723
741
|
struct OneWidgetNode: Decodable {
|
|
724
742
|
let type: String
|
|
@@ -726,11 +744,36 @@ struct OneWidgetNode: Decodable {
|
|
|
726
744
|
let style: Style?
|
|
727
745
|
let children: [OneWidgetNode]?
|
|
728
746
|
let systemName: String?
|
|
729
|
-
let value:
|
|
747
|
+
let value: Value?
|
|
730
748
|
let total: Double?
|
|
731
749
|
let fill: String?
|
|
732
750
|
let cornerRadius: Double?
|
|
733
751
|
let url: String?
|
|
752
|
+
let action: String?
|
|
753
|
+
|
|
754
|
+
enum Value: Decodable {
|
|
755
|
+
case number(Double)
|
|
756
|
+
case string(String)
|
|
757
|
+
|
|
758
|
+
var number: Double? {
|
|
759
|
+
if case .number(let value) = self { return value }
|
|
760
|
+
return nil
|
|
761
|
+
}
|
|
762
|
+
|
|
763
|
+
var string: String? {
|
|
764
|
+
if case .string(let value) = self { return value }
|
|
765
|
+
return nil
|
|
766
|
+
}
|
|
767
|
+
|
|
768
|
+
init(from decoder: Decoder) throws {
|
|
769
|
+
let container = try decoder.singleValueContainer()
|
|
770
|
+
if let number = try? container.decode(Double.self) {
|
|
771
|
+
self = .number(number)
|
|
772
|
+
} else {
|
|
773
|
+
self = .string(try container.decode(String.self))
|
|
774
|
+
}
|
|
775
|
+
}
|
|
776
|
+
}
|
|
734
777
|
|
|
735
778
|
struct Style: Decodable {
|
|
736
779
|
let color: String?
|
|
@@ -749,6 +792,43 @@ struct OneWidgetNode: Decodable {
|
|
|
749
792
|
}
|
|
750
793
|
}
|
|
751
794
|
|
|
795
|
+
struct OneWidgetButtonIntent: AppIntent {
|
|
796
|
+
static var title: LocalizedStringResource = "Widget Action"
|
|
797
|
+
|
|
798
|
+
@Parameter(title: "Action") var action: String
|
|
799
|
+
@Parameter(title: "Value") var value: String?
|
|
800
|
+
|
|
801
|
+
init() {}
|
|
802
|
+
|
|
803
|
+
init(action: String, value: String?) {
|
|
804
|
+
self.action = action
|
|
805
|
+
self.value = value
|
|
806
|
+
}
|
|
807
|
+
|
|
808
|
+
func perform() async throws -> some IntentResult {
|
|
809
|
+
if let defaults = UserDefaults(suiteName: OneWidgetContract.appGroup) {
|
|
810
|
+
let item = OneWidgetContract.Action(
|
|
811
|
+
id: UUID().uuidString,
|
|
812
|
+
action: action,
|
|
813
|
+
value: value,
|
|
814
|
+
timestampMs: Date().timeIntervalSince1970 * 1000
|
|
815
|
+
)
|
|
816
|
+
if let encoded = try? JSONEncoder().encode(item) {
|
|
817
|
+
defaults.set(encoded, forKey: OneWidgetContract.actionKeyPrefix + item.id)
|
|
818
|
+
}
|
|
819
|
+
CFNotificationCenterPostNotification(
|
|
820
|
+
CFNotificationCenterGetDarwinNotifyCenter(),
|
|
821
|
+
CFNotificationName("dev.onejs.widget.action" as CFString),
|
|
822
|
+
nil,
|
|
823
|
+
nil,
|
|
824
|
+
true
|
|
825
|
+
)
|
|
826
|
+
}
|
|
827
|
+
WidgetCenter.shared.reloadTimelines(ofKind: OneWidgetContract.kind)
|
|
828
|
+
return .result()
|
|
829
|
+
}
|
|
830
|
+
}
|
|
831
|
+
|
|
752
832
|
struct OneActivityView: Decodable {
|
|
753
833
|
let lockScreen: OneWidgetNode
|
|
754
834
|
let compactLeading: OneWidgetNode?
|
|
@@ -841,10 +921,10 @@ struct OneWidgetRendered: View {
|
|
|
841
921
|
.font(.system(size: CGFloat(node.style?.fontSize ?? 20), weight: weight))
|
|
842
922
|
}
|
|
843
923
|
case "progress":
|
|
844
|
-
ProgressView(value: node.value ?? 0, total: node.total ?? 1)
|
|
924
|
+
ProgressView(value: node.value?.number ?? 0, total: node.total ?? 1)
|
|
845
925
|
.tint(oneColor(node.style?.color))
|
|
846
926
|
case "gauge":
|
|
847
|
-
Gauge(value: node.value ?? 0, in: 0...(node.total ?? 1)) { EmptyView() }
|
|
927
|
+
Gauge(value: node.value?.number ?? 0, in: 0...(node.total ?? 1)) { EmptyView() }
|
|
848
928
|
.gaugeStyle(.accessoryCircular)
|
|
849
929
|
.tint(oneColor(node.style?.color))
|
|
850
930
|
case "circle":
|
|
@@ -862,6 +942,15 @@ struct OneWidgetRendered: View {
|
|
|
862
942
|
}
|
|
863
943
|
}
|
|
864
944
|
}
|
|
945
|
+
case "button":
|
|
946
|
+
if let action = node.action {
|
|
947
|
+
Button(intent: OneWidgetButtonIntent(action: action, value: node.value?.string)) {
|
|
948
|
+
ForEach(Array((node.children ?? []).enumerated()), id: \\.offset) { _, child in
|
|
949
|
+
OneWidgetRendered(node: child)
|
|
950
|
+
}
|
|
951
|
+
}
|
|
952
|
+
.buttonStyle(.plain)
|
|
953
|
+
}
|
|
865
954
|
default: EmptyView()
|
|
866
955
|
}
|
|
867
956
|
}
|
|
@@ -922,7 +1011,7 @@ struct OneWidget: Widget {
|
|
|
922
1011
|
}
|
|
923
1012
|
.configurationDisplayName(${JSON.stringify(widgets.displayName)})
|
|
924
1013
|
.description(${JSON.stringify(widgets.description)})
|
|
925
|
-
.supportedFamilies([
|
|
1014
|
+
.supportedFamilies([${supportedFamilies}])
|
|
926
1015
|
}
|
|
927
1016
|
}
|
|
928
1017
|
|
|
@@ -1016,28 +1105,117 @@ RCT_EXTERN_METHOD(update:(NSString *)identifier status:(NSString *)status value:
|
|
|
1016
1105
|
RCT_EXTERN_METHOD(updateView:(NSString *)identifier layout:(NSString *)layout resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject)
|
|
1017
1106
|
RCT_EXTERN_METHOD(end:(NSString *)identifier resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject)
|
|
1018
1107
|
RCT_EXTERN_METHOD(pushToken:(NSString *)identifier resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject)
|
|
1108
|
+
RCT_EXTERN_METHOD(claimActions:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject)
|
|
1019
1109
|
@end
|
|
1020
1110
|
`);
|
|
1021
1111
|
writeFileSync(path.join(appDir, "OneWidgetsBridge.swift"), `import Foundation
|
|
1112
|
+
import UIKit
|
|
1022
1113
|
import React
|
|
1023
1114
|
import WidgetKit
|
|
1024
1115
|
import ActivityKit
|
|
1025
1116
|
|
|
1117
|
+
private func oneWidgetsDarwinCallback(
|
|
1118
|
+
_ center: CFNotificationCenter?,
|
|
1119
|
+
_ observer: UnsafeMutableRawPointer?,
|
|
1120
|
+
_ name: CFNotificationName?,
|
|
1121
|
+
_ object: UnsafeRawPointer?,
|
|
1122
|
+
_ userInfo: CFDictionary?
|
|
1123
|
+
) {
|
|
1124
|
+
guard let observer else { return }
|
|
1125
|
+
let bridge = Unmanaged<OneWidgetsBridge>.fromOpaque(observer).takeUnretainedValue()
|
|
1126
|
+
bridge.flushObservedActions()
|
|
1127
|
+
}
|
|
1128
|
+
|
|
1026
1129
|
@objc(OneWidgetsBridge)
|
|
1027
1130
|
class OneWidgetsBridge: RCTEventEmitter {
|
|
1028
1131
|
private var tokenTasks: [String: Task<Void, Never>] = [:]
|
|
1132
|
+
private var isObservingEvents = false
|
|
1133
|
+
private var foregroundObserver: NSObjectProtocol?
|
|
1134
|
+
private let actionLock = NSLock()
|
|
1029
1135
|
|
|
1030
|
-
override func supportedEvents() -> [String]! { ["oneLiveActivityPushToken"] }
|
|
1136
|
+
override func supportedEvents() -> [String]! { ["oneLiveActivityPushToken", "oneWidgetAction"] }
|
|
1031
1137
|
|
|
1032
1138
|
override func startObserving() {
|
|
1139
|
+
isObservingEvents = true
|
|
1033
1140
|
for activity in Activity<OneWidgetContract.Attributes>.activities {
|
|
1034
1141
|
observeToken(activity)
|
|
1035
1142
|
}
|
|
1143
|
+
CFNotificationCenterAddObserver(
|
|
1144
|
+
CFNotificationCenterGetDarwinNotifyCenter(),
|
|
1145
|
+
Unmanaged.passUnretained(self).toOpaque(),
|
|
1146
|
+
oneWidgetsDarwinCallback,
|
|
1147
|
+
"dev.onejs.widget.action" as CFString,
|
|
1148
|
+
nil,
|
|
1149
|
+
.deliverImmediately
|
|
1150
|
+
)
|
|
1151
|
+
foregroundObserver = NotificationCenter.default.addObserver(
|
|
1152
|
+
forName: UIApplication.didBecomeActiveNotification,
|
|
1153
|
+
object: nil,
|
|
1154
|
+
queue: .main
|
|
1155
|
+
) { [weak self] _ in
|
|
1156
|
+
self?.flushObservedActions()
|
|
1157
|
+
}
|
|
1158
|
+
flushObservedActions()
|
|
1036
1159
|
}
|
|
1037
1160
|
|
|
1038
1161
|
override func stopObserving() {
|
|
1162
|
+
isObservingEvents = false
|
|
1039
1163
|
for task in tokenTasks.values { task.cancel() }
|
|
1040
1164
|
tokenTasks.removeAll()
|
|
1165
|
+
CFNotificationCenterRemoveObserver(
|
|
1166
|
+
CFNotificationCenterGetDarwinNotifyCenter(),
|
|
1167
|
+
Unmanaged.passUnretained(self).toOpaque(),
|
|
1168
|
+
CFNotificationName("dev.onejs.widget.action" as CFString),
|
|
1169
|
+
nil
|
|
1170
|
+
)
|
|
1171
|
+
if let foregroundObserver {
|
|
1172
|
+
NotificationCenter.default.removeObserver(foregroundObserver)
|
|
1173
|
+
self.foregroundObserver = nil
|
|
1174
|
+
}
|
|
1175
|
+
}
|
|
1176
|
+
|
|
1177
|
+
deinit {
|
|
1178
|
+
CFNotificationCenterRemoveObserver(
|
|
1179
|
+
CFNotificationCenterGetDarwinNotifyCenter(),
|
|
1180
|
+
Unmanaged.passUnretained(self).toOpaque(),
|
|
1181
|
+
CFNotificationName("dev.onejs.widget.action" as CFString),
|
|
1182
|
+
nil
|
|
1183
|
+
)
|
|
1184
|
+
if let foregroundObserver {
|
|
1185
|
+
NotificationCenter.default.removeObserver(foregroundObserver)
|
|
1186
|
+
}
|
|
1187
|
+
}
|
|
1188
|
+
|
|
1189
|
+
fileprivate func flushObservedActions() {
|
|
1190
|
+
guard isObservingEvents else { return }
|
|
1191
|
+
for item in drainStoredActions() {
|
|
1192
|
+
sendEvent(withName: "oneWidgetAction", body: item)
|
|
1193
|
+
}
|
|
1194
|
+
}
|
|
1195
|
+
|
|
1196
|
+
private func drainStoredActions() -> [[String: Any]] {
|
|
1197
|
+
actionLock.lock()
|
|
1198
|
+
defer { actionLock.unlock() }
|
|
1199
|
+
guard let defaults = UserDefaults(suiteName: OneWidgetContract.appGroup) else {
|
|
1200
|
+
return []
|
|
1201
|
+
}
|
|
1202
|
+
var actions: [OneWidgetContract.Action] = []
|
|
1203
|
+
for key in defaults.dictionaryRepresentation().keys where key.hasPrefix(OneWidgetContract.actionKeyPrefix) {
|
|
1204
|
+
guard let data = defaults.data(forKey: key) else { continue }
|
|
1205
|
+
defaults.removeObject(forKey: key)
|
|
1206
|
+
if let action = try? JSONDecoder().decode(OneWidgetContract.Action.self, from: data) {
|
|
1207
|
+
actions.append(action)
|
|
1208
|
+
}
|
|
1209
|
+
}
|
|
1210
|
+
actions.sort { $0.timestampMs < $1.timestampMs }
|
|
1211
|
+
return actions.map { action in
|
|
1212
|
+
[
|
|
1213
|
+
"id": action.id,
|
|
1214
|
+
"action": action.action,
|
|
1215
|
+
"value": action.value ?? NSNull(),
|
|
1216
|
+
"timestampMs": action.timestampMs,
|
|
1217
|
+
]
|
|
1218
|
+
}
|
|
1041
1219
|
}
|
|
1042
1220
|
|
|
1043
1221
|
private func observeToken(_ activity: Activity<OneWidgetContract.Attributes>) {
|
|
@@ -1179,6 +1357,15 @@ class OneWidgetsBridge: RCTEventEmitter {
|
|
|
1179
1357
|
resolve(NSNull())
|
|
1180
1358
|
}
|
|
1181
1359
|
}
|
|
1360
|
+
|
|
1361
|
+
@objc(claimActions:rejecter:)
|
|
1362
|
+
func claimActions(_ resolve: RCTPromiseResolveBlock, rejecter reject: RCTPromiseRejectBlock) {
|
|
1363
|
+
guard UserDefaults(suiteName: OneWidgetContract.appGroup) != nil else {
|
|
1364
|
+
reject("app_group", "Cannot open the configured App Group", nil)
|
|
1365
|
+
return
|
|
1366
|
+
}
|
|
1367
|
+
resolve(drainStoredActions())
|
|
1368
|
+
}
|
|
1182
1369
|
}
|
|
1183
1370
|
`);
|
|
1184
1371
|
}
|