Skip to content

Commit 2c2265d

Browse files
committed
chore: renamed plugin class to avoid collision with the original capacitor device plugin
1 parent 3056e45 commit 2c2265d

File tree

10 files changed

+34
-42
lines changed

10 files changed

+34
-42
lines changed

README.md

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ This plugin offers the API which has been removed from @capacitor/device plugin
3939

4040
## About
4141

42-
This plugin offers the API which has been removed from `@capacitor/device` plugin in v7.0 (getInfo() no longer returns diskFree, diskTotal, realDiskFree and realDiskTotal) as some apps still require this. For more details also see https://capacitorjs.com/docs/updating/7-0#device
42+
This plugin offers the API which has been removed from `@capacitor/device` plugin in v7.0 (getInfo() no longer returns diskFree, diskTotal, realDiskFree and realDiskTotal). For more details also see https://capacitorjs.com/docs/updating/7-0#device
4343

4444
This plugin contains code derived from or inspired by [@capacitor/device](https://github.com/ionic-team/capacitor-plugins/tree/main/device) plugin.
4545
Please note that it is a community plugin, not maintained by the Capacitor team.
@@ -104,10 +104,10 @@ For detailed steps on how to do this, please see the [Capacitor Docs](https://ca
104104
## Example Plugin Usage
105105

106106
```typescript
107-
import { Device } from '@capacitor-community/device';
107+
import { CommunityDevice } from '@capacitor-community/device';
108108

109109
const logDeviceInfo = async () => {
110-
const info = await Device.getInfo();
110+
const info = await CommunityDevice.getInfo();
111111

112112
console.log(info);
113113
};
@@ -117,8 +117,8 @@ const logDeviceInfo = async () => {
117117

118118
<docgen-index>
119119

120-
* [`getInfo()`](#getinfo)
121-
* [Interfaces](#interfaces)
120+
- [`getInfo()`](#getinfo)
121+
- [Interfaces](#interfaces)
122122

123123
</docgen-index>
124124

@@ -128,22 +128,20 @@ const logDeviceInfo = async () => {
128128
### getInfo()
129129

130130
```typescript
131-
getInfo() => Promise<DeviceInfo>
131+
getInfo() => Promise<CommunityDeviceInfo>
132132
```
133133

134134
Return information about the underlying device/os/platform.
135135

136-
**Returns:** <code>Promise&lt;<a href="#deviceinfo">DeviceInfo</a>&gt;</code>
136+
**Returns:** <code>Promise&lt;<a href="#communitydeviceinfo">CommunityDeviceInfo</a>&gt;</code>
137137

138138
**Since:** 7.0.0
139139

140-
--------------------
141-
140+
---
142141

143142
### Interfaces
144143

145-
146-
#### DeviceInfo
144+
#### CommunityDeviceInfo
147145

148146
| Prop | Type | Description | Since |
149147
| ------------------- | ------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----- |

android/src/main/java/com/ryltsov/alex/plugins/device/Device.java renamed to android/src/main/java/com/ryltsov/alex/plugins/device/CommunityDevice.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
package com.ryltsov.alex.plugins.device;
22

3-
import android.content.Context;
43
import android.os.Environment;
54
import android.os.StatFs;
6-
import android.util.Log;
75

8-
public class Device {
6+
public class CommunityDevice {
97

108
public long getDiskFree() {
119
StatFs statFs = new StatFs(Environment.getRootDirectory().getAbsolutePath());

android/src/main/java/com/ryltsov/alex/plugins/device/DevicePlugin.java renamed to android/src/main/java/com/ryltsov/alex/plugins/device/CommunityDevicePlugin.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@
66
import com.getcapacitor.PluginMethod;
77
import com.getcapacitor.annotation.CapacitorPlugin;
88

9-
@CapacitorPlugin(name = "Device")
10-
public class DevicePlugin extends Plugin {
9+
@CapacitorPlugin(name = "CommunityDevice")
10+
public class CommunityDevicePlugin extends Plugin {
1111

12-
private Device implementation;
12+
private CommunityDevice implementation;
1313

1414
@Override
1515
public void load() {
16-
implementation = new Device();
16+
implementation = new CommunityDevice();
1717
}
1818

1919
@PluginMethod

example-app/src/app/home/home.page.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55
} from '@ionic/angular/standalone';
66

77
// NATIVE
8-
import { Device, DeviceInfo } from '@capacitor-community/device';
8+
import { CommunityDevice, CommunityDeviceInfo } from '@capacitor-community/device';
99

1010
@Component({
1111
selector: 'app-home',
@@ -17,13 +17,13 @@ import { Device, DeviceInfo } from '@capacitor-community/device';
1717
})
1818
export class HomePage {
1919

20-
public deviceInfo: DeviceInfo | undefined;
20+
public deviceInfo: CommunityDeviceInfo | undefined;
2121

2222
constructor() { }
2323

2424
public async showDeviceInfo(): Promise<void> {
2525
try {
26-
const info: DeviceInfo = await Device.getInfo();
26+
const info: CommunityDeviceInfo = await CommunityDevice.getInfo();
2727
console.log('info', info);
2828
this.deviceInfo = info;
2929
} catch (error) {

ios/Sources/DevicePlugin/Device.swift renamed to ios/Sources/DevicePlugin/CommunityDevice.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import Foundation
22

3-
@objc public class Device: NSObject {
3+
@objc public class CommunityDevice: NSObject {
44
/**
55
* Get free disk space
66
*/

ios/Sources/DevicePlugin/DevicePlugin.swift renamed to ios/Sources/DevicePlugin/CommunityDevicePlugin.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@ import Capacitor
55
* Please read the Capacitor iOS Plugin Development Guide
66
* here: https://capacitorjs.com/docs/plugins/ios
77
*/
8-
@objc(DevicePlugin)
9-
public class DevicePlugin: CAPPlugin, CAPBridgedPlugin {
10-
public let identifier = "DevicePlugin"
11-
public let jsName = "Device"
8+
@objc(CommunityDevicePlugin)
9+
public class CommunityDevicePlugin: CAPPlugin, CAPBridgedPlugin {
10+
public let identifier = "CommunityDevicePlugin"
11+
public let jsName = "CommunityDevice"
1212
public let pluginMethods: [CAPPluginMethod] = [
1313
CAPPluginMethod(name: "getInfo", returnType: CAPPluginReturnPromise),
1414
]
15-
private let implementation = Device()
15+
private let implementation = CommunityDevice()
1616

1717
@objc func getInfo(_ call: CAPPluginCall) {
1818

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
"eslint": "eslint . --ext ts",
4343
"prettier": "prettier \"**/*.{css,html,ts,js,java}\" --plugin=prettier-plugin-java",
4444
"swiftlint": "node-swiftlint",
45-
"docgen": "docgen --api DevicePlugin --output-readme README.md --output-json dist/docs.json",
45+
"docgen": "docgen --api CommunityDevicePlugin --output-readme README.md --output-json dist/docs.json",
4646
"build": "npm run clean && npm run docgen && tsc && rollup -c rollup.config.mjs",
4747
"clean": "rimraf ./dist",
4848
"watch": "tsc --watch",

src/definitions.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
// export interface DevicePlugin {
2-
// echo(options: { value: string }): Promise<{ value: string }>;
3-
// }
4-
5-
export interface DeviceInfo {
1+
export interface CommunityDeviceInfo {
62
/**
73
* How much free disk space is available on the normal data storage
84
* path for the os, in bytes.
@@ -42,11 +38,11 @@ export interface DeviceInfo {
4238
realDiskTotal?: number;
4339
}
4440

45-
export interface DevicePlugin {
41+
export interface CommunityDevicePlugin {
4642
/**
4743
* Return information about the underlying device/os/platform.
4844
*
4945
* @since 7.0.0
5046
*/
51-
getInfo(): Promise<DeviceInfo>;
47+
getInfo(): Promise<CommunityDeviceInfo>;
5248
}

src/index.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import { registerPlugin } from '@capacitor/core';
22

3-
import type { DevicePlugin } from './definitions';
3+
import type { CommunityDevicePlugin } from './definitions';
44

5-
const Device = registerPlugin<DevicePlugin>('Device', {
6-
web: () => import('./web').then((m) => new m.DeviceWeb()),
5+
const CommunityDevice = registerPlugin<CommunityDevicePlugin>('CommunityDevice', {
6+
web: () => import('./web').then((m) => new m.CommunityDeviceWeb()),
77
});
88

99
export * from './definitions';
10-
export { Device };
10+
export { CommunityDevice };

src/web.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { WebPlugin } from '@capacitor/core';
22

3-
import type { DeviceInfo, DevicePlugin } from './definitions';
3+
import type { CommunityDeviceInfo, CommunityDevicePlugin } from './definitions';
44

5-
export class DeviceWeb extends WebPlugin implements DevicePlugin {
6-
async getInfo(): Promise<DeviceInfo> {
5+
export class CommunityDeviceWeb extends WebPlugin implements CommunityDevicePlugin {
6+
async getInfo(): Promise<CommunityDeviceInfo> {
77
throw this.unavailable('getInfo is not supported on web');
88
}
99
}

0 commit comments

Comments
 (0)