@capacitor/android 3.4.1 → 3.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/CHANGELOG.md CHANGED
@@ -3,6 +3,33 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ # [3.5.0](https://github.com/ionic-team/capacitor/compare/3.4.3...3.5.0) (2022-04-22)
7
+
8
+
9
+ ### Features
10
+
11
+ * **android:** Add overridable routing for WebViewLocalServer ([#5553](https://github.com/ionic-team/capacitor/issues/5553)) ([3bb288e](https://github.com/ionic-team/capacitor/commit/3bb288e848c5c0e49c1e58c0782e0b1ffd7b1f31))
12
+
13
+
14
+
15
+
16
+
17
+ ## [3.4.3](https://github.com/ionic-team/capacitor/compare/3.4.2...3.4.3) (2022-03-04)
18
+
19
+ **Note:** Version bump only for package @capacitor/android
20
+
21
+
22
+
23
+
24
+
25
+ ## [3.4.2](https://github.com/ionic-team/capacitor/compare/3.4.1...3.4.2) (2022-03-03)
26
+
27
+ **Note:** Version bump only for package @capacitor/android
28
+
29
+
30
+
31
+
32
+
6
33
  ## [3.4.1](https://github.com/ionic-team/capacitor/compare/3.4.0...3.4.1) (2022-02-09)
7
34
 
8
35
  **Note:** Version bump only for package @capacitor/android
@@ -130,6 +130,9 @@ public class Bridge {
130
130
  // A list of listeners that trigger when webView events occur
131
131
  private List<WebViewListener> webViewListeners = new ArrayList<>();
132
132
 
133
+ // An interface to manipulate route resolving
134
+ private RouteProcessor routeProcessor;
135
+
133
136
  /**
134
137
  * Create the Bridge with a reference to the main {@link Activity} for the
135
138
  * app, and a reference to the {@link WebView} our app will use.
@@ -1190,6 +1193,14 @@ public class Bridge {
1190
1193
  this.webViewListeners = webViewListeners;
1191
1194
  }
1192
1195
 
1196
+ RouteProcessor getRouteProcessor() {
1197
+ return routeProcessor;
1198
+ }
1199
+
1200
+ void setRouteProcessor(RouteProcessor routeProcessor) {
1201
+ this.routeProcessor = routeProcessor;
1202
+ }
1203
+
1193
1204
  /**
1194
1205
  * Add a listener that the WebViewClient can trigger on certain events.
1195
1206
  * @param webViewListener A {@link WebViewListener} to add.
@@ -1213,6 +1224,7 @@ public class Bridge {
1213
1224
  private List<Class<? extends Plugin>> plugins = new ArrayList<>();
1214
1225
  private AppCompatActivity activity;
1215
1226
  private Fragment fragment;
1227
+ private RouteProcessor routeProcessor;
1216
1228
  private final List<WebViewListener> webViewListeners = new ArrayList<>();
1217
1229
 
1218
1230
  public Builder(AppCompatActivity activity) {
@@ -1265,6 +1277,11 @@ public class Bridge {
1265
1277
  return this;
1266
1278
  }
1267
1279
 
1280
+ public Builder setRouteProcessor(RouteProcessor routeProcessor) {
1281
+ this.routeProcessor = routeProcessor;
1282
+ return this;
1283
+ }
1284
+
1268
1285
  public Bridge create() {
1269
1286
  // Cordova initialization
1270
1287
  ConfigXmlParser parser = new ConfigXmlParser();
@@ -1288,6 +1305,7 @@ public class Bridge {
1288
1305
  Bridge bridge = new Bridge(activity, fragment, webView, plugins, cordovaInterface, pluginManager, preferences, config);
1289
1306
  bridge.setCordovaWebView(mockWebView);
1290
1307
  bridge.setWebViewListeners(webViewListeners);
1308
+ bridge.setRouteProcessor(routeProcessor);
1291
1309
 
1292
1310
  if (instanceState != null) {
1293
1311
  bridge.restoreInstanceState(instanceState);
@@ -12,11 +12,11 @@ public class BridgeActivity extends AppCompatActivity {
12
12
 
13
13
  protected Bridge bridge;
14
14
  protected boolean keepRunning = true;
15
- private CapConfig config;
15
+ protected CapConfig config;
16
16
 
17
- private int activityDepth = 0;
18
- private List<Class<? extends Plugin>> initialPlugins = new ArrayList<>();
19
- private final Bridge.Builder bridgeBuilder = new Bridge.Builder(this);
17
+ protected int activityDepth = 0;
18
+ protected List<Class<? extends Plugin>> initialPlugins = new ArrayList<>();
19
+ protected final Bridge.Builder bridgeBuilder = new Bridge.Builder(this);
20
20
 
21
21
  @Override
22
22
  protected void onCreate(Bundle savedInstanceState) {
@@ -66,7 +66,7 @@ public class BridgeActivity extends AppCompatActivity {
66
66
  this.load();
67
67
  }
68
68
 
69
- private void load() {
69
+ protected void load() {
70
70
  Logger.debug("Starting BridgeActivity");
71
71
 
72
72
  bridge = bridgeBuilder.addPlugins(initialPlugins).setConfig(config).create();
@@ -0,0 +1,8 @@
1
+ package com.getcapacitor;
2
+
3
+ /**
4
+ * An interface used in the processing of routes
5
+ */
6
+ public interface RouteProcessor {
7
+ String process(String path);
8
+ }
@@ -24,7 +24,6 @@ import android.webkit.WebResourceResponse;
24
24
  import java.io.IOException;
25
25
  import java.io.InputStream;
26
26
  import java.net.HttpURLConnection;
27
- import java.net.SocketTimeoutException;
28
27
  import java.net.URL;
29
28
  import java.net.URLConnection;
30
29
  import java.nio.charset.StandardCharsets;
@@ -256,6 +255,10 @@ public class WebViewLocalServer {
256
255
  InputStream responseStream;
257
256
  try {
258
257
  String startPath = this.basePath + "/index.html";
258
+ if (bridge.getRouteProcessor() != null) {
259
+ startPath = this.basePath + bridge.getRouteProcessor().process("/index.html");
260
+ }
261
+
259
262
  if (isAsset) {
260
263
  responseStream = protocolHandler.openAsset(startPath);
261
264
  } else {
@@ -467,6 +470,13 @@ public class WebViewLocalServer {
467
470
  public InputStream handle(Uri url) {
468
471
  InputStream stream = null;
469
472
  String path = url.getPath();
473
+
474
+ // Pass path to routeProcessor if present
475
+ RouteProcessor routeProcessor = bridge.getRouteProcessor();
476
+ if (routeProcessor != null) {
477
+ path = bridge.getRouteProcessor().process(path);
478
+ }
479
+
470
480
  try {
471
481
  if (path.startsWith(capacitorContentStart)) {
472
482
  stream = protocolHandler.openContentUrl(url);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capacitor/android",
3
- "version": "3.4.1",
3
+ "version": "3.5.0",
4
4
  "description": "Capacitor: Cross-platform apps with JavaScript and the web",
5
5
  "homepage": "https://capacitorjs.com",
6
6
  "author": "Ionic Team <hi@ionic.io> (https://ionic.io)",
@@ -22,10 +22,10 @@
22
22
  "verify": "./gradlew clean lint build test -b capacitor/build.gradle"
23
23
  },
24
24
  "peerDependencies": {
25
- "@capacitor/core": "^3.4.0"
25
+ "@capacitor/core": "^3.5.0"
26
26
  },
27
27
  "publishConfig": {
28
28
  "access": "public"
29
29
  },
30
- "gitHead": "bc7b49ff2ad242fecff7bcb3900c627ff6880f7b"
30
+ "gitHead": "f03e1a67140c8af25288456f9e99dd6234b50f25"
31
31
  }