Skip to content

Commit

Permalink
update to capacitor2.4.2
Browse files Browse the repository at this point in the history
  • Loading branch information
jepiqueau committed Sep 29, 2020
1 parent a356801 commit c1fb19c
Show file tree
Hide file tree
Showing 10 changed files with 675 additions and 843 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
61 changes: 2 additions & 59 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ public class MainActivity extends BridgeActivity {
);
}
}

```

### Electron
Expand Down Expand Up @@ -95,70 +96,12 @@ npm run postinstall

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

- If you wish to have then under `YourApplication/Electron/`
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 @capacitor-community/electron
npx cap copy web
npx cap open android
npx cap open ios
Expand Down
Binary file modified android/.idea/caches/build_file_checksums.ser
Binary file not shown.
51 changes: 15 additions & 36 deletions android/.idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 4 additions & 13 deletions electron/src/electron-utils/UtilsSQLite.ts
Original file line number Diff line number Diff line change
@@ -1,32 +1,24 @@
/*const sqlite3: any = window['sqlite3' as any];
const fs: any = window['fs' as any];
const path: any = window['path' as any];
const appName: any = window['appName' as any];
const homeDir = window['homeDir' as any];
*/

export class UtilsSQLite {
public pathDB: string = 'Databases';
Path: any = null;
NodeFs: any = null;
RemoteRef: any = null;
Os: any = null;
SQLite3: any = null;
AppName: any = null;
HomeDir: any = null;
AppName: String = null;
HomeDir: String = null;

constructor() {
this.Path = require('path');
this.NodeFs = require('fs');
this.Os = require('os');
this.SQLite3 = require('sqlite3');
this.HomeDir = this.Os.homedir;
this.HomeDir = this.Os.homedir();
/**
* !!! in case you want your databases to be stored in YourApplication/Electron/
* comment the below line
*/

this.AppName = require(__dirname + '/package.json').name;
this.AppName = require('../../package.json').name;
}
public connection(dbName: string, readOnly?: boolean /*,key?:string*/): any {
const flags = readOnly
Expand Down Expand Up @@ -101,7 +93,6 @@ export class UtilsSQLite {
retPath = '';
}
}

return retPath;
}
private _createFolderIfNotExists(folder: string): boolean {
Expand Down
19 changes: 10 additions & 9 deletions electron/src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,32 @@ import { WebPlugin } from '@capacitor/core';
import {
CapacitorSQLitePlugin,
capSQLiteOptions,
capSQLiteResult /*, jsonSQLite*/,
capSQLiteResult,
} from './definitions';
import { DatabaseSQLiteHelper } from './electron-utils/DatabaseSQLiteHelper';
import { isJsonSQLite } from './electron-utils/JsonUtils';
import { UtilsSQLite } from './electron-utils/UtilsSQLite';

const { remote } = require('electron');

export class CapacitorSQLitePluginElectron extends WebPlugin
export class CapacitorSQLiteElectronWeb
extends WebPlugin
implements CapacitorSQLitePlugin {
NodeFs: any = null;
RemoteRef: any = null;
private mDb!: DatabaseSQLiteHelper;

constructor() {
super({
name: 'CapacitorSQLite',
platforms: ['electron'],
});
console.log('CapacitorSQLite Electron');
this.RemoteRef = remote;
this.NodeFs = require('fs');
}
async echo(options: { value: string }): Promise<{ value: string }> {
console.log('this.RemoteRef ' + this.RemoteRef);
console.log('ECHO in CapacitorSQLiteElectronWeb ', options);
console.log(this.RemoteRef);
return options;
}
async open(options: capSQLiteOptions): Promise<capSQLiteResult> {
Expand Down Expand Up @@ -294,9 +297,7 @@ export class CapacitorSQLitePluginElectron extends WebPlugin
return Promise.resolve({ result: ret });
}
}

const CapacitorSQLiteElectron = new CapacitorSQLitePluginElectron();

export { CapacitorSQLiteElectron };
const CapacitorSQLite = new CapacitorSQLiteElectronWeb();
export { CapacitorSQLite };
import { registerWebPlugin } from '@capacitor/core';
registerWebPlugin(CapacitorSQLiteElectron);
registerWebPlugin(CapacitorSQLite);
Loading

0 comments on commit c1fb19c

Please sign in to comment.