@capawesome/capacitor-silent-mode 0.0.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/CapawesomeCapacitorSilentMode.podspec +17 -0
- package/LICENSE +21 -0
- package/Package.swift +28 -0
- package/README.md +242 -0
- package/android/build.gradle +58 -0
- package/android/src/main/AndroidManifest.xml +2 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/silentmode/SilentMode.java +90 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/silentmode/SilentModePlugin.java +112 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/silentmode/classes/events/SilentModeChangeEvent.java +22 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/silentmode/classes/results/GetRingerModeResult.java +23 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/silentmode/classes/results/IsSilentResult.java +22 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/silentmode/interfaces/Callback.java +5 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/silentmode/interfaces/NonEmptyResultCallback.java +7 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/silentmode/interfaces/Result.java +7 -0
- package/android/src/main/res/.gitkeep +0 -0
- package/dist/docs.json +222 -0
- package/dist/esm/definitions.d.ts +92 -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 +7 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/web.d.ts +6 -0
- package/dist/esm/web.js +10 -0
- package/dist/esm/web.js.map +1 -0
- package/dist/plugin.cjs.js +24 -0
- package/dist/plugin.cjs.js.map +1 -0
- package/dist/plugin.js +27 -0
- package/dist/plugin.js.map +1 -0
- package/ios/Plugin/Classes/Events/SilentModeChangeEvent.swift +16 -0
- package/ios/Plugin/Classes/Results/IsSilentResult.swift +16 -0
- package/ios/Plugin/Info.plist +24 -0
- package/ios/Plugin/Protocols/Result.swift +5 -0
- package/ios/Plugin/SilentMode.swift +177 -0
- package/ios/Plugin/SilentModePlugin.swift +74 -0
- package/package.json +91 -0
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import Foundation
|
|
2
|
+
import Capacitor
|
|
3
|
+
|
|
4
|
+
@objc(SilentModePlugin)
|
|
5
|
+
public class SilentModePlugin: CAPPlugin, CAPBridgedPlugin {
|
|
6
|
+
public let identifier = "SilentModePlugin"
|
|
7
|
+
public let jsName = "SilentMode"
|
|
8
|
+
public let pluginMethods: [CAPPluginMethod] = [
|
|
9
|
+
CAPPluginMethod(name: "getRingerMode", returnType: CAPPluginReturnPromise),
|
|
10
|
+
CAPPluginMethod(name: "isSilent", returnType: CAPPluginReturnPromise)
|
|
11
|
+
]
|
|
12
|
+
|
|
13
|
+
public static let eventSilentModeChange = "silentModeChange"
|
|
14
|
+
|
|
15
|
+
public static let tag = "SilentModePlugin"
|
|
16
|
+
|
|
17
|
+
private var implementation: SilentMode?
|
|
18
|
+
|
|
19
|
+
override public func load() {
|
|
20
|
+
self.implementation = SilentMode(plugin: self)
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
@objc override public func addListener(_ call: CAPPluginCall) {
|
|
24
|
+
super.addListener(call)
|
|
25
|
+
implementation?.startObserving()
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
@objc func getRingerMode(_ call: CAPPluginCall) {
|
|
29
|
+
rejectCallAsUnimplemented(call)
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
@objc func isSilent(_ call: CAPPluginCall) {
|
|
33
|
+
implementation?.isSilent { result, error in
|
|
34
|
+
if let error = error {
|
|
35
|
+
self.rejectCall(call, error)
|
|
36
|
+
return
|
|
37
|
+
}
|
|
38
|
+
self.resolveCall(call, result)
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
public func notifySilentModeChangeListeners(_ event: SilentModeChangeEvent) {
|
|
43
|
+
self.notifyListeners(Self.eventSilentModeChange, data: event.toJSObject() as? [String: Any])
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
@objc override public func removeAllListeners(_ call: CAPPluginCall) {
|
|
47
|
+
super.removeAllListeners(call)
|
|
48
|
+
implementation?.stopObserving()
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
@objc override public func removeListener(_ call: CAPPluginCall) {
|
|
52
|
+
super.removeListener(call)
|
|
53
|
+
if !hasListeners(Self.eventSilentModeChange) {
|
|
54
|
+
implementation?.stopObserving()
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
private func rejectCall(_ call: CAPPluginCall, _ error: Error) {
|
|
59
|
+
CAPLog.print("[", SilentModePlugin.tag, "] ", error)
|
|
60
|
+
call.reject(error.localizedDescription)
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
private func rejectCallAsUnimplemented(_ call: CAPPluginCall) {
|
|
64
|
+
call.unimplemented("This method is not available on this platform.")
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
private func resolveCall(_ call: CAPPluginCall, _ result: Result?) {
|
|
68
|
+
if let result = result?.toJSObject() as? JSObject {
|
|
69
|
+
call.resolve(result)
|
|
70
|
+
} else {
|
|
71
|
+
call.resolve()
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@capawesome/capacitor-silent-mode",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "Capacitor plugin to detect whether the device is in silent mode.",
|
|
5
|
+
"main": "dist/plugin.cjs.js",
|
|
6
|
+
"module": "dist/esm/index.js",
|
|
7
|
+
"types": "dist/esm/index.d.ts",
|
|
8
|
+
"unpkg": "dist/plugin.js",
|
|
9
|
+
"files": [
|
|
10
|
+
"android/src/main/",
|
|
11
|
+
"android/build.gradle",
|
|
12
|
+
"dist/",
|
|
13
|
+
"ios/Plugin/",
|
|
14
|
+
"CapawesomeCapacitorSilentMode.podspec",
|
|
15
|
+
"Package.swift"
|
|
16
|
+
],
|
|
17
|
+
"author": "Robin Genz <mail@robingenz.dev>",
|
|
18
|
+
"license": "MIT",
|
|
19
|
+
"repository": {
|
|
20
|
+
"type": "git",
|
|
21
|
+
"url": "git+https://github.com/capawesome-team/capacitor-plugins.git"
|
|
22
|
+
},
|
|
23
|
+
"bugs": {
|
|
24
|
+
"url": "https://github.com/capawesome-team/capacitor-plugins/issues"
|
|
25
|
+
},
|
|
26
|
+
"funding": [
|
|
27
|
+
{
|
|
28
|
+
"type": "github",
|
|
29
|
+
"url": "https://github.com/sponsors/capawesome-team/"
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
"type": "opencollective",
|
|
33
|
+
"url": "https://opencollective.com/capawesome"
|
|
34
|
+
}
|
|
35
|
+
],
|
|
36
|
+
"homepage": "https://capawesome.io/docs/plugins/silent-mode/",
|
|
37
|
+
"keywords": [
|
|
38
|
+
"capacitor",
|
|
39
|
+
"plugin",
|
|
40
|
+
"native"
|
|
41
|
+
],
|
|
42
|
+
"scripts": {
|
|
43
|
+
"verify": "npm run verify:ios && npm run verify:android && npm run verify:web",
|
|
44
|
+
"verify:ios": "cd ios && pod install && xcodebuild -workspace Plugin.xcworkspace -scheme Plugin -destination generic/platform=iOS && cd ..",
|
|
45
|
+
"verify:android": "cd android && ./gradlew clean build test && cd ..",
|
|
46
|
+
"verify:web": "npm run build",
|
|
47
|
+
"lint": "npm run eslint && npm run prettier -- --check && npm run swiftlint -- lint",
|
|
48
|
+
"fmt": "npm run eslint -- --fix && npm run prettier -- --write && npm run swiftlint -- --fix --format",
|
|
49
|
+
"eslint": "eslint . --ext ts",
|
|
50
|
+
"prettier": "prettier \"**/*.{css,html,ts,js,java}\"",
|
|
51
|
+
"swiftlint": "node-swiftlint",
|
|
52
|
+
"docgen": "docgen --api SilentModePlugin --output-readme README.md --output-json dist/docs.json",
|
|
53
|
+
"build": "npm run clean && npm run docgen && tsc && rollup -c rollup.config.mjs",
|
|
54
|
+
"clean": "rimraf ./dist",
|
|
55
|
+
"watch": "tsc --watch",
|
|
56
|
+
"ios:pod:install": "cd ios && pod install --repo-update && cd ..",
|
|
57
|
+
"ios:spm:install": "cd ios && swift package resolve && cd ..",
|
|
58
|
+
"prepublishOnly": "npm run build"
|
|
59
|
+
},
|
|
60
|
+
"devDependencies": {
|
|
61
|
+
"@capacitor/android": "8.0.0",
|
|
62
|
+
"@capacitor/cli": "8.0.0",
|
|
63
|
+
"@capacitor/core": "8.0.0",
|
|
64
|
+
"@capacitor/docgen": "0.3.1",
|
|
65
|
+
"@capacitor/ios": "8.0.0",
|
|
66
|
+
"@ionic/eslint-config": "0.4.0",
|
|
67
|
+
"eslint": "8.57.0",
|
|
68
|
+
"prettier-plugin-java": "2.6.7",
|
|
69
|
+
"rimraf": "6.1.2",
|
|
70
|
+
"rollup": "4.53.3",
|
|
71
|
+
"swiftlint": "2.0.0",
|
|
72
|
+
"typescript": "5.9.3"
|
|
73
|
+
},
|
|
74
|
+
"peerDependencies": {
|
|
75
|
+
"@capacitor/core": ">=8.0.0"
|
|
76
|
+
},
|
|
77
|
+
"eslintConfig": {
|
|
78
|
+
"extends": "@ionic/eslint-config/recommended"
|
|
79
|
+
},
|
|
80
|
+
"capacitor": {
|
|
81
|
+
"ios": {
|
|
82
|
+
"src": "ios"
|
|
83
|
+
},
|
|
84
|
+
"android": {
|
|
85
|
+
"src": "android"
|
|
86
|
+
}
|
|
87
|
+
},
|
|
88
|
+
"publishConfig": {
|
|
89
|
+
"access": "public"
|
|
90
|
+
}
|
|
91
|
+
}
|