@haykmkrtich/react-native-patriot-native 1.0.4 → 1.0.5
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/README.md
CHANGED
|
@@ -1,87 +1,106 @@
|
|
|
1
1
|
# React Native Patriot Native
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[](https://badge.fury.io/js/%40haykmkrtich%2Freact-native-patriot-native)
|
|
4
|
+
[](https://opensource.org/licenses/MIT)
|
|
5
|
+
[](https://reactnative.dev/)
|
|
4
6
|
|
|
5
|
-
|
|
7
|
+
> 🚀 Seamlessly install WearOS watch faces and retrieve device information directly from your React Native mobile application.
|
|
6
8
|
|
|
7
|
-
|
|
9
|
+
## ✨ What's New in v1.0.5
|
|
8
10
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
11
|
+
- 🔍 **Device Detection**: New `getConnectedWatchProperties()` function
|
|
12
|
+
- 📱 **Multi-Platform Support**: Detect WearOS, Fitbit, and other wearable devices
|
|
13
|
+
- 🏷️ **Device Information**: Get name, platform, type, and unique ID
|
|
14
|
+
- 🛡️ **Enhanced Error Handling**: Improved disconnection detection
|
|
12
15
|
|
|
13
|
-
|
|
16
|
+
## 🚀 Quick Start
|
|
14
17
|
|
|
15
|
-
|
|
18
|
+
```bash
|
|
19
|
+
npm install @haykmkrtich/react-native-patriot-native
|
|
20
|
+
```
|
|
16
21
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
- Promise-based API for easy integration
|
|
20
|
-
- Native Toast notifications for user feedback
|
|
22
|
+
```typescript
|
|
23
|
+
import { installWatchface, getConnectedWatchProperties } from '@haykmkrtich/react-native-patriot-native';
|
|
21
24
|
|
|
22
|
-
|
|
25
|
+
// Install watchface
|
|
26
|
+
await installWatchface('com.example.watchface.package');
|
|
23
27
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
yarn add @haykmkrtich/react-native-patriot-native
|
|
28
|
+
// Get device info
|
|
29
|
+
const watch = await getConnectedWatchProperties();
|
|
30
|
+
console.log(`Connected: ${watch.displayName} (${watch.platform})`);
|
|
28
31
|
```
|
|
29
32
|
|
|
30
|
-
## Requirements
|
|
33
|
+
## 📋 Requirements
|
|
31
34
|
|
|
32
|
-
- React Native
|
|
33
|
-
- Android API level 21+ (Android 5.0
|
|
34
|
-
- Paired WearOS device
|
|
35
|
+
- ⚛️ React Native ≥ 0.60.0
|
|
36
|
+
- 🤖 Android API level 21+ (Android 5.0+)
|
|
37
|
+
- ⌚ Paired WearOS device
|
|
35
38
|
|
|
36
|
-
##
|
|
39
|
+
## 🎯 Features
|
|
37
40
|
|
|
38
|
-
|
|
39
|
-
|
|
41
|
+
| Feature | Description |
|
|
42
|
+
|---------|-------------|
|
|
43
|
+
| 📦 **Watch Face Installation** | Install watch faces directly on paired WearOS devices |
|
|
44
|
+
| 🔍 **Device Detection** | Retrieve detailed information about connected devices |
|
|
45
|
+
| 🏷️ **Platform Detection** | Identify WearOS, Fitbit, and other wearable platforms |
|
|
46
|
+
| 📡 **Connection Status** | Monitor device connectivity and proximity |
|
|
47
|
+
| 🔄 **Promise-based API** | Modern async/await support |
|
|
48
|
+
| 💬 **Native Feedback** | Toast notifications for user feedback |
|
|
49
|
+
|
|
50
|
+
## 📖 API Reference
|
|
40
51
|
|
|
41
|
-
|
|
52
|
+
### `installWatchface(packageName: string)`
|
|
53
|
+
|
|
54
|
+
Initiates watch face installation on connected WearOS device.
|
|
55
|
+
|
|
56
|
+
```typescript
|
|
42
57
|
try {
|
|
43
58
|
await installWatchface('com.example.watchface.package');
|
|
44
|
-
//
|
|
59
|
+
// ✅ Installation initiated successfully
|
|
45
60
|
} catch (error) {
|
|
46
|
-
// Handle
|
|
47
|
-
console.error(error);
|
|
61
|
+
// ❌ Handle installation errors
|
|
48
62
|
}
|
|
49
63
|
```
|
|
50
64
|
|
|
51
|
-
|
|
65
|
+
**Errors:**
|
|
66
|
+
- `NO_NODES` - No connected WearOS device
|
|
67
|
+
- `INSTALL_FAILED` - Installation process failed
|
|
52
68
|
|
|
53
|
-
### `
|
|
69
|
+
### `getConnectedWatchProperties()`
|
|
54
70
|
|
|
55
|
-
|
|
71
|
+
Retrieves detailed information about connected wearable devices.
|
|
56
72
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
#### Error Codes
|
|
69
|
-
|
|
70
|
-
- `NO_NODES`: No connected WearOS device found
|
|
71
|
-
- `INSTALL_FAILED`: Installation process failed
|
|
73
|
+
```typescript
|
|
74
|
+
interface WatchProperties {
|
|
75
|
+
id: string; // Unique device identifier
|
|
76
|
+
displayName: string; // Human-readable device name
|
|
77
|
+
isNearby: boolean; // Device proximity status
|
|
78
|
+
type: string; // Device type (e.g., "watch")
|
|
79
|
+
platform: string; // Platform ("wearOS" | "fitbit")
|
|
80
|
+
isDisconnected?: boolean; // No device connected
|
|
81
|
+
}
|
|
82
|
+
```
|
|
72
83
|
|
|
73
|
-
|
|
84
|
+
**Example Response:**
|
|
85
|
+
```typescript
|
|
86
|
+
// ✅ Connected Device
|
|
87
|
+
{
|
|
88
|
+
id: "node_12345_abcdef",
|
|
89
|
+
displayName: "Galaxy Watch 4",
|
|
90
|
+
isNearby: true,
|
|
91
|
+
type: "watch",
|
|
92
|
+
platform: "wearOS"
|
|
93
|
+
}
|
|
74
94
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
3. Open the Google Play Store page for the specified watch face package
|
|
95
|
+
// ❌ No Device
|
|
96
|
+
{ isDisconnected: true }
|
|
97
|
+
```
|
|
79
98
|
|
|
80
|
-
|
|
99
|
+
## 🔧 Setup Requirements
|
|
81
100
|
|
|
82
|
-
|
|
101
|
+
### Android Dependencies
|
|
83
102
|
|
|
84
|
-
Add
|
|
103
|
+
Add to your `android/app/build.gradle`:
|
|
85
104
|
|
|
86
105
|
```gradle
|
|
87
106
|
dependencies {
|
|
@@ -90,18 +109,96 @@ dependencies {
|
|
|
90
109
|
}
|
|
91
110
|
```
|
|
92
111
|
|
|
93
|
-
|
|
112
|
+
### WearOS Development Best Practices
|
|
113
|
+
|
|
114
|
+
> ⚠️ **Important**: For Google Play Console compliance, create **two applications** with identical package names:
|
|
115
|
+
> - 📱 Mobile companion app (React Native)
|
|
116
|
+
> - ⌚ WearOS watch face app
|
|
117
|
+
|
|
118
|
+
This ensures proper functionality and distribution through Google Play Store.
|
|
119
|
+
|
|
120
|
+
## 🛠️ How It Works
|
|
121
|
+
|
|
122
|
+
```mermaid
|
|
123
|
+
graph LR
|
|
124
|
+
A[Mobile App] --> B[WearOS Remote API]
|
|
125
|
+
B --> C[Connected Watch]
|
|
126
|
+
C --> D[Google Play Store]
|
|
127
|
+
D --> E[Watch Face Installation]
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
1. **Device Discovery** - Scan for connected WearOS devices
|
|
131
|
+
2. **Remote Installation** - Send installation request to watch
|
|
132
|
+
3. **Play Store Integration** - Open watch face listing on device
|
|
133
|
+
4. **User Confirmation** - User confirms installation on watch
|
|
134
|
+
|
|
135
|
+
## 💡 Usage Examples
|
|
136
|
+
|
|
137
|
+
### Basic Installation
|
|
138
|
+
```typescript
|
|
139
|
+
import { installWatchface } from '@haykmkrtich/react-native-patriot-native';
|
|
140
|
+
|
|
141
|
+
const handleInstall = async (packageName: string) => {
|
|
142
|
+
try {
|
|
143
|
+
await installWatchface(packageName);
|
|
144
|
+
console.log('✅ Check your watch for installation prompt');
|
|
145
|
+
} catch (error) {
|
|
146
|
+
console.error('❌ Installation failed:', error.message);
|
|
147
|
+
}
|
|
148
|
+
};
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
### Device Information
|
|
152
|
+
```typescript
|
|
153
|
+
import { getConnectedWatchProperties } from '@haykmkrtich/react-native-patriot-native';
|
|
154
|
+
|
|
155
|
+
const checkWatchStatus = async () => {
|
|
156
|
+
try {
|
|
157
|
+
const watch = await getConnectedWatchProperties();
|
|
158
|
+
|
|
159
|
+
if (watch.isDisconnected) {
|
|
160
|
+
return '❌ No watch connected';
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
return `✅ ${watch.displayName} (${watch.platform}) - ${watch.isNearby ? 'Nearby' : 'Away'}`;
|
|
164
|
+
} catch (error) {
|
|
165
|
+
return `❌ Detection failed: ${error.message}`;
|
|
166
|
+
}
|
|
167
|
+
};
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
## 🤝 Contributing
|
|
171
|
+
|
|
172
|
+
Contributions are welcome! Please read our [contributing guidelines](CONTRIBUTING.md) before submitting PRs.
|
|
173
|
+
|
|
174
|
+
1. Fork the repository
|
|
175
|
+
2. Create your feature branch (`git checkout -b feature/amazing-feature`)
|
|
176
|
+
3. Commit your changes (`git commit -m 'Add amazing feature'`)
|
|
177
|
+
4. Push to the branch (`git push origin feature/amazing-feature`)
|
|
178
|
+
5. Open a Pull Request
|
|
179
|
+
|
|
180
|
+
## 📄 License
|
|
181
|
+
|
|
182
|
+
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
|
|
183
|
+
|
|
184
|
+
## 👨💻 Author
|
|
185
|
+
|
|
186
|
+
**Hayk Mkrtich**
|
|
187
|
+
- GitHub: [@HaykMkrtich](https://github.com/HaykMkrtich)
|
|
188
|
+
- NPM: [@haykmkrtich](https://www.npmjs.com/~haykmkrtich)
|
|
94
189
|
|
|
95
|
-
|
|
190
|
+
## 🆘 Support
|
|
96
191
|
|
|
97
|
-
|
|
192
|
+
- 🐛 **Bug Reports**: [Create an issue](https://github.com/HaykMkrtich/react-native-patriot-native/issues/new?template=bug_report.md)
|
|
193
|
+
- 💡 **Feature Requests**: [Request a feature](https://github.com/HaykMkrtich/react-native-patriot-native/issues/new?template=feature_request.md)
|
|
194
|
+
- 📖 **Documentation**: [View full docs](https://github.com/HaykMkrtich/react-native-patriot-native/wiki)
|
|
98
195
|
|
|
99
|
-
|
|
196
|
+
---
|
|
100
197
|
|
|
101
|
-
|
|
198
|
+
<div align="center">
|
|
102
199
|
|
|
103
|
-
|
|
200
|
+
**⭐ Star this repository if it helped you!**
|
|
104
201
|
|
|
105
|
-
|
|
202
|
+
Made with ❤️ for the React Native community
|
|
106
203
|
|
|
107
|
-
|
|
204
|
+
</div>
|
|
@@ -22,6 +22,8 @@ import com.google.android.gms.wearable.Wearable;
|
|
|
22
22
|
|
|
23
23
|
import java.util.List;
|
|
24
24
|
import java.util.concurrent.Executors;
|
|
25
|
+
import com.facebook.react.bridge.WritableMap;
|
|
26
|
+
import com.facebook.react.bridge.Arguments;
|
|
25
27
|
|
|
26
28
|
public class PatriotNativeModule extends ReactContextBaseJavaModule {
|
|
27
29
|
private final ReactApplicationContext reactContext;
|
|
@@ -67,6 +69,46 @@ public class PatriotNativeModule extends ReactContextBaseJavaModule {
|
|
|
67
69
|
}).start();
|
|
68
70
|
}
|
|
69
71
|
|
|
72
|
+
@ReactMethod
|
|
73
|
+
public void getConnectedWatchProperties(Promise promise) {
|
|
74
|
+
Executors.newSingleThreadExecutor().execute(() -> {
|
|
75
|
+
try {
|
|
76
|
+
List<Node> nodes = Tasks.await(Wearable.getNodeClient(reactContext).getConnectedNodes());
|
|
77
|
+
if (nodes == null || nodes.isEmpty()) {
|
|
78
|
+
WritableMap result = Arguments.createMap();
|
|
79
|
+
result.putBoolean("isDisconnected", true);
|
|
80
|
+
promise.resolve(result);
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
for (Node node : nodes) {
|
|
85
|
+
String displayName = node.getDisplayName().toLowerCase();
|
|
86
|
+
|
|
87
|
+
// Простой фильтр: часы по ключевым словам
|
|
88
|
+
if (displayName.contains("watch") || displayName.contains("fitbit") || displayName.contains("wear")) {
|
|
89
|
+
WritableMap map = Arguments.createMap();
|
|
90
|
+
map.putString("id", node.getId());
|
|
91
|
+
map.putString("displayName", node.getDisplayName());
|
|
92
|
+
map.putBoolean("isNearby", node.isNearby());
|
|
93
|
+
map.putString("type", "watch");
|
|
94
|
+
map.putString("platform", displayName.contains("fitbit") ? "fitbit" : "wearOS");
|
|
95
|
+
|
|
96
|
+
promise.resolve(map);
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// Если ни одно устройство не подошло
|
|
102
|
+
WritableMap result = Arguments.createMap();
|
|
103
|
+
result.putBoolean("isDisconnected", true);
|
|
104
|
+
promise.resolve(result);
|
|
105
|
+
} catch (Exception e) {
|
|
106
|
+
promise.reject("WATCH_DETECTION_FAILED", e.getMessage());
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
|
|
70
112
|
private void showToast(String msg) {
|
|
71
113
|
new Handler(Looper.getMainLooper()).post(() ->
|
|
72
114
|
Toast.makeText(reactContext, msg, Toast.LENGTH_SHORT).show());
|
package/index.ts
CHANGED
|
@@ -3,10 +3,14 @@ import { NativeModules } from 'react-native';
|
|
|
3
3
|
|
|
4
4
|
type PatriotNativeType = {
|
|
5
5
|
installWatchface(packageName: string): Promise<void>;
|
|
6
|
+
getConnectedWatchProperties(): Promise<{ id: string; displayName: string; isNearby: boolean; type: string; platform: string }>;
|
|
6
7
|
};
|
|
7
8
|
|
|
8
9
|
const { PatriotNative } = NativeModules as { PatriotNative: PatriotNativeType };
|
|
9
10
|
|
|
10
|
-
|
|
11
|
-
|
|
11
|
+
if (!PatriotNative) {
|
|
12
|
+
throw new Error('PatriotNative module is not linked properly.');
|
|
12
13
|
}
|
|
14
|
+
|
|
15
|
+
export const installWatchface = PatriotNative.installWatchface;
|
|
16
|
+
export const getConnectedWatchProperties = PatriotNative.getConnectedWatchProperties;
|