codeplay-common 1.3.7 → 1.3.9

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,130 @@ 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
+
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
+ // Step 1: Update method if needed
257
+ let updated = false;
258
+
259
+ if (fileContent.includes(oldCodeStart)) {
260
+ console.log('✅ Found old onRenderProcessGone method. Replacing it...');
261
+ fileContent = fileContent.replace(oldCodeStart, newCode);
262
+ updated = true;
263
+ } else if (fileContent.includes(newCode)) {
264
+ console.log('ℹ️ Method already updated. No changes needed in "BridgeWebViewClient.java".');
265
+ } else {
266
+ console.error('❌ Error: Neither old nor new code found. Unexpected content.');
267
+ process.exit(1);
268
+ }
269
+
270
+ // Step 2: Check and add import if missing
271
+ const importToast = 'import android.widget.Toast;';
272
+ if (!fileContent.includes(importToast)) {
273
+ console.log('✅ Adding missing import for Toast...');
274
+ const importRegex = /import\s+[^;]+;/g;
275
+ const matches = [...fileContent.matchAll(importRegex)];
276
+
277
+ if (matches.length > 0) {
278
+ const lastImport = matches[matches.length - 1];
279
+ const insertPosition = lastImport.index + lastImport[0].length;
280
+ fileContent = fileContent.slice(0, insertPosition) + `\n${importToast}` + fileContent.slice(insertPosition);
281
+ updated = true;
282
+ } else {
283
+ console.error('❌ Error: No import section found in file.');
284
+ process.exit(1);
285
+ }
286
+ } else {
287
+ console.log('ℹ️ Import for Toast already exists. No changes needed.');
288
+ }
289
+
290
+ // Step 3: Save if updated
291
+ if (updated) {
292
+ fs.writeFileSync(bridgeWebViewClientFilePath, fileContent, 'utf8');
293
+ console.log('✅ File updated successfully.');
294
+ } else {
295
+ console.log('ℹ️ No changes needed.');
296
+ }
297
+
298
+
299
+
300
+
301
+ // Check and change the "BridgeWebViewClient.java" file END
302
+
303
+
304
+
305
+
306
+
307
+
308
+
309
+
310
+
311
+
188
312
 
189
313
 
190
314
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "codeplay-common",
3
- "version": "1.3.7",
3
+ "version": "1.3.9",
4
4
  "description": "Common build scripts and files",
5
5
  "scripts": {
6
6
  "postinstall": "node scripts/sync-files.js",