@capacitor/browser 5.1.1-nightly-20231108T150452.0 → 5.2.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/README.md CHANGED
@@ -35,8 +35,8 @@ const openCapacitorSite = async () => {
35
35
 
36
36
  * [`open(...)`](#open)
37
37
  * [`close()`](#close)
38
- * [`addListener('browserFinished', ...)`](#addlistenerbrowserfinished)
39
- * [`addListener('browserPageLoaded', ...)`](#addlistenerbrowserpageloaded)
38
+ * [`addListener('browserFinished', ...)`](#addlistenerbrowserfinished-)
39
+ * [`addListener('browserPageLoaded', ...)`](#addlistenerbrowserpageloaded-)
40
40
  * [`removeAllListeners()`](#removealllisteners)
41
41
  * [Interfaces](#interfaces)
42
42
 
@@ -80,7 +80,7 @@ No-op on other platforms.
80
80
  ### addListener('browserFinished', ...)
81
81
 
82
82
  ```typescript
83
- addListener(eventName: 'browserFinished', listenerFunc: () => void) => Promise<PluginListenerHandle>
83
+ addListener(eventName: 'browserFinished', listenerFunc: () => void) => Promise<PluginListenerHandle> & PluginListenerHandle
84
84
  ```
85
85
 
86
86
  Android & iOS only: Listen for the browser finished event.
@@ -91,7 +91,7 @@ It fires when the Browser is closed by the user.
91
91
  | **`eventName`** | <code>'browserFinished'</code> |
92
92
  | **`listenerFunc`** | <code>() =&gt; void</code> |
93
93
 
94
- **Returns:** <code>Promise&lt;<a href="#pluginlistenerhandle">PluginListenerHandle</a>&gt;</code>
94
+ **Returns:** <code>Promise&lt;<a href="#pluginlistenerhandle">PluginListenerHandle</a>&gt; & <a href="#pluginlistenerhandle">PluginListenerHandle</a></code>
95
95
 
96
96
  **Since:** 1.0.0
97
97
 
@@ -101,7 +101,7 @@ It fires when the Browser is closed by the user.
101
101
  ### addListener('browserPageLoaded', ...)
102
102
 
103
103
  ```typescript
104
- addListener(eventName: 'browserPageLoaded', listenerFunc: () => void) => Promise<PluginListenerHandle>
104
+ addListener(eventName: 'browserPageLoaded', listenerFunc: () => void) => Promise<PluginListenerHandle> & PluginListenerHandle
105
105
  ```
106
106
 
107
107
  Android & iOS only: Listen for the page loaded event.
@@ -113,7 +113,7 @@ It is not invoked for any subsequent page loads.
113
113
  | **`eventName`** | <code>'browserPageLoaded'</code> |
114
114
  | **`listenerFunc`** | <code>() =&gt; void</code> |
115
115
 
116
- **Returns:** <code>Promise&lt;<a href="#pluginlistenerhandle">PluginListenerHandle</a>&gt;</code>
116
+ **Returns:** <code>Promise&lt;<a href="#pluginlistenerhandle">PluginListenerHandle</a>&gt; & <a href="#pluginlistenerhandle">PluginListenerHandle</a></code>
117
117
 
118
118
  **Since:** 1.0.0
119
119
 
@@ -16,7 +16,7 @@ buildscript {
16
16
  }
17
17
  }
18
18
  dependencies {
19
- classpath 'com.android.tools.build:gradle:8.2.0-rc02'
19
+ classpath 'com.android.tools.build:gradle:8.0.0'
20
20
  if (System.getenv("CAP_PLUGIN_PUBLISH") == "true") {
21
21
  classpath 'io.github.gradle-nexus:publish-plugin:1.3.0'
22
22
  }
@@ -32,10 +32,10 @@ if (System.getenv("CAP_PLUGIN_PUBLISH") == "true") {
32
32
 
33
33
  android {
34
34
  namespace "com.capacitorjs.plugins.browser"
35
- compileSdkVersion project.hasProperty('compileSdkVersion') ? rootProject.ext.compileSdkVersion : 34
35
+ compileSdkVersion project.hasProperty('compileSdkVersion') ? rootProject.ext.compileSdkVersion : 33
36
36
  defaultConfig {
37
37
  minSdkVersion project.hasProperty('minSdkVersion') ? rootProject.ext.minSdkVersion : 22
38
- targetSdkVersion project.hasProperty('targetSdkVersion') ? rootProject.ext.targetSdkVersion : 34
38
+ targetSdkVersion project.hasProperty('targetSdkVersion') ? rootProject.ext.targetSdkVersion : 33
39
39
  versionCode 1
40
40
  versionName "1.0"
41
41
  testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
@@ -1,5 +1,11 @@
1
1
 
2
2
  <manifest xmlns:android="http://schemas.android.com/apk/res/android">
3
+ <application>
4
+ <activity android:name=".BrowserControllerActivity"
5
+ android:exported="false"
6
+ android:theme="@android:style/Theme.Translucent.NoTitleBar"
7
+ android:launchMode="singleTask"/>
8
+ </application>
3
9
  <queries>
4
10
  <intent>
5
11
  <action android:name="android.support.customtabs.action.CustomTabsService" />
@@ -0,0 +1,52 @@
1
+ package com.capacitorjs.plugins.browser;
2
+
3
+ import android.app.Activity;
4
+ import android.content.Intent;
5
+ import android.net.Uri;
6
+ import android.os.Bundle;
7
+ import androidx.annotation.Nullable;
8
+
9
+ public class BrowserControllerActivity extends Activity {
10
+
11
+ private boolean isCustomTabsOpen = false;
12
+
13
+ @Override
14
+ protected void onCreate(@Nullable Bundle savedInstanceState) {
15
+ super.onCreate(savedInstanceState);
16
+ isCustomTabsOpen = false;
17
+
18
+ if (BrowserPlugin.browserControllerListener != null) {
19
+ BrowserPlugin.browserControllerListener.onControllerReady(this);
20
+ }
21
+ }
22
+
23
+ @Override
24
+ protected void onNewIntent(Intent intent) {
25
+ super.onNewIntent(intent);
26
+ if (intent.hasExtra("close")) {
27
+ finish();
28
+ }
29
+ }
30
+
31
+ @Override
32
+ protected void onResume() {
33
+ super.onResume();
34
+ if (isCustomTabsOpen) {
35
+ isCustomTabsOpen = false;
36
+ finish();
37
+ } else {
38
+ isCustomTabsOpen = true;
39
+ }
40
+ }
41
+
42
+ public void open(Browser implementation, Uri url, Integer toolbarColor) {
43
+ implementation.open(url, toolbarColor);
44
+ }
45
+
46
+ @Override
47
+ protected void onDestroy() {
48
+ super.onDestroy();
49
+ isCustomTabsOpen = false;
50
+ BrowserPlugin.setBrowserControllerListener(null);
51
+ }
52
+ }
@@ -0,0 +1,5 @@
1
+ package com.capacitorjs.plugins.browser;
2
+
3
+ public interface BrowserControllerListener {
4
+ void onControllerReady(BrowserControllerActivity activity);
5
+ }
@@ -1,6 +1,7 @@
1
1
  package com.capacitorjs.plugins.browser;
2
2
 
3
3
  import android.content.ActivityNotFoundException;
4
+ import android.content.Intent;
4
5
  import android.net.Uri;
5
6
  import com.getcapacitor.Logger;
6
7
  import com.getcapacitor.Plugin;
@@ -14,6 +15,16 @@ public class BrowserPlugin extends Plugin {
14
15
 
15
16
  private Browser implementation;
16
17
 
18
+ public static BrowserControllerListener browserControllerListener;
19
+ private static BrowserControllerActivity browserControllerActivityInstance;
20
+
21
+ public static void setBrowserControllerListener(BrowserControllerListener listener) {
22
+ browserControllerListener = listener;
23
+ if (listener == null) {
24
+ browserControllerActivityInstance = null;
25
+ }
26
+ }
27
+
17
28
  public void load() {
18
29
  implementation = new Browser(getContext());
19
30
  implementation.setBrowserEventListener(this::onBrowserEvent);
@@ -50,18 +61,35 @@ public class BrowserPlugin extends Plugin {
50
61
 
51
62
  // open the browser and finish
52
63
  try {
53
- implementation.open(url, toolbarColor);
64
+ Intent intent = new Intent(getContext(), BrowserControllerActivity.class);
65
+ intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
66
+ intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
67
+ getContext().startActivity(intent);
68
+
69
+ Integer finalToolbarColor = toolbarColor;
70
+ setBrowserControllerListener(
71
+ activity -> {
72
+ activity.open(implementation, url, finalToolbarColor);
73
+ browserControllerActivityInstance = activity;
74
+ call.resolve();
75
+ }
76
+ );
54
77
  } catch (ActivityNotFoundException ex) {
55
78
  Logger.error(getLogTag(), ex.getLocalizedMessage(), null);
56
79
  call.reject("Unable to display URL");
57
80
  return;
58
81
  }
59
- call.resolve();
60
82
  }
61
83
 
62
84
  @PluginMethod
63
85
  public void close(PluginCall call) {
64
- call.unimplemented();
86
+ if (browserControllerActivityInstance != null) {
87
+ browserControllerActivityInstance = null;
88
+ Intent intent = new Intent(getContext(), BrowserControllerActivity.class);
89
+ intent.putExtra("close", true);
90
+ getContext().startActivity(intent);
91
+ }
92
+ call.resolve();
65
93
  }
66
94
 
67
95
  @Override
package/dist/docs.json CHANGED
@@ -45,7 +45,7 @@
45
45
  },
46
46
  {
47
47
  "name": "addListener",
48
- "signature": "(eventName: 'browserFinished', listenerFunc: () => void) => Promise<PluginListenerHandle>",
48
+ "signature": "(eventName: 'browserFinished', listenerFunc: () => void) => Promise<PluginListenerHandle> & PluginListenerHandle",
49
49
  "parameters": [
50
50
  {
51
51
  "name": "eventName",
@@ -58,7 +58,7 @@
58
58
  "type": "() => void"
59
59
  }
60
60
  ],
61
- "returns": "Promise<PluginListenerHandle>",
61
+ "returns": "Promise<PluginListenerHandle> & PluginListenerHandle",
62
62
  "tags": [
63
63
  {
64
64
  "name": "since",
@@ -69,11 +69,11 @@
69
69
  "complexTypes": [
70
70
  "PluginListenerHandle"
71
71
  ],
72
- "slug": "addlistenerbrowserfinished"
72
+ "slug": "addlistenerbrowserfinished-"
73
73
  },
74
74
  {
75
75
  "name": "addListener",
76
- "signature": "(eventName: 'browserPageLoaded', listenerFunc: () => void) => Promise<PluginListenerHandle>",
76
+ "signature": "(eventName: 'browserPageLoaded', listenerFunc: () => void) => Promise<PluginListenerHandle> & PluginListenerHandle",
77
77
  "parameters": [
78
78
  {
79
79
  "name": "eventName",
@@ -86,7 +86,7 @@
86
86
  "type": "() => void"
87
87
  }
88
88
  ],
89
- "returns": "Promise<PluginListenerHandle>",
89
+ "returns": "Promise<PluginListenerHandle> & PluginListenerHandle",
90
90
  "tags": [
91
91
  {
92
92
  "name": "since",
@@ -97,7 +97,7 @@
97
97
  "complexTypes": [
98
98
  "PluginListenerHandle"
99
99
  ],
100
- "slug": "addlistenerbrowserpageloaded"
100
+ "slug": "addlistenerbrowserpageloaded-"
101
101
  },
102
102
  {
103
103
  "name": "removeAllListeners",
@@ -20,7 +20,7 @@ export interface BrowserPlugin {
20
20
  *
21
21
  * @since 1.0.0
22
22
  */
23
- addListener(eventName: 'browserFinished', listenerFunc: () => void): Promise<PluginListenerHandle>;
23
+ addListener(eventName: 'browserFinished', listenerFunc: () => void): Promise<PluginListenerHandle> & PluginListenerHandle;
24
24
  /**
25
25
  * Android & iOS only: Listen for the page loaded event.
26
26
  * It's only fired when the URL passed to open method finish loading.
@@ -28,7 +28,7 @@ export interface BrowserPlugin {
28
28
  *
29
29
  * @since 1.0.0
30
30
  */
31
- addListener(eventName: 'browserPageLoaded', listenerFunc: () => void): Promise<PluginListenerHandle>;
31
+ addListener(eventName: 'browserPageLoaded', listenerFunc: () => void): Promise<PluginListenerHandle> & PluginListenerHandle;
32
32
  /**
33
33
  * Remove all native listeners for this plugin.
34
34
  *
@@ -1 +1 @@
1
- {"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"","sourcesContent":["import type { PluginListenerHandle } from '@capacitor/core';\n\nexport interface BrowserPlugin {\n /**\n * Open a page with the specified options.\n *\n * @since 1.0.0\n */\n open(options: OpenOptions): Promise<void>;\n\n /**\n * Web & iOS only: Close an open browser window.\n *\n * No-op on other platforms.\n *\n * @since 1.0.0\n */\n close(): Promise<void>;\n\n /**\n * Android & iOS only: Listen for the browser finished event.\n * It fires when the Browser is closed by the user.\n *\n * @since 1.0.0\n */\n addListener(\n eventName: 'browserFinished',\n listenerFunc: () => void,\n ): Promise<PluginListenerHandle>;\n\n /**\n * Android & iOS only: Listen for the page loaded event.\n * It's only fired when the URL passed to open method finish loading.\n * It is not invoked for any subsequent page loads.\n *\n * @since 1.0.0\n */\n addListener(\n eventName: 'browserPageLoaded',\n listenerFunc: () => void,\n ): Promise<PluginListenerHandle>;\n\n /**\n * Remove all native listeners for this plugin.\n *\n * @since 1.0.0\n */\n removeAllListeners(): Promise<void>;\n}\n\n/**\n * Represents the options passed to `open`.\n *\n * @since 1.0.0\n */\nexport interface OpenOptions {\n /**\n * The URL to which the browser is opened.\n *\n * @since 1.0.0\n */\n url: string;\n\n /**\n * Web only: Optional target for browser open. Follows\n * the `target` property for window.open. Defaults\n * to _blank.\n *\n * Ignored on other platforms.\n *\n * @since 1.0.0\n */\n windowName?: string;\n\n /**\n * A hex color to which the toolbar color is set.\n *\n * @since 1.0.0\n */\n toolbarColor?: string;\n\n /**\n * iOS only: The presentation style of the browser. Defaults to fullscreen.\n *\n * Ignored on other platforms.\n *\n * @since 1.0.0\n */\n presentationStyle?: 'fullscreen' | 'popover';\n\n /**\n * iOS only: The width the browser when using presentationStyle 'popover' on iPads.\n *\n * Ignored on other platforms.\n *\n * @since 4.0.0\n */\n width?: number;\n\n /**\n * iOS only: The height the browser when using presentationStyle 'popover' on iPads.\n *\n * Ignored on other platforms.\n *\n * @since 4.0.0\n */\n height?: number;\n}\n\n/**\n * @deprecated Use `OpenOptions`.\n * @since 1.0.0\n */\nexport type BrowserOpenOptions = OpenOptions;\n"]}
1
+ {"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"","sourcesContent":["import type { PluginListenerHandle } from '@capacitor/core';\n\nexport interface BrowserPlugin {\n /**\n * Open a page with the specified options.\n *\n * @since 1.0.0\n */\n open(options: OpenOptions): Promise<void>;\n\n /**\n * Web & iOS only: Close an open browser window.\n *\n * No-op on other platforms.\n *\n * @since 1.0.0\n */\n close(): Promise<void>;\n\n /**\n * Android & iOS only: Listen for the browser finished event.\n * It fires when the Browser is closed by the user.\n *\n * @since 1.0.0\n */\n addListener(\n eventName: 'browserFinished',\n listenerFunc: () => void,\n ): Promise<PluginListenerHandle> & PluginListenerHandle;\n\n /**\n * Android & iOS only: Listen for the page loaded event.\n * It's only fired when the URL passed to open method finish loading.\n * It is not invoked for any subsequent page loads.\n *\n * @since 1.0.0\n */\n addListener(\n eventName: 'browserPageLoaded',\n listenerFunc: () => void,\n ): Promise<PluginListenerHandle> & PluginListenerHandle;\n\n /**\n * Remove all native listeners for this plugin.\n *\n * @since 1.0.0\n */\n removeAllListeners(): Promise<void>;\n}\n\n/**\n * Represents the options passed to `open`.\n *\n * @since 1.0.0\n */\nexport interface OpenOptions {\n /**\n * The URL to which the browser is opened.\n *\n * @since 1.0.0\n */\n url: string;\n\n /**\n * Web only: Optional target for browser open. Follows\n * the `target` property for window.open. Defaults\n * to _blank.\n *\n * Ignored on other platforms.\n *\n * @since 1.0.0\n */\n windowName?: string;\n\n /**\n * A hex color to which the toolbar color is set.\n *\n * @since 1.0.0\n */\n toolbarColor?: string;\n\n /**\n * iOS only: The presentation style of the browser. Defaults to fullscreen.\n *\n * Ignored on other platforms.\n *\n * @since 1.0.0\n */\n presentationStyle?: 'fullscreen' | 'popover';\n\n /**\n * iOS only: The width the browser when using presentationStyle 'popover' on iPads.\n *\n * Ignored on other platforms.\n *\n * @since 4.0.0\n */\n width?: number;\n\n /**\n * iOS only: The height the browser when using presentationStyle 'popover' on iPads.\n *\n * Ignored on other platforms.\n *\n * @since 4.0.0\n */\n height?: number;\n}\n\n/**\n * @deprecated Use `OpenOptions`.\n * @since 1.0.0\n */\nexport type BrowserOpenOptions = OpenOptions;\n"]}
@@ -4,4 +4,5 @@
4
4
  CAP_PLUGIN(CAPBrowserPlugin, "Browser",
5
5
  CAP_PLUGIN_METHOD(open, CAPPluginReturnPromise);
6
6
  CAP_PLUGIN_METHOD(close, CAPPluginReturnPromise);
7
+ CAP_PLUGIN_METHOD(removeAllListeners, CAPPluginReturnPromise);
7
8
  )
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capacitor/browser",
3
- "version": "5.1.1-nightly-20231108T150452.0",
3
+ "version": "5.2.0",
4
4
  "description": "The Browser API provides the ability to open an in-app browser and subscribe to browser events.",
5
5
  "main": "dist/plugin.cjs.js",
6
6
  "module": "dist/esm/index.js",
@@ -47,7 +47,7 @@
47
47
  "devDependencies": {
48
48
  "@capacitor/android": "^5.0.0",
49
49
  "@capacitor/core": "^5.0.0",
50
- "@capacitor/docgen": "0.2.0",
50
+ "@capacitor/docgen": "0.2.2",
51
51
  "@capacitor/ios": "^5.0.0",
52
52
  "@ionic/eslint-config": "^0.3.0",
53
53
  "@ionic/prettier-config": "~1.0.1",
@@ -79,5 +79,5 @@
79
79
  "publishConfig": {
80
80
  "access": "public"
81
81
  },
82
- "gitHead": "c44bf164b01d5f5ed405695f06efd36a881c4272"
82
+ "gitHead": "d5483ce9f666f1a38c25a11e63899fd35701ca45"
83
83
  }