@bacons/apple-targets 3.0.0 → 3.0.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 +11 -0
- package/build/ExtensionStorage.d.ts +3 -0
- package/build/ExtensionStorage.js +12 -1
- package/ios/ExtensionStorageModule.swift +28 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -388,6 +388,9 @@ ExtensionStorage.reloadWidget();
|
|
|
388
388
|
|
|
389
389
|
- `set(key: string, value: string | number | Record<string, string | number> | Array<Record<string, string | number>> | undefined): void` - Sets a value in the shared storage for a given key. Setting `undefined` will remove the key.
|
|
390
390
|
- `ExtensionStorage.reloadWidget(name?: string): void` - A static method for reloading the widget. Behind the scenes, this calls `WidgetCenter.shared.reloadAllTimelines()`. If given a name, it will reload a specific widget using `WidgetCenter.shared.reloadTimelines(ofKind: timeline)`.
|
|
391
|
+
- `ExtensionStorage.reloadControls(name?: string): void` - A static method for reloading the controls. Behind the scenes, this calls `ControlCenter.shared.reloadAllControls(): void`. If given a name, it will reload a specific widget using `ControlCenter.shared.reloadControls(ofKind?: string): void`.
|
|
392
|
+
- `remove(key: string): void` - A method for removing the key from the shared storage.
|
|
393
|
+
- `get(key: string): string | null` - A static method for getting the value from the shared storage.
|
|
391
394
|
|
|
392
395
|
### Accessing shared data
|
|
393
396
|
|
|
@@ -476,6 +479,14 @@ struct OpenAppIntent0: ControlConfigurationIntent {
|
|
|
476
479
|
|
|
477
480
|
You should copy the intents into your main `WidgetBundle` struct.
|
|
478
481
|
|
|
482
|
+
**Reloading Controls from Your App**
|
|
483
|
+
|
|
484
|
+
Changes in your app’s state may affect control displays. You can request a reload of specific controls or all controls using
|
|
485
|
+
|
|
486
|
+
```js
|
|
487
|
+
ExtensionStorage.reloadControls();
|
|
488
|
+
```
|
|
489
|
+
|
|
479
490
|
Custom images can be used but they must be SF Symbols, you can use a tool like [Create Custom Symbols](https://github.com/jaywcjlove/create-custom-symbols) to do this. Then simply add to the Assets.xcassets folder and reference it in the `Label`.
|
|
480
491
|
|
|
481
492
|
You can do a lot of things with Control Widgets like launching a custom UI instead of opening the app. This plugin should allow for most of these things to work.
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
export declare class ExtensionStorage {
|
|
2
2
|
private readonly appGroup;
|
|
3
3
|
static reloadWidget(name?: string): void;
|
|
4
|
+
static reloadControls(name?: string): void;
|
|
4
5
|
constructor(appGroup: string);
|
|
5
6
|
set(key: string, value?: string | number | Record<string, string | number> | Array<Record<string, string | number>>): void;
|
|
7
|
+
get(key: string): string | null;
|
|
8
|
+
remove(key: string): void;
|
|
6
9
|
}
|
|
@@ -8,9 +8,11 @@ const nativeModule = ExtensionStorageModule !== null && ExtensionStorageModule !
|
|
|
8
8
|
setInt() { },
|
|
9
9
|
setString() { },
|
|
10
10
|
reloadWidget() { },
|
|
11
|
+
reloadControls() { },
|
|
11
12
|
setObject() { },
|
|
12
|
-
remove() { },
|
|
13
13
|
setArray() { },
|
|
14
|
+
get() { },
|
|
15
|
+
remove() { },
|
|
14
16
|
};
|
|
15
17
|
const originalSetObject = nativeModule.setObject;
|
|
16
18
|
// Sweet API doesn't support doing this natively.
|
|
@@ -24,6 +26,9 @@ class ExtensionStorage {
|
|
|
24
26
|
static reloadWidget(name) {
|
|
25
27
|
nativeModule.reloadWidget(name);
|
|
26
28
|
}
|
|
29
|
+
static reloadControls(name) {
|
|
30
|
+
nativeModule.reloadControls(name);
|
|
31
|
+
}
|
|
27
32
|
constructor(appGroup) {
|
|
28
33
|
this.appGroup = appGroup;
|
|
29
34
|
}
|
|
@@ -44,5 +49,11 @@ class ExtensionStorage {
|
|
|
44
49
|
nativeModule.setObject(key, value, this.appGroup);
|
|
45
50
|
}
|
|
46
51
|
}
|
|
52
|
+
get(key) {
|
|
53
|
+
return nativeModule.get(key, this.appGroup);
|
|
54
|
+
}
|
|
55
|
+
remove(key) {
|
|
56
|
+
nativeModule.remove(key, this.appGroup);
|
|
57
|
+
}
|
|
47
58
|
}
|
|
48
59
|
exports.ExtensionStorage = ExtensionStorage;
|
|
@@ -17,6 +17,16 @@ public class ExtensionStorageModule: Module {
|
|
|
17
17
|
}
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
+
Function("reloadControls") { (kind: String?) in
|
|
21
|
+
if #available(iOS 18.0, *) {
|
|
22
|
+
if let kind = kind {
|
|
23
|
+
ControlCenter.shared.reloadControls(ofKind: kind)
|
|
24
|
+
} else {
|
|
25
|
+
ControlCenter.shared.reloadAllControls()
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
20
30
|
Function("setArray") { (forKey: String, data: [[String: Any]], suiteName: String?) -> Bool in
|
|
21
31
|
// Convert the incoming array of dictionaries directly to JSON data
|
|
22
32
|
do {
|
|
@@ -48,6 +58,24 @@ public class ExtensionStorageModule: Module {
|
|
|
48
58
|
Function("setString") { (key: String, value: String, group: String?) in
|
|
49
59
|
let userDefaults = UserDefaults(suiteName: group)
|
|
50
60
|
userDefaults?.set(value, forKey: key)
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
Function("get") { (key: String, group: String?) -> String? in
|
|
64
|
+
let userDefaults = UserDefaults(suiteName: group)
|
|
65
|
+
if let data = userDefaults?.data(forKey: key) {
|
|
66
|
+
do {
|
|
67
|
+
let jsonObject = try JSONSerialization.jsonObject(with: data, options: [])
|
|
68
|
+
let jsonData = try JSONSerialization.data(withJSONObject: jsonObject, options: [.prettyPrinted])
|
|
69
|
+
return String(data: jsonData, encoding: .utf8)
|
|
70
|
+
} catch {
|
|
71
|
+
return nil
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
if let value = userDefaults?.object(forKey: key) {
|
|
76
|
+
return String(describing: value)
|
|
77
|
+
}
|
|
78
|
+
return nil
|
|
51
79
|
}
|
|
52
80
|
}
|
|
53
81
|
}
|