@dreiver1/capacitor-step-counter 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/Package.swift ADDED
@@ -0,0 +1,28 @@
1
+ // swift-tools-version: 5.9
2
+ import PackageDescription
3
+
4
+ let package = Package(
5
+ name: "StepCounter",
6
+ platforms: [.iOS(.v15)],
7
+ products: [
8
+ .library(
9
+ name: "StepCounter",
10
+ targets: ["StepCounterPlugin"])
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: "StepCounterPlugin",
18
+ dependencies: [
19
+ .product(name: "Capacitor", package: "capacitor-swift-pm"),
20
+ .product(name: "Cordova", package: "capacitor-swift-pm")
21
+ ],
22
+ path: "ios/Sources/StepCounterPlugin"),
23
+ .testTarget(
24
+ name: "StepCounterPluginTests",
25
+ dependencies: ["StepCounterPlugin"],
26
+ path: "ios/Tests/StepCounterPluginTests")
27
+ ]
28
+ )
package/README.md ADDED
@@ -0,0 +1,96 @@
1
+ # step-counter
2
+
3
+ A Capacitor plugin that provides access to the device step counter sensor on Androi, with a web fallback.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ npm install step-counter
9
+ npx cap sync
10
+ ```
11
+
12
+ ## API
13
+
14
+ <docgen-index>
15
+
16
+ * [`start()`](#start)
17
+ * [`stop()`](#stop)
18
+ * [`getCurrentSteps()`](#getcurrentsteps)
19
+ * [`addListener('step', ...)`](#addlistenerstep-)
20
+ * [Interfaces](#interfaces)
21
+
22
+ </docgen-index>
23
+
24
+ <docgen-api>
25
+ <!--Update the source file JSDoc comments and rerun docgen to update the docs below-->
26
+
27
+ ### start()
28
+
29
+ ```typescript
30
+ start() => Promise<void>
31
+ ```
32
+
33
+ Starts listening to the step counter sensor
34
+
35
+ --------------------
36
+
37
+
38
+ ### stop()
39
+
40
+ ```typescript
41
+ stop() => Promise<void>
42
+ ```
43
+
44
+ Stops listening to the step counter sensor
45
+
46
+ --------------------
47
+
48
+
49
+ ### getCurrentSteps()
50
+
51
+ ```typescript
52
+ getCurrentSteps() => Promise<StepCounterData>
53
+ ```
54
+
55
+ Returns the current step count since device boot
56
+
57
+ **Returns:** <code>Promise&lt;<a href="#stepcounterdata">StepCounterData</a>&gt;</code>
58
+
59
+ --------------------
60
+
61
+
62
+ ### addListener('step', ...)
63
+
64
+ ```typescript
65
+ addListener(eventName: 'step', listenerFunc: (data: StepCounterData) => void) => Promise<PluginListenerHandle>
66
+ ```
67
+
68
+ Emits step updates
69
+
70
+ | Param | Type |
71
+ | ------------------ | ------------------------------------------------------------------------------ |
72
+ | **`eventName`** | <code>'step'</code> |
73
+ | **`listenerFunc`** | <code>(data: <a href="#stepcounterdata">StepCounterData</a>) =&gt; void</code> |
74
+
75
+ **Returns:** <code>Promise&lt;<a href="#pluginlistenerhandle">PluginListenerHandle</a>&gt;</code>
76
+
77
+ --------------------
78
+
79
+
80
+ ### Interfaces
81
+
82
+
83
+ #### StepCounterData
84
+
85
+ | Prop | Type |
86
+ | ----------- | ------------------- |
87
+ | **`steps`** | <code>number</code> |
88
+
89
+
90
+ #### PluginListenerHandle
91
+
92
+ | Prop | Type |
93
+ | ------------ | ----------------------------------------- |
94
+ | **`remove`** | <code>() =&gt; Promise&lt;void&gt;</code> |
95
+
96
+ </docgen-api>
@@ -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 = 'StepCounter'
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
@@ -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.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 = "com.davidnascimento.plugins.stepcounter"
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.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,3 @@
1
+ <manifest xmlns:android="http://schemas.android.com/apk/res/android">
2
+ <uses-permission android:name="android.permission.ACTIVITY_RECOGNITION" />
3
+ </manifest>
@@ -0,0 +1,11 @@
1
+ package com.davidnascimento.plugins.stepcounter;
2
+
3
+ import com.getcapacitor.Logger;
4
+
5
+ public class StepCounter {
6
+
7
+ public String echo(String value) {
8
+ Logger.info("Echo", value);
9
+ return value;
10
+ }
11
+ }
@@ -0,0 +1,90 @@
1
+ package com.davidnascimento.plugins.stepcounter;
2
+
3
+ import android.content.Context;
4
+ import android.hardware.Sensor;
5
+ import android.hardware.SensorEvent;
6
+ import android.hardware.SensorEventListener;
7
+ import android.hardware.SensorManager;
8
+ import android.os.Build;
9
+
10
+ import androidx.core.app.ActivityCompat;
11
+
12
+ import com.getcapacitor.*;
13
+ import com.getcapacitor.annotation.CapacitorPlugin;
14
+ import com.getcapacitor.annotation.Permission;
15
+
16
+ @CapacitorPlugin(
17
+ name = "StepCounter",
18
+ permissions = {
19
+ @Permission(
20
+ alias = "activityRecognition",
21
+ strings = { android.Manifest.permission.ACTIVITY_RECOGNITION }
22
+ )
23
+ }
24
+ )
25
+ public class StepCounterPlugin extends Plugin implements SensorEventListener {
26
+
27
+ private SensorManager sensorManager;
28
+ private Sensor stepSensor;
29
+ private float currentSteps = 0;
30
+
31
+ @Override
32
+ public void load() {
33
+ sensorManager = (SensorManager)
34
+ getContext().getSystemService(Context.SENSOR_SERVICE);
35
+ stepSensor = sensorManager.getDefaultSensor(Sensor.TYPE_STEP_COUNTER);
36
+ }
37
+
38
+ @PluginMethod
39
+ public void start(PluginCall call) {
40
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q &&
41
+ !getPermissionState("activityRecognition").equals(PermissionState.GRANTED)) {
42
+ requestPermissionForAlias("activityRecognition", call, "permissionCallback");
43
+ return;
44
+ }
45
+
46
+ if (stepSensor == null) {
47
+ call.reject("Step Counter sensor not available");
48
+ return;
49
+ }
50
+
51
+ sensorManager.registerListener(
52
+ this,
53
+ stepSensor,
54
+ SensorManager.SENSOR_DELAY_NORMAL
55
+ );
56
+
57
+ call.resolve();
58
+ }
59
+
60
+ @PluginMethod
61
+ public void stop(PluginCall call) {
62
+ sensorManager.unregisterListener(this);
63
+ call.resolve();
64
+ }
65
+
66
+ @PluginMethod
67
+ public void getCurrentSteps(PluginCall call) {
68
+ JSObject ret = new JSObject();
69
+ ret.put("steps", currentSteps);
70
+ call.resolve(ret);
71
+ }
72
+
73
+ @PermissionCallback
74
+ private void permissionCallback(PluginCall call) {
75
+ start(call);
76
+ }
77
+
78
+ @Override
79
+ public void onSensorChanged(SensorEvent event) {
80
+ currentSteps = event.values[0];
81
+
82
+ JSObject data = new JSObject();
83
+ data.put("steps", currentSteps);
84
+
85
+ notifyListeners("step", data);
86
+ }
87
+
88
+ @Override
89
+ public void onAccuracyChanged(Sensor sensor, int accuracy) {}
90
+ }
File without changes
package/dist/docs.json ADDED
@@ -0,0 +1,104 @@
1
+ {
2
+ "api": {
3
+ "name": "StepCounterPlugin",
4
+ "slug": "stepcounterplugin",
5
+ "docs": "",
6
+ "tags": [],
7
+ "methods": [
8
+ {
9
+ "name": "start",
10
+ "signature": "() => Promise<void>",
11
+ "parameters": [],
12
+ "returns": "Promise<void>",
13
+ "tags": [],
14
+ "docs": "Starts listening to the step counter sensor",
15
+ "complexTypes": [],
16
+ "slug": "start"
17
+ },
18
+ {
19
+ "name": "stop",
20
+ "signature": "() => Promise<void>",
21
+ "parameters": [],
22
+ "returns": "Promise<void>",
23
+ "tags": [],
24
+ "docs": "Stops listening to the step counter sensor",
25
+ "complexTypes": [],
26
+ "slug": "stop"
27
+ },
28
+ {
29
+ "name": "getCurrentSteps",
30
+ "signature": "() => Promise<StepCounterData>",
31
+ "parameters": [],
32
+ "returns": "Promise<StepCounterData>",
33
+ "tags": [],
34
+ "docs": "Returns the current step count since device boot",
35
+ "complexTypes": [
36
+ "StepCounterData"
37
+ ],
38
+ "slug": "getcurrentsteps"
39
+ },
40
+ {
41
+ "name": "addListener",
42
+ "signature": "(eventName: 'step', listenerFunc: (data: StepCounterData) => void) => Promise<PluginListenerHandle>",
43
+ "parameters": [
44
+ {
45
+ "name": "eventName",
46
+ "docs": "",
47
+ "type": "'step'"
48
+ },
49
+ {
50
+ "name": "listenerFunc",
51
+ "docs": "",
52
+ "type": "(data: StepCounterData) => void"
53
+ }
54
+ ],
55
+ "returns": "Promise<PluginListenerHandle>",
56
+ "tags": [],
57
+ "docs": "Emits step updates",
58
+ "complexTypes": [
59
+ "PluginListenerHandle",
60
+ "StepCounterData"
61
+ ],
62
+ "slug": "addlistenerstep-"
63
+ }
64
+ ],
65
+ "properties": []
66
+ },
67
+ "interfaces": [
68
+ {
69
+ "name": "StepCounterData",
70
+ "slug": "stepcounterdata",
71
+ "docs": "",
72
+ "tags": [],
73
+ "methods": [],
74
+ "properties": [
75
+ {
76
+ "name": "steps",
77
+ "tags": [],
78
+ "docs": "",
79
+ "complexTypes": [],
80
+ "type": "number"
81
+ }
82
+ ]
83
+ },
84
+ {
85
+ "name": "PluginListenerHandle",
86
+ "slug": "pluginlistenerhandle",
87
+ "docs": "",
88
+ "tags": [],
89
+ "methods": [],
90
+ "properties": [
91
+ {
92
+ "name": "remove",
93
+ "tags": [],
94
+ "docs": "",
95
+ "complexTypes": [],
96
+ "type": "() => Promise<void>"
97
+ }
98
+ ]
99
+ }
100
+ ],
101
+ "enums": [],
102
+ "typeAliases": [],
103
+ "pluginConfigs": []
104
+ }
@@ -0,0 +1,22 @@
1
+ import type { PluginListenerHandle } from '@capacitor/core';
2
+ export interface StepCounterData {
3
+ steps: number;
4
+ }
5
+ export interface StepCounterPlugin {
6
+ /**
7
+ * Starts listening to the step counter sensor
8
+ */
9
+ start(): Promise<void>;
10
+ /**
11
+ * Stops listening to the step counter sensor
12
+ */
13
+ stop(): Promise<void>;
14
+ /**
15
+ * Returns the current step count since device boot
16
+ */
17
+ getCurrentSteps(): Promise<StepCounterData>;
18
+ /**
19
+ * Emits step updates
20
+ */
21
+ addListener(eventName: 'step', listenerFunc: (data: StepCounterData) => void): Promise<PluginListenerHandle>;
22
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=definitions.js.map
@@ -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 interface StepCounterData {\n steps: number;\n}\n\nexport interface StepCounterPlugin {\n /**\n * Starts listening to the step counter sensor\n */\n start(): Promise<void>;\n\n /**\n * Stops listening to the step counter sensor\n */\n stop(): Promise<void>;\n\n /**\n * Returns the current step count since device boot\n */\n getCurrentSteps(): Promise<StepCounterData>;\n\n /**\n * Emits step updates\n */\n addListener(\n eventName: 'step',\n listenerFunc: (data: StepCounterData) => void\n ): Promise<PluginListenerHandle>;\n}\n"]}
@@ -0,0 +1,4 @@
1
+ import type { StepCounterPlugin } from './definitions';
2
+ declare const StepCounter: StepCounterPlugin;
3
+ export * from './definitions';
4
+ export { StepCounter };
@@ -0,0 +1,7 @@
1
+ import { registerPlugin } from '@capacitor/core';
2
+ const StepCounter = registerPlugin('StepCounter', {
3
+ web: () => import('./web').then((m) => new m.StepCounterWeb()),
4
+ });
5
+ export * from './definitions';
6
+ export { StepCounter };
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,WAAW,GAAG,cAAc,CAAoB,aAAa,EAAE;IACnE,GAAG,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,CAAC,cAAc,EAAE,CAAC;CAC/D,CAAC,CAAC;AAEH,cAAc,eAAe,CAAC;AAC9B,OAAO,EAAE,WAAW,EAAE,CAAC","sourcesContent":["import { registerPlugin } from '@capacitor/core';\n\nimport type { StepCounterPlugin } from './definitions';\n\nconst StepCounter = registerPlugin<StepCounterPlugin>('StepCounter', {\n web: () => import('./web').then((m) => new m.StepCounterWeb()),\n});\n\nexport * from './definitions';\nexport { StepCounter };\n"]}
@@ -0,0 +1,9 @@
1
+ import { WebPlugin } from '@capacitor/core';
2
+ import type { StepCounterPlugin, StepCounterData } from './definitions';
3
+ export declare class StepCounterWeb extends WebPlugin implements StepCounterPlugin {
4
+ private steps;
5
+ private interval?;
6
+ start(): Promise<void>;
7
+ stop(): Promise<void>;
8
+ getCurrentSteps(): Promise<StepCounterData>;
9
+ }
@@ -0,0 +1,23 @@
1
+ import { WebPlugin } from '@capacitor/core';
2
+ export class StepCounterWeb extends WebPlugin {
3
+ constructor() {
4
+ super(...arguments);
5
+ this.steps = 0;
6
+ }
7
+ async start() {
8
+ this.interval = window.setInterval(() => {
9
+ this.steps += Math.floor(Math.random() * 3);
10
+ this.notifyListeners('step', { steps: this.steps });
11
+ }, 2000);
12
+ }
13
+ async stop() {
14
+ if (this.interval) {
15
+ clearInterval(this.interval);
16
+ this.interval = undefined;
17
+ }
18
+ }
19
+ async getCurrentSteps() {
20
+ return { steps: this.steps };
21
+ }
22
+ }
23
+ //# 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;AAG5C,MAAM,OAAO,cAAe,SAAQ,SAAS;IAA7C;;QACU,UAAK,GAAG,CAAC,CAAC;IAoBpB,CAAC;IAjBC,KAAK,CAAC,KAAK;QACT,IAAI,CAAC,QAAQ,GAAG,MAAM,CAAC,WAAW,CAAC,GAAG,EAAE;YACtC,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,CAAC;YAC5C,IAAI,CAAC,eAAe,CAAC,MAAM,EAAE,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,CAAC,CAAC;QACtD,CAAC,EAAE,IAAI,CAAC,CAAC;IACX,CAAC;IAED,KAAK,CAAC,IAAI;QACR,IAAI,IAAI,CAAC,QAAQ,EAAE,CAAC;YAClB,aAAa,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;YAC7B,IAAI,CAAC,QAAQ,GAAG,SAAS,CAAC;QAC5B,CAAC;IACH,CAAC;IAED,KAAK,CAAC,eAAe;QACnB,OAAO,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,CAAC;IAC/B,CAAC;CACF","sourcesContent":["import { WebPlugin } from '@capacitor/core';\nimport type { StepCounterPlugin, StepCounterData } from './definitions';\n\nexport class StepCounterWeb extends WebPlugin implements StepCounterPlugin {\n private steps = 0;\n private interval?: number;\n\n async start(): Promise<void> {\n this.interval = window.setInterval(() => {\n this.steps += Math.floor(Math.random() * 3);\n this.notifyListeners('step', { steps: this.steps });\n }, 2000);\n }\n\n async stop(): Promise<void> {\n if (this.interval) {\n clearInterval(this.interval);\n this.interval = undefined;\n }\n }\n\n async getCurrentSteps(): Promise<StepCounterData> {\n return { steps: this.steps };\n }\n}\n"]}
@@ -0,0 +1,37 @@
1
+ 'use strict';
2
+
3
+ var core = require('@capacitor/core');
4
+
5
+ const StepCounter = core.registerPlugin('StepCounter', {
6
+ web: () => Promise.resolve().then(function () { return web; }).then((m) => new m.StepCounterWeb()),
7
+ });
8
+
9
+ class StepCounterWeb extends core.WebPlugin {
10
+ constructor() {
11
+ super(...arguments);
12
+ this.steps = 0;
13
+ }
14
+ async start() {
15
+ this.interval = window.setInterval(() => {
16
+ this.steps += Math.floor(Math.random() * 3);
17
+ this.notifyListeners('step', { steps: this.steps });
18
+ }, 2000);
19
+ }
20
+ async stop() {
21
+ if (this.interval) {
22
+ clearInterval(this.interval);
23
+ this.interval = undefined;
24
+ }
25
+ }
26
+ async getCurrentSteps() {
27
+ return { steps: this.steps };
28
+ }
29
+ }
30
+
31
+ var web = /*#__PURE__*/Object.freeze({
32
+ __proto__: null,
33
+ StepCounterWeb: StepCounterWeb
34
+ });
35
+
36
+ exports.StepCounter = StepCounter;
37
+ //# 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 StepCounter = registerPlugin('StepCounter', {\n web: () => import('./web').then((m) => new m.StepCounterWeb()),\n});\nexport * from './definitions';\nexport { StepCounter };\n//# sourceMappingURL=index.js.map","import { WebPlugin } from '@capacitor/core';\nexport class StepCounterWeb extends WebPlugin {\n constructor() {\n super(...arguments);\n this.steps = 0;\n }\n async start() {\n this.interval = window.setInterval(() => {\n this.steps += Math.floor(Math.random() * 3);\n this.notifyListeners('step', { steps: this.steps });\n }, 2000);\n }\n async stop() {\n if (this.interval) {\n clearInterval(this.interval);\n this.interval = undefined;\n }\n }\n async getCurrentSteps() {\n return { steps: this.steps };\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["registerPlugin","WebPlugin"],"mappings":";;;;AACK,MAAC,WAAW,GAAGA,mBAAc,CAAC,aAAa,EAAE;AAClD,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,cAAc,EAAE,CAAC;AAClE,CAAC;;ACFM,MAAM,cAAc,SAASC,cAAS,CAAC;AAC9C,IAAI,WAAW,GAAG;AAClB,QAAQ,KAAK,CAAC,GAAG,SAAS,CAAC;AAC3B,QAAQ,IAAI,CAAC,KAAK,GAAG,CAAC;AACtB,IAAI;AACJ,IAAI,MAAM,KAAK,GAAG;AAClB,QAAQ,IAAI,CAAC,QAAQ,GAAG,MAAM,CAAC,WAAW,CAAC,MAAM;AACjD,YAAY,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;AACvD,YAAY,IAAI,CAAC,eAAe,CAAC,MAAM,EAAE,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,CAAC;AAC/D,QAAQ,CAAC,EAAE,IAAI,CAAC;AAChB,IAAI;AACJ,IAAI,MAAM,IAAI,GAAG;AACjB,QAAQ,IAAI,IAAI,CAAC,QAAQ,EAAE;AAC3B,YAAY,aAAa,CAAC,IAAI,CAAC,QAAQ,CAAC;AACxC,YAAY,IAAI,CAAC,QAAQ,GAAG,SAAS;AACrC,QAAQ;AACR,IAAI;AACJ,IAAI,MAAM,eAAe,GAAG;AAC5B,QAAQ,OAAO,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE;AACpC,IAAI;AACJ;;;;;;;;;"}
package/dist/plugin.js ADDED
@@ -0,0 +1,40 @@
1
+ var capacitorStepCounter = (function (exports, core) {
2
+ 'use strict';
3
+
4
+ const StepCounter = core.registerPlugin('StepCounter', {
5
+ web: () => Promise.resolve().then(function () { return web; }).then((m) => new m.StepCounterWeb()),
6
+ });
7
+
8
+ class StepCounterWeb extends core.WebPlugin {
9
+ constructor() {
10
+ super(...arguments);
11
+ this.steps = 0;
12
+ }
13
+ async start() {
14
+ this.interval = window.setInterval(() => {
15
+ this.steps += Math.floor(Math.random() * 3);
16
+ this.notifyListeners('step', { steps: this.steps });
17
+ }, 2000);
18
+ }
19
+ async stop() {
20
+ if (this.interval) {
21
+ clearInterval(this.interval);
22
+ this.interval = undefined;
23
+ }
24
+ }
25
+ async getCurrentSteps() {
26
+ return { steps: this.steps };
27
+ }
28
+ }
29
+
30
+ var web = /*#__PURE__*/Object.freeze({
31
+ __proto__: null,
32
+ StepCounterWeb: StepCounterWeb
33
+ });
34
+
35
+ exports.StepCounter = StepCounter;
36
+
37
+ return exports;
38
+
39
+ })({}, capacitorExports);
40
+ //# 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 StepCounter = registerPlugin('StepCounter', {\n web: () => import('./web').then((m) => new m.StepCounterWeb()),\n});\nexport * from './definitions';\nexport { StepCounter };\n//# sourceMappingURL=index.js.map","import { WebPlugin } from '@capacitor/core';\nexport class StepCounterWeb extends WebPlugin {\n constructor() {\n super(...arguments);\n this.steps = 0;\n }\n async start() {\n this.interval = window.setInterval(() => {\n this.steps += Math.floor(Math.random() * 3);\n this.notifyListeners('step', { steps: this.steps });\n }, 2000);\n }\n async stop() {\n if (this.interval) {\n clearInterval(this.interval);\n this.interval = undefined;\n }\n }\n async getCurrentSteps() {\n return { steps: this.steps };\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["registerPlugin","WebPlugin"],"mappings":";;;AACK,UAAC,WAAW,GAAGA,mBAAc,CAAC,aAAa,EAAE;IAClD,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,cAAc,EAAE,CAAC;IAClE,CAAC;;ICFM,MAAM,cAAc,SAASC,cAAS,CAAC;IAC9C,IAAI,WAAW,GAAG;IAClB,QAAQ,KAAK,CAAC,GAAG,SAAS,CAAC;IAC3B,QAAQ,IAAI,CAAC,KAAK,GAAG,CAAC;IACtB,IAAI;IACJ,IAAI,MAAM,KAAK,GAAG;IAClB,QAAQ,IAAI,CAAC,QAAQ,GAAG,MAAM,CAAC,WAAW,CAAC,MAAM;IACjD,YAAY,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IACvD,YAAY,IAAI,CAAC,eAAe,CAAC,MAAM,EAAE,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,CAAC;IAC/D,QAAQ,CAAC,EAAE,IAAI,CAAC;IAChB,IAAI;IACJ,IAAI,MAAM,IAAI,GAAG;IACjB,QAAQ,IAAI,IAAI,CAAC,QAAQ,EAAE;IAC3B,YAAY,aAAa,CAAC,IAAI,CAAC,QAAQ,CAAC;IACxC,YAAY,IAAI,CAAC,QAAQ,GAAG,SAAS;IACrC,QAAQ;IACR,IAAI;IACJ,IAAI,MAAM,eAAe,GAAG;IAC5B,QAAQ,OAAO,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE;IACpC,IAAI;IACJ;;;;;;;;;;;;;;;"}
@@ -0,0 +1,8 @@
1
+ import Foundation
2
+
3
+ @objc public class StepCounter: NSObject {
4
+ @objc public func echo(_ value: String) -> String {
5
+ print(value)
6
+ return value
7
+ }
8
+ }
@@ -0,0 +1,23 @@
1
+ import Foundation
2
+ import Capacitor
3
+
4
+ /**
5
+ * Please read the Capacitor iOS Plugin Development Guide
6
+ * here: https://capacitorjs.com/docs/plugins/ios
7
+ */
8
+ @objc(StepCounterPlugin)
9
+ public class StepCounterPlugin: CAPPlugin, CAPBridgedPlugin {
10
+ public let identifier = "StepCounterPlugin"
11
+ public let jsName = "StepCounter"
12
+ public let pluginMethods: [CAPPluginMethod] = [
13
+ CAPPluginMethod(name: "echo", returnType: CAPPluginReturnPromise)
14
+ ]
15
+ private let implementation = StepCounter()
16
+
17
+ @objc func echo(_ call: CAPPluginCall) {
18
+ let value = call.getString("value") ?? ""
19
+ call.resolve([
20
+ "value": implementation.echo(value)
21
+ ])
22
+ }
23
+ }
@@ -0,0 +1,15 @@
1
+ import XCTest
2
+ @testable import StepCounterPlugin
3
+
4
+ class StepCounterTests: 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 = StepCounter()
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,86 @@
1
+ {
2
+ "name": "@dreiver1/capacitor-step-counter",
3
+ "version": "0.0.1",
4
+ "description": "A Capacitor plugin that provides access to the device step counter sensor on Android and iOS, with a web fallback.",
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
+ "StepCounter.podspec",
17
+ "README.md",
18
+ "LICENSE"
19
+ ],
20
+ "author": "David Nascimento",
21
+ "license": "MIT",
22
+ "repository": {
23
+ "type": "git",
24
+ "url": "git+https://github.com/dreiver1/capacitor-step-counter.git"
25
+ },
26
+ "bugs": {
27
+ "url": "https://github.com/dreiver1/capacitor-step-counter/issues"
28
+ },
29
+ "keywords": [
30
+ "capacitor",
31
+ "capacitor-plugin",
32
+ "step-counter",
33
+ "pedometer",
34
+ "fitness",
35
+ "android",
36
+ "ios"
37
+ ],
38
+ "scripts": {
39
+ "verify": "npm run verify:ios && npm run verify:android && npm run verify:web",
40
+ "verify:ios": "xcodebuild -scheme StepCounter -destination generic/platform=iOS",
41
+ "verify:android": "cd android && ./gradlew clean build test && cd ..",
42
+ "verify:web": "npm run build",
43
+ "lint": "npm run eslint && npm run prettier -- --check && npm run swiftlint -- lint",
44
+ "fmt": "npm run eslint -- --fix && npm run prettier -- --write && npm run swiftlint -- --fix --format",
45
+ "eslint": "eslint . --ext ts",
46
+ "prettier": "prettier \"**/*.{css,html,ts,js,java}\" --plugin=prettier-plugin-java",
47
+ "swiftlint": "node-swiftlint",
48
+ "docgen": "docgen --api StepCounterPlugin --output-readme README.md --output-json dist/docs.json",
49
+ "build": "npm run clean && npm run docgen && tsc && rollup -c rollup.config.mjs",
50
+ "clean": "rimraf ./dist",
51
+ "watch": "tsc --watch",
52
+ "prepublishOnly": "npm run build"
53
+ },
54
+ "devDependencies": {
55
+ "@capacitor/android": "^8.0.0",
56
+ "@capacitor/core": "^8.0.0",
57
+ "@capacitor/docgen": "^0.3.1",
58
+ "@capacitor/ios": "^8.0.0",
59
+ "@ionic/eslint-config": "^0.4.0",
60
+ "@ionic/prettier-config": "^4.0.0",
61
+ "@ionic/swiftlint-config": "^2.0.0",
62
+ "eslint": "^8.57.1",
63
+ "prettier": "^3.6.2",
64
+ "prettier-plugin-java": "^2.7.7",
65
+ "rimraf": "^6.1.0",
66
+ "rollup": "^4.53.2",
67
+ "swiftlint": "^2.0.0",
68
+ "typescript": "^5.9.3"
69
+ },
70
+ "peerDependencies": {
71
+ "@capacitor/core": ">=8.0.0"
72
+ },
73
+ "prettier": "@ionic/prettier-config",
74
+ "swiftlint": "@ionic/swiftlint-config",
75
+ "eslintConfig": {
76
+ "extends": "@ionic/eslint-config/recommended"
77
+ },
78
+ "capacitor": {
79
+ "ios": {
80
+ "src": "ios"
81
+ },
82
+ "android": {
83
+ "src": "android"
84
+ }
85
+ }
86
+ }