@capgo/capacitor-volume-buttons 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/CapgoCapacitorVolumeButtons.podspec +17 -0
- package/Package.swift +28 -0
- package/README.md +89 -0
- package/android/build.gradle +58 -0
- package/android/src/main/AndroidManifest.xml +2 -0
- package/android/src/main/java/com/capgo/volumebuttons/VolumeButtons.java +10 -0
- package/android/src/main/java/com/capgo/volumebuttons/VolumeButtonsPlugin.java +42 -0
- package/android/src/main/res/.gitkeep +0 -0
- package/dist/docs.json +113 -0
- package/dist/esm/definitions.d.ts +16 -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 +9 -0
- package/dist/esm/web.js +21 -0
- package/dist/esm/web.js.map +1 -0
- package/dist/plugin.cjs.js +35 -0
- package/dist/plugin.cjs.js.map +1 -0
- package/dist/plugin.js +38 -0
- package/dist/plugin.js.map +1 -0
- package/ios/Sources/VolumeButtonsPlugin/VolumeButtons.swift +3 -0
- package/ios/Sources/VolumeButtonsPlugin/VolumeButtonsPlugin.swift +84 -0
- package/ios/Tests/VolumeButtonsPluginTests/VolumeButtonsPluginTests.swift +15 -0
- package/package.json +82 -0
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
require 'json'
|
|
2
|
+
|
|
3
|
+
package = JSON.parse(File.read(File.join(__dir__, 'package.json')))
|
|
4
|
+
|
|
5
|
+
Pod::Spec.new do |s|
|
|
6
|
+
s.name = 'CapgoCapacitorVolumeButtons'
|
|
7
|
+
s.version = package['version']
|
|
8
|
+
s.summary = package['description']
|
|
9
|
+
s.license = package['license']
|
|
10
|
+
s.homepage = package['repository']['url']
|
|
11
|
+
s.author = package['author']
|
|
12
|
+
s.source = { :git => package['repository']['url'], :tag => s.version.to_s }
|
|
13
|
+
s.source_files = 'ios/Sources/**/*.{swift,h,m,c,cc,mm,cpp}'
|
|
14
|
+
s.ios.deployment_target = '14.0'
|
|
15
|
+
s.dependency 'Capacitor'
|
|
16
|
+
s.swift_version = '5.1'
|
|
17
|
+
end
|
package/Package.swift
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// swift-tools-version: 5.9
|
|
2
|
+
import PackageDescription
|
|
3
|
+
|
|
4
|
+
let package = Package(
|
|
5
|
+
name: "CapgoCapacitorVolumeButtons",
|
|
6
|
+
platforms: [.iOS(.v14)],
|
|
7
|
+
products: [
|
|
8
|
+
.library(
|
|
9
|
+
name: "CapgoCapacitorVolumeButtons",
|
|
10
|
+
targets: ["VolumeButtonsPlugin"])
|
|
11
|
+
],
|
|
12
|
+
dependencies: [
|
|
13
|
+
.package(url: "https://github.com/ionic-team/capacitor-swift-pm.git", from: "7.0.0")
|
|
14
|
+
],
|
|
15
|
+
targets: [
|
|
16
|
+
.target(
|
|
17
|
+
name: "VolumeButtonsPlugin",
|
|
18
|
+
dependencies: [
|
|
19
|
+
.product(name: "Capacitor", package: "capacitor-swift-pm"),
|
|
20
|
+
.product(name: "Cordova", package: "capacitor-swift-pm")
|
|
21
|
+
],
|
|
22
|
+
path: "ios/Sources/VolumeButtonsPlugin"),
|
|
23
|
+
.testTarget(
|
|
24
|
+
name: "VolumeButtonsPluginTests",
|
|
25
|
+
dependencies: ["VolumeButtonsPlugin"],
|
|
26
|
+
path: "ios/Tests/VolumeButtonsPluginTests")
|
|
27
|
+
]
|
|
28
|
+
)
|
package/README.md
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
# @capgo/capacitor-volume-buttons
|
|
2
|
+
<a href="https://capgo.app/"><img src='https://raw.githubusercontent.com/Cap-go/capgo/main/assets/capgo_banner.png' alt='Capgo - Instant updates for capacitor'/></a>
|
|
3
|
+
|
|
4
|
+
<div align="center">
|
|
5
|
+
<h2><a href="https://capgo.app/?ref=plugin"> ➡️ Get Instant updates for your App with Capgo</a></h2>
|
|
6
|
+
<h2><a href="https://capgo.app/consulting/?ref=plugin"> Missing a feature? We’ll build the plugin for you 💪</a></h2>
|
|
7
|
+
</div>
|
|
8
|
+
Listen to volume button presses in Capacitor apps
|
|
9
|
+
|
|
10
|
+
## Install
|
|
11
|
+
|
|
12
|
+
```bash
|
|
13
|
+
npm install @capgo/capacitor-volume-buttons
|
|
14
|
+
npx cap sync
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## API
|
|
18
|
+
|
|
19
|
+
<docgen-index>
|
|
20
|
+
|
|
21
|
+
* [`addListener('volumeButtonPressed', ...)`](#addlistenervolumebuttonpressed-)
|
|
22
|
+
* [`removeAllListeners()`](#removealllisteners)
|
|
23
|
+
* [Interfaces](#interfaces)
|
|
24
|
+
* [Type Aliases](#type-aliases)
|
|
25
|
+
|
|
26
|
+
</docgen-index>
|
|
27
|
+
|
|
28
|
+
<docgen-api>
|
|
29
|
+
<!--Update the source file JSDoc comments and rerun docgen to update the docs below-->
|
|
30
|
+
|
|
31
|
+
### addListener('volumeButtonPressed', ...)
|
|
32
|
+
|
|
33
|
+
```typescript
|
|
34
|
+
addListener(eventName: 'volumeButtonPressed', listenerFunc: VolumeButtonListener) => Promise<PluginListenerHandle> & PluginListenerHandle
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
Listen for presses on the hardware volume buttons.
|
|
38
|
+
|
|
39
|
+
| Param | Type |
|
|
40
|
+
| ------------------ | --------------------------------------------------------------------- |
|
|
41
|
+
| **`eventName`** | <code>'volumeButtonPressed'</code> |
|
|
42
|
+
| **`listenerFunc`** | <code><a href="#volumebuttonlistener">VolumeButtonListener</a></code> |
|
|
43
|
+
|
|
44
|
+
**Returns:** <code>Promise<<a href="#pluginlistenerhandle">PluginListenerHandle</a>> & <a href="#pluginlistenerhandle">PluginListenerHandle</a></code>
|
|
45
|
+
|
|
46
|
+
--------------------
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
### removeAllListeners()
|
|
50
|
+
|
|
51
|
+
```typescript
|
|
52
|
+
removeAllListeners() => Promise<void>
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
Removes all listeners for this plugin.
|
|
56
|
+
|
|
57
|
+
--------------------
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
### Interfaces
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
#### PluginListenerHandle
|
|
64
|
+
|
|
65
|
+
| Prop | Type |
|
|
66
|
+
| ------------ | ----------------------------------------- |
|
|
67
|
+
| **`remove`** | <code>() => Promise<void></code> |
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
#### VolumeButtonPressed
|
|
71
|
+
|
|
72
|
+
| Prop | Type |
|
|
73
|
+
| --------------- | ----------------------------------------------------------------------- |
|
|
74
|
+
| **`direction`** | <code><a href="#volumebuttondirection">VolumeButtonDirection</a></code> |
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
### Type Aliases
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
#### VolumeButtonListener
|
|
81
|
+
|
|
82
|
+
<code>(event: <a href="#volumebuttonpressed">VolumeButtonPressed</a>): void</code>
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
#### VolumeButtonDirection
|
|
86
|
+
|
|
87
|
+
<code>'up' | 'down'</code>
|
|
88
|
+
|
|
89
|
+
</docgen-api>
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
ext {
|
|
2
|
+
junitVersion = project.hasProperty('junitVersion') ? rootProject.ext.junitVersion : '4.13.2'
|
|
3
|
+
androidxAppCompatVersion = project.hasProperty('androidxAppCompatVersion') ? rootProject.ext.androidxAppCompatVersion : '1.7.0'
|
|
4
|
+
androidxJunitVersion = project.hasProperty('androidxJunitVersion') ? rootProject.ext.androidxJunitVersion : '1.2.1'
|
|
5
|
+
androidxEspressoCoreVersion = project.hasProperty('androidxEspressoCoreVersion') ? rootProject.ext.androidxEspressoCoreVersion : '3.6.1'
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
buildscript {
|
|
9
|
+
repositories {
|
|
10
|
+
google()
|
|
11
|
+
mavenCentral()
|
|
12
|
+
}
|
|
13
|
+
dependencies {
|
|
14
|
+
classpath 'com.android.tools.build:gradle:8.7.2'
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
apply plugin: 'com.android.library'
|
|
19
|
+
|
|
20
|
+
android {
|
|
21
|
+
namespace "com.capgo.volumebuttons"
|
|
22
|
+
compileSdk project.hasProperty('compileSdkVersion') ? rootProject.ext.compileSdkVersion : 35
|
|
23
|
+
defaultConfig {
|
|
24
|
+
minSdkVersion project.hasProperty('minSdkVersion') ? rootProject.ext.minSdkVersion : 23
|
|
25
|
+
targetSdkVersion project.hasProperty('targetSdkVersion') ? rootProject.ext.targetSdkVersion : 35
|
|
26
|
+
versionCode 1
|
|
27
|
+
versionName "1.0"
|
|
28
|
+
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
|
29
|
+
}
|
|
30
|
+
buildTypes {
|
|
31
|
+
release {
|
|
32
|
+
minifyEnabled false
|
|
33
|
+
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
lintOptions {
|
|
37
|
+
abortOnError false
|
|
38
|
+
}
|
|
39
|
+
compileOptions {
|
|
40
|
+
sourceCompatibility JavaVersion.VERSION_21
|
|
41
|
+
targetCompatibility JavaVersion.VERSION_21
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
repositories {
|
|
46
|
+
google()
|
|
47
|
+
mavenCentral()
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
dependencies {
|
|
52
|
+
implementation fileTree(dir: 'libs', include: ['*.jar'])
|
|
53
|
+
implementation project(':capacitor-android')
|
|
54
|
+
implementation "androidx.appcompat:appcompat:$androidxAppCompatVersion"
|
|
55
|
+
testImplementation "junit:junit:$junitVersion"
|
|
56
|
+
androidTestImplementation "androidx.test.ext:junit:$androidxJunitVersion"
|
|
57
|
+
androidTestImplementation "androidx.test.espresso:espresso-core:$androidxEspressoCoreVersion"
|
|
58
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
package com.capgo.volumebuttons;
|
|
2
|
+
|
|
3
|
+
import android.view.KeyEvent;
|
|
4
|
+
import android.view.View;
|
|
5
|
+
import com.getcapacitor.JSObject;
|
|
6
|
+
import com.getcapacitor.Plugin;
|
|
7
|
+
import com.getcapacitor.annotation.CapacitorPlugin;
|
|
8
|
+
|
|
9
|
+
@CapacitorPlugin(name = "VolumeButtons")
|
|
10
|
+
public class VolumeButtonsPlugin extends Plugin {
|
|
11
|
+
|
|
12
|
+
@Override
|
|
13
|
+
public void load() {
|
|
14
|
+
super.load();
|
|
15
|
+
getBridge()
|
|
16
|
+
.getWebView()
|
|
17
|
+
.setOnKeyListener(
|
|
18
|
+
new View.OnKeyListener() {
|
|
19
|
+
@Override
|
|
20
|
+
public boolean onKey(View v, int keyCode, KeyEvent event) {
|
|
21
|
+
if (event.getAction() != KeyEvent.ACTION_UP) {
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
|
|
26
|
+
JSObject data = new JSObject();
|
|
27
|
+
data.put("direction", "up");
|
|
28
|
+
notifyListeners(VolumeButtons.EVENT_VOLUME_BUTTON_PRESSED, data);
|
|
29
|
+
return true;
|
|
30
|
+
} else if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
|
|
31
|
+
JSObject data = new JSObject();
|
|
32
|
+
data.put("direction", "down");
|
|
33
|
+
notifyListeners(VolumeButtons.EVENT_VOLUME_BUTTON_PRESSED, data);
|
|
34
|
+
return true;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return false;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
File without changes
|
package/dist/docs.json
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
{
|
|
2
|
+
"api": {
|
|
3
|
+
"name": "VolumeButtonsPlugin",
|
|
4
|
+
"slug": "volumebuttonsplugin",
|
|
5
|
+
"docs": "",
|
|
6
|
+
"tags": [],
|
|
7
|
+
"methods": [
|
|
8
|
+
{
|
|
9
|
+
"name": "addListener",
|
|
10
|
+
"signature": "(eventName: 'volumeButtonPressed', listenerFunc: VolumeButtonListener) => Promise<PluginListenerHandle> & PluginListenerHandle",
|
|
11
|
+
"parameters": [
|
|
12
|
+
{
|
|
13
|
+
"name": "eventName",
|
|
14
|
+
"docs": "",
|
|
15
|
+
"type": "'volumeButtonPressed'"
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
"name": "listenerFunc",
|
|
19
|
+
"docs": "",
|
|
20
|
+
"type": "VolumeButtonListener"
|
|
21
|
+
}
|
|
22
|
+
],
|
|
23
|
+
"returns": "Promise<PluginListenerHandle> & PluginListenerHandle",
|
|
24
|
+
"tags": [],
|
|
25
|
+
"docs": "Listen for presses on the hardware volume buttons.",
|
|
26
|
+
"complexTypes": [
|
|
27
|
+
"PluginListenerHandle",
|
|
28
|
+
"VolumeButtonListener"
|
|
29
|
+
],
|
|
30
|
+
"slug": "addlistenervolumebuttonpressed-"
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
"name": "removeAllListeners",
|
|
34
|
+
"signature": "() => Promise<void>",
|
|
35
|
+
"parameters": [],
|
|
36
|
+
"returns": "Promise<void>",
|
|
37
|
+
"tags": [],
|
|
38
|
+
"docs": "Removes all listeners for this plugin.",
|
|
39
|
+
"complexTypes": [],
|
|
40
|
+
"slug": "removealllisteners"
|
|
41
|
+
}
|
|
42
|
+
],
|
|
43
|
+
"properties": []
|
|
44
|
+
},
|
|
45
|
+
"interfaces": [
|
|
46
|
+
{
|
|
47
|
+
"name": "PluginListenerHandle",
|
|
48
|
+
"slug": "pluginlistenerhandle",
|
|
49
|
+
"docs": "",
|
|
50
|
+
"tags": [],
|
|
51
|
+
"methods": [],
|
|
52
|
+
"properties": [
|
|
53
|
+
{
|
|
54
|
+
"name": "remove",
|
|
55
|
+
"tags": [],
|
|
56
|
+
"docs": "",
|
|
57
|
+
"complexTypes": [],
|
|
58
|
+
"type": "() => Promise<void>"
|
|
59
|
+
}
|
|
60
|
+
]
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
"name": "VolumeButtonPressed",
|
|
64
|
+
"slug": "volumebuttonpressed",
|
|
65
|
+
"docs": "",
|
|
66
|
+
"tags": [],
|
|
67
|
+
"methods": [],
|
|
68
|
+
"properties": [
|
|
69
|
+
{
|
|
70
|
+
"name": "direction",
|
|
71
|
+
"tags": [],
|
|
72
|
+
"docs": "",
|
|
73
|
+
"complexTypes": [
|
|
74
|
+
"VolumeButtonDirection"
|
|
75
|
+
],
|
|
76
|
+
"type": "VolumeButtonDirection"
|
|
77
|
+
}
|
|
78
|
+
]
|
|
79
|
+
}
|
|
80
|
+
],
|
|
81
|
+
"enums": [],
|
|
82
|
+
"typeAliases": [
|
|
83
|
+
{
|
|
84
|
+
"name": "VolumeButtonListener",
|
|
85
|
+
"slug": "volumebuttonlistener",
|
|
86
|
+
"docs": "",
|
|
87
|
+
"types": [
|
|
88
|
+
{
|
|
89
|
+
"text": "(event: VolumeButtonPressed): void",
|
|
90
|
+
"complexTypes": [
|
|
91
|
+
"VolumeButtonPressed"
|
|
92
|
+
]
|
|
93
|
+
}
|
|
94
|
+
]
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
"name": "VolumeButtonDirection",
|
|
98
|
+
"slug": "volumebuttondirection",
|
|
99
|
+
"docs": "",
|
|
100
|
+
"types": [
|
|
101
|
+
{
|
|
102
|
+
"text": "'up'",
|
|
103
|
+
"complexTypes": []
|
|
104
|
+
},
|
|
105
|
+
{
|
|
106
|
+
"text": "'down'",
|
|
107
|
+
"complexTypes": []
|
|
108
|
+
}
|
|
109
|
+
]
|
|
110
|
+
}
|
|
111
|
+
],
|
|
112
|
+
"pluginConfigs": []
|
|
113
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { PluginListenerHandle } from '@capacitor/core';
|
|
2
|
+
export declare type VolumeButtonDirection = 'up' | 'down';
|
|
3
|
+
export interface VolumeButtonPressed {
|
|
4
|
+
direction: VolumeButtonDirection;
|
|
5
|
+
}
|
|
6
|
+
export declare type VolumeButtonListener = (event: VolumeButtonPressed) => void;
|
|
7
|
+
export interface VolumeButtonsPlugin {
|
|
8
|
+
/**
|
|
9
|
+
* Listen for presses on the hardware volume buttons.
|
|
10
|
+
*/
|
|
11
|
+
addListener(eventName: 'volumeButtonPressed', listenerFunc: VolumeButtonListener): Promise<PluginListenerHandle> & PluginListenerHandle;
|
|
12
|
+
/**
|
|
13
|
+
* Removes all listeners for this plugin.
|
|
14
|
+
*/
|
|
15
|
+
removeAllListeners(): Promise<void>;
|
|
16
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"","sourcesContent":["import type { PluginListenerHandle } from '@capacitor/core';\n\nexport type VolumeButtonDirection = 'up' | 'down';\n\nexport interface VolumeButtonPressed {\n direction: VolumeButtonDirection;\n}\n\nexport type VolumeButtonListener = (event: VolumeButtonPressed) => void;\n\nexport interface VolumeButtonsPlugin {\n /**\n * Listen for presses on the hardware volume buttons.\n */\n addListener(\n eventName: 'volumeButtonPressed',\n listenerFunc: VolumeButtonListener,\n ): Promise<PluginListenerHandle> & PluginListenerHandle;\n /**\n * Removes all listeners for this plugin.\n */\n removeAllListeners(): Promise<void>;\n}\n"]}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { registerPlugin } from '@capacitor/core';
|
|
2
|
+
const VolumeButtons = registerPlugin('VolumeButtons', {
|
|
3
|
+
web: () => import('./web').then((m) => new m.VolumeButtonsWeb()),
|
|
4
|
+
});
|
|
5
|
+
export * from './definitions';
|
|
6
|
+
export { VolumeButtons };
|
|
7
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAIjD,MAAM,aAAa,GAAG,cAAc,CAAsB,eAAe,EAAE;IACzE,GAAG,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,CAAC,gBAAgB,EAAE,CAAC;CACjE,CAAC,CAAC;AAEH,cAAc,eAAe,CAAC;AAC9B,OAAO,EAAE,aAAa,EAAE,CAAC","sourcesContent":["import { registerPlugin } from '@capacitor/core';\n\nimport type { VolumeButtonsPlugin } from './definitions';\n\nconst VolumeButtons = registerPlugin<VolumeButtonsPlugin>('VolumeButtons', {\n web: () => import('./web').then((m) => new m.VolumeButtonsWeb()),\n});\n\nexport * from './definitions';\nexport { VolumeButtons };\n"]}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { WebPlugin } from '@capacitor/core';
|
|
2
|
+
import type { PluginListenerHandle } from '@capacitor/core';
|
|
3
|
+
import type { VolumeButtonListener, VolumeButtonsPlugin } from './definitions';
|
|
4
|
+
export declare class VolumeButtonsWeb extends WebPlugin implements VolumeButtonsPlugin {
|
|
5
|
+
private readonly platform;
|
|
6
|
+
addListener(eventName: 'volumeButtonPressed', listenerFunc: VolumeButtonListener): Promise<PluginListenerHandle> & PluginListenerHandle;
|
|
7
|
+
removeAllListeners(): Promise<void>;
|
|
8
|
+
private notifyUnsupported;
|
|
9
|
+
}
|
package/dist/esm/web.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Capacitor, WebPlugin } from '@capacitor/core';
|
|
2
|
+
export class VolumeButtonsWeb extends WebPlugin {
|
|
3
|
+
constructor() {
|
|
4
|
+
super(...arguments);
|
|
5
|
+
this.platform = Capacitor.getPlatform();
|
|
6
|
+
}
|
|
7
|
+
addListener(eventName, listenerFunc) {
|
|
8
|
+
this.notifyUnsupported();
|
|
9
|
+
return super.addListener(eventName, listenerFunc);
|
|
10
|
+
}
|
|
11
|
+
removeAllListeners() {
|
|
12
|
+
this.notifyUnsupported();
|
|
13
|
+
return super.removeAllListeners();
|
|
14
|
+
}
|
|
15
|
+
notifyUnsupported() {
|
|
16
|
+
if (this.platform === 'web') {
|
|
17
|
+
console.warn('VolumeButtons is not supported in web builds.');
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=web.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"web.js","sourceRoot":"","sources":["../../src/web.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAKvD,MAAM,OAAO,gBAAiB,SAAQ,SAAS;IAA/C;;QACmB,aAAQ,GAAG,SAAS,CAAC,WAAW,EAAE,CAAC;IAoBtD,CAAC;IAlBC,WAAW,CACT,SAAgC,EAChC,YAAkC;QAElC,IAAI,CAAC,iBAAiB,EAAE,CAAC;QACzB,OAAO,KAAK,CAAC,WAAW,CAAC,SAAS,EAAE,YAAY,CAAyD,CAAC;IAC5G,CAAC;IAED,kBAAkB;QAChB,IAAI,CAAC,iBAAiB,EAAE,CAAC;QACzB,OAAO,KAAK,CAAC,kBAAkB,EAAE,CAAC;IACpC,CAAC;IAEO,iBAAiB;QACvB,IAAI,IAAI,CAAC,QAAQ,KAAK,KAAK,EAAE;YAC3B,OAAO,CAAC,IAAI,CAAC,+CAA+C,CAAC,CAAC;SAC/D;IACH,CAAC;CACF","sourcesContent":["import { Capacitor, WebPlugin } from '@capacitor/core';\nimport type { PluginListenerHandle } from '@capacitor/core';\n\nimport type { VolumeButtonListener, VolumeButtonsPlugin } from './definitions';\n\nexport class VolumeButtonsWeb extends WebPlugin implements VolumeButtonsPlugin {\n private readonly platform = Capacitor.getPlatform();\n\n addListener(\n eventName: 'volumeButtonPressed',\n listenerFunc: VolumeButtonListener,\n ): Promise<PluginListenerHandle> & PluginListenerHandle {\n this.notifyUnsupported();\n return super.addListener(eventName, listenerFunc) as Promise<PluginListenerHandle> & PluginListenerHandle;\n }\n\n removeAllListeners(): Promise<void> {\n this.notifyUnsupported();\n return super.removeAllListeners();\n }\n\n private notifyUnsupported() {\n if (this.platform === 'web') {\n console.warn('VolumeButtons is not supported in web builds.');\n }\n }\n}\n"]}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var core = require('@capacitor/core');
|
|
4
|
+
|
|
5
|
+
const VolumeButtons = core.registerPlugin('VolumeButtons', {
|
|
6
|
+
web: () => Promise.resolve().then(function () { return web; }).then((m) => new m.VolumeButtonsWeb()),
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
class VolumeButtonsWeb extends core.WebPlugin {
|
|
10
|
+
constructor() {
|
|
11
|
+
super(...arguments);
|
|
12
|
+
this.platform = core.Capacitor.getPlatform();
|
|
13
|
+
}
|
|
14
|
+
addListener(eventName, listenerFunc) {
|
|
15
|
+
this.notifyUnsupported();
|
|
16
|
+
return super.addListener(eventName, listenerFunc);
|
|
17
|
+
}
|
|
18
|
+
removeAllListeners() {
|
|
19
|
+
this.notifyUnsupported();
|
|
20
|
+
return super.removeAllListeners();
|
|
21
|
+
}
|
|
22
|
+
notifyUnsupported() {
|
|
23
|
+
if (this.platform === 'web') {
|
|
24
|
+
console.warn('VolumeButtons is not supported in web builds.');
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
var web = /*#__PURE__*/Object.freeze({
|
|
30
|
+
__proto__: null,
|
|
31
|
+
VolumeButtonsWeb: VolumeButtonsWeb
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
exports.VolumeButtons = VolumeButtons;
|
|
35
|
+
//# sourceMappingURL=plugin.cjs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin.cjs.js","sources":["esm/index.js","esm/web.js"],"sourcesContent":["import { registerPlugin } from '@capacitor/core';\nconst VolumeButtons = registerPlugin('VolumeButtons', {\n web: () => import('./web').then((m) => new m.VolumeButtonsWeb()),\n});\nexport * from './definitions';\nexport { VolumeButtons };\n//# sourceMappingURL=index.js.map","import { Capacitor, WebPlugin } from '@capacitor/core';\nexport class VolumeButtonsWeb extends WebPlugin {\n constructor() {\n super(...arguments);\n this.platform = Capacitor.getPlatform();\n }\n addListener(eventName, listenerFunc) {\n this.notifyUnsupported();\n return super.addListener(eventName, listenerFunc);\n }\n removeAllListeners() {\n this.notifyUnsupported();\n return super.removeAllListeners();\n }\n notifyUnsupported() {\n if (this.platform === 'web') {\n console.warn('VolumeButtons is not supported in web builds.');\n }\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["registerPlugin","WebPlugin","Capacitor"],"mappings":";;;;AACK,MAAC,aAAa,GAAGA,mBAAc,CAAC,eAAe,EAAE;AACtD,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,gBAAgB,EAAE,CAAC;AACpE,CAAC;;ACFM,MAAM,gBAAgB,SAASC,cAAS,CAAC;AAChD,IAAI,WAAW,GAAG;AAClB,QAAQ,KAAK,CAAC,GAAG,SAAS,CAAC;AAC3B,QAAQ,IAAI,CAAC,QAAQ,GAAGC,cAAS,CAAC,WAAW,EAAE;AAC/C,IAAI;AACJ,IAAI,WAAW,CAAC,SAAS,EAAE,YAAY,EAAE;AACzC,QAAQ,IAAI,CAAC,iBAAiB,EAAE;AAChC,QAAQ,OAAO,KAAK,CAAC,WAAW,CAAC,SAAS,EAAE,YAAY,CAAC;AACzD,IAAI;AACJ,IAAI,kBAAkB,GAAG;AACzB,QAAQ,IAAI,CAAC,iBAAiB,EAAE;AAChC,QAAQ,OAAO,KAAK,CAAC,kBAAkB,EAAE;AACzC,IAAI;AACJ,IAAI,iBAAiB,GAAG;AACxB,QAAQ,IAAI,IAAI,CAAC,QAAQ,KAAK,KAAK,EAAE;AACrC,YAAY,OAAO,CAAC,IAAI,CAAC,+CAA+C,CAAC;AACzE,QAAQ;AACR,IAAI;AACJ;;;;;;;;;"}
|
package/dist/plugin.js
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
var capacitorVolumeButtons = (function (exports, core) {
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
const VolumeButtons = core.registerPlugin('VolumeButtons', {
|
|
5
|
+
web: () => Promise.resolve().then(function () { return web; }).then((m) => new m.VolumeButtonsWeb()),
|
|
6
|
+
});
|
|
7
|
+
|
|
8
|
+
class VolumeButtonsWeb extends core.WebPlugin {
|
|
9
|
+
constructor() {
|
|
10
|
+
super(...arguments);
|
|
11
|
+
this.platform = core.Capacitor.getPlatform();
|
|
12
|
+
}
|
|
13
|
+
addListener(eventName, listenerFunc) {
|
|
14
|
+
this.notifyUnsupported();
|
|
15
|
+
return super.addListener(eventName, listenerFunc);
|
|
16
|
+
}
|
|
17
|
+
removeAllListeners() {
|
|
18
|
+
this.notifyUnsupported();
|
|
19
|
+
return super.removeAllListeners();
|
|
20
|
+
}
|
|
21
|
+
notifyUnsupported() {
|
|
22
|
+
if (this.platform === 'web') {
|
|
23
|
+
console.warn('VolumeButtons is not supported in web builds.');
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
var web = /*#__PURE__*/Object.freeze({
|
|
29
|
+
__proto__: null,
|
|
30
|
+
VolumeButtonsWeb: VolumeButtonsWeb
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
exports.VolumeButtons = VolumeButtons;
|
|
34
|
+
|
|
35
|
+
return exports;
|
|
36
|
+
|
|
37
|
+
})({}, capacitorExports);
|
|
38
|
+
//# sourceMappingURL=plugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin.js","sources":["esm/index.js","esm/web.js"],"sourcesContent":["import { registerPlugin } from '@capacitor/core';\nconst VolumeButtons = registerPlugin('VolumeButtons', {\n web: () => import('./web').then((m) => new m.VolumeButtonsWeb()),\n});\nexport * from './definitions';\nexport { VolumeButtons };\n//# sourceMappingURL=index.js.map","import { Capacitor, WebPlugin } from '@capacitor/core';\nexport class VolumeButtonsWeb extends WebPlugin {\n constructor() {\n super(...arguments);\n this.platform = Capacitor.getPlatform();\n }\n addListener(eventName, listenerFunc) {\n this.notifyUnsupported();\n return super.addListener(eventName, listenerFunc);\n }\n removeAllListeners() {\n this.notifyUnsupported();\n return super.removeAllListeners();\n }\n notifyUnsupported() {\n if (this.platform === 'web') {\n console.warn('VolumeButtons is not supported in web builds.');\n }\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["registerPlugin","WebPlugin","Capacitor"],"mappings":";;;AACK,UAAC,aAAa,GAAGA,mBAAc,CAAC,eAAe,EAAE;IACtD,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,gBAAgB,EAAE,CAAC;IACpE,CAAC;;ICFM,MAAM,gBAAgB,SAASC,cAAS,CAAC;IAChD,IAAI,WAAW,GAAG;IAClB,QAAQ,KAAK,CAAC,GAAG,SAAS,CAAC;IAC3B,QAAQ,IAAI,CAAC,QAAQ,GAAGC,cAAS,CAAC,WAAW,EAAE;IAC/C,IAAI;IACJ,IAAI,WAAW,CAAC,SAAS,EAAE,YAAY,EAAE;IACzC,QAAQ,IAAI,CAAC,iBAAiB,EAAE;IAChC,QAAQ,OAAO,KAAK,CAAC,WAAW,CAAC,SAAS,EAAE,YAAY,CAAC;IACzD,IAAI;IACJ,IAAI,kBAAkB,GAAG;IACzB,QAAQ,IAAI,CAAC,iBAAiB,EAAE;IAChC,QAAQ,OAAO,KAAK,CAAC,kBAAkB,EAAE;IACzC,IAAI;IACJ,IAAI,iBAAiB,GAAG;IACxB,QAAQ,IAAI,IAAI,CAAC,QAAQ,KAAK,KAAK,EAAE;IACrC,YAAY,OAAO,CAAC,IAAI,CAAC,+CAA+C,CAAC;IACzE,QAAQ;IACR,IAAI;IACJ;;;;;;;;;;;;;;;"}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import AVFoundation
|
|
2
|
+
import Capacitor
|
|
3
|
+
import Foundation
|
|
4
|
+
import MediaPlayer
|
|
5
|
+
import UIKit
|
|
6
|
+
|
|
7
|
+
private extension MPVolumeView {
|
|
8
|
+
static func setSystemVolume(_ volume: Float) {
|
|
9
|
+
let volumeView = MPVolumeView(frame: .zero)
|
|
10
|
+
guard let slider = volumeView.subviews.first(where: { $0 is UISlider }) as? UISlider else {
|
|
11
|
+
return
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
DispatchQueue.main.asyncAfter(deadline: .now() + 0.01) {
|
|
15
|
+
slider.value = volume
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
@objc(VolumeButtonsPlugin)
|
|
21
|
+
public class VolumeButtonsPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
22
|
+
public let identifier = "VolumeButtonsPlugin"
|
|
23
|
+
public let jsName = "VolumeButtons"
|
|
24
|
+
public let pluginMethods: [CAPPluginMethod] = []
|
|
25
|
+
|
|
26
|
+
private var audioLevel: Float = 0.0
|
|
27
|
+
private var observingVolume = false
|
|
28
|
+
private let audioSession = AVAudioSession.sharedInstance()
|
|
29
|
+
|
|
30
|
+
override public func load() {
|
|
31
|
+
super.load()
|
|
32
|
+
|
|
33
|
+
do {
|
|
34
|
+
try audioSession.setActive(true, options: [])
|
|
35
|
+
audioLevel = audioSession.outputVolume
|
|
36
|
+
audioSession.addObserver(self, forKeyPath: "outputVolume", options: .new, context: nil)
|
|
37
|
+
observingVolume = true
|
|
38
|
+
} catch {
|
|
39
|
+
CAPLog.print("VolumeButtonsPlugin", "Failed to activate audio session: \(error.localizedDescription)")
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
deinit {
|
|
44
|
+
removeVolumeObserver()
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
private func removeVolumeObserver() {
|
|
48
|
+
guard observingVolume else { return }
|
|
49
|
+
|
|
50
|
+
audioSession.removeObserver(self, forKeyPath: "outputVolume", context: nil)
|
|
51
|
+
observingVolume = false
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
override public func observeValue(
|
|
55
|
+
forKeyPath keyPath: String?,
|
|
56
|
+
of object: Any?,
|
|
57
|
+
change: [NSKeyValueChangeKey: Any]?,
|
|
58
|
+
context: UnsafeMutableRawPointer?
|
|
59
|
+
) {
|
|
60
|
+
guard keyPath == "outputVolume" else {
|
|
61
|
+
return
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
let newVolume = audioSession.outputVolume
|
|
65
|
+
|
|
66
|
+
let eventName = "volumeButtonPressed"
|
|
67
|
+
|
|
68
|
+
if newVolume > audioLevel {
|
|
69
|
+
audioLevel = newVolume
|
|
70
|
+
notifyListeners(eventName, data: ["direction": "up"])
|
|
71
|
+
} else if newVolume < audioLevel {
|
|
72
|
+
audioLevel = newVolume
|
|
73
|
+
notifyListeners(eventName, data: ["direction": "down"])
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
if newVolume >= 0.999 {
|
|
77
|
+
MPVolumeView.setSystemVolume(0.9375)
|
|
78
|
+
audioLevel = 0.9375
|
|
79
|
+
} else if newVolume <= 0.001 {
|
|
80
|
+
MPVolumeView.setSystemVolume(0.0625)
|
|
81
|
+
audioLevel = 0.0625
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import XCTest
|
|
2
|
+
@testable import VolumeButtonsPlugin
|
|
3
|
+
|
|
4
|
+
class VolumeButtonsTests: XCTestCase {
|
|
5
|
+
func testEcho() {
|
|
6
|
+
// This is an example of a functional test case for a plugin.
|
|
7
|
+
// Use XCTAssert and related functions to verify your tests produce the correct results.
|
|
8
|
+
|
|
9
|
+
let implementation = VolumeButtons()
|
|
10
|
+
let value = "Hello, World!"
|
|
11
|
+
let result = implementation.echo(value)
|
|
12
|
+
|
|
13
|
+
XCTAssertEqual(value, result)
|
|
14
|
+
}
|
|
15
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@capgo/capacitor-volume-buttons",
|
|
3
|
+
"version": "7.0.0",
|
|
4
|
+
"description": "Capacitor plugin to listen to volume button presses",
|
|
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/Sources",
|
|
14
|
+
"ios/Tests",
|
|
15
|
+
"Package.swift",
|
|
16
|
+
"CapgoCapacitorVolumeButtons.podspec"
|
|
17
|
+
],
|
|
18
|
+
"author": "Martin Donadieu <martin@capgo.app>",
|
|
19
|
+
"license": "MIT",
|
|
20
|
+
"repository": {
|
|
21
|
+
"type": "git",
|
|
22
|
+
"url": "git+https://github.com/Cap-go/capacitor-volume-buttons.git"
|
|
23
|
+
},
|
|
24
|
+
"bugs": {
|
|
25
|
+
"url": "https://github.com/Cap-go/capacitor-volume-buttons/issues"
|
|
26
|
+
},
|
|
27
|
+
"keywords": [
|
|
28
|
+
"capacitor",
|
|
29
|
+
"plugin",
|
|
30
|
+
"native",
|
|
31
|
+
"volume",
|
|
32
|
+
"buttons"
|
|
33
|
+
],
|
|
34
|
+
"scripts": {
|
|
35
|
+
"verify": "npm run verify:ios && npm run verify:android && npm run verify:web",
|
|
36
|
+
"verify:ios": "xcodebuild -scheme CapgoCapacitorVolumeButtons -destination generic/platform=iOS",
|
|
37
|
+
"verify:android": "cd android && ./gradlew clean build test && cd ..",
|
|
38
|
+
"verify:web": "npm run build",
|
|
39
|
+
"lint": "npm run eslint && npm run prettier -- --check && npm run swiftlint -- lint",
|
|
40
|
+
"fmt": "npm run eslint -- --fix && npm run prettier -- --write && npm run swiftlint -- --fix --format",
|
|
41
|
+
"eslint": "eslint . --ext ts",
|
|
42
|
+
"prettier": "prettier \"**/*.{css,html,ts,js,java}\" --plugin=prettier-plugin-java",
|
|
43
|
+
"swiftlint": "node-swiftlint",
|
|
44
|
+
"docgen": "docgen --api VolumeButtonsPlugin --output-readme README.md --output-json dist/docs.json",
|
|
45
|
+
"build": "npm run clean && npm run docgen && tsc && rollup -c rollup.config.mjs",
|
|
46
|
+
"clean": "rimraf ./dist",
|
|
47
|
+
"watch": "tsc --watch",
|
|
48
|
+
"prepublishOnly": "npm run build"
|
|
49
|
+
},
|
|
50
|
+
"devDependencies": {
|
|
51
|
+
"@capacitor/android": "^7.0.0",
|
|
52
|
+
"@capacitor/core": "^7.0.0",
|
|
53
|
+
"@capacitor/docgen": "^0.3.0",
|
|
54
|
+
"@capacitor/ios": "^7.0.0",
|
|
55
|
+
"@ionic/eslint-config": "^0.4.0",
|
|
56
|
+
"@ionic/prettier-config": "^4.0.0",
|
|
57
|
+
"@ionic/swiftlint-config": "^2.0.0",
|
|
58
|
+
"eslint": "^8.57.0",
|
|
59
|
+
"prettier": "^3.4.2",
|
|
60
|
+
"prettier-plugin-java": "^2.6.6",
|
|
61
|
+
"rimraf": "^6.0.1",
|
|
62
|
+
"rollup": "^4.30.1",
|
|
63
|
+
"swiftlint": "^2.0.0",
|
|
64
|
+
"typescript": "~4.1.5"
|
|
65
|
+
},
|
|
66
|
+
"peerDependencies": {
|
|
67
|
+
"@capacitor/core": ">=7.0.0"
|
|
68
|
+
},
|
|
69
|
+
"prettier": "@ionic/prettier-config",
|
|
70
|
+
"swiftlint": "@ionic/swiftlint-config",
|
|
71
|
+
"eslintConfig": {
|
|
72
|
+
"extends": "@ionic/eslint-config/recommended"
|
|
73
|
+
},
|
|
74
|
+
"capacitor": {
|
|
75
|
+
"ios": {
|
|
76
|
+
"src": "ios"
|
|
77
|
+
},
|
|
78
|
+
"android": {
|
|
79
|
+
"src": "android"
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|