@capgo/capacitor-proximity 8.1.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/CapgoCapacitorProximity.podspec +17 -0
- package/Package.swift +28 -0
- package/README.md +176 -0
- package/android/build.gradle +59 -0
- package/android/gradle.properties +22 -0
- package/android/proguard-rules.pro +21 -0
- package/android/settings.gradle +2 -0
- package/android/src/main/AndroidManifest.xml +3 -0
- package/android/src/main/java/app/capgo/proximity/CapacitorProximity.java +160 -0
- package/android/src/main/java/app/capgo/proximity/CapacitorProximityPlugin.java +49 -0
- package/android/src/main/res/.gitkeep +0 -0
- package/dist/docs.json +193 -0
- package/dist/esm/definitions.d.ts +95 -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 +8 -0
- package/dist/esm/web.js +22 -0
- package/dist/esm/web.js.map +1 -0
- package/dist/plugin.cjs.js +36 -0
- package/dist/plugin.cjs.js.map +1 -0
- package/dist/plugin.js +39 -0
- package/dist/plugin.js.map +1 -0
- package/ios/Sources/CapacitorProximityPlugin/CapacitorProximity.swift +31 -0
- package/ios/Sources/CapacitorProximityPlugin/CapacitorProximityPlugin.swift +54 -0
- package/ios/Tests/CapacitorProximityPluginTests/CapacitorProximityPluginTests.swift +9 -0
- package/package.json +93 -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 = 'CapgoCapacitorProximity'
|
|
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 = '15.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: "CapgoCapacitorProximity",
|
|
6
|
+
platforms: [.iOS(.v15)],
|
|
7
|
+
products: [
|
|
8
|
+
.library(
|
|
9
|
+
name: "CapgoCapacitorProximity",
|
|
10
|
+
targets: ["CapacitorProximityPlugin"])
|
|
11
|
+
],
|
|
12
|
+
dependencies: [
|
|
13
|
+
.package(url: "https://github.com/ionic-team/capacitor-swift-pm.git", from: "8.0.0")
|
|
14
|
+
],
|
|
15
|
+
targets: [
|
|
16
|
+
.target(
|
|
17
|
+
name: "CapacitorProximityPlugin",
|
|
18
|
+
dependencies: [
|
|
19
|
+
.product(name: "Capacitor", package: "capacitor-swift-pm"),
|
|
20
|
+
.product(name: "Cordova", package: "capacitor-swift-pm")
|
|
21
|
+
],
|
|
22
|
+
path: "ios/Sources/CapacitorProximityPlugin"),
|
|
23
|
+
.testTarget(
|
|
24
|
+
name: "CapacitorProximityPluginTests",
|
|
25
|
+
dependencies: ["CapacitorProximityPlugin"],
|
|
26
|
+
path: "ios/Tests/CapacitorProximityPluginTests")
|
|
27
|
+
]
|
|
28
|
+
)
|
package/README.md
ADDED
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
# @capgo/capacitor-proximity
|
|
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_proximity"> ➡️ Get Instant updates for your App with Capgo</a></h2>
|
|
6
|
+
<h2><a href="https://capgo.app/consulting/?ref=plugin_proximity"> Missing a feature? We'll build the plugin for you 💪</a></h2>
|
|
7
|
+
</div>
|
|
8
|
+
|
|
9
|
+
Capacitor plugin for enabling proximity monitoring in mobile apps.
|
|
10
|
+
|
|
11
|
+
## Why this plugin
|
|
12
|
+
|
|
13
|
+
This plugin wraps the native proximity APIs used by iOS and Android so a Capacitor app can:
|
|
14
|
+
|
|
15
|
+
- Enable proximity monitoring when a screen should react to the user's face or hand.
|
|
16
|
+
- Disable it cleanly when the flow ends.
|
|
17
|
+
- Check whether the current device supports the sensor.
|
|
18
|
+
- Read the plugin version from native code.
|
|
19
|
+
|
|
20
|
+
On iOS, the plugin forwards directly to `UIDevice.isProximityMonitoringEnabled`.
|
|
21
|
+
On Android, it listens to the device proximity sensor and dims the active app window while the sensor is covered.
|
|
22
|
+
|
|
23
|
+
## Platform support
|
|
24
|
+
|
|
25
|
+
| Platform | Support |
|
|
26
|
+
|----------|---------|
|
|
27
|
+
| iOS | ✅ Uses native proximity monitoring |
|
|
28
|
+
| Android | ✅ Uses `Sensor.TYPE_PROXIMITY` and dims the current app window |
|
|
29
|
+
| Web | ❌ Not available |
|
|
30
|
+
|
|
31
|
+
## Compatibility
|
|
32
|
+
|
|
33
|
+
| Plugin version | Capacitor compatibility | Maintained |
|
|
34
|
+
| -------------- | ----------------------- | ---------- |
|
|
35
|
+
| v8.*.* | v8.*.* | ✅ |
|
|
36
|
+
| v7.*.* | v7.*.* | On demand |
|
|
37
|
+
| v6.*.* | v6.*.* | ❌ |
|
|
38
|
+
| v5.*.* | v5.*.* | ❌ |
|
|
39
|
+
|
|
40
|
+
> The plugin major version follows the Capacitor major version.
|
|
41
|
+
|
|
42
|
+
## Install
|
|
43
|
+
|
|
44
|
+
```bash
|
|
45
|
+
bun add @capgo/capacitor-proximity
|
|
46
|
+
bunx cap sync
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
## Usage
|
|
50
|
+
|
|
51
|
+
```ts
|
|
52
|
+
import { CapacitorProximity } from '@capgo/capacitor-proximity';
|
|
53
|
+
|
|
54
|
+
const status = await CapacitorProximity.getStatus();
|
|
55
|
+
|
|
56
|
+
if (status.available) {
|
|
57
|
+
await CapacitorProximity.enable();
|
|
58
|
+
|
|
59
|
+
// ...run your near-ear or face-down flow...
|
|
60
|
+
|
|
61
|
+
await CapacitorProximity.disable();
|
|
62
|
+
}
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
## Notes
|
|
66
|
+
|
|
67
|
+
- Test on a real device. Simulators and most desktop browsers do not expose a proximity sensor.
|
|
68
|
+
- On Android, the plugin only affects the current app window. It does not control the full system display outside your app.
|
|
69
|
+
- On iOS, Apple controls the exact screen-off behavior once proximity monitoring is enabled.
|
|
70
|
+
|
|
71
|
+
## Example app
|
|
72
|
+
|
|
73
|
+
The `example-app/` folder contains a small Vite demo for checking status, enabling the plugin, disabling it, and reading the native version.
|
|
74
|
+
|
|
75
|
+
## API
|
|
76
|
+
|
|
77
|
+
<docgen-index>
|
|
78
|
+
|
|
79
|
+
* [`enable()`](#enable)
|
|
80
|
+
* [`disable()`](#disable)
|
|
81
|
+
* [`getStatus()`](#getstatus)
|
|
82
|
+
* [`getPluginVersion()`](#getpluginversion)
|
|
83
|
+
* [Interfaces](#interfaces)
|
|
84
|
+
|
|
85
|
+
</docgen-index>
|
|
86
|
+
<!-- test-->
|
|
87
|
+
<docgen-api>
|
|
88
|
+
<!--Update the source file JSDoc comments and rerun docgen to update the docs below-->
|
|
89
|
+
|
|
90
|
+
Capacitor plugin for enabling proximity monitoring in mobile apps.
|
|
91
|
+
|
|
92
|
+
### enable()
|
|
93
|
+
|
|
94
|
+
```typescript
|
|
95
|
+
enable() => Promise<void>
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
Enable proximity monitoring.
|
|
99
|
+
|
|
100
|
+
On iOS this enables `UIDevice.isProximityMonitoringEnabled`.
|
|
101
|
+
On Android this starts listening to `TYPE_PROXIMITY` and dims the current
|
|
102
|
+
app window while the sensor is covered.
|
|
103
|
+
|
|
104
|
+
**Since:** 0.0.1
|
|
105
|
+
|
|
106
|
+
--------------------
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
### disable()
|
|
110
|
+
|
|
111
|
+
```typescript
|
|
112
|
+
disable() => Promise<void>
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
Disable proximity monitoring.
|
|
116
|
+
|
|
117
|
+
This restores the default app window behavior and stops sensor monitoring.
|
|
118
|
+
|
|
119
|
+
**Since:** 0.0.1
|
|
120
|
+
|
|
121
|
+
--------------------
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
### getStatus()
|
|
125
|
+
|
|
126
|
+
```typescript
|
|
127
|
+
getStatus() => Promise<ProximityStatusResult>
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
Get the current sensor availability and plugin enabled state.
|
|
131
|
+
|
|
132
|
+
**Returns:** <code>Promise<<a href="#proximitystatusresult">ProximityStatusResult</a>></code>
|
|
133
|
+
|
|
134
|
+
**Since:** 0.0.1
|
|
135
|
+
|
|
136
|
+
--------------------
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
### getPluginVersion()
|
|
140
|
+
|
|
141
|
+
```typescript
|
|
142
|
+
getPluginVersion() => Promise<PluginVersionResult>
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
Get the current native plugin version.
|
|
146
|
+
|
|
147
|
+
**Returns:** <code>Promise<<a href="#pluginversionresult">PluginVersionResult</a>></code>
|
|
148
|
+
|
|
149
|
+
**Since:** 0.0.1
|
|
150
|
+
|
|
151
|
+
--------------------
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
### Interfaces
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
#### ProximityStatusResult
|
|
158
|
+
|
|
159
|
+
Result returned by `getStatus()`.
|
|
160
|
+
|
|
161
|
+
| Prop | Type | Description | Since |
|
|
162
|
+
| --------------- | ---------------------------------------- | ---------------------------------------------------------------- | ----- |
|
|
163
|
+
| **`available`** | <code>boolean</code> | Whether the current device exposes a usable proximity sensor. | 0.0.1 |
|
|
164
|
+
| **`enabled`** | <code>boolean</code> | Whether proximity monitoring is currently enabled by the plugin. | 0.0.1 |
|
|
165
|
+
| **`platform`** | <code>'ios' \| 'android' \| 'web'</code> | Platform label returned by the native or web implementation. | 0.0.1 |
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
#### PluginVersionResult
|
|
169
|
+
|
|
170
|
+
Result returned when requesting the plugin version.
|
|
171
|
+
|
|
172
|
+
| Prop | Type | Description | Since |
|
|
173
|
+
| ------------- | ------------------- | ----------------------------- | ----- |
|
|
174
|
+
| **`version`** | <code>string</code> | Native plugin version string. | 0.0.1 |
|
|
175
|
+
|
|
176
|
+
</docgen-api>
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
ext {
|
|
2
|
+
junitVersion = project.hasProperty('junitVersion') ? rootProject.ext.junitVersion : '4.13.2'
|
|
3
|
+
androidxAppCompatVersion = project.hasProperty('androidxAppCompatVersion') ? rootProject.ext.androidxAppCompatVersion : '1.7.1'
|
|
4
|
+
androidxJunitVersion = project.hasProperty('androidxJunitVersion') ? rootProject.ext.androidxJunitVersion : '1.3.0'
|
|
5
|
+
androidxEspressoCoreVersion = project.hasProperty('androidxEspressoCoreVersion') ? rootProject.ext.androidxEspressoCoreVersion : '3.7.0'
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
buildscript {
|
|
9
|
+
repositories {
|
|
10
|
+
google()
|
|
11
|
+
mavenCentral()
|
|
12
|
+
}
|
|
13
|
+
dependencies {
|
|
14
|
+
classpath 'com.android.tools.build:gradle:8.13.0'
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
apply plugin: 'com.android.library'
|
|
19
|
+
|
|
20
|
+
android {
|
|
21
|
+
namespace = "app.capgo.proximity"
|
|
22
|
+
compileSdk = project.hasProperty('compileSdkVersion') ? rootProject.ext.compileSdkVersion : 36
|
|
23
|
+
defaultConfig {
|
|
24
|
+
minSdkVersion project.hasProperty('minSdkVersion') ? rootProject.ext.minSdkVersion : 24
|
|
25
|
+
targetSdkVersion project.hasProperty('targetSdkVersion') ? rootProject.ext.targetSdkVersion : 36
|
|
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-optimize.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
|
+
annotationProcessor project(':capacitor-android')
|
|
55
|
+
implementation "androidx.appcompat:appcompat:$androidxAppCompatVersion"
|
|
56
|
+
testImplementation "junit:junit:$junitVersion"
|
|
57
|
+
androidTestImplementation "androidx.test.ext:junit:$androidxJunitVersion"
|
|
58
|
+
androidTestImplementation "androidx.test.espresso:espresso-core:$androidxEspressoCoreVersion"
|
|
59
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# Project-wide Gradle settings.
|
|
2
|
+
|
|
3
|
+
# IDE (e.g. Android Studio) users:
|
|
4
|
+
# Gradle settings configured through the IDE *will override*
|
|
5
|
+
# any settings specified in this file.
|
|
6
|
+
|
|
7
|
+
# For more details on how to configure your build environment visit
|
|
8
|
+
# http://www.gradle.org/docs/current/userguide/build_environment.html
|
|
9
|
+
|
|
10
|
+
# Specifies the JVM arguments used for the daemon process.
|
|
11
|
+
# The setting is particularly useful for tweaking memory settings.
|
|
12
|
+
org.gradle.jvmargs=-Xmx1536m
|
|
13
|
+
|
|
14
|
+
# When configured, Gradle will run in incubating parallel mode.
|
|
15
|
+
# This option should only be used with decoupled projects. More details, visit
|
|
16
|
+
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
|
|
17
|
+
# org.gradle.parallel=true
|
|
18
|
+
|
|
19
|
+
# AndroidX package structure to make it clearer which packages are bundled with the
|
|
20
|
+
# Android operating system, and which are packaged with your app's APK
|
|
21
|
+
# https://developer.android.com/topic/libraries/support-library/androidx-rn
|
|
22
|
+
android.useAndroidX=true
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# Add project specific ProGuard rules here.
|
|
2
|
+
# You can control the set of applied configuration files using the
|
|
3
|
+
# proguardFiles setting in build.gradle.
|
|
4
|
+
#
|
|
5
|
+
# For more details, see
|
|
6
|
+
# http://developer.android.com/guide/developing/tools/proguard.html
|
|
7
|
+
|
|
8
|
+
# If your project uses WebView with JS, uncomment the following
|
|
9
|
+
# and specify the fully qualified class name to the JavaScript interface
|
|
10
|
+
# class:
|
|
11
|
+
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
|
|
12
|
+
# public *;
|
|
13
|
+
#}
|
|
14
|
+
|
|
15
|
+
# Uncomment this to preserve the line number information for
|
|
16
|
+
# debugging stack traces.
|
|
17
|
+
#-keepattributes SourceFile,LineNumberTable
|
|
18
|
+
|
|
19
|
+
# If you keep the line number information, uncomment this to
|
|
20
|
+
# hide the original source file name.
|
|
21
|
+
#-renamesourcefileattribute SourceFile
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
package app.capgo.proximity;
|
|
2
|
+
|
|
3
|
+
import android.app.Activity;
|
|
4
|
+
import android.content.Context;
|
|
5
|
+
import android.hardware.Sensor;
|
|
6
|
+
import android.hardware.SensorEvent;
|
|
7
|
+
import android.hardware.SensorEventListener;
|
|
8
|
+
import android.hardware.SensorManager;
|
|
9
|
+
import android.view.Window;
|
|
10
|
+
import android.view.WindowManager;
|
|
11
|
+
import com.getcapacitor.JSObject;
|
|
12
|
+
import com.getcapacitor.Logger;
|
|
13
|
+
import com.getcapacitor.PluginCall;
|
|
14
|
+
|
|
15
|
+
public class CapacitorProximity {
|
|
16
|
+
|
|
17
|
+
public static final String PLUGIN_VERSION = "8.0.0";
|
|
18
|
+
private static final String TAG = "CapacitorProximity";
|
|
19
|
+
|
|
20
|
+
private final Activity activity;
|
|
21
|
+
private final SensorManager sensorManager;
|
|
22
|
+
private final Sensor proximitySensor;
|
|
23
|
+
|
|
24
|
+
private SensorEventListener proximitySensorListener;
|
|
25
|
+
private boolean enabled = false;
|
|
26
|
+
private float originalBrightness = WindowManager.LayoutParams.BRIGHTNESS_OVERRIDE_NONE;
|
|
27
|
+
private boolean originalKeepScreenOn = false;
|
|
28
|
+
|
|
29
|
+
public CapacitorProximity(Activity activity) {
|
|
30
|
+
this.activity = activity;
|
|
31
|
+
|
|
32
|
+
if (activity != null) {
|
|
33
|
+
sensorManager = (SensorManager) activity.getSystemService(Context.SENSOR_SERVICE);
|
|
34
|
+
proximitySensor = sensorManager != null ? sensorManager.getDefaultSensor(Sensor.TYPE_PROXIMITY) : null;
|
|
35
|
+
} else {
|
|
36
|
+
sensorManager = null;
|
|
37
|
+
proximitySensor = null;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
public void enable(PluginCall call) {
|
|
42
|
+
if (activity == null) {
|
|
43
|
+
call.reject("Activity not available.");
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
if (proximitySensor == null || sensorManager == null) {
|
|
48
|
+
call.reject("Proximity sensor not available on this device.");
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
if (enabled) {
|
|
53
|
+
call.resolve();
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
Window window = activity.getWindow();
|
|
58
|
+
WindowManager.LayoutParams params = window.getAttributes();
|
|
59
|
+
originalBrightness = params.screenBrightness;
|
|
60
|
+
originalKeepScreenOn = (params.flags & WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON) != 0;
|
|
61
|
+
|
|
62
|
+
proximitySensorListener = new SensorEventListener() {
|
|
63
|
+
@Override
|
|
64
|
+
public void onSensorChanged(SensorEvent event) {
|
|
65
|
+
if (event.sensor.getType() != Sensor.TYPE_PROXIMITY) {
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
float distance = event.values[0];
|
|
70
|
+
boolean isNear = distance < proximitySensor.getMaximumRange();
|
|
71
|
+
|
|
72
|
+
if (isNear) {
|
|
73
|
+
dimScreen();
|
|
74
|
+
} else {
|
|
75
|
+
restoreScreen();
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
@Override
|
|
80
|
+
public void onAccuracyChanged(Sensor sensor, int accuracy) {
|
|
81
|
+
// No-op
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
boolean registered = sensorManager.registerListener(proximitySensorListener, proximitySensor, SensorManager.SENSOR_DELAY_NORMAL);
|
|
86
|
+
|
|
87
|
+
if (!registered) {
|
|
88
|
+
proximitySensorListener = null;
|
|
89
|
+
call.reject("Failed to register the proximity sensor listener.");
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
enabled = true;
|
|
94
|
+
call.resolve();
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
public void disable(PluginCall call) {
|
|
98
|
+
stopMonitoring();
|
|
99
|
+
call.resolve();
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
public JSObject getStatus() {
|
|
103
|
+
JSObject result = new JSObject();
|
|
104
|
+
result.put("available", proximitySensor != null);
|
|
105
|
+
result.put("enabled", enabled);
|
|
106
|
+
result.put("platform", "android");
|
|
107
|
+
return result;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
public String getPluginVersion() {
|
|
111
|
+
return PLUGIN_VERSION;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
public void stopMonitoring() {
|
|
115
|
+
restoreScreen();
|
|
116
|
+
|
|
117
|
+
if (sensorManager != null && proximitySensorListener != null) {
|
|
118
|
+
sensorManager.unregisterListener(proximitySensorListener);
|
|
119
|
+
proximitySensorListener = null;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
enabled = false;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
private void dimScreen() {
|
|
126
|
+
if (activity == null) {
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
try {
|
|
131
|
+
Window window = activity.getWindow();
|
|
132
|
+
WindowManager.LayoutParams params = window.getAttributes();
|
|
133
|
+
params.flags |= WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON;
|
|
134
|
+
params.screenBrightness = 0.0f;
|
|
135
|
+
window.setAttributes(params);
|
|
136
|
+
} catch (Exception exception) {
|
|
137
|
+
Logger.error(TAG, "Failed to dim the app window.", exception);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
private void restoreScreen() {
|
|
142
|
+
if (activity == null) {
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
try {
|
|
147
|
+
Window window = activity.getWindow();
|
|
148
|
+
WindowManager.LayoutParams params = window.getAttributes();
|
|
149
|
+
|
|
150
|
+
params.screenBrightness = originalBrightness;
|
|
151
|
+
if (!originalKeepScreenOn) {
|
|
152
|
+
params.flags &= ~WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
window.setAttributes(params);
|
|
156
|
+
} catch (Exception exception) {
|
|
157
|
+
Logger.error(TAG, "Failed to restore the app window.", exception);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
package app.capgo.proximity;
|
|
2
|
+
|
|
3
|
+
import com.getcapacitor.JSObject;
|
|
4
|
+
import com.getcapacitor.Plugin;
|
|
5
|
+
import com.getcapacitor.PluginCall;
|
|
6
|
+
import com.getcapacitor.PluginMethod;
|
|
7
|
+
import com.getcapacitor.annotation.CapacitorPlugin;
|
|
8
|
+
|
|
9
|
+
@CapacitorPlugin(name = "CapacitorProximity")
|
|
10
|
+
public class CapacitorProximityPlugin extends Plugin {
|
|
11
|
+
|
|
12
|
+
private CapacitorProximity implementation;
|
|
13
|
+
|
|
14
|
+
@Override
|
|
15
|
+
public void load() {
|
|
16
|
+
super.load();
|
|
17
|
+
implementation = new CapacitorProximity(getActivity());
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
@Override
|
|
21
|
+
protected void handleOnDestroy() {
|
|
22
|
+
if (implementation != null) {
|
|
23
|
+
implementation.stopMonitoring();
|
|
24
|
+
}
|
|
25
|
+
super.handleOnDestroy();
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
@PluginMethod
|
|
29
|
+
public void enable(PluginCall call) {
|
|
30
|
+
bridge.executeOnMainThread(() -> implementation.enable(call));
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
@PluginMethod
|
|
34
|
+
public void disable(PluginCall call) {
|
|
35
|
+
bridge.executeOnMainThread(() -> implementation.disable(call));
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
@PluginMethod
|
|
39
|
+
public void getStatus(PluginCall call) {
|
|
40
|
+
call.resolve(implementation.getStatus());
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
@PluginMethod
|
|
44
|
+
public void getPluginVersion(PluginCall call) {
|
|
45
|
+
JSObject result = new JSObject();
|
|
46
|
+
result.put("version", implementation.getPluginVersion());
|
|
47
|
+
call.resolve(result);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
File without changes
|
package/dist/docs.json
ADDED
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
{
|
|
2
|
+
"api": {
|
|
3
|
+
"name": "CapacitorProximityPlugin",
|
|
4
|
+
"slug": "capacitorproximityplugin",
|
|
5
|
+
"docs": "Capacitor plugin for enabling proximity monitoring in mobile apps.",
|
|
6
|
+
"tags": [
|
|
7
|
+
{
|
|
8
|
+
"text": "0.0.1",
|
|
9
|
+
"name": "since"
|
|
10
|
+
}
|
|
11
|
+
],
|
|
12
|
+
"methods": [
|
|
13
|
+
{
|
|
14
|
+
"name": "enable",
|
|
15
|
+
"signature": "() => Promise<void>",
|
|
16
|
+
"parameters": [],
|
|
17
|
+
"returns": "Promise<void>",
|
|
18
|
+
"tags": [
|
|
19
|
+
{
|
|
20
|
+
"name": "returns",
|
|
21
|
+
"text": "Promise that resolves when proximity monitoring is active"
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
"name": "since",
|
|
25
|
+
"text": "0.0.1"
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
"name": "example",
|
|
29
|
+
"text": "```typescript\nawait CapacitorProximity.enable();\n```"
|
|
30
|
+
}
|
|
31
|
+
],
|
|
32
|
+
"docs": "Enable proximity monitoring.\n\nOn iOS this enables `UIDevice.isProximityMonitoringEnabled`.\nOn Android this starts listening to `TYPE_PROXIMITY` and dims the current\napp window while the sensor is covered.",
|
|
33
|
+
"complexTypes": [],
|
|
34
|
+
"slug": "enable"
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
"name": "disable",
|
|
38
|
+
"signature": "() => Promise<void>",
|
|
39
|
+
"parameters": [],
|
|
40
|
+
"returns": "Promise<void>",
|
|
41
|
+
"tags": [
|
|
42
|
+
{
|
|
43
|
+
"name": "returns",
|
|
44
|
+
"text": "Promise that resolves when proximity monitoring is disabled"
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
"name": "since",
|
|
48
|
+
"text": "0.0.1"
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
"name": "example",
|
|
52
|
+
"text": "```typescript\nawait CapacitorProximity.disable();\n```"
|
|
53
|
+
}
|
|
54
|
+
],
|
|
55
|
+
"docs": "Disable proximity monitoring.\n\nThis restores the default app window behavior and stops sensor monitoring.",
|
|
56
|
+
"complexTypes": [],
|
|
57
|
+
"slug": "disable"
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
"name": "getStatus",
|
|
61
|
+
"signature": "() => Promise<ProximityStatusResult>",
|
|
62
|
+
"parameters": [],
|
|
63
|
+
"returns": "Promise<ProximityStatusResult>",
|
|
64
|
+
"tags": [
|
|
65
|
+
{
|
|
66
|
+
"name": "returns",
|
|
67
|
+
"text": "Promise resolving to the current plugin status"
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
"name": "since",
|
|
71
|
+
"text": "0.0.1"
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
"name": "example",
|
|
75
|
+
"text": "```typescript\nconst status = await CapacitorProximity.getStatus();\n```"
|
|
76
|
+
}
|
|
77
|
+
],
|
|
78
|
+
"docs": "Get the current sensor availability and plugin enabled state.",
|
|
79
|
+
"complexTypes": [
|
|
80
|
+
"ProximityStatusResult"
|
|
81
|
+
],
|
|
82
|
+
"slug": "getstatus"
|
|
83
|
+
},
|
|
84
|
+
{
|
|
85
|
+
"name": "getPluginVersion",
|
|
86
|
+
"signature": "() => Promise<PluginVersionResult>",
|
|
87
|
+
"parameters": [],
|
|
88
|
+
"returns": "Promise<PluginVersionResult>",
|
|
89
|
+
"tags": [
|
|
90
|
+
{
|
|
91
|
+
"name": "returns",
|
|
92
|
+
"text": "Promise resolving to the plugin version"
|
|
93
|
+
},
|
|
94
|
+
{
|
|
95
|
+
"name": "since",
|
|
96
|
+
"text": "0.0.1"
|
|
97
|
+
},
|
|
98
|
+
{
|
|
99
|
+
"name": "example",
|
|
100
|
+
"text": "```typescript\nconst { version } = await CapacitorProximity.getPluginVersion();\n```"
|
|
101
|
+
}
|
|
102
|
+
],
|
|
103
|
+
"docs": "Get the current native plugin version.",
|
|
104
|
+
"complexTypes": [
|
|
105
|
+
"PluginVersionResult"
|
|
106
|
+
],
|
|
107
|
+
"slug": "getpluginversion"
|
|
108
|
+
}
|
|
109
|
+
],
|
|
110
|
+
"properties": []
|
|
111
|
+
},
|
|
112
|
+
"interfaces": [
|
|
113
|
+
{
|
|
114
|
+
"name": "ProximityStatusResult",
|
|
115
|
+
"slug": "proximitystatusresult",
|
|
116
|
+
"docs": "Result returned by `getStatus()`.",
|
|
117
|
+
"tags": [
|
|
118
|
+
{
|
|
119
|
+
"text": "0.0.1",
|
|
120
|
+
"name": "since"
|
|
121
|
+
}
|
|
122
|
+
],
|
|
123
|
+
"methods": [],
|
|
124
|
+
"properties": [
|
|
125
|
+
{
|
|
126
|
+
"name": "available",
|
|
127
|
+
"tags": [
|
|
128
|
+
{
|
|
129
|
+
"text": "0.0.1",
|
|
130
|
+
"name": "since"
|
|
131
|
+
}
|
|
132
|
+
],
|
|
133
|
+
"docs": "Whether the current device exposes a usable proximity sensor.",
|
|
134
|
+
"complexTypes": [],
|
|
135
|
+
"type": "boolean"
|
|
136
|
+
},
|
|
137
|
+
{
|
|
138
|
+
"name": "enabled",
|
|
139
|
+
"tags": [
|
|
140
|
+
{
|
|
141
|
+
"text": "0.0.1",
|
|
142
|
+
"name": "since"
|
|
143
|
+
}
|
|
144
|
+
],
|
|
145
|
+
"docs": "Whether proximity monitoring is currently enabled by the plugin.",
|
|
146
|
+
"complexTypes": [],
|
|
147
|
+
"type": "boolean"
|
|
148
|
+
},
|
|
149
|
+
{
|
|
150
|
+
"name": "platform",
|
|
151
|
+
"tags": [
|
|
152
|
+
{
|
|
153
|
+
"text": "0.0.1",
|
|
154
|
+
"name": "since"
|
|
155
|
+
}
|
|
156
|
+
],
|
|
157
|
+
"docs": "Platform label returned by the native or web implementation.",
|
|
158
|
+
"complexTypes": [],
|
|
159
|
+
"type": "'ios' | 'android' | 'web'"
|
|
160
|
+
}
|
|
161
|
+
]
|
|
162
|
+
},
|
|
163
|
+
{
|
|
164
|
+
"name": "PluginVersionResult",
|
|
165
|
+
"slug": "pluginversionresult",
|
|
166
|
+
"docs": "Result returned when requesting the plugin version.",
|
|
167
|
+
"tags": [
|
|
168
|
+
{
|
|
169
|
+
"text": "0.0.1",
|
|
170
|
+
"name": "since"
|
|
171
|
+
}
|
|
172
|
+
],
|
|
173
|
+
"methods": [],
|
|
174
|
+
"properties": [
|
|
175
|
+
{
|
|
176
|
+
"name": "version",
|
|
177
|
+
"tags": [
|
|
178
|
+
{
|
|
179
|
+
"text": "0.0.1",
|
|
180
|
+
"name": "since"
|
|
181
|
+
}
|
|
182
|
+
],
|
|
183
|
+
"docs": "Native plugin version string.",
|
|
184
|
+
"complexTypes": [],
|
|
185
|
+
"type": "string"
|
|
186
|
+
}
|
|
187
|
+
]
|
|
188
|
+
}
|
|
189
|
+
],
|
|
190
|
+
"enums": [],
|
|
191
|
+
"typeAliases": [],
|
|
192
|
+
"pluginConfigs": []
|
|
193
|
+
}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Result returned by `getStatus()`.
|
|
3
|
+
*
|
|
4
|
+
* @since 0.0.1
|
|
5
|
+
*/
|
|
6
|
+
export interface ProximityStatusResult {
|
|
7
|
+
/**
|
|
8
|
+
* Whether the current device exposes a usable proximity sensor.
|
|
9
|
+
*
|
|
10
|
+
* @since 0.0.1
|
|
11
|
+
*/
|
|
12
|
+
available: boolean;
|
|
13
|
+
/**
|
|
14
|
+
* Whether proximity monitoring is currently enabled by the plugin.
|
|
15
|
+
*
|
|
16
|
+
* @since 0.0.1
|
|
17
|
+
*/
|
|
18
|
+
enabled: boolean;
|
|
19
|
+
/**
|
|
20
|
+
* Platform label returned by the native or web implementation.
|
|
21
|
+
*
|
|
22
|
+
* @since 0.0.1
|
|
23
|
+
*/
|
|
24
|
+
platform: 'ios' | 'android' | 'web';
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Result returned when requesting the plugin version.
|
|
28
|
+
*
|
|
29
|
+
* @since 0.0.1
|
|
30
|
+
*/
|
|
31
|
+
export interface PluginVersionResult {
|
|
32
|
+
/**
|
|
33
|
+
* Native plugin version string.
|
|
34
|
+
*
|
|
35
|
+
* @since 0.0.1
|
|
36
|
+
*/
|
|
37
|
+
version: string;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Capacitor plugin for enabling proximity monitoring in mobile apps.
|
|
41
|
+
*
|
|
42
|
+
* @since 0.0.1
|
|
43
|
+
*/
|
|
44
|
+
export interface CapacitorProximityPlugin {
|
|
45
|
+
/**
|
|
46
|
+
* Enable proximity monitoring.
|
|
47
|
+
*
|
|
48
|
+
* On iOS this enables `UIDevice.isProximityMonitoringEnabled`.
|
|
49
|
+
* On Android this starts listening to `TYPE_PROXIMITY` and dims the current
|
|
50
|
+
* app window while the sensor is covered.
|
|
51
|
+
*
|
|
52
|
+
* @returns Promise that resolves when proximity monitoring is active
|
|
53
|
+
* @since 0.0.1
|
|
54
|
+
* @example
|
|
55
|
+
* ```typescript
|
|
56
|
+
* await CapacitorProximity.enable();
|
|
57
|
+
* ```
|
|
58
|
+
*/
|
|
59
|
+
enable(): Promise<void>;
|
|
60
|
+
/**
|
|
61
|
+
* Disable proximity monitoring.
|
|
62
|
+
*
|
|
63
|
+
* This restores the default app window behavior and stops sensor monitoring.
|
|
64
|
+
*
|
|
65
|
+
* @returns Promise that resolves when proximity monitoring is disabled
|
|
66
|
+
* @since 0.0.1
|
|
67
|
+
* @example
|
|
68
|
+
* ```typescript
|
|
69
|
+
* await CapacitorProximity.disable();
|
|
70
|
+
* ```
|
|
71
|
+
*/
|
|
72
|
+
disable(): Promise<void>;
|
|
73
|
+
/**
|
|
74
|
+
* Get the current sensor availability and plugin enabled state.
|
|
75
|
+
*
|
|
76
|
+
* @returns Promise resolving to the current plugin status
|
|
77
|
+
* @since 0.0.1
|
|
78
|
+
* @example
|
|
79
|
+
* ```typescript
|
|
80
|
+
* const status = await CapacitorProximity.getStatus();
|
|
81
|
+
* ```
|
|
82
|
+
*/
|
|
83
|
+
getStatus(): Promise<ProximityStatusResult>;
|
|
84
|
+
/**
|
|
85
|
+
* Get the current native plugin version.
|
|
86
|
+
*
|
|
87
|
+
* @returns Promise resolving to the plugin version
|
|
88
|
+
* @since 0.0.1
|
|
89
|
+
* @example
|
|
90
|
+
* ```typescript
|
|
91
|
+
* const { version } = await CapacitorProximity.getPluginVersion();
|
|
92
|
+
* ```
|
|
93
|
+
*/
|
|
94
|
+
getPluginVersion(): Promise<PluginVersionResult>;
|
|
95
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"","sourcesContent":["/**\n * Result returned by `getStatus()`.\n *\n * @since 0.0.1\n */\nexport interface ProximityStatusResult {\n /**\n * Whether the current device exposes a usable proximity sensor.\n *\n * @since 0.0.1\n */\n available: boolean;\n\n /**\n * Whether proximity monitoring is currently enabled by the plugin.\n *\n * @since 0.0.1\n */\n enabled: boolean;\n\n /**\n * Platform label returned by the native or web implementation.\n *\n * @since 0.0.1\n */\n platform: 'ios' | 'android' | 'web';\n}\n\n/**\n * Result returned when requesting the plugin version.\n *\n * @since 0.0.1\n */\nexport interface PluginVersionResult {\n /**\n * Native plugin version string.\n *\n * @since 0.0.1\n */\n version: string;\n}\n\n/**\n * Capacitor plugin for enabling proximity monitoring in mobile apps.\n *\n * @since 0.0.1\n */\nexport interface CapacitorProximityPlugin {\n /**\n * Enable proximity monitoring.\n *\n * On iOS this enables `UIDevice.isProximityMonitoringEnabled`.\n * On Android this starts listening to `TYPE_PROXIMITY` and dims the current\n * app window while the sensor is covered.\n *\n * @returns Promise that resolves when proximity monitoring is active\n * @since 0.0.1\n * @example\n * ```typescript\n * await CapacitorProximity.enable();\n * ```\n */\n enable(): Promise<void>;\n\n /**\n * Disable proximity monitoring.\n *\n * This restores the default app window behavior and stops sensor monitoring.\n *\n * @returns Promise that resolves when proximity monitoring is disabled\n * @since 0.0.1\n * @example\n * ```typescript\n * await CapacitorProximity.disable();\n * ```\n */\n disable(): Promise<void>;\n\n /**\n * Get the current sensor availability and plugin enabled state.\n *\n * @returns Promise resolving to the current plugin status\n * @since 0.0.1\n * @example\n * ```typescript\n * const status = await CapacitorProximity.getStatus();\n * ```\n */\n getStatus(): Promise<ProximityStatusResult>;\n\n /**\n * Get the current native plugin version.\n *\n * @returns Promise resolving to the plugin version\n * @since 0.0.1\n * @example\n * ```typescript\n * const { version } = await CapacitorProximity.getPluginVersion();\n * ```\n */\n getPluginVersion(): Promise<PluginVersionResult>;\n}\n"]}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { registerPlugin } from '@capacitor/core';
|
|
2
|
+
const CapacitorProximity = registerPlugin('CapacitorProximity', {
|
|
3
|
+
web: () => import('./web').then((module) => new module.CapacitorProximityWeb()),
|
|
4
|
+
});
|
|
5
|
+
export * from './definitions';
|
|
6
|
+
export { CapacitorProximity };
|
|
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,kBAAkB,GAAG,cAAc,CAA2B,oBAAoB,EAAE;IACxF,GAAG,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,IAAI,MAAM,CAAC,qBAAqB,EAAE,CAAC;CAChF,CAAC,CAAC;AAEH,cAAc,eAAe,CAAC;AAC9B,OAAO,EAAE,kBAAkB,EAAE,CAAC","sourcesContent":["import { registerPlugin } from '@capacitor/core';\n\nimport type { CapacitorProximityPlugin } from './definitions';\n\nconst CapacitorProximity = registerPlugin<CapacitorProximityPlugin>('CapacitorProximity', {\n web: () => import('./web').then((module) => new module.CapacitorProximityWeb()),\n});\n\nexport * from './definitions';\nexport { CapacitorProximity };\n"]}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { WebPlugin } from '@capacitor/core';
|
|
2
|
+
import type { CapacitorProximityPlugin, PluginVersionResult, ProximityStatusResult } from './definitions';
|
|
3
|
+
export declare class CapacitorProximityWeb extends WebPlugin implements CapacitorProximityPlugin {
|
|
4
|
+
enable(): Promise<void>;
|
|
5
|
+
disable(): Promise<void>;
|
|
6
|
+
getStatus(): Promise<ProximityStatusResult>;
|
|
7
|
+
getPluginVersion(): Promise<PluginVersionResult>;
|
|
8
|
+
}
|
package/dist/esm/web.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { WebPlugin } from '@capacitor/core';
|
|
2
|
+
export class CapacitorProximityWeb extends WebPlugin {
|
|
3
|
+
async enable() {
|
|
4
|
+
throw this.unavailable('Proximity monitoring is not available on web.');
|
|
5
|
+
}
|
|
6
|
+
async disable() {
|
|
7
|
+
throw this.unavailable('Proximity monitoring is not available on web.');
|
|
8
|
+
}
|
|
9
|
+
async getStatus() {
|
|
10
|
+
return {
|
|
11
|
+
available: false,
|
|
12
|
+
enabled: false,
|
|
13
|
+
platform: 'web',
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
async getPluginVersion() {
|
|
17
|
+
return {
|
|
18
|
+
version: 'web',
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
//# 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,MAAM,iBAAiB,CAAC;AAI5C,MAAM,OAAO,qBAAsB,SAAQ,SAAS;IAClD,KAAK,CAAC,MAAM;QACV,MAAM,IAAI,CAAC,WAAW,CAAC,+CAA+C,CAAC,CAAC;IAC1E,CAAC;IAED,KAAK,CAAC,OAAO;QACX,MAAM,IAAI,CAAC,WAAW,CAAC,+CAA+C,CAAC,CAAC;IAC1E,CAAC;IAED,KAAK,CAAC,SAAS;QACb,OAAO;YACL,SAAS,EAAE,KAAK;YAChB,OAAO,EAAE,KAAK;YACd,QAAQ,EAAE,KAAK;SAChB,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,gBAAgB;QACpB,OAAO;YACL,OAAO,EAAE,KAAK;SACf,CAAC;IACJ,CAAC;CACF","sourcesContent":["import { WebPlugin } from '@capacitor/core';\n\nimport type { CapacitorProximityPlugin, PluginVersionResult, ProximityStatusResult } from './definitions';\n\nexport class CapacitorProximityWeb extends WebPlugin implements CapacitorProximityPlugin {\n async enable(): Promise<void> {\n throw this.unavailable('Proximity monitoring is not available on web.');\n }\n\n async disable(): Promise<void> {\n throw this.unavailable('Proximity monitoring is not available on web.');\n }\n\n async getStatus(): Promise<ProximityStatusResult> {\n return {\n available: false,\n enabled: false,\n platform: 'web',\n };\n }\n\n async getPluginVersion(): Promise<PluginVersionResult> {\n return {\n version: 'web',\n };\n }\n}\n"]}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var core = require('@capacitor/core');
|
|
4
|
+
|
|
5
|
+
const CapacitorProximity = core.registerPlugin('CapacitorProximity', {
|
|
6
|
+
web: () => Promise.resolve().then(function () { return web; }).then((module) => new module.CapacitorProximityWeb()),
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
class CapacitorProximityWeb extends core.WebPlugin {
|
|
10
|
+
async enable() {
|
|
11
|
+
throw this.unavailable('Proximity monitoring is not available on web.');
|
|
12
|
+
}
|
|
13
|
+
async disable() {
|
|
14
|
+
throw this.unavailable('Proximity monitoring is not available on web.');
|
|
15
|
+
}
|
|
16
|
+
async getStatus() {
|
|
17
|
+
return {
|
|
18
|
+
available: false,
|
|
19
|
+
enabled: false,
|
|
20
|
+
platform: 'web',
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
async getPluginVersion() {
|
|
24
|
+
return {
|
|
25
|
+
version: 'web',
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
var web = /*#__PURE__*/Object.freeze({
|
|
31
|
+
__proto__: null,
|
|
32
|
+
CapacitorProximityWeb: CapacitorProximityWeb
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
exports.CapacitorProximity = CapacitorProximity;
|
|
36
|
+
//# 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 CapacitorProximity = registerPlugin('CapacitorProximity', {\n web: () => import('./web').then((module) => new module.CapacitorProximityWeb()),\n});\nexport * from './definitions';\nexport { CapacitorProximity };\n//# sourceMappingURL=index.js.map","import { WebPlugin } from '@capacitor/core';\nexport class CapacitorProximityWeb extends WebPlugin {\n async enable() {\n throw this.unavailable('Proximity monitoring is not available on web.');\n }\n async disable() {\n throw this.unavailable('Proximity monitoring is not available on web.');\n }\n async getStatus() {\n return {\n available: false,\n enabled: false,\n platform: 'web',\n };\n }\n async getPluginVersion() {\n return {\n version: 'web',\n };\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["registerPlugin","WebPlugin"],"mappings":";;;;AACK,MAAC,kBAAkB,GAAGA,mBAAc,CAAC,oBAAoB,EAAE;AAChE,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,MAAM,KAAK,IAAI,MAAM,CAAC,qBAAqB,EAAE,CAAC;AACnF,CAAC;;ACFM,MAAM,qBAAqB,SAASC,cAAS,CAAC;AACrD,IAAI,MAAM,MAAM,GAAG;AACnB,QAAQ,MAAM,IAAI,CAAC,WAAW,CAAC,+CAA+C,CAAC;AAC/E,IAAI;AACJ,IAAI,MAAM,OAAO,GAAG;AACpB,QAAQ,MAAM,IAAI,CAAC,WAAW,CAAC,+CAA+C,CAAC;AAC/E,IAAI;AACJ,IAAI,MAAM,SAAS,GAAG;AACtB,QAAQ,OAAO;AACf,YAAY,SAAS,EAAE,KAAK;AAC5B,YAAY,OAAO,EAAE,KAAK;AAC1B,YAAY,QAAQ,EAAE,KAAK;AAC3B,SAAS;AACT,IAAI;AACJ,IAAI,MAAM,gBAAgB,GAAG;AAC7B,QAAQ,OAAO;AACf,YAAY,OAAO,EAAE,KAAK;AAC1B,SAAS;AACT,IAAI;AACJ;;;;;;;;;"}
|
package/dist/plugin.js
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
var capacitorProximity = (function (exports, core) {
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
const CapacitorProximity = core.registerPlugin('CapacitorProximity', {
|
|
5
|
+
web: () => Promise.resolve().then(function () { return web; }).then((module) => new module.CapacitorProximityWeb()),
|
|
6
|
+
});
|
|
7
|
+
|
|
8
|
+
class CapacitorProximityWeb extends core.WebPlugin {
|
|
9
|
+
async enable() {
|
|
10
|
+
throw this.unavailable('Proximity monitoring is not available on web.');
|
|
11
|
+
}
|
|
12
|
+
async disable() {
|
|
13
|
+
throw this.unavailable('Proximity monitoring is not available on web.');
|
|
14
|
+
}
|
|
15
|
+
async getStatus() {
|
|
16
|
+
return {
|
|
17
|
+
available: false,
|
|
18
|
+
enabled: false,
|
|
19
|
+
platform: 'web',
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
async getPluginVersion() {
|
|
23
|
+
return {
|
|
24
|
+
version: 'web',
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
var web = /*#__PURE__*/Object.freeze({
|
|
30
|
+
__proto__: null,
|
|
31
|
+
CapacitorProximityWeb: CapacitorProximityWeb
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
exports.CapacitorProximity = CapacitorProximity;
|
|
35
|
+
|
|
36
|
+
return exports;
|
|
37
|
+
|
|
38
|
+
})({}, capacitorExports);
|
|
39
|
+
//# 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 CapacitorProximity = registerPlugin('CapacitorProximity', {\n web: () => import('./web').then((module) => new module.CapacitorProximityWeb()),\n});\nexport * from './definitions';\nexport { CapacitorProximity };\n//# sourceMappingURL=index.js.map","import { WebPlugin } from '@capacitor/core';\nexport class CapacitorProximityWeb extends WebPlugin {\n async enable() {\n throw this.unavailable('Proximity monitoring is not available on web.');\n }\n async disable() {\n throw this.unavailable('Proximity monitoring is not available on web.');\n }\n async getStatus() {\n return {\n available: false,\n enabled: false,\n platform: 'web',\n };\n }\n async getPluginVersion() {\n return {\n version: 'web',\n };\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["registerPlugin","WebPlugin"],"mappings":";;;AACK,UAAC,kBAAkB,GAAGA,mBAAc,CAAC,oBAAoB,EAAE;IAChE,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,MAAM,KAAK,IAAI,MAAM,CAAC,qBAAqB,EAAE,CAAC;IACnF,CAAC;;ICFM,MAAM,qBAAqB,SAASC,cAAS,CAAC;IACrD,IAAI,MAAM,MAAM,GAAG;IACnB,QAAQ,MAAM,IAAI,CAAC,WAAW,CAAC,+CAA+C,CAAC;IAC/E,IAAI;IACJ,IAAI,MAAM,OAAO,GAAG;IACpB,QAAQ,MAAM,IAAI,CAAC,WAAW,CAAC,+CAA+C,CAAC;IAC/E,IAAI;IACJ,IAAI,MAAM,SAAS,GAAG;IACtB,QAAQ,OAAO;IACf,YAAY,SAAS,EAAE,KAAK;IAC5B,YAAY,OAAO,EAAE,KAAK;IAC1B,YAAY,QAAQ,EAAE,KAAK;IAC3B,SAAS;IACT,IAAI;IACJ,IAAI,MAAM,gBAAgB,GAAG;IAC7B,QAAQ,OAAO;IACf,YAAY,OAAO,EAAE,KAAK;IAC1B,SAAS;IACT,IAAI;IACJ;;;;;;;;;;;;;;;"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import Foundation
|
|
2
|
+
import UIKit
|
|
3
|
+
|
|
4
|
+
@objc public class CapacitorProximity: NSObject {
|
|
5
|
+
public static let pluginVersion = "8.0.0"
|
|
6
|
+
|
|
7
|
+
@objc public func enable() -> Bool {
|
|
8
|
+
UIDevice.current.isProximityMonitoringEnabled = true
|
|
9
|
+
return UIDevice.current.isProximityMonitoringEnabled
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
@objc public func disable() {
|
|
13
|
+
UIDevice.current.isProximityMonitoringEnabled = false
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
@objc public func isAvailable() -> Bool {
|
|
17
|
+
let original = UIDevice.current.isProximityMonitoringEnabled
|
|
18
|
+
UIDevice.current.isProximityMonitoringEnabled = true
|
|
19
|
+
let available = UIDevice.current.isProximityMonitoringEnabled
|
|
20
|
+
UIDevice.current.isProximityMonitoringEnabled = original
|
|
21
|
+
return available
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
@objc public func isEnabled() -> Bool {
|
|
25
|
+
UIDevice.current.isProximityMonitoringEnabled
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
@objc public func getPluginVersion() -> String {
|
|
29
|
+
Self.pluginVersion
|
|
30
|
+
}
|
|
31
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import Capacitor
|
|
2
|
+
import Foundation
|
|
3
|
+
|
|
4
|
+
@objc(CapacitorProximityPlugin)
|
|
5
|
+
public class CapacitorProximityPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
6
|
+
public let identifier = "CapacitorProximityPlugin"
|
|
7
|
+
public let jsName = "CapacitorProximity"
|
|
8
|
+
public let pluginMethods: [CAPPluginMethod] = [
|
|
9
|
+
CAPPluginMethod(name: "enable", returnType: CAPPluginReturnPromise),
|
|
10
|
+
CAPPluginMethod(name: "disable", returnType: CAPPluginReturnPromise),
|
|
11
|
+
CAPPluginMethod(name: "getStatus", returnType: CAPPluginReturnPromise),
|
|
12
|
+
CAPPluginMethod(name: "getPluginVersion", returnType: CAPPluginReturnPromise)
|
|
13
|
+
]
|
|
14
|
+
|
|
15
|
+
private let implementation = CapacitorProximity()
|
|
16
|
+
|
|
17
|
+
deinit {
|
|
18
|
+
implementation.disable()
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
@objc func enable(_ call: CAPPluginCall) {
|
|
22
|
+
DispatchQueue.main.async {
|
|
23
|
+
if self.implementation.enable() {
|
|
24
|
+
call.resolve()
|
|
25
|
+
return
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
call.reject("Proximity sensor not available on this device.")
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
@objc func disable(_ call: CAPPluginCall) {
|
|
33
|
+
DispatchQueue.main.async {
|
|
34
|
+
self.implementation.disable()
|
|
35
|
+
call.resolve()
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
@objc func getStatus(_ call: CAPPluginCall) {
|
|
40
|
+
DispatchQueue.main.async {
|
|
41
|
+
call.resolve([
|
|
42
|
+
"available": self.implementation.isAvailable(),
|
|
43
|
+
"enabled": self.implementation.isEnabled(),
|
|
44
|
+
"platform": "ios"
|
|
45
|
+
])
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
@objc func getPluginVersion(_ call: CAPPluginCall) {
|
|
50
|
+
call.resolve([
|
|
51
|
+
"version": implementation.getPluginVersion()
|
|
52
|
+
])
|
|
53
|
+
}
|
|
54
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@capgo/capacitor-proximity",
|
|
3
|
+
"version": "8.1.1",
|
|
4
|
+
"description": "Capacitor plugin for enabling proximity monitoring in mobile apps.",
|
|
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
|
+
"android/gradle.properties",
|
|
16
|
+
"android/settings.gradle",
|
|
17
|
+
"android/proguard-rules.pro",
|
|
18
|
+
"Package.swift",
|
|
19
|
+
"CapgoCapacitorProximity.podspec"
|
|
20
|
+
],
|
|
21
|
+
"author": "Capgo",
|
|
22
|
+
"license": "MIT",
|
|
23
|
+
"repository": {
|
|
24
|
+
"type": "git",
|
|
25
|
+
"url": "git+https://github.com/Cap-go/capacitor-proximity.git"
|
|
26
|
+
},
|
|
27
|
+
"bugs": {
|
|
28
|
+
"url": "https://github.com/Cap-go/capacitor-proximity/issues"
|
|
29
|
+
},
|
|
30
|
+
"homepage": "https://capgo.app/docs/plugins/proximity/",
|
|
31
|
+
"keywords": [
|
|
32
|
+
"capacitor",
|
|
33
|
+
"plugin",
|
|
34
|
+
"proximity",
|
|
35
|
+
"sensor",
|
|
36
|
+
"screen",
|
|
37
|
+
"ios",
|
|
38
|
+
"android"
|
|
39
|
+
],
|
|
40
|
+
"scripts": {
|
|
41
|
+
"verify": "bun run verify:ios && bun run verify:android && bun run verify:web",
|
|
42
|
+
"verify:ios": "xcodebuild -scheme CapgoCapacitorProximity -destination generic/platform=iOS",
|
|
43
|
+
"verify:android": "cd android && ./gradlew clean build test && cd ..",
|
|
44
|
+
"verify:web": "bun run build",
|
|
45
|
+
"lint": "bun run eslint && bun run prettier -- --check && bun run swiftlint -- lint",
|
|
46
|
+
"fmt": "bun run eslint -- --fix && bun run prettier -- --write && bun run swiftlint -- --fix --format",
|
|
47
|
+
"eslint": "eslint . --ext .ts",
|
|
48
|
+
"prettier": "prettier-pretty-check \"**/*.{css,html,ts,js,java}\" --plugin=prettier-plugin-java",
|
|
49
|
+
"swiftlint": "node-swiftlint",
|
|
50
|
+
"docgen": "docgen --api CapacitorProximityPlugin --output-readme README.md --output-json dist/docs.json",
|
|
51
|
+
"build": "bun run clean && bun run docgen && tsc && rollup -c rollup.config.mjs",
|
|
52
|
+
"clean": "rimraf ./dist",
|
|
53
|
+
"watch": "tsc --watch",
|
|
54
|
+
"prepublishOnly": "bun run build",
|
|
55
|
+
"check:wiring": "node scripts/check-capacitor-plugin-wiring.mjs"
|
|
56
|
+
},
|
|
57
|
+
"devDependencies": {
|
|
58
|
+
"@capacitor/android": "^8.0.0",
|
|
59
|
+
"@capacitor/cli": "^8.0.0",
|
|
60
|
+
"@capacitor/core": "^8.0.0",
|
|
61
|
+
"@capacitor/docgen": "^0.3.1",
|
|
62
|
+
"@capacitor/ios": "^8.0.0",
|
|
63
|
+
"@ionic/eslint-config": "^0.4.0",
|
|
64
|
+
"@ionic/prettier-config": "^4.0.0",
|
|
65
|
+
"@ionic/swiftlint-config": "^2.0.0",
|
|
66
|
+
"@types/node": "^24.10.1",
|
|
67
|
+
"eslint": "^8.57.1",
|
|
68
|
+
"eslint-plugin-import": "^2.31.0",
|
|
69
|
+
"prettier": "^3.6.2",
|
|
70
|
+
"prettier-pretty-check": "^0.2.0",
|
|
71
|
+
"prettier-plugin-java": "^2.7.7",
|
|
72
|
+
"rimraf": "^6.1.0",
|
|
73
|
+
"rollup": "^4.53.2",
|
|
74
|
+
"swiftlint": "^2.0.0",
|
|
75
|
+
"typescript": "^5.9.3"
|
|
76
|
+
},
|
|
77
|
+
"peerDependencies": {
|
|
78
|
+
"@capacitor/core": ">=8.0.0"
|
|
79
|
+
},
|
|
80
|
+
"prettier": "@ionic/prettier-config",
|
|
81
|
+
"swiftlint": "@ionic/swiftlint-config",
|
|
82
|
+
"eslintConfig": {
|
|
83
|
+
"extends": "@ionic/eslint-config/recommended"
|
|
84
|
+
},
|
|
85
|
+
"capacitor": {
|
|
86
|
+
"ios": {
|
|
87
|
+
"src": "ios"
|
|
88
|
+
},
|
|
89
|
+
"android": {
|
|
90
|
+
"src": "android"
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|