@unvired/cordova-plugin-unvired-electron-db 0.0.36 → 0.0.38
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/package.json +1 -1
- package/plugin.xml +2 -2
- package/src/electron/package.json +1 -1
- package/src/electron/unvired-db-proxy.js +56 -34
package/package.json
CHANGED
package/plugin.xml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
<?xml version='1.0' encoding='utf-8'?>
|
|
2
2
|
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
|
|
3
|
-
id="cordova-plugin-unvired-electron-db"
|
|
4
|
-
version="0.0.
|
|
3
|
+
id="@unvired/cordova-plugin-unvired-electron-db"
|
|
4
|
+
version="0.0.38"
|
|
5
5
|
xmlns:android="http://schemas.android.com/apk/res/android">
|
|
6
6
|
<name>Unvired DB</name>
|
|
7
7
|
<description>Unvired DB Native Support for Cordova</description>
|
|
@@ -100,16 +100,40 @@ const execute = (args) => {
|
|
|
100
100
|
});
|
|
101
101
|
}
|
|
102
102
|
|
|
103
|
-
const close = ()=>{
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
103
|
+
const close = () => {
|
|
104
|
+
return new Promise((resolve, reject) => {
|
|
105
|
+
const closeAppDb = new Promise((res) => {
|
|
106
|
+
if (appDb) {
|
|
107
|
+
appDb.close((err) => {
|
|
108
|
+
if (err) console.error("Error closing appDb:", err);
|
|
109
|
+
appDb = null;
|
|
110
|
+
appDbFilePath = null;
|
|
111
|
+
res();
|
|
112
|
+
});
|
|
113
|
+
} else {
|
|
114
|
+
res();
|
|
115
|
+
}
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
const closeFwDb = new Promise((res) => {
|
|
119
|
+
if (fwDb) {
|
|
120
|
+
fwDb.close((err) => {
|
|
121
|
+
if (err) console.error("Error closing fwDb:", err);
|
|
122
|
+
fwDb = null;
|
|
123
|
+
fwDbFilePath = null;
|
|
124
|
+
res();
|
|
125
|
+
});
|
|
126
|
+
} else {
|
|
127
|
+
res();
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
Promise.all([closeAppDb, closeFwDb]).then(() => {
|
|
132
|
+
resolve("DB connection closed");
|
|
133
|
+
}).catch(err => {
|
|
134
|
+
reject(err);
|
|
135
|
+
});
|
|
136
|
+
});
|
|
113
137
|
}
|
|
114
138
|
|
|
115
139
|
const getDBFilePath = (args) => {
|
|
@@ -143,9 +167,9 @@ const saveWebDB = (args) => {
|
|
|
143
167
|
/**
|
|
144
168
|
* Deletes the user directory and all its contents for the given userId.
|
|
145
169
|
* @param {Array} args - Array with an object containing userId.
|
|
146
|
-
* @returns {string} - Success or error message.
|
|
170
|
+
* @returns {Promise<string>} - Success or error message.
|
|
147
171
|
*/
|
|
148
|
-
const deleteUserData = (args) => {
|
|
172
|
+
const deleteUserData = async (args) => {
|
|
149
173
|
const userId = args[0]?.userId;
|
|
150
174
|
if (!userId) {
|
|
151
175
|
throw new Error("userId is required");
|
|
@@ -154,30 +178,28 @@ const deleteUserData = (args) => {
|
|
|
154
178
|
if (!fs.existsSync(userPath)) {
|
|
155
179
|
return `User directory does not exist: ${userPath}`;
|
|
156
180
|
}
|
|
157
|
-
|
|
158
|
-
if
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
if (fwDb) {
|
|
181
|
+
|
|
182
|
+
// Close DBs if they are open. We must wait for them to close to release file locks on Windows.
|
|
183
|
+
await close();
|
|
184
|
+
|
|
185
|
+
// On Windows, file locks might take a few milliseconds to be released by the OS even after closing the connection.
|
|
186
|
+
// We use a retry mechanism to handle this.
|
|
187
|
+
const maxRetries = 10;
|
|
188
|
+
const retryDelay = 100; // ms
|
|
189
|
+
|
|
190
|
+
for (let i = 0; i < maxRetries; i++) {
|
|
168
191
|
try {
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
192
|
+
if (fs.existsSync(userPath)) {
|
|
193
|
+
fs.rmSync(userPath, { recursive: true, force: true });
|
|
194
|
+
}
|
|
195
|
+
return `User directory deleted: ${userPath}`;
|
|
196
|
+
} catch (err) {
|
|
197
|
+
if (i === maxRetries - 1) {
|
|
198
|
+
throw new Error(`Failed to delete user directory after ${maxRetries} attempts: ${err.message}`);
|
|
199
|
+
}
|
|
200
|
+
// Wait before retrying
|
|
201
|
+
await new Promise(resolve => setTimeout(resolve, retryDelay));
|
|
172
202
|
}
|
|
173
|
-
fwDb = null;
|
|
174
|
-
fwDbFilePath = null;
|
|
175
|
-
}
|
|
176
|
-
try {
|
|
177
|
-
fs.rmSync(userPath, { recursive: true, force: true });
|
|
178
|
-
return `User directory deleted: ${userPath}`;
|
|
179
|
-
} catch (err) {
|
|
180
|
-
throw new Error(`Failed to delete user directory: ${err.message}`);
|
|
181
203
|
}
|
|
182
204
|
}
|
|
183
205
|
|