yaver-feedback-react-native 0.3.0 → 0.5.0
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/LICENSE +201 -0
- package/README.md +29 -11
- package/android/src/main/java/io/yaver/feedback/YaverHotReloadModule.java +188 -0
- package/android/src/main/java/io/yaver/feedback/YaverHotReloadPackage.java +33 -0
- package/app.plugin.js +263 -5
- package/ios/YaverHotReload.m +16 -0
- package/ios/YaverHotReload.swift +112 -0
- package/package.json +24 -7
- package/src/AuthOverlay.tsx +97 -0
- package/src/BlackBox.ts +41 -2
- package/src/Discovery.ts +141 -8
- package/src/FeedbackModal.tsx +9 -2
- package/src/FloatingButton.tsx +19 -7
- package/src/LoginScreen.tsx +395 -0
- package/src/MachinePickerScreen.tsx +196 -0
- package/src/P2PClient.ts +110 -0
- package/src/YaverFeedback.ts +363 -14
- package/src/YaverUpdates.ts +334 -0
- package/src/__tests__/Discovery.test.ts +8 -2
- package/src/__tests__/YaverFeedback.test.ts +4 -1
- package/src/auth.ts +338 -0
- package/src/index.ts +36 -0
- package/src/types.ts +21 -2
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for describing the origin of the Work and
|
|
141
|
+
reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2026 SIMKAB ELEKTRIK
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
200
|
+
implied. See the License for the specific language governing
|
|
201
|
+
permissions and limitations under the License.
|
package/README.md
CHANGED
|
@@ -23,23 +23,28 @@ npm install react-native-view-shot
|
|
|
23
23
|
npm install react-native-audio-recorder-player
|
|
24
24
|
```
|
|
25
25
|
|
|
26
|
-
## Quick Start
|
|
26
|
+
## Quick Start (0.5+: zero-config auth)
|
|
27
|
+
|
|
28
|
+
Starting with **0.5.0**, the SDK ships its own login screen + remote machine picker. Drop in `<FeedbackModal />` and the first time a user triggers feedback without a cached session, they get:
|
|
29
|
+
|
|
30
|
+
1. A full-screen login modal — Apple / Google / GitHub / GitLab / Microsoft via [device-code flow](https://yaver.io/auth/device), or inline email + password.
|
|
31
|
+
2. A picker of the machines they can reach — **their own dev boxes** plus **guest-shared machines** (where another user invited them).
|
|
32
|
+
|
|
33
|
+
Both screens persist their selection to `AsyncStorage`, so subsequent launches reconnect silently.
|
|
27
34
|
|
|
28
35
|
```tsx
|
|
29
36
|
import { YaverFeedback, BlackBox, FeedbackModal } from 'yaver-feedback-react-native';
|
|
30
37
|
|
|
31
|
-
//
|
|
38
|
+
// Zero-config: no agentUrl, no authToken — the SDK handles auth + discovery.
|
|
32
39
|
YaverFeedback.init({
|
|
33
|
-
agentUrl: 'http://192.168.1.10:18080',
|
|
34
|
-
authToken: 'your-sdk-token', // SDK token (recommended) or CLI token
|
|
35
40
|
trigger: 'shake',
|
|
36
41
|
});
|
|
37
42
|
|
|
38
|
-
// Start Black Box flight recorder
|
|
43
|
+
// Start Black Box flight recorder once the user has signed in
|
|
39
44
|
BlackBox.start();
|
|
40
45
|
BlackBox.wrapConsole(); // opt-in: stream console.log/warn/error to the agent
|
|
41
46
|
|
|
42
|
-
// Add FeedbackModal to your root component
|
|
47
|
+
// Add FeedbackModal to your root component — it embeds the login + picker UI.
|
|
43
48
|
function App() {
|
|
44
49
|
return (
|
|
45
50
|
<>
|
|
@@ -50,7 +55,20 @@ function App() {
|
|
|
50
55
|
}
|
|
51
56
|
```
|
|
52
57
|
|
|
53
|
-
Shake your phone to open the feedback modal. Take screenshots, record voice notes, and send everything to your Yaver agent in one tap.
|
|
58
|
+
Shake your phone to open the feedback modal. Take screenshots, record voice notes, and send everything to your Yaver agent in one tap — LAN-direct when available, Convex/relay-routed when you're on cell data.
|
|
59
|
+
|
|
60
|
+
### Opt-out: bring-your-own auth (pre-0.5 behavior)
|
|
61
|
+
|
|
62
|
+
If your app already authenticates against yaver.io on its own and just wants to pass a ready token:
|
|
63
|
+
|
|
64
|
+
```tsx
|
|
65
|
+
YaverFeedback.init({
|
|
66
|
+
agentUrl: 'http://192.168.1.10:18080',
|
|
67
|
+
authToken: 'your-sdk-token', // SDK token (recommended) or CLI token
|
|
68
|
+
trigger: 'shake',
|
|
69
|
+
autoLogin: false, // don't show the in-app login flow
|
|
70
|
+
});
|
|
71
|
+
```
|
|
54
72
|
|
|
55
73
|
## Authentication
|
|
56
74
|
|
|
@@ -62,7 +80,7 @@ SDK tokens are **long-lived (1 year)** and **independent from CLI session tokens
|
|
|
62
80
|
|
|
63
81
|
```bash
|
|
64
82
|
# Create an SDK token
|
|
65
|
-
yaver sdk-token create --label "
|
|
83
|
+
yaver sdk-token create --label "BentoApp dev"
|
|
66
84
|
# prints: 4a8f...b3c2
|
|
67
85
|
```
|
|
68
86
|
|
|
@@ -121,7 +139,7 @@ The SDK implements defense-in-depth with 6 security layers:
|
|
|
121
139
|
|
|
122
140
|
```bash
|
|
123
141
|
# Default scopes (safe for embedding in app builds)
|
|
124
|
-
yaver sdk-token create --label "
|
|
142
|
+
yaver sdk-token create --label "BentoApp"
|
|
125
143
|
# → scopes: feedback, blackbox, voice, builds
|
|
126
144
|
|
|
127
145
|
# Narrow scopes (feedback only)
|
|
@@ -170,7 +188,7 @@ import { BlackBox } from 'yaver-feedback-react-native';
|
|
|
170
188
|
BlackBox.start({
|
|
171
189
|
flushInterval: 2000, // send buffered events every 2s (default)
|
|
172
190
|
maxBufferSize: 50, // flush immediately at 50 events (default)
|
|
173
|
-
appName: '
|
|
191
|
+
appName: 'BentoApp',
|
|
174
192
|
});
|
|
175
193
|
|
|
176
194
|
// Logging
|
|
@@ -259,7 +277,7 @@ YaverFeedback.init({
|
|
|
259
277
|
});
|
|
260
278
|
|
|
261
279
|
// Start BlackBox — this also connects the command channel
|
|
262
|
-
BlackBox.start({ appName: '
|
|
280
|
+
BlackBox.start({ appName: 'BentoApp' });
|
|
263
281
|
```
|
|
264
282
|
|
|
265
283
|
### Custom Command Handlers
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
package io.yaver.feedback;
|
|
2
|
+
|
|
3
|
+
import android.app.Activity;
|
|
4
|
+
import android.content.Context;
|
|
5
|
+
import android.content.SharedPreferences;
|
|
6
|
+
import android.os.Handler;
|
|
7
|
+
import android.os.Looper;
|
|
8
|
+
import android.util.Log;
|
|
9
|
+
|
|
10
|
+
import androidx.annotation.NonNull;
|
|
11
|
+
|
|
12
|
+
import com.facebook.react.bridge.Promise;
|
|
13
|
+
import com.facebook.react.bridge.ReactApplicationContext;
|
|
14
|
+
import com.facebook.react.bridge.ReactContextBaseJavaModule;
|
|
15
|
+
import com.facebook.react.bridge.ReactMethod;
|
|
16
|
+
import com.facebook.react.bridge.ReadableMap;
|
|
17
|
+
import com.facebook.react.bridge.WritableMap;
|
|
18
|
+
import com.facebook.react.bridge.Arguments;
|
|
19
|
+
import com.facebook.react.ReactApplication;
|
|
20
|
+
import com.facebook.react.ReactInstanceManager;
|
|
21
|
+
|
|
22
|
+
import java.io.File;
|
|
23
|
+
import java.io.FileOutputStream;
|
|
24
|
+
import java.io.InputStream;
|
|
25
|
+
import java.net.HttpURLConnection;
|
|
26
|
+
import java.net.URL;
|
|
27
|
+
import java.util.concurrent.Executors;
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Hot reload native module for the Yaver Feedback SDK (Android).
|
|
31
|
+
*
|
|
32
|
+
* Downloads a Hermes bytecode bundle from the agent, saves it to the app's
|
|
33
|
+
* files directory, and recreates the React Native context to load the new bundle.
|
|
34
|
+
*
|
|
35
|
+
* Supports N reloads — each reload recreates the ReactContext with the updated bundle.
|
|
36
|
+
*/
|
|
37
|
+
public class YaverHotReloadModule extends ReactContextBaseJavaModule {
|
|
38
|
+
|
|
39
|
+
private static final String TAG = "YaverHotReload";
|
|
40
|
+
private static final String MODULE_NAME = "YaverHotReload";
|
|
41
|
+
private static final String BUNDLE_DIR = "yaver-hot-reload";
|
|
42
|
+
private static final String BUNDLE_FILE = "index.android.bundle";
|
|
43
|
+
private static final String PREFS_NAME = "yaver_hot_reload";
|
|
44
|
+
private static final String PREFS_KEY_BUNDLE = "bundle_path";
|
|
45
|
+
|
|
46
|
+
public YaverHotReloadModule(ReactApplicationContext context) {
|
|
47
|
+
super(context);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
@Override
|
|
51
|
+
@NonNull
|
|
52
|
+
public String getName() {
|
|
53
|
+
return MODULE_NAME;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Download a Hermes bundle from the agent and trigger a bridge reload.
|
|
58
|
+
*/
|
|
59
|
+
@ReactMethod
|
|
60
|
+
public void loadBundle(String urlString, ReadableMap headers, Promise promise) {
|
|
61
|
+
Executors.newSingleThreadExecutor().execute(() -> {
|
|
62
|
+
try {
|
|
63
|
+
URL url = new URL(urlString);
|
|
64
|
+
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
|
|
65
|
+
conn.setConnectTimeout(60000);
|
|
66
|
+
conn.setReadTimeout(60000);
|
|
67
|
+
|
|
68
|
+
// Set auth headers
|
|
69
|
+
if (headers != null) {
|
|
70
|
+
if (headers.hasKey("Authorization")) {
|
|
71
|
+
conn.setRequestProperty("Authorization", headers.getString("Authorization"));
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
int responseCode = conn.getResponseCode();
|
|
76
|
+
if (responseCode != 200) {
|
|
77
|
+
promise.reject("HTTP_ERROR", "Status " + responseCode);
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
InputStream is = conn.getInputStream();
|
|
82
|
+
File dir = new File(getReactApplicationContext().getFilesDir(), BUNDLE_DIR);
|
|
83
|
+
if (!dir.exists()) dir.mkdirs();
|
|
84
|
+
File bundleFile = new File(dir, BUNDLE_FILE);
|
|
85
|
+
|
|
86
|
+
FileOutputStream fos = new FileOutputStream(bundleFile);
|
|
87
|
+
byte[] buffer = new byte[8192];
|
|
88
|
+
int bytesRead;
|
|
89
|
+
int totalBytes = 0;
|
|
90
|
+
while ((bytesRead = is.read(buffer)) != -1) {
|
|
91
|
+
fos.write(buffer, 0, bytesRead);
|
|
92
|
+
totalBytes += bytesRead;
|
|
93
|
+
}
|
|
94
|
+
fos.close();
|
|
95
|
+
is.close();
|
|
96
|
+
conn.disconnect();
|
|
97
|
+
|
|
98
|
+
Log.i(TAG, "saved " + totalBytes + " bytes to " + bundleFile.getAbsolutePath());
|
|
99
|
+
|
|
100
|
+
// Validate Hermes bytecode (magic bytes at offset 4)
|
|
101
|
+
if (totalBytes >= 12) {
|
|
102
|
+
java.io.RandomAccessFile raf = new java.io.RandomAccessFile(bundleFile, "r");
|
|
103
|
+
raf.seek(4);
|
|
104
|
+
int magic = Integer.reverseBytes(raf.readInt());
|
|
105
|
+
if (magic == 0x1F1903C1) {
|
|
106
|
+
int bcVersion = Integer.reverseBytes(raf.readInt());
|
|
107
|
+
Log.i(TAG, "Hermes bytecode BC" + bcVersion);
|
|
108
|
+
} else {
|
|
109
|
+
Log.w(TAG, "not Hermes bytecode (magic=0x" + Integer.toHexString(magic) + ")");
|
|
110
|
+
}
|
|
111
|
+
raf.close();
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// Save bundle path to SharedPreferences for next app launch
|
|
115
|
+
SharedPreferences prefs = getReactApplicationContext()
|
|
116
|
+
.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE);
|
|
117
|
+
prefs.edit().putString(PREFS_KEY_BUNDLE, bundleFile.getAbsolutePath()).apply();
|
|
118
|
+
|
|
119
|
+
WritableMap result = Arguments.createMap();
|
|
120
|
+
result.putBoolean("loaded", true);
|
|
121
|
+
result.putInt("size", totalBytes);
|
|
122
|
+
promise.resolve(result);
|
|
123
|
+
|
|
124
|
+
// Reload the bridge on the main thread
|
|
125
|
+
new Handler(Looper.getMainLooper()).post(() -> reloadBridge());
|
|
126
|
+
|
|
127
|
+
} catch (Exception e) {
|
|
128
|
+
Log.e(TAG, "download failed", e);
|
|
129
|
+
promise.reject("DOWNLOAD_FAILED", e.getMessage(), e);
|
|
130
|
+
}
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
@ReactMethod
|
|
135
|
+
public void hasBundle(Promise promise) {
|
|
136
|
+
File bundleFile = getSavedBundleFile(getReactApplicationContext());
|
|
137
|
+
promise.resolve(bundleFile != null && bundleFile.exists());
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
@ReactMethod
|
|
141
|
+
public void clearBundle(Promise promise) {
|
|
142
|
+
File dir = new File(getReactApplicationContext().getFilesDir(), BUNDLE_DIR);
|
|
143
|
+
if (dir.exists()) {
|
|
144
|
+
for (File f : dir.listFiles()) f.delete();
|
|
145
|
+
dir.delete();
|
|
146
|
+
}
|
|
147
|
+
SharedPreferences prefs = getReactApplicationContext()
|
|
148
|
+
.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE);
|
|
149
|
+
prefs.edit().remove(PREFS_KEY_BUNDLE).apply();
|
|
150
|
+
promise.resolve(true);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* Recreate the React Native context with the new bundle.
|
|
155
|
+
*/
|
|
156
|
+
private void reloadBridge() {
|
|
157
|
+
Activity activity = getCurrentActivity();
|
|
158
|
+
if (activity == null) {
|
|
159
|
+
Log.e(TAG, "no current activity");
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
if (activity.getApplication() instanceof ReactApplication) {
|
|
164
|
+
ReactApplication app = (ReactApplication) activity.getApplication();
|
|
165
|
+
ReactInstanceManager manager = app.getReactNativeHost().getReactInstanceManager();
|
|
166
|
+
Log.i(TAG, "recreating React context with new bundle");
|
|
167
|
+
manager.recreateReactContextInBackground();
|
|
168
|
+
} else {
|
|
169
|
+
Log.e(TAG, "Application does not implement ReactApplication");
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
// MARK: - Static helpers for Application/MainApplication
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* Returns the hot-reloaded bundle file if it exists.
|
|
177
|
+
* Call from MainApplication.getJSBundleFile() to load the hot bundle on startup.
|
|
178
|
+
*/
|
|
179
|
+
public static File getSavedBundleFile(Context context) {
|
|
180
|
+
SharedPreferences prefs = context.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE);
|
|
181
|
+
String path = prefs.getString(PREFS_KEY_BUNDLE, null);
|
|
182
|
+
if (path != null) {
|
|
183
|
+
File f = new File(path);
|
|
184
|
+
if (f.exists()) return f;
|
|
185
|
+
}
|
|
186
|
+
return null;
|
|
187
|
+
}
|
|
188
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
package io.yaver.feedback;
|
|
2
|
+
|
|
3
|
+
import androidx.annotation.NonNull;
|
|
4
|
+
|
|
5
|
+
import com.facebook.react.ReactPackage;
|
|
6
|
+
import com.facebook.react.bridge.NativeModule;
|
|
7
|
+
import com.facebook.react.bridge.ReactApplicationContext;
|
|
8
|
+
import com.facebook.react.uimanager.ViewManager;
|
|
9
|
+
|
|
10
|
+
import java.util.ArrayList;
|
|
11
|
+
import java.util.Collections;
|
|
12
|
+
import java.util.List;
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* React Native package that registers the YaverHotReload native module.
|
|
16
|
+
* Auto-linked via the Expo config plugin.
|
|
17
|
+
*/
|
|
18
|
+
public class YaverHotReloadPackage implements ReactPackage {
|
|
19
|
+
|
|
20
|
+
@NonNull
|
|
21
|
+
@Override
|
|
22
|
+
public List<NativeModule> createNativeModules(@NonNull ReactApplicationContext reactContext) {
|
|
23
|
+
List<NativeModule> modules = new ArrayList<>();
|
|
24
|
+
modules.add(new YaverHotReloadModule(reactContext));
|
|
25
|
+
return modules;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
@NonNull
|
|
29
|
+
@Override
|
|
30
|
+
public List<ViewManager> createViewManagers(@NonNull ReactApplicationContext reactContext) {
|
|
31
|
+
return Collections.emptyList();
|
|
32
|
+
}
|
|
33
|
+
}
|