@capacitor-community/sqlite 3.4.1-2 → 3.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -28,10 +28,35 @@
28
28
 
29
29
  ## CAPACITOR 3 (Master)
30
30
 
31
+ 🚨 Since release 3.4.1 ->> 🚨
32
+ Databases location for Electron can be set in `the config.config.ts` as followed:
33
+ plugins: {
34
+ CapacitorSQLite: {
35
+ electronMacLocation: "/YOUR_DATABASES_PATH",
36
+ electronWindowsLocation: "C:\\ProgramData\\CapacitorDatabases",
37
+ electronLinuxLocation: "/home/CapacitorDatabases"
38
+ }
39
+ }
40
+ For existing databases, YOU MUST COPY old databases to the new location
41
+ You MUST remove the Electron folder and add it again with
42
+ ```
43
+ npx cap add @capacitor-community/electron
44
+ npm run build
45
+ cd electron
46
+ npm i --save sqlite3
47
+ npm i --save @types:sqlite3
48
+ npm run rebuild
49
+ cd ..
50
+ npx cap sync @capacitor-community/electron
51
+ npm run build
52
+ npx cap copy @capacitor-community/electron
53
+ npx cap open @capacitor-community/electron
54
+ 🚨 Since release 3.4.1 <<- 🚨
55
+
31
56
  🚨 Since release 3.4.1-1 ->> 🚨
32
57
 
33
58
  - add iosIsEncryption, androidIsEncryption in capacitor.config.ts
34
- When your application use only `non-encrypted dzatabases` set those parameter to false then iOS KeyChain & Android MasterKey are not defined.
59
+ When your application use only `non-encrypted databases` set those parameter to false then iOS KeyChain & Android MasterKey are not defined.
35
60
 
36
61
  🚨 Since release 3.4.1-1 <<- 🚨
37
62
 
@@ -29,6 +29,7 @@ import java.io.IOException;
29
29
  import java.nio.charset.Charset;
30
30
  import java.nio.charset.StandardCharsets;
31
31
  import java.security.GeneralSecurityException;
32
+ import java.security.KeyStore;
32
33
  import java.util.ArrayList;
33
34
  import java.util.Arrays;
34
35
  import java.util.Collections;
@@ -63,7 +64,7 @@ public class CapacitorSQLite {
63
64
  private Boolean biometricAuth = false;
64
65
  private String biometricTitle;
65
66
  private String biometricSubTitle;
66
- private int VALIDITY_DURATION = 1;
67
+ private int VALIDITY_DURATION = 5;
67
68
  private RetHandler rHandler = new RetHandler();
68
69
  private PluginCall call;
69
70
 
@@ -86,11 +87,18 @@ public class CapacitorSQLite {
86
87
  @Override
87
88
  public void onSuccess(BiometricPrompt.AuthenticationResult result) {
88
89
  try {
89
- masterKeyAlias =
90
- new MasterKey.Builder(context)
91
- .setKeyScheme(MasterKey.KeyScheme.AES256_GCM)
92
- .setUserAuthenticationRequired(true, VALIDITY_DURATION)
93
- .build();
90
+ KeyStore ks = KeyStore.getInstance("AndroidKeyStore");
91
+ ks.load(null);
92
+ Enumeration<String> aliases = ks.aliases();
93
+ if (aliases.hasMoreElements()) {
94
+ masterKeyAlias =
95
+ new MasterKey.Builder(context)
96
+ .setKeyScheme(MasterKey.KeyScheme.AES256_GCM)
97
+ .setUserAuthenticationRequired(true, VALIDITY_DURATION)
98
+ .build();
99
+ } else {
100
+ masterKeyAlias = new MasterKey.Builder(context).setKeyScheme(MasterKey.KeyScheme.AES256_GCM).build();
101
+ }
94
102
  setSharedPreferences();
95
103
  notifyBiometricEvent(true, null);
96
104
  return;
@@ -7,6 +7,7 @@ var require$$0$1 = require('path');
7
7
  var require$$1 = require('fs');
8
8
  var require$$2 = require('os');
9
9
  var require$$3 = require('jszip');
10
+ var require$$4 = require('electron');
10
11
 
11
12
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
12
13
 
@@ -15,6 +16,7 @@ var require$$0__default$1 = /*#__PURE__*/_interopDefaultLegacy(require$$0$1);
15
16
  var require$$1__default = /*#__PURE__*/_interopDefaultLegacy(require$$1);
16
17
  var require$$2__default = /*#__PURE__*/_interopDefaultLegacy(require$$2);
17
18
  var require$$3__default = /*#__PURE__*/_interopDefaultLegacy(require$$3);
19
+ var require$$4__default = /*#__PURE__*/_interopDefaultLegacy(require$$4);
18
20
 
19
21
  var src = {};
20
22
 
@@ -2159,6 +2161,7 @@ class UtilsFile {
2159
2161
  this.NodeFs = null;
2160
2162
  this.JSZip = null;
2161
2163
  this.Os = null;
2164
+ this.Electron = null;
2162
2165
  this.AppName = '';
2163
2166
  this.HomeDir = '';
2164
2167
  this.sep = '/';
@@ -2166,15 +2169,38 @@ class UtilsFile {
2166
2169
  this.NodeFs = require$$1__default['default'];
2167
2170
  this.Os = require$$2__default['default'];
2168
2171
  this.JSZip = require$$3__default['default'];
2172
+ this.Electron = require$$4__default['default'];
2169
2173
  this.HomeDir = this.Os.homedir();
2170
2174
  const dir = __dirname;
2171
2175
  const idx = dir.indexOf('\\');
2172
2176
  if (idx != -1)
2173
2177
  this.sep = '\\';
2174
- this.appPath = dir.substring(0, dir.indexOf(`electron${this.sep}`) /* + 8*/);
2178
+ this.appPath = this.Electron.app.getAppPath();
2175
2179
  const rawdata = this.NodeFs.readFileSync(this.Path.resolve(this.appPath, 'package.json'));
2176
2180
  this.AppName = JSON.parse(rawdata).name;
2181
+ const pathToBuild = this.Path.join(this.appPath, 'build');
2182
+ if (this.NodeFs.existsSync(this.Path.join(pathToBuild, 'capacitor.config.js'))) {
2183
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
2184
+ this.capConfig = require(this.Path.join(pathToBuild, 'capacitor.config.js')).default;
2185
+ }
2186
+ else {
2187
+ this.capConfig = JSON.parse(this.NodeFs.readFileSync(this.Path.join(this.appPath, 'capacitor.config.json')).toString());
2188
+ }
2177
2189
  this.osType = this.Os.type();
2190
+ switch (this.osType) {
2191
+ case 'Darwin':
2192
+ this.pathDB = this.capConfig.plugins.CapacitorSQLite.electronMacLocation;
2193
+ break;
2194
+ case 'Linux':
2195
+ this.pathDB = this.capConfig.plugins.CapacitorSQLite.electronLinuxLocation;
2196
+ break;
2197
+ case 'Windows_NT':
2198
+ this.pathDB = this.capConfig.plugins.CapacitorSQLite.electronWindowsLocation;
2199
+ break;
2200
+ default:
2201
+ console.log('other operating system');
2202
+ }
2203
+ console.log(`&&& Databases path: ${this.pathDB}`);
2178
2204
  }
2179
2205
  /**
2180
2206
  * IsPathExists
@@ -2213,37 +2239,26 @@ class UtilsFile {
2213
2239
  getFilePath(fileName) {
2214
2240
  return this.Path.join(this.getDatabasesPath(), fileName);
2215
2241
  }
2216
- /**
2217
- * GetCustomerPath
2218
- * get the customer path
2219
- */
2220
- getCustomerPath(custPath) {
2221
- return this.Path.join(this.HomeDir, custPath);
2222
- }
2223
- /**
2224
- * GetCustomerFilePath
2225
- * get the customer file path
2226
- */
2227
- getCustomerFilePath(custPath, file) {
2228
- return this.Path.join(custPath, file);
2229
- }
2230
2242
  /**
2231
2243
  * GetDatabasesPath
2232
2244
  * get the database folder path
2233
2245
  */
2234
2246
  getDatabasesPath() {
2235
2247
  let retPath = '';
2248
+ const sep = this.Path.sep;
2236
2249
  const dbFolder = this.pathDB;
2237
- retPath = this.Path.join(this.HomeDir, dbFolder, this.AppName);
2238
- let retB = this._createFolderIfNotExists(this.Path.join(this.HomeDir, dbFolder));
2239
- if (retB) {
2240
- retB = this._createFolderIfNotExists(this.Path.join(this.HomeDir, dbFolder, this.AppName));
2241
- if (!retB)
2242
- retPath = '';
2250
+ if (dbFolder.includes(sep)) {
2251
+ retPath = dbFolder;
2252
+ if (this.Path.basename(dbFolder) !== this.AppName) {
2253
+ retPath = this.Path.join(dbFolder, this.AppName);
2254
+ }
2243
2255
  }
2244
2256
  else {
2245
- retPath = '';
2257
+ retPath = this.Path.join(this.HomeDir, dbFolder, this.AppName);
2246
2258
  }
2259
+ const retB = this._createFolderIfNotExists(retPath);
2260
+ if (!retB)
2261
+ retPath = '';
2247
2262
  return retPath;
2248
2263
  }
2249
2264
  /**
@@ -2547,9 +2562,10 @@ class UtilsFile {
2547
2562
  * @param directory
2548
2563
  */
2549
2564
  _mkdirSyncRecursive(directory) {
2550
- const path = directory.replace(/\/$/, '').split('/');
2565
+ const sep = this.Path.sep;
2566
+ const path = directory.replace(/\/$/, '').split(sep);
2551
2567
  for (let i = 1; i <= path.length; i++) {
2552
- const segment = path.slice(0, i).join('/');
2568
+ const segment = path.slice(0, i).join(sep);
2553
2569
  segment.length > 0 && !this.NodeFs.existsSync(segment)
2554
2570
  ? this.NodeFs.mkdirSync(segment)
2555
2571
  : null;