Skip to content

Commit

Permalink
feat(app/capacitor): upgrade to capacitor 2.0, fixes #5823 (#6808)
Browse files Browse the repository at this point in the history
* feat(app/capacitor): upgrade to capacitor 2.0

* fix(app/capacitor): fix https ssl enable

* fix(app/capacitor): https with non-default app ID

Co-authored-by: Razvan Stoenescu <[email protected]>
  • Loading branch information
nklayman and rstoenescu authored Jun 4, 2020
1 parent e4f4534 commit 7366b85
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 11 deletions.
29 changes: 20 additions & 9 deletions app/lib/capacitor/capacitor-config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const fs = require('fs')
const path = require('path')
const fg = require('fast-glob')

const appPaths = require('../app-paths')
const { log, warn } = require('../helpers/logger')
Expand Down Expand Up @@ -185,18 +186,26 @@ class CapacitorConfig {
}

__handleSSLonAndroid (add) {
const mainActivityPath = appPaths.resolve.capacitor(
'android/app/src/main/java/org/cordova/quasar/app/MainActivity.java'
)
const enableHttpsSelfSignedPath = appPaths.resolve.capacitor(
'android/app/src/main/java/org/cordova/quasar/app/EnableHttpsSelfSigned.java'
const capacitorSrcPath = appPaths.resolve.capacitor(
'android/app/src/main/java'
)
let mainActivityPath = fg.sync(`**/MainActivity.java`, { cwd: capacitorSrcPath, absolute: true })
if (mainActivityPath.length > 0) {
if (mainActivityPath.length > 1) {
warn(`Found multiple matches for MainActivity.java file, https might not work. Using file ${mainActivityPath[0]}.`)
}
mainActivityPath = mainActivityPath[0]
} else if (mainActivityPath.length === 0) {
warn('Could not find MainActivity.java file and therefore cannot enable https support.')
process.exit(1)
}
const enableHttpsSelfSignedPath = path.join(path.dirname(mainActivityPath), 'EnableHttpsSelfSigned.java')
if (fs.existsSync(mainActivityPath)) {
let mainActivity = fs.readFileSync(mainActivityPath, 'utf8')

const sslString = `
if (BuildConfig.DEBUG) {
EnableHttpsSelfSigned.enable(findViewById(R.id.webview));
EnableHttpsSelfSigned.enable(this.bridge);
}
`

Expand All @@ -221,10 +230,12 @@ package ${appId};
import android.net.http.SslError;
import android.webkit.SslErrorHandler;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import com.getcapacitor.Bridge;
import com.getcapacitor.BridgeWebViewClient;
public class EnableHttpsSelfSigned {
public static void enable(WebView webview) {
webview.setWebViewClient(new WebViewClient() {
public static void enable(Bridge bridge) {
bridge.getWebView().setWebViewClient(new BridgeWebViewClient(bridge) {
@Override
public void onReceivedSslError(WebView view, final SslErrorHandler handler, SslError error) {
handler.proceed();
Expand Down
4 changes: 2 additions & 2 deletions app/templates/capacitor/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<% if (pkg.author) { %> "author": <%= JSON.stringify(pkg.author) %>,<% } %>
"private": true,
"dependencies": {
"@capacitor/cli": "^1.0.0",
"@capacitor/core": "^1.0.0"
"@capacitor/cli": "^2.0.0",
"@capacitor/core": "^2.0.0"
}
}

0 comments on commit 7366b85

Please sign in to comment.