Skip to content

Commit

Permalink
feat(app-vite/app-webpack): Add Capacitor 4 support (#14226)
Browse files Browse the repository at this point in the history
Co-authored-by: Razvan Stoenescu <razvan.stoenescu@gmail.com>
  • Loading branch information
jcesarmobile and rstoenescu authored May 8, 2023
1 parent 19f666e commit 6505221
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 20 deletions.
2 changes: 1 addition & 1 deletion app-vite/lib/modes/capacitor/capacitor-installation.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ function addPlatform (target) {

if (capVersion >= 3) {
nodePackager.installPackage(
`@capacitor/${ target }@^${ capVersion }.0.0-beta.0`,
`@capacitor/${target}@^${capVersion}.0.0`,
{ displayName: 'Capacitor platform', cwd: appPaths.capacitorDir }
)
}
Expand Down
37 changes: 30 additions & 7 deletions app-vite/lib/modes/capacitor/config-file.js
Original file line number Diff line number Diff line change
Expand Up @@ -262,13 +262,36 @@ class CapacitorConfigFile {

if (add) {
// Allow unsigned certificates in MainActivity
if (!/EnableHttpsSelfSigned\.enable/.test(mainActivity)) {
mainActivity = mainActivity.replace(
/this\.init\(.*}}\);/ms,
match => `${ match }
${ sslString }
`
)
if (capVersion >= 4) {
if (!/super\.onCreate/.test(mainActivity)) {
mainActivity = mainActivity.replace('{}',
`{
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
}`
);
mainActivity = mainActivity.replace('import com.getcapacitor.BridgeActivity;',
`import android.os.Bundle;
import com.getcapacitor.BridgeActivity;`);
}
if (!/EnableHttpsSelfSigned\.enable/.test(mainActivity)) {
mainActivity = mainActivity.replace(
/super\.onCreate\(.*\);/ms,
match => `${match}
${sslString}`
)
}
} else {
if (!/EnableHttpsSelfSigned\.enable/.test(mainActivity)) {
mainActivity = mainActivity.replace(
/this\.init\(.*}}\);/ms,
match => `${match}
${sslString}
`
)
}
}

// Add helper file
Expand Down
37 changes: 30 additions & 7 deletions app-webpack/lib/capacitor/capacitor-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -256,13 +256,36 @@ class CapacitorConfig {

if (add) {
// Allow unsigned certificates in MainActivity
if (!/EnableHttpsSelfSigned\.enable/.test(mainActivity)) {
mainActivity = mainActivity.replace(
/this\.init\(.*}}\);/ms,
match => `${ match }
${ sslString }
`
)
if (capVersion >= 4) {
if (!/super\.onCreate/.test(mainActivity)) {
mainActivity = mainActivity.replace('{}',
`{
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
}`
);
mainActivity = mainActivity.replace('import com.getcapacitor.BridgeActivity;',
`import android.os.Bundle;
import com.getcapacitor.BridgeActivity;`);
}
if (!/EnableHttpsSelfSigned\.enable/.test(mainActivity)) {
mainActivity = mainActivity.replace(
/super\.onCreate\(.*\);/ms,
match => `${match}
${sslString}`
)
}
} else {
if (!/EnableHttpsSelfSigned\.enable/.test(mainActivity)) {
mainActivity = mainActivity.replace(
/this\.init\(.*}}\);/ms,
match => `${match}
${sslString}
`
)
}
}

// Add helper file
Expand Down
2 changes: 1 addition & 1 deletion app-webpack/lib/mode/mode-capacitor.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ class Mode {

if (capVersion >= 3) {
nodePackager.installPackage(
`@capacitor/${ target }@^${ capVersion }.0.0-beta.0`,
`@capacitor/${target}@^${capVersion}.0.0`,
{ displayName: 'Capacitor platform', cwd: appPaths.capacitorDir }
)
}
Expand Down
6 changes: 4 additions & 2 deletions app-webpack/templates/capacitor/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
<% if (pkg.author) { %> "author": <%= JSON.stringify(pkg.author) %>,<% } %>
"private": true,
"dependencies": {
"@capacitor/cli": "^2.0.0",
"@capacitor/core": "^2.0.0"
"@capacitor/app": "^4.0.0",
"@capacitor/cli": "^4.0.0",
"@capacitor/core": "^4.0.0",
"@capacitor/splash-screen": "^4.0.0"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ title: Capacitor versions
desc: (@quasar/app-vite) Supported Capacitor versions in Quasar. How to upgrade to a newer Capacitor version.
---

The officially supported versions of Capacitor are v1, v2 and v3.
The officially supported versions of Capacitor are v1, v2, v3 and v4.

## Upgrading Capacitor

Expand All @@ -16,10 +16,25 @@ If you previously used a lower version of Capacitor and you want to upgrade to a

It would also be wise to check the changelog of Capacitor itself to see what breaking changes it has.

## Capacitor v4

Assuming that you've installed Capacitor mode already, this is how your dependencies in /src-capacitor/package.json should look like:

```
dependencies: {
"@capacitor/app": "^4.0.0",
"@capacitor/cli": "^4.0.0",
"@capacitor/core": "^4.0.0",
"@capacitor/splash-screen": "^4.0.0"
}
```

The `@capacitor/app` and `@capacitor/splash-screen` are optional, but it helps Quasar with some UI functionality if they are installed.

## Capacitor v3

::: warning Known issue
HTTPS devserver (through quasar.config.js > devServer > https: true) is not **yet** supported. If you are using Capacitor plugins that depend on it, it's better to stay with Capacitor v2 for the moment.
HTTPS devserver (through quasar.config.js > devServer > https: true) is not **yet** supported. If you are using Capacitor plugins that depend on it, it's better to upgrade to Capacitor v4.
:::

Assuming that you've installed Capacitor mode already, this is how your dependencies in /src-capacitor/package.json should look like:
Expand Down

0 comments on commit 6505221

Please sign in to comment.