Skip to content
This repository was archived by the owner on Aug 6, 2023. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
4f3f53c
Motivation and implementation plan
fkirc Mar 20, 2021
0b4178f
Android: Pass urlPath to BridgeFragment
fkirc Mar 20, 2021
f98ee4d
Android: Skip registration of unneeded plugins to improve performance…
fkirc Mar 20, 2021
6691148
Fix Android-crashes related to LocalNotificationRestoreReceiver inten…
fkirc Mar 20, 2021
c01388a
Reduce AndroidManifest.xml to a minimum; removing unnecessary permiss…
fkirc Mar 20, 2021
1e5b45d
Document Android usage
fkirc Mar 20, 2021
fd59b5d
Cleanup
fkirc Mar 20, 2021
9528e4c
iOS: Open CAPBridgeViewController for subclassing
fkirc Mar 20, 2021
95210f0
Fix GitHub refs
fkirc Mar 20, 2021
b1614ab
iOS: Add setUrlPath function to CAPBridgeViewController.swift
fkirc Mar 20, 2021
c5af029
publish iOS
fkirc Mar 20, 2021
0f674c9
Remove iOS splashscreen by default
fkirc Mar 20, 2021
7eeb05c
Android: Only disable splash screen plugin by default
fkirc Mar 20, 2021
60ed753
Update docs
fkirc Mar 20, 2021
738cf01
Show diff
fkirc Mar 20, 2021
95e763b
Doc cleanup
fkirc Mar 20, 2021
33a7541
Simplify README
fkirc Mar 20, 2021
10b9a62
diff cleanup
fkirc Mar 20, 2021
a10ce52
Reduce diff
fkirc Mar 20, 2021
c86bef6
Reduce diff
fkirc Mar 20, 2021
2a257b3
reduce diff
fkirc Mar 20, 2021
d165baa
Reduce deprecation
fkirc Mar 20, 2021
279739a
symlinks
fkirc Mar 20, 2021
4c52e42
Re-publish iOS
fkirc Mar 20, 2021
aeea90f
Re-publish Android
fkirc Mar 20, 2021
173a758
Typo
fkirc Mar 20, 2021
81ef4bf
Recommend postinstall script
fkirc Mar 20, 2021
480583c
Cleanup
fkirc Mar 20, 2021
21e189d
recommend capsafe
fkirc Mar 20, 2021
b0d0d09
disable workflows
fkirc Mar 20, 2021
8c09bfd
Document Android crashes
fkirc Mar 20, 2021
79df04f
fix of capacitor-cordova-android-plugin build.gradle as implemented w…
maierhjakob Aug 9, 2021
0d75391
Merge pull request #3 from maierhjakob/master
fkirc Aug 9, 2021
2574720
Deprecation Notice
fkirc Oct 14, 2021
a4af3e1
in favor of
fkirc Mar 3, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 88 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,91 @@
# Deprecation Notice

This package is deprecated in favor of https://ionic.io/portals.
"Portals" provides a better dev-experience and is actively supported by Ionic and newer Capacitor-versions.
__________

# Embedded Capacitor

This project enables an "embedded usage" of https://capacitorjs.com/ within existing native apps.
It exists because of the following frustrating situation:

