Skip to content

Commit

Permalink
Update to @capacitor/[email protected]
Browse files Browse the repository at this point in the history
  • Loading branch information
jepiqueau committed Oct 5, 2023
1 parent 7cbf54b commit c9a2687
Show file tree
Hide file tree
Showing 10 changed files with 83 additions and 573 deletions.
16 changes: 16 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
# 5.4.0 (2023-10-05)

### Chore

- Update to @capacitor/core@5.4.0
- Update to @capacitor/ios@5.4.0
- Update to @capacitor/android@5.4.0

### Added Features

- Add Electron decryptDatabase method

### Bug Fixes

- Fix Electron setEncryptSecret

# 5.2.5 (2023-09-28)

### Bug Fixes
Expand Down
12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -182,10 +182,20 @@ npm install --save crypto-js
npm install --save-dev @types/better-sqlite3
npm install --save-dev @types/electron-json-storage
npm install --save-dev @types/crypto-js
npm install --save-dev [email protected]
```
- **Important**: `node-fetch` version must be `<=2.6.7`; otherwise [you'll get an error](https://github.com/capacitor-community/sqlite/issues/349 "you'll get an error ERR_REQUIRE_ESM") running the app.

- **Important**: if you are using `@capacitor-community/electron v5`
- you have to stick to [email protected] till further notice so do:
```bash
npm install --save-dev [email protected]
npm uninstall --save-dev electron-rebuild
npm install --save-dev @electron/rebuild
npm install --save-dev [email protected]
```
- in electron folder open the `tsconfig.json` file and add `"skipLibCheck": true,`


## IOS Quirks

- on iOS, no further steps needed.
Expand Down
Binary file modified android/.gradle/buildOutputCleanup/buildOutputCleanup.lock
Binary file not shown.
7 changes: 6 additions & 1 deletion electron/src/electron-utils/Database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ export class Database {
try {
if (
this._encrypted &&
(this._mode === 'secret' || this._mode === 'encryption')
(this._mode === 'secret' || this._mode === 'encryption'
|| this._mode === 'decryption')
) {
password = this.secretUtil.getPassphrase();

Expand All @@ -99,6 +100,10 @@ export class Database {
if (this._mode === 'encryption') {
await this.encryptionUtil.encryptDatabase(this.pathDB, password);
}
if (this._mode === 'decryption') {
await this.encryptionUtil.decryptDatabase(this.pathDB, password);
password = ""
}
this.database = this.sqliteUtil.openOrCreateDatabase(
this.pathDB,
password,
Expand Down
25 changes: 25 additions & 0 deletions electron/src/electron-utils/utilsEncryption.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,29 @@ export class UtilsEncryption {
);
}
}
public async decryptDatabase(
pathDB: string,
password: string,
): Promise<void> {
const msg = 'DecryptDatabase: ';
const retB: boolean = this.fileUtil.isPathExists(pathDB);
if (retB) {
try {
const mDB = await this.sqliteUtil.openOrCreateDatabase(
pathDB,
password,
false,
);
this.sqliteUtil.pragmaReKey(mDB, password, '');
this.sqliteUtil.closeDB(mDB);
return Promise.resolve();
} catch (err) {
return Promise.reject(new Error(`${msg} ${err.message} `));
}
} else {
return Promise.reject(
new Error(`${msg}file path ${pathDB} ` + 'does not exist'),
);
}
}
}
2 changes: 1 addition & 1 deletion electron/src/electron-utils/utilsSecret.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ export class UtilsSecret {
}
public isSecretStored(): boolean {
const secret = this.getPassphrase();

if (secret.length <= 0) return false;
return true;
}
Expand All @@ -42,6 +41,7 @@ export class UtilsSecret {
if (error) throw new Error(`setEncryptSecret: ${error.message}`);
},
);
return;
});
}
} catch (err) {
Expand Down
2 changes: 2 additions & 0 deletions electron/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ export class CapacitorSQLite implements CapacitorSQLitePlugin {
? 'secret'
: encrypted && options.mode === 'encryption'
? 'encryption'
: encrypted && options.mode === 'decryption'
? 'decryption'
: 'no-encryption';
if (!this.isEncryption) {
encrypted = false;
Expand Down
Loading

0 comments on commit c9a2687

Please sign in to comment.