Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Monorepo of all my Capacitor plugins.
| [`@danyalwe/capacitor-battery`](packages/battery) | [![npm](https://img.shields.io/npm/v/@danyalwe/capacitor-battery)](https://www.npmjs.com/package/@danyalwe/capacitor-battery) | Capacitor plugin for battery monitoring |
| [`@danyalwe/capacitor-sensors`](packages/sensors) | [![npm](https://img.shields.io/npm/v/@danyalwe/capacitor-sensors)](https://www.npmjs.com/package/@danyalwe/capacitor-sensors) | Capacitor plugin for device sensors |
| [`@danyalwe/capacitor-systeminfo`](packages/systeminfo) | [![npm](https://img.shields.io/npm/v/@danyalwe/capacitor-systeminfo)](https://www.npmjs.com/package/@danyalwe/capacitor-systeminfo) | Capacitor plugin for device system information |
| [`@danyalwe/capacitor-connection`](packages/connection) | [![npm](https://img.shields.io/npm/v/@danyalwe/capacitor-connection)](https://www.npmjs.com/package/@danyalwe/capacitor-connection) | Capacitor plugin for network connection monitoring |

## Development

Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
"docs:preview": "bun run --cwd docs preview",
"release:battery": "bun run --cwd packages/battery release",
"release:sensors": "bun run --cwd packages/sensors release",
"release:systeminfo": "bun run --cwd packages/systeminfo release"
"release:systeminfo": "bun run --cwd packages/systeminfo release",
"release:connection": "bun run --cwd packages/connection release"
},
"devDependencies": {
"@antfu/eslint-config": "^9.1.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ import com.getcapacitor.JSObject
import java.util.Timer
import java.util.TimerTask
import kotlin.math.abs
import kotlin.math.max


class Battery(
private val plugin: BatteryPlugin,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.danyalwe.capacitor.battery

import android.content.Intent
import android.util.Log
import com.getcapacitor.JSObject
import com.getcapacitor.Plugin
import com.getcapacitor.PluginCall
Expand All @@ -27,11 +27,13 @@ class BatteryPlugin : Plugin() {

@PluginMethod
fun start(call: PluginCall) {
Log.d("Start", "Battery Plugin")
implementation.start()
}

@PluginMethod
fun stop(call: PluginCall) {
implementation.stop()
Log.d("Stop", "Battery Plugin")
}
}
3 changes: 3 additions & 0 deletions packages/connection/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
build
dist
example-app
70 changes: 70 additions & 0 deletions packages/connection/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# node files
dist
node_modules

# iOS files
Pods
Podfile.lock
Package.resolved
Build
xcuserdata
/.build
/Packages
xcuserdata/
DerivedData/
.swiftpm/configuration/registries.json
.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata
.netrc


# macOS files
.DS_Store



# Based on Android gitignore template: https://github.com/github/gitignore/blob/HEAD/Android.gitignore

# Built application files
*.apk
*.ap_

# Files for the ART/Dalvik VM
*.dex

# Java class files
*.class

# Generated files
bin
gen
out

# Gradle files
.gradle
build

# Local configuration file (sdk path, etc)
local.properties

# Proguard folder generated by Eclipse
proguard

# Log Files
*.log

# Android Studio Navigation editor temp files
.navigation

# Android Studio captures folder
captures

# IntelliJ
*.iml
.idea

# Keystore files
# Uncomment the following line if you do not want to check your keystore files in.
#*.jks

# External native build folder generated in Android Studio 2.2 and later
.externalNativeBuild
1 change: 1 addition & 0 deletions packages/connection/.prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
example-app
13 changes: 13 additions & 0 deletions packages/connection/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Changelog

All notable changes to this project will be documented in this file. See [commit-and-tag-version](https://github.com/absolute-version/commit-and-tag-version) for commit guidelines.

## 1.0.0 (2026-07-09)

### ⚠ BREAKING CHANGES

* upgraded to Capacitor v8 (peer dependency bumped to `@capacitor/core >=8.0.0`)

### Code Refactoring

* migrated to a Bun workspace monorepo (build, lint, and test now run from the repo root via tsdown, ESLint flat config, and vitest)
54 changes: 54 additions & 0 deletions packages/connection/CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# Contributing

This guide provides instructions for contributing to this Capacitor plugin.

## Developing

### Local Setup

1. Fork and clone the repo.
1. Install the dependencies from the **repo root** (this plugin is part of a Bun workspace monorepo).

```shell
bun install
```

1. Install SwiftLint if you're on macOS.

```shell
brew install swiftlint
```

### Scripts

#### `bun run build` (repo root)

Building web assets happens once for all plugins from the **monorepo root**, not per-plugin. From the repo root, run:

```shell
bun run build
```

This compiles the TypeScript code from each plugin's `src/` using [tsdown](https://tsdown.dev) in workspace mode, producing ESM (`dist/index.mjs`), CJS (`dist/index.cjs`), and type declarations (`dist/index.d.mts` / `dist/index.d.cts`).

To generate plugin API documentation, run `bun run docgen` from the repo root (uses [`@capacitor/docgen`](https://github.com/ionic-team/capacitor-docgen)).

#### `bun run verify`

Validate the native iOS and Android projects build correctly. Web build/lint/test is handled by the root CI, not this script.

#### `bun run lint` / `bun run fmt`

Check formatting and code quality for this plugin, autoformat/autofix if possible.

This checks Prettier and SwiftLint. Linting of TypeScript code (ESLint) is handled at the monorepo root via `bun run lint`.

## Publishing

Publishing is automated via GitHub Actions and is not done manually with `npm publish`.

1. From the repo root, run this plugin's release script (e.g. `bun run release:sensors`), which uses `commit-and-tag-version` to bump the version, update `CHANGELOG.md`, and create a git tag.
1. Push the tag: `git push --follow-tags`.
1. Pushing a tag matching `capacitor-*@*` triggers the `release.yml` GitHub Actions workflow, which builds from the repo root and publishes this plugin to npm via [trusted publishing](https://docs.npmjs.com/trusted-publishers) (OIDC) — no npm token or manual `npm publish` needed.

> **Note**: The [`files`](https://docs.npmjs.com/cli/v7/configuring-npm/package-json#files) array in `package.json` specifies which files get published. If you rename files/directories or add files elsewhere, you may need to update it.
17 changes: 17 additions & 0 deletions packages/connection/Connection.podspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
require 'json'

package = JSON.parse(File.read(File.join(__dir__, 'package.json')))

Pod::Spec.new do |s|
s.name = 'Battery'
s.version = package['version']
s.summary = package['description']
s.license = package['license']
s.homepage = package['repository']['url']
s.author = package['author']
s.source = { :git => package['repository']['url'], :tag => s.version.to_s }
s.source_files = 'ios/Sources/**/*.{swift,h,m,c,cc,mm,cpp}'
s.ios.deployment_target = '15.0'
s.dependency 'Capacitor'
s.swift_version = '5.1'
end
28 changes: 28 additions & 0 deletions packages/connection/Package.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// swift-tools-version: 5.9
import PackageDescription

let package = Package(
name: "Connection",
platforms: [.iOS(.v15)],
products: [
.library(
name: "Connection",
targets: ["ConnectionPlugin"])
],
dependencies: [
.package(url: "https://github.com/ionic-team/capacitor-swift-pm.git", from: "8.0.0")
],
targets: [
.target(
name: "ConnectionPlugin",
dependencies: [
.product(name: "Capacitor", package: "capacitor-swift-pm"),
.product(name: "Cordova", package: "capacitor-swift-pm")
],
path: "ios/Sources/ConnectionPlugin"),
.testTarget(
name: "ConnectionPluginTests",
dependencies: ["ConnectionPlugin"],
path: "ios/Tests/ConnectionPluginTests")
]
)
123 changes: 123 additions & 0 deletions packages/connection/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
# Capacitor Plugin - Battery

Get access to every info about the device battery!

Supported Android version: `24+`\
Supported iOS version: `Not supported`\
Supported Browsers: `Chromium-based`

## Install

```bash
npm install @danyalwe/capacitor-battery
npx cap sync
```

## Todos

- [ ] Add support for iOS

## Supported methods

| Name | Android | iOS | Web |
| :----------------- | :------ | :-- | :-- |
| start | ✅ | ❌ | ✅ |
| stop | ✅ | ❌ | ✅ |
| addListener | ✅ | ❌ | ✅ |
| removeAllListeners | ✅ | ❌ | ✅ |

## Supported properties

| Property | Android | iOS | Web |
| :-------------------- | :------ | :-- | :-- |
| **`currentCapacity`** | ✅ | ❌ | ❌ |
| **`totalCapacity`** | ✅ | ❌ | ❌ |
| **`realPercentage`** | ✅ | ❌ | ❌ |
| **`technology`** | ✅ | ❌ | ❌ |
| **`temperature`** | ✅ | ❌ | ❌ |
| **`voltage`** | ✅ | ❌ | ❌ |
| **`amperage`** | ✅ | ❌ | ❌ |
| **`wattage`** | ✅ | ❌ | ❌ |
| **`health`** | ✅ | ❌ | ❌ |
| **`status`** | ✅ | ❌ | ❌ |
| **`chargeMode`** | ✅ | ❌ | ❌ |
| **`level`** | ✅ | ❌ | ✅ |
| **`hasBattery`** | ✅ | ❌ | ✅ |
| **`isCharging`** | ✅ | ❌ | ✅ |
| **`chargingTime`** | ❌ | ❌ | ✅ |
| **`dischargingTime`** | ❌ | ❌ | ✅ |

## API

<docgen-index>

* [Interfaces](#interfaces)
* [Type Aliases](#type-aliases)

</docgen-index>

<docgen-api>
<!--Update the source file JSDoc comments and rerun docgen to update the docs below-->

Represents the BatteryPlugin interface.

### Interfaces


#### BatteryInfo

Represents the battery information of the device.

| Prop | Type | Description |
| ------------------- | -------------------- | ---------------------------------------- |
| **`totalCapacity`** | <code>number</code> | The total battery capacity (in mAh). |
| **`technology`** | <code>string</code> | The technology used in the battery. |
| **`hasBattery`** | <code>boolean</code> | Whether the device has a battery or not. |


#### BatteryData

Represents the battery data that can change over time.

| Prop | Type | Description |
| --------------------- | --------------------------------------------------------------- | -------------------------------------------------------------------------------- |
| **`level`** | <code>number</code> | The current battery level as a percentage (0-100). |
| **`isCharging`** | <code>boolean</code> | Whether the device is currently charging or not. |
| **`chargingTime`** | <code>number</code> | The estimated time remaining until the battery is fully charged (in minutes). |
| **`dischargingTime`** | <code>number</code> | The estimated time remaining until the battery is fully discharged (in minutes). |
| **`currentCapacity`** | <code>number</code> | The current battery capacity (in mAh). |
| **`realPercentage`** | <code>number</code> | The real battery percentage, which may differ from the reported percentage. |
| **`temperature`** | <code>number</code> | The current temperature of the battery (in Celsius). |
| **`voltage`** | <code>number</code> | The current voltage of the battery (in volts). |
| **`amperage`** | <code>number</code> | The current amperage of the battery (in amperes). |
| **`wattage`** | <code>number</code> | The current wattage of the battery (in watts). |
| **`health`** | <code><a href="#batteryhealth">BatteryHealth</a></code> | The health status of the battery. |
| **`status`** | <code><a href="#batterystatus">BatteryStatus</a></code> | The status of the battery. |
| **`chargeMode`** | <code><a href="#batterychargemode">BatteryChargeMode</a></code> | The charging mode of the battery. |


#### PluginListenerHandle

| Prop | Type |
| ------------ | ----------------------------------------- |
| **`remove`** | <code>() =&gt; Promise&lt;void&gt;</code> |


### Type Aliases


#### BatteryHealth

<code>(typeof BatteryHealths)[number]</code>


#### BatteryStatus

<code>(typeof BatteryStatuses)[number]</code>


#### BatteryChargeMode

<code>(typeof BatteryChargeModes)[number]</code>

</docgen-api>
1 change: 1 addition & 0 deletions packages/connection/android/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
Loading