- Capacitor 2.X provides only bad support for "embedded usage", but promised to deliver with Capacitor 3.X [[3405](https://github.com/ionic-team/capacitor/pull/3405)]
- Capacitor 3.X deliberately destroyed "embedded usage", but promised to deliver an embedded closed-source-solution [[4343](https://github.com/ionic-team/capacitor/issues/4343), [4370](https://github.com/ionic-team/capacitor/issues/4370)]

For the time being, I consider Capacitor 2.X as more stable for embedded usage.
Therefore, this project only works with Capacitor 2.X.

## Improvements over Ionic's Capacitor

With only minimal changes, this project provides the following improvements over Ionic's Capacitor 2.X:

- Configure custom URL-paths for Android/iOS: [3405](https://github.com/ionic-team/capacitor/pull/3405), [3106](https://github.com/ionic-team/capacitor/issues/3106)
- Make iOS `CAPBridgeViewController` extensible to better support embedded usage: [1972](https://github.com/ionic-team/capacitor/pull/1972)
- Fix Android-crashes related to unneeded plugins: [4379](https://github.com/ionic-team/capacitor/issues/4379)
- Disable splashscreen-plugin by default to speedup launches (you can still enable it).

To convince yourself, here are the differences between this project and Ionic's Capacitor: https://github.com/fkirc/embedded-capacitor/pull/1/files

## Installation

Before you install this project, ensure that regular Capacitor 2.X is working with your project (e.g. it should work in "fullscreen-mode").
Once you finished a regular Capacitor 2.X setup, replace your `@capacitor/android` or `@capacitor/ios` packages as follows:

`npm uninstall @capacitor/android`
`npm install capacitor-embedded-android`

`npm uninstall @capacitor/ios`
`npm install capacitor-embedded-ios`

Next, create symlinks from the original package-locations to the new package-locations:

`ln -s "$PWD/node_modules/capacitor-embedded-android/" node_modules/@capacitor/android`
`ln -s "$PWD/node_modules/capacitor-embedded-ios/" node_modules/@capacitor/ios`

Those symlinks need to be created every time when `node_modules` is created.
Therefore, I recommend adding a `postinstall`-script to your `package.json`:

````
"scripts": {
"postinstall": "ln -s \"$PWD/node_modules/capacitor-embedded-android/\" node_modules/@capacitor/android && ln -s \"$PWD/node_modules/capacitor-embedded-ios/\" node_modules/@capacitor/ios"
},
````

Optionally, I recommend the [capsafe](https://github.com/fkirc/capacitor-build-safety) tool to increase safety and traceability of your Capacitor-apps.

Finally, follow the Android/iOS-specific instructions below.

### Embedded Android

For Android, I recommend to subclass `BridgeFragment` for embedded usage:

````Kotlin
import android.os.Bundle
import com.getcapacitor.BridgeFragment

class MyBridgeFragment : BridgeFragment() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
super.setUrlPath("/#embedded_feature_1") // Set an URL-path for your embedded usage
}
}
````

### Embedded iOS

For iOS, I recommend to subclass `CAPBridgeViewController` for embedded usage:

````Swift
public class MyCAPBridgeViewController: CAPBridgeViewController {
public override func loadView() {
super.setUrlPath(path: "/#embedded_feature_1") // Set an URL-path for your embedded usage
super.loadView()
}
}
````

---

<br />
<p align="center">
<img src="https://user-images.githubusercontent.com/236501/83809024-9da80580-a66a-11ea-8a1d-090fe6f8b01e.png" width="372" height="70" /><br />
Expand Down
24 changes: 0 additions & 24 deletions android/capacitor/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,28 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.getcapacitor.android">
<uses-feature android:name="android.hardware.camera"
android:required="false" />

<application>
<service android:name="com.getcapacitor.plugin.background.BackgroundTaskService" android:exported="false" />
<receiver android:name="com.getcapacitor.plugin.notification.TimedNotificationPublisher" />
<receiver android:name="com.getcapacitor.plugin.notification.NotificationDismissReceiver" />
<meta-data android:name="firebase_messaging_auto_init_enabled" android:value="false" />
<service android:name="com.getcapacitor.CapacitorFirebaseMessagingService" android:stopWithTask="false">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
<receiver android:name="com.getcapacitor.plugin.notification.LocalNotificationRestoreReceiver" android:directBootAware="true" android:exported="false">
<intent-filter>
<action android:name="android.intent.action.LOCKED_BOOT_COMPLETED"/>
<action android:name="android.intent.action.BOOT_COMPLETED"/>
<action android:name="android.intent.action.QUICKBOOT_POWERON" />
</intent-filter>
</receiver>
</application>

<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<uses-permission android:name="android.permission.WAKE_LOCK"/>
</manifest>
11 changes: 7 additions & 4 deletions android/capacitor/src/main/java/com/getcapacitor/Bridge.java
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ public class Bridge {
* @param context
* @param webView
*/
public Bridge(Activity context, WebView webView, List<Class<? extends Plugin>> initialPlugins, CordovaInterfaceImpl cordovaInterface, PluginManager pluginManager, CordovaPreferences preferences, JSONObject config) {
public Bridge(Activity context, WebView webView, List<Class<? extends Plugin>> initialPlugins, CordovaInterfaceImpl cordovaInterface, PluginManager pluginManager, CordovaPreferences preferences, JSONObject config, String urlPath) {
this.context = context;
this.webView = webView;
this.webViewClient = new BridgeWebViewClient(this);
Expand Down Expand Up @@ -169,10 +169,10 @@ public Bridge(Activity context, WebView webView, List<Class<? extends Plugin>> i
// Register our core plugins
this.registerAllPlugins();

this.loadWebView();
this.loadWebView(urlPath);
}

private void loadWebView() {
private void loadWebView(String urlPath) {
appUrlConfig = this.getServerUrl();
String[] appAllowNavigationConfig = this.config.getArray("server.allowNavigation");

Expand Down Expand Up @@ -207,6 +207,9 @@ private void loadWebView() {
appUrl += "/";
}
}
if (urlPath != null) {
appUrl += urlPath;
}

final boolean html5mode = this.config.getBoolean("server.html5mode", true);

Expand Down Expand Up @@ -430,7 +433,7 @@ private void registerAllPlugins() {
this.registerPlugin(Photos.class);
this.registerPlugin(PushNotifications.class);
this.registerPlugin(Share.class);
this.registerPlugin(SplashScreen.class);
//this.registerPlugin(SplashScreen.class);
this.registerPlugin(StatusBar.class);
this.registerPlugin(Storage.class);
this.registerPlugin(com.getcapacitor.plugin.Toast.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ protected void load(Bundle savedInstanceState) {

pluginManager = mockWebView.getPluginManager();
cordovaInterface.onCordovaInit(pluginManager);
bridge = new Bridge(this, webView, initialPlugins, cordovaInterface, pluginManager, preferences, this.config);
bridge = new Bridge(this, webView, initialPlugins, cordovaInterface, pluginManager, preferences, this.config, null);

if (savedInstanceState != null) {
bridge.restoreInstanceState(savedInstanceState);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ public BridgeFragment() {
// Required empty public constructor
}

private String urlPath;
public void setUrlPath(String urlPath) {
this.urlPath = urlPath;
}

/**
* Use this factory method to create a new instance of
* this fragment using the provided parameters.
Expand Down Expand Up @@ -72,7 +77,7 @@ public void addPlugin(Class<? extends Plugin> plugin) {
* Load the WebView and create the Bridge
*/
protected void load(Bundle savedInstanceState) {
Logger.debug("Starting BridgeActivity");
Logger.debug("Starting BridgeFragment");

Bundle args = getArguments();
String startDir = null;
Expand All @@ -97,7 +102,7 @@ protected void load(Bundle savedInstanceState) {
preferences = new CordovaPreferences();
}

bridge = new Bridge(this.getActivity(), webView, initialPlugins, cordovaInterface, pluginManager, preferences, config);
bridge = new Bridge(this.getActivity(), webView, initialPlugins, cordovaInterface, pluginManager, preferences, config, urlPath);

if (startDir != null) {
bridge.setServerAssetPath(startDir);
Expand Down
4 changes: 2 additions & 2 deletions android/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@capacitor/android",
"version": "2.4.7",
"name": "capacitor-embedded-android",
"version": "2.4.7-1",
"description": "Capacitor: cross-platform mobile apps with the web",
"homepage": "https://capacitor.ionicframework.com/",
"author": "Ionic Team <hi@ionic.io> (https://ionicframework.com) ",
Expand Down
2 changes: 1 addition & 1 deletion capacitor-cordova-android-plugins/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ android {
compileSdkVersion project.hasProperty('compileSdkVersion') ? rootProject.ext.compileSdkVersion : 29
defaultConfig {
minSdkVersion project.hasProperty('minSdkVersion') ? rootProject.ext.minSdkVersion : 21
targetSdkVersion targetSdkVersion = project.hasProperty('targetSdkVersion') ? rootProject.ext.targetSdkVersion : 29
targetSdkVersion project.hasProperty('targetSdkVersion') ? rootProject.ext.targetSdkVersion : 29
versionCode 1
versionName "1.0"
}
Expand Down
Loading