codeplay-common 1.3.7 → 1.3.8
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.
|
@@ -185,6 +185,100 @@ const routes = [
|
|
|
185
185
|
|
|
186
186
|
|
|
187
187
|
|
|
188
|
+
// Check and change the "BridgeWebViewClient.java" file START
|
|
189
|
+
/*
|
|
190
|
+
For crash issue due to low memory problem, we need to modify the onRenderProcessGone method in BridgeWebViewClient.java.
|
|
191
|
+
*/
|
|
192
|
+
//const filePath = path.join(__dirname, 'node_modules/@capacitor/android/capacitor/src/main/java/com/getcapacitor/BridgeWebViewClient.java');
|
|
193
|
+
|
|
194
|
+
const bridgeWebViewClientFilePath = path.join(process.cwd(), 'node_modules', '@capacitor/android/capacitor/src/main/java/com/getcapacitor', 'BridgeWebViewClient.java');
|
|
195
|
+
|
|
196
|
+
// Read the file
|
|
197
|
+
if (!fs.existsSync(bridgeWebViewClientFilePath)) {
|
|
198
|
+
console.error('❌ Error: BridgeWebViewClient.java not found.');
|
|
199
|
+
process.exit(1);
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
let fileContent = fs.readFileSync(bridgeWebViewClientFilePath, 'utf8');
|
|
203
|
+
|
|
204
|
+
// Define old and new code
|
|
205
|
+
const oldCodeStart = `@Override
|
|
206
|
+
public boolean onRenderProcessGone(WebView view, RenderProcessGoneDetail detail) {
|
|
207
|
+
super.onRenderProcessGone(view, detail);
|
|
208
|
+
boolean result = false;
|
|
209
|
+
|
|
210
|
+
List<WebViewListener> webViewListeners = bridge.getWebViewListeners();
|
|
211
|
+
if (webViewListeners != null) {
|
|
212
|
+
for (WebViewListener listener : bridge.getWebViewListeners()) {
|
|
213
|
+
result = listener.onRenderProcessGone(view, detail) || result;
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
return result;
|
|
218
|
+
}`;
|
|
219
|
+
|
|
220
|
+
const newCode = `@Override
|
|
221
|
+
public boolean onRenderProcessGone(WebView view, RenderProcessGoneDetail detail) {
|
|
222
|
+
super.onRenderProcessGone(view, detail);
|
|
223
|
+
|
|
224
|
+
boolean result = false;
|
|
225
|
+
|
|
226
|
+
List<WebViewListener> webViewListeners = bridge.getWebViewListeners();
|
|
227
|
+
if (webViewListeners != null) {
|
|
228
|
+
for (WebViewListener listener : bridge.getWebViewListeners()) {
|
|
229
|
+
result = listener.onRenderProcessGone(view, detail) || result;
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
if (!result) {
|
|
234
|
+
// If no one handled it, handle it ourselves!
|
|
235
|
+
|
|
236
|
+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
|
237
|
+
if (detail.didCrash()) {
|
|
238
|
+
//Log.e("CapacitorWebView", "WebView crashed internally!");
|
|
239
|
+
} else {
|
|
240
|
+
//Log.w("CapacitorWebView", "WebView was killed by system (low memory) internally!");
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
view.post(() -> {
|
|
245
|
+
Toast.makeText(view.getContext(), "Reloading due to low memory issue", Toast.LENGTH_SHORT).show();
|
|
246
|
+
});
|
|
247
|
+
|
|
248
|
+
view.reload(); // Safely reload WebView
|
|
249
|
+
|
|
250
|
+
return true; // We handled it
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
return result;
|
|
254
|
+
}`;
|
|
255
|
+
|
|
256
|
+
// Logic to update
|
|
257
|
+
if (fileContent.includes(oldCodeStart)) {
|
|
258
|
+
console.log('✅ Found old onRenderProcessGone method. Replacing it...');
|
|
259
|
+
const updatedContent = fileContent.replace(oldCodeStart, newCode);
|
|
260
|
+
fs.writeFileSync(bridgeWebViewClientFilePath, updatedContent, 'utf8');
|
|
261
|
+
console.log('✅ Replacement done.');
|
|
262
|
+
} else if (fileContent.includes(newCode)) {
|
|
263
|
+
console.log('ℹ️ Already onRenderProcessGone updated . No changes needed.');
|
|
264
|
+
} else {
|
|
265
|
+
console.error('❌ Error: Neither old nor new code found. Unexpected content.');
|
|
266
|
+
process.exit(1);
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
|
|
270
|
+
|
|
271
|
+
// Check and change the "BridgeWebViewClient.java" file END
|
|
272
|
+
|
|
273
|
+
|
|
274
|
+
|
|
275
|
+
|
|
276
|
+
|
|
277
|
+
|
|
278
|
+
|
|
279
|
+
|
|
280
|
+
|
|
281
|
+
|
|
188
282
|
|
|
189
283
|
|
|
190
284
|
|