@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
- A React Native module that enables seamless installation of WearOS watch faces directly from your React Native mobile application.
3
+ [![npm version](https://badge.fury.io/js/%40haykmkrtich%2Freact-native-patriot-native.svg)](https://badge.fury.io/js/%40haykmkrtich%2Freact-native-patriot-native)
4
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
5
+ [![Platform](https://img.shields.io/badge/platform-react--native-lightgrey)](https://reactnative.dev/)
4
6
 
5
- ## Important Note for WearOS Development
7
+ > 🚀 Seamlessly install WearOS watch faces and retrieve device information directly from your React Native mobile application.
6
8
 
7
- This module is specifically designed for WearOS watch face companion apps. When developing a complete wearable product, it's crucial to follow the Google Play Console best practices:
9
+ ## What's New in v1.0.5
8
10
 
9
- 1. Create two applications with **identical package names**:
10
- - One for the mobile companion app (using this React Native module)
11
- - One for the WearOS watch face itself
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
- This package name consistency is required for proper functionality and distribution through the Google Play Store.
16
+ ## 🚀 Quick Start
14
17
 
15
- ## Features
18
+ ```bash
19
+ npm install @haykmkrtich/react-native-patriot-native
20
+ ```
16
21
 
17
- - Install watch faces on paired WearOS devices
18
- - Handle connection status with WearOS devices
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
- ## Installation
25
+ // Install watchface
26
+ await installWatchface('com.example.watchface.package');
23
27
 
24
- ```bash
25
- npm install @haykmkrtich/react-native-patriot-native
26
- # or
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 >= 0.60.0
33
- - Android API level 21+ (Android 5.0 or later)
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
- ## Usage
39
+ ## 🎯 Features
37
40
 
38
- ```typescript
39
- import { installWatchface } from '@haykmkrtich/react-native-patriot-native';
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
- // Example: Installing a watch face
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
- // Watch face installation initiated on the connected WearOS device
59
+ // Installation initiated successfully
45
60
  } catch (error) {
46
- // Handle errors (e.g., no connected device, installation failed)
47
- console.error(error);
61
+ // Handle installation errors
48
62
  }
49
63
  ```
50
64
 
51
- ## API Reference
65
+ **Errors:**
66
+ - `NO_NODES` - No connected WearOS device
67
+ - `INSTALL_FAILED` - Installation process failed
52
68
 
53
- ### `installWatchface(packageName: string): Promise<void>`
69
+ ### `getConnectedWatchProperties()`
54
70
 
55
- Initiates the installation of a watch face on the connected WearOS device.
71
+ Retrieves detailed information about connected wearable devices.
56
72
 
57
- #### Parameters
58
-
59
- - `packageName` (string): The package name of the watch face to install from the Google Play Store.
60
-
61
- #### Returns
62
-
63
- - Promise that resolves when the installation request is successfully sent to the watch.
64
- - Promise rejection if:
65
- - No WearOS device is connected
66
- - Installation process fails
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
- ## How It Works
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
- The module uses the WearOS Remote API to:
76
- 1. Check for connected WearOS devices
77
- 2. Send an installation request to the connected watch
78
- 3. Open the Google Play Store page for the specified watch face package
95
+ // No Device
96
+ { isDisconnected: true }
97
+ ```
79
98
 
80
- The user will receive a prompt on their WearOS device to install the watch face.
99
+ ## 🔧 Setup Requirements
81
100
 
82
- ## Requirements for Android
101
+ ### Android Dependencies
83
102
 
84
- Add the following to your app's `build.gradle`:
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
- ## Contributing
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
- Contributions are welcome! Please feel free to submit a Pull Request.
190
+ ## 🆘 Support
96
191
 
97
- ## License
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
- MIT License - see the [LICENSE](LICENSE) file for details.
196
+ ---
100
197
 
101
- ## Author
198
+ <div align="center">
102
199
 
103
- Hayk Mkrtich
200
+ **⭐ Star this repository if it helped you!**
104
201
 
105
- ## Support
202
+ Made with ❤️ for the React Native community
106
203
 
107
- For issues and feature requests, please [create an issue](https://github.com/HaykMkrtich/react-native-patriot-native/issues) on GitHub.
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
- export function installWatchface(packageName: string): Promise<void> {
11
- return PatriotNative.installWatchface(packageName);
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;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@haykmkrtich/react-native-patriot-native",
3
- "version": "1.0.4",
3
+ "version": "1.0.5",
4
4
  "main": "index.ts",
5
5
  "files": [
6
6
  "index.ts",