@bubble-labs/capacitor-plugin-siri-shorts 7.0.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/CapacitorPluginSiriShorts.podspec +17 -0
- package/LICENSE +21 -0
- package/README.md +251 -0
- package/android/build.gradle +58 -0
- package/android/gradle/wrapper/gradle-wrapper.jar +0 -0
- package/android/gradle/wrapper/gradle-wrapper.properties +7 -0
- package/android/gradle.properties +23 -0
- package/android/gradlew +248 -0
- package/android/gradlew.bat +92 -0
- package/android/proguard-rules.pro +21 -0
- package/android/settings.gradle +2 -0
- package/android/src/androidTest/java/com/getcapacitor/android/ExampleInstrumentedTest.java +26 -0
- package/android/src/main/AndroidManifest.xml +5 -0
- package/android/src/main/java/com/timozacherl/plugins/CapSiriShortcuts/SiriShortcuts.java +38 -0
- package/android/src/main/res/layout/bridge_layout_main.xml +15 -0
- package/android/src/main/res/values/colors.xml +3 -0
- package/android/src/main/res/values/strings.xml +3 -0
- package/android/src/main/res/values/styles.xml +3 -0
- package/android/src/test/java/com/getcapacitor/ExampleUnitTest.java +18 -0
- package/dist/docs.json +279 -0
- package/dist/esm/definitions.d.ts +112 -0
- package/dist/esm/definitions.js +2 -0
- package/dist/esm/definitions.js.map +1 -0
- package/dist/esm/index.d.ts +4 -0
- package/dist/esm/index.js +5 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/plugin.cjs.js +10 -0
- package/dist/plugin.cjs.js.map +1 -0
- package/dist/plugin.js +13 -0
- package/dist/plugin.js.map +1 -0
- package/ios/Plugin/Info.plist +24 -0
- package/ios/Plugin/Plugin.h +10 -0
- package/ios/Plugin/Plugin.m +11 -0
- package/ios/Plugin/Plugin.swift +169 -0
- package/ios/Plugin.xcodeproj/project.pbxproj +554 -0
- package/ios/Plugin.xcodeproj/xcshareddata/xcschemes/Plugin.xcscheme +77 -0
- package/ios/Plugin.xcworkspace/contents.xcworkspacedata +10 -0
- package/ios/Plugin.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +8 -0
- package/ios/PluginTests/Info.plist +22 -0
- package/ios/PluginTests/PluginTests.swift +35 -0
- package/ios/Podfile +16 -0
- package/ios/Podfile.lock +22 -0
- package/package.json +80 -0
package/dist/plugin.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
var capacitorPluginShiriShorts = (function (exports, core) {
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
const SiriShortcuts = core.registerPlugin('SiriShortcuts');
|
|
5
|
+
|
|
6
|
+
exports.SiriShortcuts = SiriShortcuts;
|
|
7
|
+
|
|
8
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
9
|
+
|
|
10
|
+
return exports;
|
|
11
|
+
|
|
12
|
+
})({}, capacitorExports);
|
|
13
|
+
//# sourceMappingURL=plugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin.js","sources":["esm/index.js"],"sourcesContent":["import { registerPlugin } from '@capacitor/core';\nconst SiriShortcuts = registerPlugin('SiriShortcuts');\nexport * from './definitions';\nexport { SiriShortcuts };\n//# sourceMappingURL=index.js.map"],"names":["registerPlugin"],"mappings":";;;AACK,OAAC,aAAa,GAAGA,mBAAc,CAAC,eAAe;;;;;;;;;;;;"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
|
3
|
+
<plist version="1.0">
|
|
4
|
+
<dict>
|
|
5
|
+
<key>CFBundleDevelopmentRegion</key>
|
|
6
|
+
<string>$(DEVELOPMENT_LANGUAGE)</string>
|
|
7
|
+
<key>CFBundleExecutable</key>
|
|
8
|
+
<string>$(EXECUTABLE_NAME)</string>
|
|
9
|
+
<key>CFBundleIdentifier</key>
|
|
10
|
+
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
|
|
11
|
+
<key>CFBundleInfoDictionaryVersion</key>
|
|
12
|
+
<string>6.0</string>
|
|
13
|
+
<key>CFBundleName</key>
|
|
14
|
+
<string>$(PRODUCT_NAME)</string>
|
|
15
|
+
<key>CFBundlePackageType</key>
|
|
16
|
+
<string>FMWK</string>
|
|
17
|
+
<key>CFBundleShortVersionString</key>
|
|
18
|
+
<string>1.0</string>
|
|
19
|
+
<key>CFBundleVersion</key>
|
|
20
|
+
<string>$(CURRENT_PROJECT_VERSION)</string>
|
|
21
|
+
<key>NSPrincipalClass</key>
|
|
22
|
+
<string></string>
|
|
23
|
+
</dict>
|
|
24
|
+
</plist>
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
#import <UIKit/UIKit.h>
|
|
2
|
+
|
|
3
|
+
//! Project version number for Plugin.
|
|
4
|
+
FOUNDATION_EXPORT double PluginVersionNumber;
|
|
5
|
+
|
|
6
|
+
//! Project version string for Plugin.
|
|
7
|
+
FOUNDATION_EXPORT const unsigned char PluginVersionString[];
|
|
8
|
+
|
|
9
|
+
// In this header, you should import all the public headers of your framework using statements like #import <Plugin/PublicHeader.h>
|
|
10
|
+
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
#import <Foundation/Foundation.h>
|
|
2
|
+
#import <Capacitor/Capacitor.h>
|
|
3
|
+
|
|
4
|
+
// Define the plugin using the CAP_PLUGIN Macro, and
|
|
5
|
+
// each method the plugin supports using the CAP_PLUGIN_METHOD macro.
|
|
6
|
+
CAP_PLUGIN(SiriShortcuts, "SiriShortcuts",
|
|
7
|
+
CAP_PLUGIN_METHOD(donate, CAPPluginReturnPromise);
|
|
8
|
+
CAP_PLUGIN_METHOD(present, CAPPluginReturnPromise);
|
|
9
|
+
CAP_PLUGIN_METHOD(delete, CAPPluginReturnPromise);
|
|
10
|
+
CAP_PLUGIN_METHOD(deleteAll, CAPPluginReturnPromise);
|
|
11
|
+
)
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
import Foundation
|
|
2
|
+
import Intents
|
|
3
|
+
import IntentsUI
|
|
4
|
+
import Capacitor
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Please read the Capacitor iOS Plugin Development Guide
|
|
8
|
+
* here: https://capacitorjs.com/docs/plugins/ios
|
|
9
|
+
*/
|
|
10
|
+
@objc(SiriShortcuts)
|
|
11
|
+
public class SiriShortcuts: CAPPlugin {
|
|
12
|
+
var activity: NSUserActivity?
|
|
13
|
+
var currentCall: CAPPluginCall?
|
|
14
|
+
|
|
15
|
+
public override func load() {
|
|
16
|
+
NotificationCenter.default.addObserver(self,
|
|
17
|
+
selector: #selector(self.onOpenAppByUserActivity(notification:)),
|
|
18
|
+
name: NSNotification.Name("appLaunchBySiriShortcuts"), object: nil)
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
public static func getActivityName() -> String? {
|
|
22
|
+
guard let identifier = Bundle.main.bundleIdentifier else { return nil }
|
|
23
|
+
|
|
24
|
+
let activityName = identifier + ".shortcut"
|
|
25
|
+
|
|
26
|
+
return activityName
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
@objc func donate(_ call: CAPPluginCall) {
|
|
30
|
+
self.activity = self.createUserActivity(from: call, makeActive: true)
|
|
31
|
+
|
|
32
|
+
call.resolve()
|
|
33
|
+
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
@objc func present(_ call: CAPPluginCall) {
|
|
37
|
+
self.activity = self.createUserActivity(from: call, makeActive: true)
|
|
38
|
+
|
|
39
|
+
if let userActivity = self.activity {
|
|
40
|
+
let shortcut = INShortcut(userActivity: userActivity)
|
|
41
|
+
let viewController = INUIAddVoiceShortcutViewController(shortcut: shortcut)
|
|
42
|
+
self.currentCall = call
|
|
43
|
+
DispatchQueue.main.async {
|
|
44
|
+
viewController.modalPresentationStyle = .formSheet
|
|
45
|
+
viewController.delegate = self
|
|
46
|
+
self.bridge?.viewController?.present(viewController, animated: true, completion: nil)
|
|
47
|
+
}
|
|
48
|
+
return
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
call.reject("No activity provided")
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
@objc func delete(_ call: CAPPluginCall) {
|
|
55
|
+
guard let identifiers = call.getArray("identifiers", String.self) else {
|
|
56
|
+
call.reject("No identifiers provided")
|
|
57
|
+
return
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
DispatchQueue.main.async {
|
|
61
|
+
NSUserActivity.deleteSavedUserActivities(withPersistentIdentifiers: identifiers) {
|
|
62
|
+
call.resolve()
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
@objc func deleteAll(_ call: CAPPluginCall) {
|
|
68
|
+
DispatchQueue.main.async {
|
|
69
|
+
NSUserActivity.deleteAllSavedUserActivities {
|
|
70
|
+
call.resolve()
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Create User Activity
|
|
77
|
+
* @param call: Capacitor Call
|
|
78
|
+
*/
|
|
79
|
+
private func createUserActivity(from call: CAPPluginCall, makeActive: Bool) -> NSUserActivity? {
|
|
80
|
+
guard let activityName = SiriShortcuts.getActivityName() else {
|
|
81
|
+
call.reject("ActivityName not provided")
|
|
82
|
+
return nil
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
guard let persistentIdentifier = call.getString("persistentIdentifier") else {
|
|
86
|
+
call.reject("persistentIdentifier not provided")
|
|
87
|
+
return nil
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
guard let title = call.getString("title") else {
|
|
91
|
+
call.reject("title not provided")
|
|
92
|
+
return nil
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
let suggestedInvocationPhrase = call.getString("suggestedInvocationPhrase")
|
|
96
|
+
|
|
97
|
+
var userInfo = call.getObject("userInfo") ?? [:]
|
|
98
|
+
|
|
99
|
+
let isEligibleForSearch = call.getBool("isEligibleForSearch") ?? true
|
|
100
|
+
let isEligibleForPrediction = call.getBool("isEligibleForPrediction") ?? true
|
|
101
|
+
|
|
102
|
+
userInfo["persistentIdentifier"] = persistentIdentifier
|
|
103
|
+
|
|
104
|
+
// Shortcut creation
|
|
105
|
+
let activity = NSUserActivity(activityType: activityName)
|
|
106
|
+
activity.title = title
|
|
107
|
+
activity.suggestedInvocationPhrase = suggestedInvocationPhrase
|
|
108
|
+
activity.persistentIdentifier = NSUserActivityPersistentIdentifier(persistentIdentifier)
|
|
109
|
+
activity.isEligibleForSearch = isEligibleForSearch
|
|
110
|
+
activity.isEligibleForPrediction = isEligibleForPrediction
|
|
111
|
+
|
|
112
|
+
if (makeActive) {
|
|
113
|
+
ActivityDataHolder.setUserInfo(userInfo)
|
|
114
|
+
|
|
115
|
+
activity.needsSave = true
|
|
116
|
+
|
|
117
|
+
activity.addUserInfoEntries(from: userInfo)
|
|
118
|
+
} else {
|
|
119
|
+
activity.userInfo = userInfo
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
DispatchQueue.main.async {
|
|
123
|
+
self.bridge?.viewController?.userActivity = activity
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
activity.becomeCurrent()
|
|
127
|
+
|
|
128
|
+
return activity
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
extension SiriShortcuts: INUIAddVoiceShortcutViewControllerDelegate {
|
|
133
|
+
public func addVoiceShortcutViewController(_ controller: INUIAddVoiceShortcutViewController, didFinishWith voiceShortcut: INVoiceShortcut?, error: Error?) {
|
|
134
|
+
self.bridge?.viewController?.dismiss(animated: true, completion: {
|
|
135
|
+
if error == nil {
|
|
136
|
+
self.currentCall?.resolve()
|
|
137
|
+
} else {
|
|
138
|
+
self.currentCall?.reject(error!.localizedDescription)
|
|
139
|
+
}
|
|
140
|
+
self.currentCall = nil
|
|
141
|
+
})
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
public func addVoiceShortcutViewControllerDidCancel(_ controller: INUIAddVoiceShortcutViewController) {
|
|
145
|
+
self.bridge?.viewController?.dismiss(animated: true, completion: {
|
|
146
|
+
self.currentCall?.reject("Adding voice shortcut cancelled by user")
|
|
147
|
+
self.currentCall = nil
|
|
148
|
+
})
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
extension SiriShortcuts {
|
|
153
|
+
@objc public func onOpenAppByUserActivity(notification: Notification) {
|
|
154
|
+
debugPrint(notification)
|
|
155
|
+
self.notifyListeners("appLaunchBySiriShortcuts", data: notification.userInfo as? [String : Any] ?? ["something": "happened"], retainUntilConsumed: true)
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
class ActivityDataHolder {
|
|
160
|
+
private static var userInfo: [AnyHashable: Any]?
|
|
161
|
+
|
|
162
|
+
public static func getUserInfo() -> [AnyHashable: Any]? {
|
|
163
|
+
return self.userInfo
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
public static func setUserInfo(_ userInfo: [AnyHashable: Any]?) -> Void {
|
|
167
|
+
self.userInfo = userInfo
|
|
168
|
+
}
|
|
169
|
+
}
|