Skip to content

Commit

Permalink
Merge pull request #44 from capacitor-community/dev-electron
Browse files Browse the repository at this point in the history
Dev electron
  • Loading branch information
jepiqueau authored Sep 29, 2020
2 parents faea058 + c1fb19c commit 6ac509b
Show file tree
Hide file tree
Showing 49 changed files with 1,196 additions and 6,838 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
## 2.4.2-1 (2020-09-29)

### Chores

- Capacitor: update 2.4.2

### ### Added Features

- The electron plugin is now compatible with @capacitor-community/electron

## 2.4.1-1 (2020-09-22)

### Bug Fixes
Expand Down
171 changes: 64 additions & 107 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,128 +28,85 @@
```bash
npm install @capacitor-community/sqlite
npx cap sync
npx cap add ios
npx cap add android
npx cap add @capacitor-community/electron
```

### iOS

- On iOS, no further steps are needed.

### Android

- On Android, register the plugin in your main activity:

```java
import com.getcapacitor.community.database.sqlite.CapacitorSQLite;
```java
import com.getcapacitor.community.database.sqlite.CapacitorSQLite;

public class MainActivity extends BridgeActivity {
public class MainActivity extends BridgeActivity {

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

// Initializes the Bridge
this.init(
savedInstanceState,
new ArrayList<Class<? extends Plugin>>() {
// Initializes the Bridge
this.init(
savedInstanceState,
new ArrayList<Class<? extends Plugin>>() {

{
// Additional plugins you've installed go here
// Ex: add(TotallyAwesomePlugin.class);
add(CapacitorSQLite.class);
}
{
// Additional plugins you've installed go here
// Ex: add(TotallyAwesomePlugin.class);
add(CapacitorSQLite.class);
}
);
}
}
);
}
```
}

```

### Electron

- On Electron, go to the Electron folder of YOUR_APPLICATION

```bash
npm install --save sqlite3
npm install --save-dev @types/sqlite3
npm install --save-dev electron-rebuild
```

Modify the Electron package.json file by adding a script "postinstall"

```json
"scripts": {
"electron:start": "electron ./",
"postinstall": "electron-rebuild -f -w sqlite3"
},
```

Execute the postinstall script

```bash
npm run postinstall
```

Go back in the main folder of your application
Add a script in the index.html file of your application in the body tag

- case databases under `YourApplication/Electron/`

```html
<body>
<app-root></app-root>
<script>
try {
if (
process &&
typeof process.versions.electron === 'string' &&
process.versions.hasOwnProperty('electron')
) {
const sqlite3 = require('sqlite3');
const fs = require('fs');
const path = require('path');
window.sqlite3 = sqlite3;
window.fs = fs;
window.path = path;
}
} catch {
console.log("process doesn't exists");
}
</script>
</body>
```

- case databases under `User/Databases/APP_NAME/`

```html
<body>
<app-root></app-root>
<script>
try {
if (
process &&
typeof process.versions.electron === 'string' &&
process.versions.hasOwnProperty('electron')
) {
const sqlite3 = require('sqlite3');
const fs = require('fs');
const path = require('path');
const homeDir = require('os').homedir();
window.sqlite3 = sqlite3;
window.fs = fs;
window.path = path;
window.appName = 'YOUR_APP_NAME';
window.homeDir = homeDir;
}
} catch {
console.log("process doesn't exists");
}
</script>
</body>
```

Then build YOUR_APPLICATION

```
npm run build
npx cap copy
npx cap copy web
npx cap open android
npx cap open ios
npx cap open electron
```
```bash
npm install --save sqlite3
npm install --save-dev @types/sqlite3
npm install --save-dev electron-rebuild
```

Modify the Electron package.json file by adding a script "postinstall"

```json
"scripts": {
"electron:start": "electron ./",
"postinstall": "electron-rebuild -f -w sqlite3"
},
```

Execute the postinstall script

```bash
npm run postinstall
```

#### Electron databases location

- There are by default under `User/Databases/APP_NAME/`

Then build YOUR_APPLICATION

```
npm run build
npx cap copy
npx cap copy @capacitor-community/electron
npx cap copy web
npx cap open android
npx cap open ios
npx cap open @capacitor-community/electron
```

## Configuration

Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

Binary file not shown.

This file was deleted.

Empty file.
Binary file not shown.
Loading

0 comments on commit 6ac509b

Please sign in to comment.