@capgo/capacitor-updater 3.0.10 → 3.2.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 +1 -1
- package/android/src/main/java/ee/forgr/capacitor_updater/CapacitorUpdater.java +169 -159
- package/android/src/main/java/ee/forgr/capacitor_updater/CapacitorUpdaterEvents.java +11 -0
- package/android/src/main/java/ee/forgr/capacitor_updater/CapacitorUpdaterPlugin.java +164 -159
- package/ios/Plugin/CapacitorUpdater.swift +12 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -53,7 +53,7 @@ Create account in [capgo.app](https://capgo.app) and get your [API key](https://
|
|
|
53
53
|
- If update fail it will roolback to previous version.
|
|
54
54
|
|
|
55
55
|
See more there in the [Auto update](
|
|
56
|
-
https://
|
|
56
|
+
https://github.com/Cap-go/capacitor-updater/wiki) documentation.
|
|
57
57
|
|
|
58
58
|
|
|
59
59
|
## Manual setup
|
|
@@ -5,6 +5,7 @@ import android.content.Context;
|
|
|
5
5
|
import android.content.SharedPreferences;
|
|
6
6
|
import android.content.pm.PackageInfo;
|
|
7
7
|
import android.content.pm.PackageManager;
|
|
8
|
+
import android.os.Build;
|
|
8
9
|
import android.util.Log;
|
|
9
10
|
|
|
10
11
|
import com.android.volley.AuthFailureError;
|
|
@@ -47,81 +48,84 @@ public class CapacitorUpdater {
|
|
|
47
48
|
public String statsUrl = "";
|
|
48
49
|
public String appId = "";
|
|
49
50
|
public String deviceID = "";
|
|
50
|
-
private String pluginVersion = "3.
|
|
51
|
+
private final String pluginVersion = "3.2.1";
|
|
51
52
|
|
|
52
53
|
|
|
53
|
-
private FilenameFilter filter = new FilenameFilter() {
|
|
54
|
+
private final FilenameFilter filter = new FilenameFilter() {
|
|
54
55
|
@Override
|
|
55
|
-
public boolean accept(File f, String name) {
|
|
56
|
+
public boolean accept(final File f, final String name) {
|
|
56
57
|
// ignore directories generated by mac os x
|
|
57
58
|
return !name.startsWith("__MACOSX") && !name.startsWith(".") && !name.startsWith(".DS_Store");
|
|
58
59
|
}
|
|
59
60
|
};
|
|
60
|
-
private final
|
|
61
|
+
private final Context context;
|
|
62
|
+
private final CapacitorUpdaterEvents events;
|
|
63
|
+
|
|
61
64
|
private String versionBuild = "";
|
|
62
|
-
private String
|
|
63
|
-
private
|
|
64
|
-
private String
|
|
65
|
-
private
|
|
66
|
-
private SharedPreferences
|
|
65
|
+
private String versionCode = "";
|
|
66
|
+
private String versionOs = "";
|
|
67
|
+
private final String TAG = "Capacitor-updater";
|
|
68
|
+
private final String basePathHot = "versions";
|
|
69
|
+
private final SharedPreferences prefs;
|
|
70
|
+
private final SharedPreferences.Editor editor;
|
|
67
71
|
|
|
68
72
|
static final String AB = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
|
|
69
73
|
static SecureRandom rnd = new SecureRandom();
|
|
70
74
|
|
|
71
|
-
private int calcTotalPercent(int percent, int min, int max) {
|
|
75
|
+
private int calcTotalPercent(final int percent, final int min, final int max) {
|
|
72
76
|
return (percent * (max - min)) / 100 + min;
|
|
73
77
|
}
|
|
74
78
|
|
|
75
|
-
private String randomString(int len){
|
|
76
|
-
StringBuilder sb = new StringBuilder(len);
|
|
79
|
+
private String randomString(final int len){
|
|
80
|
+
final StringBuilder sb = new StringBuilder(len);
|
|
77
81
|
for(int i = 0; i < len; i++)
|
|
78
82
|
sb.append(AB.charAt(rnd.nextInt(AB.length())));
|
|
79
83
|
return sb.toString();
|
|
80
84
|
}
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
this
|
|
84
|
-
this.prefs = context.getSharedPreferences("CapWebViewSettings", Activity.MODE_PRIVATE);
|
|
85
|
-
this.editor = prefs.edit();
|
|
86
|
-
this.deviceID = Secure.getString(context.getContentResolver(), Secure.ANDROID_ID);
|
|
87
|
-
PackageInfo pInfo = context.getPackageManager().getPackageInfo(context.getPackageName(), 0);
|
|
88
|
-
this.versionBuild = pInfo.versionName;
|
|
85
|
+
|
|
86
|
+
public CapacitorUpdater(final Context context) throws PackageManager.NameNotFoundException {
|
|
87
|
+
this(context, new CapacitorUpdaterEvents() {});
|
|
89
88
|
}
|
|
90
|
-
|
|
89
|
+
|
|
90
|
+
public CapacitorUpdater (final Context context, final CapacitorUpdaterEvents events) throws PackageManager.NameNotFoundException {
|
|
91
91
|
this.context = context;
|
|
92
|
-
this.
|
|
93
|
-
|
|
94
|
-
this.
|
|
92
|
+
this.events = events;
|
|
93
|
+
|
|
94
|
+
this.prefs = this.context.getSharedPreferences("CapWebViewSettings", Activity.MODE_PRIVATE);
|
|
95
|
+
this.editor = this.prefs.edit();
|
|
96
|
+
this.versionOs = Build.VERSION.RELEASE;
|
|
95
97
|
this.deviceID = Secure.getString(context.getContentResolver(), Secure.ANDROID_ID);
|
|
96
|
-
|
|
98
|
+
|
|
99
|
+
final PackageInfo pInfo = context.getPackageManager().getPackageInfo(context.getPackageName(), 0);
|
|
97
100
|
this.versionBuild = pInfo.versionName;
|
|
101
|
+
this.versionCode = Integer.toString(pInfo.versionCode);
|
|
98
102
|
}
|
|
99
103
|
|
|
100
|
-
private Boolean unzip(String source, String dest) {
|
|
101
|
-
File zipFile = new File(this.context.getFilesDir() + "/" + source);
|
|
102
|
-
File targetDirectory = new File(this.context.getFilesDir() + "/" + dest);
|
|
104
|
+
private Boolean unzip(final String source, final String dest) {
|
|
105
|
+
final File zipFile = new File(this.context.getFilesDir() + "/" + source);
|
|
106
|
+
final File targetDirectory = new File(this.context.getFilesDir() + "/" + dest);
|
|
103
107
|
ZipInputStream zis = null;
|
|
104
108
|
try {
|
|
105
109
|
zis = new ZipInputStream(
|
|
106
110
|
new BufferedInputStream(new FileInputStream(zipFile)));
|
|
107
|
-
} catch (FileNotFoundException e) {
|
|
111
|
+
} catch (final FileNotFoundException e) {
|
|
108
112
|
e.printStackTrace();
|
|
109
113
|
return false;
|
|
110
114
|
}
|
|
111
115
|
try {
|
|
112
116
|
ZipEntry ze;
|
|
113
117
|
int count;
|
|
114
|
-
int buffLength = 8192;
|
|
115
|
-
byte[] buffer = new byte[buffLength];
|
|
116
|
-
long totalLength = zipFile.length();
|
|
117
|
-
long
|
|
118
|
+
final int buffLength = 8192;
|
|
119
|
+
final byte[] buffer = new byte[buffLength];
|
|
120
|
+
final long totalLength = zipFile.length();
|
|
121
|
+
long readLength = buffLength;
|
|
118
122
|
int percent = 0;
|
|
119
|
-
this.
|
|
123
|
+
this.events.notifyDownload(75);
|
|
120
124
|
while ((ze = zis.getNextEntry()) != null) {
|
|
121
|
-
File file = new File(targetDirectory, ze.getName());
|
|
122
|
-
String canonicalPath = file.getCanonicalPath();
|
|
123
|
-
String canonicalDir = (new File(String.valueOf(targetDirectory))).getCanonicalPath();
|
|
124
|
-
File dir = ze.isDirectory() ? file : file.getParentFile();
|
|
125
|
+
final File file = new File(targetDirectory, ze.getName());
|
|
126
|
+
final String canonicalPath = file.getCanonicalPath();
|
|
127
|
+
final String canonicalDir = (new File(String.valueOf(targetDirectory))).getCanonicalPath();
|
|
128
|
+
final File dir = ze.isDirectory() ? file : file.getParentFile();
|
|
125
129
|
if (!canonicalPath.startsWith(canonicalDir)) {
|
|
126
130
|
throw new FileNotFoundException("SecurityException, Failed to ensure directory is the start path : " +
|
|
127
131
|
canonicalDir + " of " + canonicalPath);
|
|
@@ -131,27 +135,27 @@ public class CapacitorUpdater {
|
|
|
131
135
|
dir.getAbsolutePath());
|
|
132
136
|
if (ze.isDirectory())
|
|
133
137
|
continue;
|
|
134
|
-
FileOutputStream
|
|
138
|
+
final FileOutputStream fileOut = new FileOutputStream(file);
|
|
135
139
|
try {
|
|
136
140
|
while ((count = zis.read(buffer)) != -1)
|
|
137
|
-
|
|
141
|
+
fileOut.write(buffer, 0, count);
|
|
138
142
|
} finally {
|
|
139
|
-
|
|
143
|
+
fileOut.close();
|
|
140
144
|
}
|
|
141
|
-
int newPercent = (int)((
|
|
145
|
+
final int newPercent = (int)((readLength * 100) / totalLength);
|
|
142
146
|
if (totalLength > 1 && newPercent != percent) {
|
|
143
147
|
percent = newPercent;
|
|
144
|
-
this.
|
|
148
|
+
this.events.notifyDownload(this.calcTotalPercent(percent, 75, 90));
|
|
145
149
|
}
|
|
146
|
-
|
|
150
|
+
readLength += ze.getCompressedSize();
|
|
147
151
|
}
|
|
148
|
-
} catch (Exception e) {
|
|
149
|
-
Log.i(TAG, "unzip error", e);
|
|
152
|
+
} catch (final Exception e) {
|
|
153
|
+
Log.i(this.TAG, "unzip error", e);
|
|
150
154
|
return false;
|
|
151
155
|
} finally {
|
|
152
156
|
try {
|
|
153
157
|
zis.close();
|
|
154
|
-
} catch (IOException e) {
|
|
158
|
+
} catch (final IOException e) {
|
|
155
159
|
e.printStackTrace();
|
|
156
160
|
return false;
|
|
157
161
|
}
|
|
@@ -159,19 +163,19 @@ public class CapacitorUpdater {
|
|
|
159
163
|
}
|
|
160
164
|
}
|
|
161
165
|
|
|
162
|
-
private Boolean flattenAssets(String source, String dest) {
|
|
163
|
-
File current = new File(this.context.getFilesDir() + "/" + source);
|
|
166
|
+
private Boolean flattenAssets(final String source, final String dest) {
|
|
167
|
+
final File current = new File(this.context.getFilesDir() + "/" + source);
|
|
164
168
|
if (!current.exists()) {
|
|
165
169
|
return false;
|
|
166
170
|
}
|
|
167
|
-
File fDest = new File(this.context.getFilesDir() + "/" + dest);
|
|
171
|
+
final File fDest = new File(this.context.getFilesDir() + "/" + dest);
|
|
168
172
|
fDest.getParentFile().mkdirs();
|
|
169
|
-
String[] pathsName = current.list(filter);
|
|
173
|
+
final String[] pathsName = current.list(this.filter);
|
|
170
174
|
if (pathsName == null || pathsName.length == 0) {
|
|
171
175
|
return false;
|
|
172
176
|
}
|
|
173
177
|
if (pathsName.length == 1 && !pathsName[0].equals("index.html")) {
|
|
174
|
-
File newFlat = new File(current.getPath() + "/" + pathsName[0]);
|
|
178
|
+
final File newFlat = new File(current.getPath() + "/" + pathsName[0]);
|
|
175
179
|
newFlat.renameTo(fDest);
|
|
176
180
|
} else {
|
|
177
181
|
current.renameTo(fDest);
|
|
@@ -180,45 +184,45 @@ public class CapacitorUpdater {
|
|
|
180
184
|
return true;
|
|
181
185
|
}
|
|
182
186
|
|
|
183
|
-
private Boolean downloadFile(String url, String dest) throws JSONException {
|
|
187
|
+
private Boolean downloadFile(final String url, final String dest) throws JSONException {
|
|
184
188
|
try {
|
|
185
|
-
URL u = new URL(url);
|
|
186
|
-
URLConnection uc = u.openConnection();
|
|
187
|
-
InputStream is = u.openStream();
|
|
188
|
-
DataInputStream dis = new DataInputStream(is);
|
|
189
|
-
long totalLength = uc.getContentLength();
|
|
190
|
-
int buffLength = 1024;
|
|
191
|
-
byte[] buffer = new byte[buffLength];
|
|
189
|
+
final URL u = new URL(url);
|
|
190
|
+
final URLConnection uc = u.openConnection();
|
|
191
|
+
final InputStream is = u.openStream();
|
|
192
|
+
final DataInputStream dis = new DataInputStream(is);
|
|
193
|
+
final long totalLength = uc.getContentLength();
|
|
194
|
+
final int buffLength = 1024;
|
|
195
|
+
final byte[] buffer = new byte[buffLength];
|
|
192
196
|
int length;
|
|
193
|
-
File downFile = new File(this.context.getFilesDir() + "/" + dest);
|
|
197
|
+
final File downFile = new File(this.context.getFilesDir() + "/" + dest);
|
|
194
198
|
downFile.getParentFile().mkdirs();
|
|
195
199
|
downFile.createNewFile();
|
|
196
|
-
FileOutputStream fos = new FileOutputStream(downFile);
|
|
197
|
-
int
|
|
200
|
+
final FileOutputStream fos = new FileOutputStream(downFile);
|
|
201
|
+
int readLength = buffLength;
|
|
198
202
|
int percent = 0;
|
|
199
|
-
this.
|
|
203
|
+
this.events.notifyDownload(10);
|
|
200
204
|
while ((length = dis.read(buffer))>0) {
|
|
201
205
|
fos.write(buffer, 0, length);
|
|
202
|
-
int newPercent = (int)((
|
|
206
|
+
final int newPercent = (int)((readLength * 100) / totalLength);
|
|
203
207
|
if (totalLength > 1 && newPercent != percent) {
|
|
204
208
|
percent = newPercent;
|
|
205
|
-
this.
|
|
209
|
+
this.events.notifyDownload(this.calcTotalPercent(percent, 10, 70));
|
|
206
210
|
}
|
|
207
|
-
|
|
211
|
+
readLength += length;
|
|
208
212
|
}
|
|
209
|
-
} catch (Exception e) {
|
|
210
|
-
Log.e(TAG, "downloadFile error", e);
|
|
213
|
+
} catch (final Exception e) {
|
|
214
|
+
Log.e(this.TAG, "downloadFile error", e);
|
|
211
215
|
return false;
|
|
212
216
|
}
|
|
213
217
|
return true;
|
|
214
218
|
}
|
|
215
219
|
|
|
216
|
-
private void deleteDirectory(File file) throws IOException {
|
|
220
|
+
private void deleteDirectory(final File file) throws IOException {
|
|
217
221
|
if (file.isDirectory()) {
|
|
218
|
-
File[] entries = file.listFiles();
|
|
222
|
+
final File[] entries = file.listFiles();
|
|
219
223
|
if (entries != null) {
|
|
220
|
-
for (File entry : entries) {
|
|
221
|
-
deleteDirectory(entry);
|
|
224
|
+
for (final File entry : entries) {
|
|
225
|
+
this.deleteDirectory(entry);
|
|
222
226
|
}
|
|
223
227
|
}
|
|
224
228
|
}
|
|
@@ -227,145 +231,151 @@ public class CapacitorUpdater {
|
|
|
227
231
|
}
|
|
228
232
|
}
|
|
229
233
|
|
|
230
|
-
public String download(String url) {
|
|
234
|
+
public String download(final String url) {
|
|
231
235
|
try {
|
|
232
|
-
this.
|
|
233
|
-
String folderNameZip = this.randomString(10);
|
|
234
|
-
File fileZip = new File(this.context.getFilesDir() + "/" + folderNameZip);
|
|
235
|
-
String folderNameUnZip = this.randomString(10);
|
|
236
|
-
String version = this.randomString(10);
|
|
237
|
-
String folderName = basePathHot + "/" + version;
|
|
238
|
-
this.
|
|
239
|
-
Boolean downloaded = this.downloadFile(url, folderNameZip);
|
|
236
|
+
this.events.notifyDownload(0);
|
|
237
|
+
final String folderNameZip = this.randomString(10);
|
|
238
|
+
final File fileZip = new File(this.context.getFilesDir() + "/" + folderNameZip);
|
|
239
|
+
final String folderNameUnZip = this.randomString(10);
|
|
240
|
+
final String version = this.randomString(10);
|
|
241
|
+
final String folderName = this.basePathHot + "/" + version;
|
|
242
|
+
this.events.notifyDownload(5);
|
|
243
|
+
final Boolean downloaded = this.downloadFile(url, folderNameZip);
|
|
240
244
|
if(!downloaded) return "";
|
|
241
|
-
this.
|
|
242
|
-
Boolean unzipped = this.unzip(folderNameZip, folderNameUnZip);
|
|
245
|
+
this.events.notifyDownload(71);
|
|
246
|
+
final Boolean unzipped = this.unzip(folderNameZip, folderNameUnZip);
|
|
243
247
|
if(!unzipped) return "";
|
|
244
248
|
fileZip.delete();
|
|
245
|
-
this.
|
|
246
|
-
Boolean flatt = this.flattenAssets(folderNameUnZip, folderName);
|
|
249
|
+
this.events.notifyDownload(91);
|
|
250
|
+
final Boolean flatt = this.flattenAssets(folderNameUnZip, folderName);
|
|
247
251
|
if(!flatt) return "";
|
|
248
|
-
this.
|
|
252
|
+
this.events.notifyDownload(100);
|
|
249
253
|
return version;
|
|
250
|
-
} catch (Exception e) {
|
|
251
|
-
Log.e(TAG, "updateApp error", e);
|
|
254
|
+
} catch (final Exception e) {
|
|
255
|
+
Log.e(this.TAG, "updateApp error", e);
|
|
252
256
|
return "";
|
|
253
257
|
}
|
|
254
258
|
}
|
|
255
259
|
|
|
256
260
|
public ArrayList<String> list() {
|
|
257
|
-
ArrayList<String> res = new ArrayList<String>();
|
|
258
|
-
File destHot = new File(this.context.getFilesDir() + "/" + basePathHot);
|
|
259
|
-
Log.i(TAG, "list File : " + destHot.getPath());
|
|
261
|
+
final ArrayList<String> res = new ArrayList<String>();
|
|
262
|
+
final File destHot = new File(this.context.getFilesDir() + "/" + this.basePathHot);
|
|
263
|
+
Log.i(this.TAG, "list File : " + destHot.getPath());
|
|
260
264
|
if (destHot.exists()) {
|
|
261
|
-
for (File i : destHot.listFiles()) {
|
|
265
|
+
for (final File i : destHot.listFiles()) {
|
|
262
266
|
res.add(i.getName());
|
|
263
267
|
}
|
|
264
268
|
} else {
|
|
265
|
-
Log.i(TAG, "No version available" + destHot);
|
|
269
|
+
Log.i(this.TAG, "No version available" + destHot);
|
|
266
270
|
}
|
|
267
271
|
return res;
|
|
268
272
|
}
|
|
269
273
|
|
|
270
|
-
public Boolean delete(String version, String versionName) throws IOException {
|
|
271
|
-
File destHot = new File(this.context.getFilesDir() + "/" + basePathHot + "/" + version);
|
|
274
|
+
public Boolean delete(final String version, final String versionName) throws IOException {
|
|
275
|
+
final File destHot = new File(this.context.getFilesDir() + "/" + this.basePathHot + "/" + version);
|
|
272
276
|
if (destHot.exists()) {
|
|
273
|
-
deleteDirectory(destHot);
|
|
277
|
+
this.deleteDirectory(destHot);
|
|
274
278
|
return true;
|
|
275
279
|
}
|
|
276
|
-
Log.i(TAG, "Directory not removed: " + destHot.getPath());
|
|
280
|
+
Log.i(this.TAG, "Directory not removed: " + destHot.getPath());
|
|
277
281
|
this.sendStats("delete", versionName);
|
|
278
282
|
return false;
|
|
279
283
|
}
|
|
280
284
|
|
|
281
|
-
public Boolean set(String version, String versionName) {
|
|
282
|
-
File destHot = new File(this.context.getFilesDir() + "/" + basePathHot + "/" + version);
|
|
283
|
-
File destIndex = new File(destHot.getPath() + "/index.html");
|
|
285
|
+
public Boolean set(final String version, final String versionName) {
|
|
286
|
+
final File destHot = new File(this.context.getFilesDir() + "/" + this.basePathHot + "/" + version);
|
|
287
|
+
final File destIndex = new File(destHot.getPath() + "/index.html");
|
|
284
288
|
if (destHot.exists() && destIndex.exists()) {
|
|
285
|
-
editor.putString("lastPathHot", destHot.getPath());
|
|
286
|
-
editor.putString("serverBasePath", destHot.getPath());
|
|
287
|
-
editor.putString("versionName", versionName);
|
|
288
|
-
editor.commit();
|
|
289
|
-
sendStats("set", versionName);
|
|
289
|
+
this.editor.putString("lastPathHot", destHot.getPath());
|
|
290
|
+
this.editor.putString("serverBasePath", destHot.getPath());
|
|
291
|
+
this.editor.putString("versionName", versionName);
|
|
292
|
+
this.editor.commit();
|
|
293
|
+
this.sendStats("set", versionName);
|
|
290
294
|
return true;
|
|
291
295
|
}
|
|
292
|
-
sendStats("set_fail", versionName);
|
|
296
|
+
this.sendStats("set_fail", versionName);
|
|
293
297
|
return false;
|
|
294
298
|
}
|
|
295
299
|
|
|
296
|
-
public void getLatest(String url, Callback callback) {
|
|
297
|
-
String deviceID = this.deviceID;
|
|
298
|
-
String appId = this.appId;
|
|
299
|
-
String versionBuild = this.versionBuild;
|
|
300
|
-
String
|
|
301
|
-
String
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
300
|
+
public void getLatest(final String url, final Callback callback) {
|
|
301
|
+
final String deviceID = this.deviceID;
|
|
302
|
+
final String appId = this.appId;
|
|
303
|
+
final String versionBuild = this.versionBuild;
|
|
304
|
+
final String versionCode = this.versionCode;
|
|
305
|
+
final String versionOs = this.versionOs;
|
|
306
|
+
final String pluginVersion = this.pluginVersion;
|
|
307
|
+
final String versionName = this.getVersionName().equals("") ? "builtin" : this.getVersionName();
|
|
308
|
+
final StringRequest stringRequest = new StringRequest(Request.Method.GET, url,
|
|
309
|
+
new Response.Listener<String>() {
|
|
310
|
+
@Override
|
|
311
|
+
public void onResponse(final String response) {
|
|
312
|
+
try {
|
|
313
|
+
final JSONObject jsonObject = new JSONObject(response);
|
|
314
|
+
callback.callback(jsonObject);
|
|
315
|
+
} catch (final JSONException e) {
|
|
316
|
+
e.printStackTrace();
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
}, new Response.ErrorListener() {
|
|
314
320
|
@Override
|
|
315
|
-
public void onErrorResponse(VolleyError error) {
|
|
316
|
-
Log.e(TAG, "Error getting Latest" + error);
|
|
321
|
+
public void onErrorResponse(final VolleyError error) {
|
|
322
|
+
Log.e(CapacitorUpdater.this.TAG, "Error getting Latest" + error);
|
|
317
323
|
}
|
|
318
|
-
}) {
|
|
324
|
+
}) {
|
|
319
325
|
@Override
|
|
320
326
|
public Map<String, String> getHeaders() throws AuthFailureError {
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
327
|
+
final Map<String, String> params = new HashMap<String, String>();
|
|
328
|
+
params.put("cap_platform", "android");
|
|
329
|
+
params.put("cap_device_id", deviceID);
|
|
330
|
+
params.put("cap_app_id", appId);
|
|
331
|
+
params.put("cap_version_build", versionBuild);
|
|
332
|
+
params.put("cap_version_code", versionCode);
|
|
333
|
+
params.put("cap_version_os", versionOs);
|
|
334
|
+
params.put("cap_version_name", versionName);
|
|
335
|
+
params.put("cap_plugin_version", pluginVersion);
|
|
336
|
+
return params;
|
|
329
337
|
}
|
|
330
338
|
};
|
|
331
|
-
RequestQueue requestQueue = Volley.newRequestQueue(this.context);
|
|
339
|
+
final RequestQueue requestQueue = Volley.newRequestQueue(this.context);
|
|
332
340
|
requestQueue.add(stringRequest);
|
|
333
341
|
}
|
|
334
342
|
|
|
335
343
|
public String getLastPathHot() {
|
|
336
|
-
return prefs.getString("lastPathHot", "public");
|
|
344
|
+
return this.prefs.getString("lastPathHot", "public");
|
|
337
345
|
}
|
|
338
346
|
|
|
339
347
|
public String getVersionName() {
|
|
340
|
-
return prefs.getString("versionName", "");
|
|
348
|
+
return this.prefs.getString("versionName", "");
|
|
341
349
|
}
|
|
342
350
|
|
|
343
|
-
public void reset() {
|
|
344
|
-
String version = prefs.getString("versionName", "");
|
|
351
|
+
public void reset() {
|
|
352
|
+
final String version = this.prefs.getString("versionName", "");
|
|
345
353
|
this.sendStats("reset", version);
|
|
346
|
-
editor.putString("lastPathHot", "public");
|
|
347
|
-
editor.putString("serverBasePath", "public");
|
|
348
|
-
editor.putString("versionName", "");
|
|
349
|
-
editor.commit();
|
|
354
|
+
this.editor.putString("lastPathHot", "public");
|
|
355
|
+
this.editor.putString("serverBasePath", "public");
|
|
356
|
+
this.editor.putString("versionName", "");
|
|
357
|
+
this.editor.commit();
|
|
350
358
|
}
|
|
351
359
|
|
|
352
|
-
public void sendStats(String action, String version) {
|
|
353
|
-
if (statsUrl == "") { return; }
|
|
354
|
-
URL url;
|
|
355
|
-
JSONObject json = new JSONObject();
|
|
356
|
-
String jsonString;
|
|
360
|
+
public void sendStats(final String action, final String version) {
|
|
361
|
+
if (this.statsUrl == "") { return; }
|
|
362
|
+
final URL url;
|
|
363
|
+
final JSONObject json = new JSONObject();
|
|
364
|
+
final String jsonString;
|
|
357
365
|
try {
|
|
358
|
-
url = new URL(statsUrl);
|
|
366
|
+
url = new URL(this.statsUrl);
|
|
359
367
|
json.put("platform", "android");
|
|
360
368
|
json.put("action", action);
|
|
361
369
|
json.put("version_name", version);
|
|
362
370
|
json.put("device_id", this.deviceID);
|
|
363
371
|
json.put("version_build", this.versionBuild);
|
|
372
|
+
json.put("version_code", this.versionCode);
|
|
373
|
+
json.put("version_os", this.versionOs);
|
|
364
374
|
json.put("plugin_version", this.pluginVersion);
|
|
365
375
|
json.put("app_id", this.appId);
|
|
366
376
|
jsonString = json.toString();
|
|
367
|
-
} catch (Exception ex) {
|
|
368
|
-
Log.e(TAG, "Error get stats", ex);
|
|
377
|
+
} catch (final Exception ex) {
|
|
378
|
+
Log.e(this.TAG, "Error get stats", ex);
|
|
369
379
|
return;
|
|
370
380
|
}
|
|
371
381
|
new Thread(new Runnable(){
|
|
@@ -380,17 +390,17 @@ public class CapacitorUpdater {
|
|
|
380
390
|
con.setRequestProperty("Content-Length", Integer.toString(jsonString.getBytes().length));
|
|
381
391
|
con.setDoOutput(true);
|
|
382
392
|
con.setConnectTimeout(500);
|
|
383
|
-
DataOutputStream wr = new DataOutputStream (con.getOutputStream());
|
|
393
|
+
final DataOutputStream wr = new DataOutputStream (con.getOutputStream());
|
|
384
394
|
wr.writeBytes(jsonString);
|
|
385
395
|
wr.close();
|
|
386
|
-
int responseCode = con.getResponseCode();
|
|
396
|
+
final int responseCode = con.getResponseCode();
|
|
387
397
|
if (responseCode != 200) {
|
|
388
|
-
Log.e(TAG, "Stats error responseCode: " + responseCode);
|
|
398
|
+
Log.e(CapacitorUpdater.this.TAG, "Stats error responseCode: " + responseCode);
|
|
389
399
|
} else {
|
|
390
|
-
Log.i(TAG, "Stats send for \"" + action + "\", version " + version);
|
|
400
|
+
Log.i(CapacitorUpdater.this.TAG, "Stats send for \"" + action + "\", version " + version);
|
|
391
401
|
}
|
|
392
|
-
} catch (Exception ex) {
|
|
393
|
-
Log.e(TAG, "Error post stats", ex);
|
|
402
|
+
} catch (final Exception ex) {
|
|
403
|
+
Log.e(CapacitorUpdater.this.TAG, "Error post stats", ex);
|
|
394
404
|
} finally {
|
|
395
405
|
if (con != null) {
|
|
396
406
|
con.disconnect();
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
package ee.forgr.capacitor_updater;
|
|
2
|
+
|
|
3
|
+
public interface CapacitorUpdaterEvents {
|
|
4
|
+
/**
|
|
5
|
+
* Notify listeners of download progress.
|
|
6
|
+
* @param percent Current percentage as an integer (e.g.: N out of 100)
|
|
7
|
+
*/
|
|
8
|
+
default void notifyDownload(final int percent) {
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
@@ -29,7 +29,7 @@ import java.util.ArrayList;
|
|
|
29
29
|
|
|
30
30
|
@CapacitorPlugin(name = "CapacitorUpdater")
|
|
31
31
|
public class CapacitorUpdaterPlugin extends Plugin implements Application.ActivityLifecycleCallbacks {
|
|
32
|
-
private String TAG = "Capacitor-updater";
|
|
32
|
+
private final String TAG = "Capacitor-updater";
|
|
33
33
|
private CapacitorUpdater implementation;
|
|
34
34
|
private SharedPreferences prefs;
|
|
35
35
|
private SharedPreferences.Editor editor;
|
|
@@ -45,74 +45,79 @@ public class CapacitorUpdaterPlugin extends Plugin implements Application.Activi
|
|
|
45
45
|
public void load() {
|
|
46
46
|
super.load();
|
|
47
47
|
this.prefs = this.getContext().getSharedPreferences("CapWebViewSettings", Activity.MODE_PRIVATE);
|
|
48
|
-
this.editor = prefs.edit();
|
|
48
|
+
this.editor = this.prefs.edit();
|
|
49
49
|
try {
|
|
50
|
-
implementation = new CapacitorUpdater(this.getContext(),
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
50
|
+
this.implementation = new CapacitorUpdater(this.getContext(), new CapacitorUpdaterEvents() {
|
|
51
|
+
@Override
|
|
52
|
+
public void notifyDownload(final int percent) {
|
|
53
|
+
CapacitorUpdaterPlugin.this.notifyDownload(percent);
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
final PackageInfo pInfo = this.getContext().getPackageManager().getPackageInfo(this.getContext().getPackageName(), 0);
|
|
57
|
+
this.currentVersionNative = new Version(pInfo.versionName);
|
|
58
|
+
} catch (final PackageManager.NameNotFoundException e) {
|
|
54
59
|
e.printStackTrace();
|
|
55
60
|
return;
|
|
56
|
-
} catch (Exception ex) {
|
|
57
|
-
Log.e(TAG, "Error get currentVersionNative", ex);
|
|
61
|
+
} catch (final Exception ex) {
|
|
62
|
+
Log.e(this.TAG, "Error get currentVersionNative", ex);
|
|
58
63
|
return;
|
|
59
64
|
}
|
|
60
|
-
CapConfig config = CapConfig.loadDefault(getActivity());
|
|
61
|
-
implementation.appId = config.getString("appId", "");
|
|
62
|
-
implementation.statsUrl = getConfig().getString("statsUrl", statsUrlDefault);
|
|
63
|
-
this.autoUpdateUrl = getConfig().getString("autoUpdateUrl", autoUpdateUrlDefault);
|
|
64
|
-
this.autoUpdate = getConfig().getBoolean("autoUpdate", false);
|
|
65
|
-
resetWhenUpdate = getConfig().getBoolean("resetWhenUpdate", true);
|
|
66
|
-
if (resetWhenUpdate) {
|
|
67
|
-
Version LatestVersionNative = new Version(prefs.getString("LatestVersionNative", ""));
|
|
65
|
+
final CapConfig config = CapConfig.loadDefault(this.getActivity());
|
|
66
|
+
this.implementation.appId = config.getString("appId", "");
|
|
67
|
+
this.implementation.statsUrl = this.getConfig().getString("statsUrl", statsUrlDefault);
|
|
68
|
+
this.autoUpdateUrl = this.getConfig().getString("autoUpdateUrl", autoUpdateUrlDefault);
|
|
69
|
+
this.autoUpdate = this.getConfig().getBoolean("autoUpdate", false);
|
|
70
|
+
this.resetWhenUpdate = this.getConfig().getBoolean("resetWhenUpdate", true);
|
|
71
|
+
if (this.resetWhenUpdate) {
|
|
72
|
+
final Version LatestVersionNative = new Version(this.prefs.getString("LatestVersionNative", ""));
|
|
68
73
|
try {
|
|
69
|
-
if (!LatestVersionNative.equals("") && currentVersionNative.getMajor() > LatestVersionNative.getMajor()) {
|
|
74
|
+
if (!LatestVersionNative.equals("") && this.currentVersionNative.getMajor() > LatestVersionNative.getMajor()) {
|
|
70
75
|
this._reset(false);
|
|
71
|
-
editor.putString("LatestVersionAutoUpdate", "");
|
|
72
|
-
editor.putString("LatestVersionNameAutoUpdate", "");
|
|
73
|
-
ArrayList<String> res = implementation.list();
|
|
76
|
+
this.editor.putString("LatestVersionAutoUpdate", "");
|
|
77
|
+
this.editor.putString("LatestVersionNameAutoUpdate", "");
|
|
78
|
+
final ArrayList<String> res = this.implementation.list();
|
|
74
79
|
for (int i = 0; i < res.size(); i++) {
|
|
75
80
|
try {
|
|
76
|
-
implementation.delete(res.get(i), "");
|
|
77
|
-
} catch (IOException e) {
|
|
81
|
+
this.implementation.delete(res.get(i), "");
|
|
82
|
+
} catch (final IOException e) {
|
|
78
83
|
e.printStackTrace();
|
|
79
84
|
}
|
|
80
85
|
}
|
|
81
86
|
}
|
|
82
|
-
editor.putString("LatestVersionNative", currentVersionNative.toString());
|
|
83
|
-
editor.commit();
|
|
84
|
-
} catch (Exception ex) {
|
|
87
|
+
this.editor.putString("LatestVersionNative", this.currentVersionNative.toString());
|
|
88
|
+
this.editor.commit();
|
|
89
|
+
} catch (final Exception ex) {
|
|
85
90
|
Log.e("CapacitorUpdater", "Cannot get the current version " + ex.getMessage());
|
|
86
91
|
}
|
|
87
92
|
}
|
|
88
|
-
if (!autoUpdate || this.autoUpdateUrl.equals("")) return;
|
|
89
|
-
Application application = (Application) this.getContext().getApplicationContext();
|
|
93
|
+
if (!this.autoUpdate || this.autoUpdateUrl.equals("")) return;
|
|
94
|
+
final Application application = (Application) this.getContext().getApplicationContext();
|
|
90
95
|
application.registerActivityLifecycleCallbacks(this);
|
|
91
|
-
onActivityStarted(getActivity());
|
|
96
|
+
this.onActivityStarted(this.getActivity());
|
|
92
97
|
}
|
|
93
98
|
|
|
94
|
-
public void notifyDownload(int percent) {
|
|
95
|
-
JSObject ret = new JSObject();
|
|
99
|
+
public void notifyDownload(final int percent) {
|
|
100
|
+
final JSObject ret = new JSObject();
|
|
96
101
|
ret.put("percent", percent);
|
|
97
|
-
notifyListeners("download", ret);
|
|
102
|
+
this.notifyListeners("download", ret);
|
|
98
103
|
}
|
|
99
104
|
|
|
100
105
|
@PluginMethod
|
|
101
|
-
public void getId(PluginCall call) {
|
|
102
|
-
JSObject ret = new JSObject();
|
|
103
|
-
ret.put("id", implementation.deviceID);
|
|
106
|
+
public void getId(final PluginCall call) {
|
|
107
|
+
final JSObject ret = new JSObject();
|
|
108
|
+
ret.put("id", this.implementation.deviceID);
|
|
104
109
|
call.resolve(ret);
|
|
105
110
|
}
|
|
106
111
|
|
|
107
112
|
@PluginMethod
|
|
108
|
-
public void download(PluginCall call) {
|
|
113
|
+
public void download(final PluginCall call) {
|
|
109
114
|
new Thread(new Runnable(){
|
|
110
115
|
@Override
|
|
111
116
|
public void run() {
|
|
112
|
-
String url = call.getString("url");
|
|
113
|
-
String res = implementation.download(url);
|
|
117
|
+
final String url = call.getString("url");
|
|
118
|
+
final String res = CapacitorUpdaterPlugin.this.implementation.download(url);
|
|
114
119
|
if (!res.equals("")) {
|
|
115
|
-
JSObject ret = new JSObject();
|
|
120
|
+
final JSObject ret = new JSObject();
|
|
116
121
|
ret.put("version", res);
|
|
117
122
|
call.resolve(ret);
|
|
118
123
|
} else {
|
|
@@ -123,13 +128,13 @@ public class CapacitorUpdaterPlugin extends Plugin implements Application.Activi
|
|
|
123
128
|
}
|
|
124
129
|
|
|
125
130
|
private boolean _reload() {
|
|
126
|
-
String pathHot = implementation.getLastPathHot();
|
|
131
|
+
final String pathHot = this.implementation.getLastPathHot();
|
|
127
132
|
this.bridge.setServerBasePath(pathHot);
|
|
128
133
|
return true;
|
|
129
134
|
}
|
|
130
135
|
|
|
131
136
|
@PluginMethod
|
|
132
|
-
public void reload(PluginCall call) {
|
|
137
|
+
public void reload(final PluginCall call) {
|
|
133
138
|
if (this._reload()) {
|
|
134
139
|
call.resolve();
|
|
135
140
|
} else {
|
|
@@ -138,10 +143,10 @@ public class CapacitorUpdaterPlugin extends Plugin implements Application.Activi
|
|
|
138
143
|
}
|
|
139
144
|
|
|
140
145
|
@PluginMethod
|
|
141
|
-
public void set(PluginCall call) {
|
|
142
|
-
String version = call.getString("version");
|
|
143
|
-
String versionName = call.getString("versionName", version);
|
|
144
|
-
Boolean res = implementation.set(version, versionName);
|
|
146
|
+
public void set(final PluginCall call) {
|
|
147
|
+
final String version = call.getString("version");
|
|
148
|
+
final String versionName = call.getString("versionName", version);
|
|
149
|
+
final Boolean res = this.implementation.set(version, versionName);
|
|
145
150
|
|
|
146
151
|
if (!res) {
|
|
147
152
|
call.reject("Update failed, version " + version + " doesn't exist");
|
|
@@ -151,38 +156,38 @@ public class CapacitorUpdaterPlugin extends Plugin implements Application.Activi
|
|
|
151
156
|
}
|
|
152
157
|
|
|
153
158
|
@PluginMethod
|
|
154
|
-
public void delete(PluginCall call) {
|
|
155
|
-
String version = call.getString("version");
|
|
159
|
+
public void delete(final PluginCall call) {
|
|
160
|
+
final String version = call.getString("version");
|
|
156
161
|
try {
|
|
157
|
-
Boolean res = implementation.delete(version, "");
|
|
162
|
+
final Boolean res = this.implementation.delete(version, "");
|
|
158
163
|
if (res) {
|
|
159
164
|
call.resolve();
|
|
160
165
|
} else {
|
|
161
166
|
call.reject("Delete failed, version " + version + " doesn't exist");
|
|
162
167
|
}
|
|
163
|
-
} catch(IOException ex) {
|
|
168
|
+
} catch(final IOException ex) {
|
|
164
169
|
Log.e("CapacitorUpdater", "An unexpected error occurred during deletion of folder. Message: " + ex.getMessage());
|
|
165
170
|
call.reject("An unexpected error occurred during deletion of folder.");
|
|
166
171
|
}
|
|
167
172
|
}
|
|
168
173
|
|
|
169
174
|
@PluginMethod
|
|
170
|
-
public void list(PluginCall call) {
|
|
171
|
-
ArrayList<String> res = implementation.list();
|
|
172
|
-
JSObject ret = new JSObject();
|
|
175
|
+
public void list(final PluginCall call) {
|
|
176
|
+
final ArrayList<String> res = this.implementation.list();
|
|
177
|
+
final JSObject ret = new JSObject();
|
|
173
178
|
ret.put("versions", new JSArray(res));
|
|
174
179
|
call.resolve(ret);
|
|
175
180
|
}
|
|
176
181
|
|
|
177
|
-
private boolean _reset(Boolean toAutoUpdate) {
|
|
178
|
-
String version = prefs.getString("LatestVersionAutoUpdate", "");
|
|
179
|
-
String versionName = prefs.getString("LatestVersionNameAutoUpdate", "");
|
|
182
|
+
private boolean _reset(final Boolean toAutoUpdate) {
|
|
183
|
+
final String version = this.prefs.getString("LatestVersionAutoUpdate", "");
|
|
184
|
+
final String versionName = this.prefs.getString("LatestVersionNameAutoUpdate", "");
|
|
180
185
|
if (toAutoUpdate && !version.equals("") && !versionName.equals("")) {
|
|
181
|
-
Boolean res = implementation.set(version, versionName);
|
|
186
|
+
final Boolean res = this.implementation.set(version, versionName);
|
|
182
187
|
return res && this._reload();
|
|
183
188
|
}
|
|
184
|
-
implementation.reset();
|
|
185
|
-
String pathHot = implementation.getLastPathHot();
|
|
189
|
+
this.implementation.reset();
|
|
190
|
+
final String pathHot = this.implementation.getLastPathHot();
|
|
186
191
|
if (this.bridge.getLocalServer() != null) {
|
|
187
192
|
// if the server is not ready yet, hot reload is not needed
|
|
188
193
|
this.bridge.setServerAssetPath(pathHot);
|
|
@@ -191,8 +196,8 @@ public class CapacitorUpdaterPlugin extends Plugin implements Application.Activi
|
|
|
191
196
|
}
|
|
192
197
|
|
|
193
198
|
@PluginMethod
|
|
194
|
-
public void reset(PluginCall call) {
|
|
195
|
-
Boolean toAutoUpdate = call.getBoolean("toAutoUpdate");
|
|
199
|
+
public void reset(final PluginCall call) {
|
|
200
|
+
final Boolean toAutoUpdate = call.getBoolean("toAutoUpdate", false);
|
|
196
201
|
if (this._reset(toAutoUpdate)) {
|
|
197
202
|
call.resolve();
|
|
198
203
|
return;
|
|
@@ -201,101 +206,101 @@ public class CapacitorUpdaterPlugin extends Plugin implements Application.Activi
|
|
|
201
206
|
}
|
|
202
207
|
|
|
203
208
|
@PluginMethod
|
|
204
|
-
public void versionName(PluginCall call) {
|
|
205
|
-
String name = implementation.getVersionName();
|
|
206
|
-
JSObject ret = new JSObject();
|
|
209
|
+
public void versionName(final PluginCall call) {
|
|
210
|
+
final String name = this.implementation.getVersionName();
|
|
211
|
+
final JSObject ret = new JSObject();
|
|
207
212
|
ret.put("versionName", name);
|
|
208
213
|
call.resolve(ret);
|
|
209
214
|
}
|
|
210
215
|
|
|
211
216
|
@PluginMethod
|
|
212
|
-
public void current(PluginCall call) {
|
|
213
|
-
String pathHot = implementation.getLastPathHot();
|
|
214
|
-
JSObject ret = new JSObject();
|
|
215
|
-
String current = pathHot.length() >= 10 ? pathHot.substring(pathHot.length() - 10) : "builtin";
|
|
217
|
+
public void current(final PluginCall call) {
|
|
218
|
+
final String pathHot = this.implementation.getLastPathHot();
|
|
219
|
+
final JSObject ret = new JSObject();
|
|
220
|
+
final String current = pathHot.length() >= 10 ? pathHot.substring(pathHot.length() - 10) : "builtin";
|
|
216
221
|
ret.put("current", current);
|
|
217
|
-
ret.put("currentNative", currentVersionNative);
|
|
222
|
+
ret.put("currentNative", this.currentVersionNative);
|
|
218
223
|
call.resolve(ret);
|
|
219
224
|
}
|
|
220
225
|
|
|
221
226
|
@PluginMethod
|
|
222
|
-
public void notifyAppReady(PluginCall call) {
|
|
223
|
-
editor.putBoolean("notifyAppReady", true);
|
|
224
|
-
editor.commit();
|
|
227
|
+
public void notifyAppReady(final PluginCall call) {
|
|
228
|
+
this.editor.putBoolean("notifyAppReady", true);
|
|
229
|
+
this.editor.commit();
|
|
225
230
|
call.resolve();
|
|
226
231
|
}
|
|
227
232
|
|
|
228
233
|
@PluginMethod
|
|
229
|
-
public void delayUpdate(PluginCall call) {
|
|
230
|
-
editor.putBoolean("delayUpdate", true);
|
|
231
|
-
editor.commit();
|
|
234
|
+
public void delayUpdate(final PluginCall call) {
|
|
235
|
+
this.editor.putBoolean("delayUpdate", true);
|
|
236
|
+
this.editor.commit();
|
|
232
237
|
call.resolve();
|
|
233
238
|
}
|
|
234
239
|
|
|
235
240
|
@PluginMethod
|
|
236
|
-
public void cancelDelay(PluginCall call) {
|
|
237
|
-
editor.putBoolean("delayUpdate", false);
|
|
238
|
-
editor.commit();
|
|
241
|
+
public void cancelDelay(final PluginCall call) {
|
|
242
|
+
this.editor.putBoolean("delayUpdate", false);
|
|
243
|
+
this.editor.commit();
|
|
239
244
|
call.resolve();
|
|
240
245
|
}
|
|
241
246
|
|
|
242
247
|
@Override
|
|
243
|
-
public void onActivityStarted(@NonNull Activity activity) {
|
|
248
|
+
public void onActivityStarted(@NonNull final Activity activity) {
|
|
244
249
|
// disableRevert disableBreaking
|
|
245
250
|
String currentVersionNative = "";
|
|
246
251
|
try {
|
|
247
|
-
PackageInfo pInfo = this.getContext().getPackageManager().getPackageInfo(this.getContext().getPackageName(), 0);
|
|
252
|
+
final PackageInfo pInfo = this.getContext().getPackageManager().getPackageInfo(this.getContext().getPackageName(), 0);
|
|
248
253
|
currentVersionNative = pInfo.versionName;
|
|
249
|
-
} catch (Exception ex) {
|
|
250
|
-
Log.e(TAG, "Error get stats", ex);
|
|
254
|
+
} catch (final Exception ex) {
|
|
255
|
+
Log.e(this.TAG, "Error get stats", ex);
|
|
251
256
|
return;
|
|
252
257
|
}
|
|
253
|
-
Log.i(TAG, "Check for update in the server");
|
|
254
|
-
if (autoUpdateUrl.equals("")) return;
|
|
255
|
-
String finalCurrentVersionNative = currentVersionNative;
|
|
258
|
+
Log.i(this.TAG, "Check for update in the server");
|
|
259
|
+
if (this.autoUpdateUrl.equals("")) return;
|
|
260
|
+
final String finalCurrentVersionNative = currentVersionNative;
|
|
256
261
|
new Thread(new Runnable(){
|
|
257
262
|
@Override
|
|
258
263
|
public void run() {
|
|
259
|
-
implementation.getLatest(autoUpdateUrl, (res) -> {
|
|
264
|
+
CapacitorUpdaterPlugin.this.implementation.getLatest(CapacitorUpdaterPlugin.this.autoUpdateUrl, (res) -> {
|
|
260
265
|
try {
|
|
261
266
|
if (res.has("message")) {
|
|
262
|
-
Log.i(TAG, "Capacitor-updater: " + res.get("message"));
|
|
267
|
+
Log.i(CapacitorUpdaterPlugin.this.TAG, "Capacitor-updater: " + res.get("message"));
|
|
263
268
|
if (res.has("major") && res.getBoolean("major") && res.has("version")) {
|
|
264
|
-
JSObject ret = new JSObject();
|
|
269
|
+
final JSObject ret = new JSObject();
|
|
265
270
|
ret.put("newVersion", (String) res.get("version"));
|
|
266
|
-
notifyListeners("majorAvailable", ret);
|
|
271
|
+
CapacitorUpdaterPlugin.this.notifyListeners("majorAvailable", ret);
|
|
267
272
|
}
|
|
268
273
|
return;
|
|
269
274
|
}
|
|
270
|
-
String currentVersion = implementation.getVersionName();
|
|
271
|
-
String newVersion = (String) res.get("version");
|
|
272
|
-
JSObject ret = new JSObject();
|
|
275
|
+
final String currentVersion = CapacitorUpdaterPlugin.this.implementation.getVersionName();
|
|
276
|
+
final String newVersion = (String) res.get("version");
|
|
277
|
+
final JSObject ret = new JSObject();
|
|
273
278
|
ret.put("newVersion", newVersion);
|
|
274
|
-
String failingVersion = prefs.getString("failingVersion", "");
|
|
279
|
+
final String failingVersion = CapacitorUpdaterPlugin.this.prefs.getString("failingVersion", "");
|
|
275
280
|
if (!newVersion.equals("") && !newVersion.equals(failingVersion)) {
|
|
276
281
|
new Thread(new Runnable(){
|
|
277
282
|
@Override
|
|
278
283
|
public void run() {
|
|
279
284
|
try {
|
|
280
|
-
String dl = implementation.download((String) res.get("url"));
|
|
285
|
+
final String dl = CapacitorUpdaterPlugin.this.implementation.download((String) res.get("url"));
|
|
281
286
|
if (dl.equals("")) {
|
|
282
|
-
Log.i(TAG, "Download version: " + newVersion + " failed");
|
|
287
|
+
Log.i(CapacitorUpdaterPlugin.this.TAG, "Download version: " + newVersion + " failed");
|
|
283
288
|
return;
|
|
284
289
|
}
|
|
285
|
-
Log.i(TAG, "New version: " + newVersion + " found. Current is " + (currentVersion.equals("") ? "builtin" : currentVersion) + ", next backgrounding will trigger update");
|
|
286
|
-
editor.putString("nextVersion", dl);
|
|
287
|
-
editor.putString("nextVersionName", (String) res.get("version"));
|
|
288
|
-
editor.commit();
|
|
289
|
-
notifyListeners("updateAvailable", ret);
|
|
290
|
-
} catch (JSONException e) {
|
|
290
|
+
Log.i(CapacitorUpdaterPlugin.this.TAG, "New version: " + newVersion + " found. Current is " + (currentVersion.equals("") ? "builtin" : currentVersion) + ", next backgrounding will trigger update");
|
|
291
|
+
CapacitorUpdaterPlugin.this.editor.putString("nextVersion", dl);
|
|
292
|
+
CapacitorUpdaterPlugin.this.editor.putString("nextVersionName", (String) res.get("version"));
|
|
293
|
+
CapacitorUpdaterPlugin.this.editor.commit();
|
|
294
|
+
CapacitorUpdaterPlugin.this.notifyListeners("updateAvailable", ret);
|
|
295
|
+
} catch (final JSONException e) {
|
|
291
296
|
e.printStackTrace();
|
|
292
297
|
}
|
|
293
298
|
}
|
|
294
299
|
}).start();
|
|
295
300
|
} else {
|
|
296
|
-
Log.i(TAG, "No need to update, " + currentVersion + " is the latest");
|
|
301
|
+
Log.i(CapacitorUpdaterPlugin.this.TAG, "No need to update, " + currentVersion + " is the latest");
|
|
297
302
|
}
|
|
298
|
-
} catch (JSONException e) {
|
|
303
|
+
} catch (final JSONException e) {
|
|
299
304
|
e.printStackTrace();
|
|
300
305
|
}
|
|
301
306
|
});
|
|
@@ -304,106 +309,106 @@ public class CapacitorUpdaterPlugin extends Plugin implements Application.Activi
|
|
|
304
309
|
}
|
|
305
310
|
|
|
306
311
|
@Override
|
|
307
|
-
public void onActivityStopped(@NonNull Activity activity) {
|
|
308
|
-
String pathHot = implementation.getLastPathHot();
|
|
309
|
-
Log.i(TAG, "Check for waiting update");
|
|
310
|
-
String nextVersion = prefs.getString("nextVersion", "");
|
|
311
|
-
Boolean delayUpdate = prefs.getBoolean("delayUpdate", false);
|
|
312
|
-
editor.putBoolean("delayUpdate", false);
|
|
313
|
-
editor.commit();
|
|
312
|
+
public void onActivityStopped(@NonNull final Activity activity) {
|
|
313
|
+
final String pathHot = this.implementation.getLastPathHot();
|
|
314
|
+
Log.i(this.TAG, "Check for waiting update");
|
|
315
|
+
final String nextVersion = this.prefs.getString("nextVersion", "");
|
|
316
|
+
final Boolean delayUpdate = this.prefs.getBoolean("delayUpdate", false);
|
|
317
|
+
this.editor.putBoolean("delayUpdate", false);
|
|
318
|
+
this.editor.commit();
|
|
314
319
|
if (delayUpdate) {
|
|
315
|
-
Log.i(TAG, "Update delayed to next backgrounding");
|
|
320
|
+
Log.i(this.TAG, "Update delayed to next backgrounding");
|
|
316
321
|
return;
|
|
317
322
|
}
|
|
318
|
-
String nextVersionName = prefs.getString("nextVersionName", "");
|
|
319
|
-
String pastVersion = prefs.getString("pastVersion", "");
|
|
320
|
-
String pastVersionName = prefs.getString("pastVersionName", "");
|
|
321
|
-
Boolean notifyAppReady = prefs.getBoolean("notifyAppReady", false);
|
|
322
|
-
String tmpCurVersion = implementation.getLastPathHot();
|
|
323
|
-
String curVersion = tmpCurVersion.substring(tmpCurVersion.lastIndexOf('/') +1);
|
|
324
|
-
String curVersionName = implementation.getVersionName();
|
|
323
|
+
final String nextVersionName = this.prefs.getString("nextVersionName", "");
|
|
324
|
+
final String pastVersion = this.prefs.getString("pastVersion", "");
|
|
325
|
+
final String pastVersionName = this.prefs.getString("pastVersionName", "");
|
|
326
|
+
final Boolean notifyAppReady = this.prefs.getBoolean("notifyAppReady", false);
|
|
327
|
+
final String tmpCurVersion = this.implementation.getLastPathHot();
|
|
328
|
+
final String curVersion = tmpCurVersion.substring(tmpCurVersion.lastIndexOf('/') +1);
|
|
329
|
+
final String curVersionName = this.implementation.getVersionName();
|
|
325
330
|
if (!nextVersion.equals("") && !nextVersionName.equals("")) {
|
|
326
|
-
Boolean res = implementation.set(nextVersion, nextVersionName);
|
|
331
|
+
final Boolean res = this.implementation.set(nextVersion, nextVersionName);
|
|
327
332
|
if (res && this._reload()) {
|
|
328
|
-
Log.i(TAG, "Auto update to version: " + nextVersionName);
|
|
329
|
-
editor.putString("LatestVersionAutoUpdate", nextVersion);
|
|
330
|
-
editor.putString("LatestVersionNameAutoUpdate", nextVersionName);
|
|
331
|
-
editor.putString("nextVersion", "");
|
|
332
|
-
editor.putString("nextVersionName", "");
|
|
333
|
-
editor.putString("pastVersion", curVersion);
|
|
334
|
-
editor.putString("pastVersionName", curVersionName);
|
|
335
|
-
editor.putBoolean("notifyAppReady", false);
|
|
336
|
-
editor.commit();
|
|
333
|
+
Log.i(this.TAG, "Auto update to version: " + nextVersionName);
|
|
334
|
+
this.editor.putString("LatestVersionAutoUpdate", nextVersion);
|
|
335
|
+
this.editor.putString("LatestVersionNameAutoUpdate", nextVersionName);
|
|
336
|
+
this.editor.putString("nextVersion", "");
|
|
337
|
+
this.editor.putString("nextVersionName", "");
|
|
338
|
+
this.editor.putString("pastVersion", curVersion);
|
|
339
|
+
this.editor.putString("pastVersionName", curVersionName);
|
|
340
|
+
this.editor.putBoolean("notifyAppReady", false);
|
|
341
|
+
this.editor.commit();
|
|
337
342
|
} else {
|
|
338
|
-
Log.i(TAG, "Auto update to version: " + nextVersionName + "Failed");
|
|
343
|
+
Log.i(this.TAG, "Auto update to version: " + nextVersionName + "Failed");
|
|
339
344
|
}
|
|
340
345
|
} else if (!notifyAppReady && !pathHot.equals("public")) {
|
|
341
|
-
Log.i(TAG, "notifyAppReady never trigger");
|
|
342
|
-
Log.i(TAG, "Version: " + curVersionName + ", is considered broken");
|
|
343
|
-
Log.i(TAG, "Will downgraded to version: " + (pastVersionName.equals("") ? "builtin" : pastVersionName) + " for next start");
|
|
344
|
-
Log.i(TAG, "Don't forget to trigger 'notifyAppReady()' in js code to validate a version.");
|
|
346
|
+
Log.i(this.TAG, "notifyAppReady never trigger");
|
|
347
|
+
Log.i(this.TAG, "Version: " + curVersionName + ", is considered broken");
|
|
348
|
+
Log.i(this.TAG, "Will downgraded to version: " + (pastVersionName.equals("") ? "builtin" : pastVersionName) + " for next start");
|
|
349
|
+
Log.i(this.TAG, "Don't forget to trigger 'notifyAppReady()' in js code to validate a version.");
|
|
345
350
|
if (!pastVersion.equals("") && !pastVersionName.equals("")) {
|
|
346
|
-
Boolean res = implementation.set(pastVersion, pastVersionName);
|
|
351
|
+
final Boolean res = this.implementation.set(pastVersion, pastVersionName);
|
|
347
352
|
if (res && this._reload()) {
|
|
348
|
-
Log.i(TAG, "Revert to version: " + (pastVersionName.equals("") ? "builtin" : pastVersionName));
|
|
349
|
-
editor.putString("LatestVersionAutoUpdate", pastVersion);
|
|
350
|
-
editor.putString("LatestVersionNameAutoUpdate", pastVersionName);
|
|
351
|
-
editor.putString("pastVersion", "");
|
|
352
|
-
editor.putString("pastVersionName", "");
|
|
353
|
-
editor.commit();
|
|
353
|
+
Log.i(this.TAG, "Revert to version: " + (pastVersionName.equals("") ? "builtin" : pastVersionName));
|
|
354
|
+
this.editor.putString("LatestVersionAutoUpdate", pastVersion);
|
|
355
|
+
this.editor.putString("LatestVersionNameAutoUpdate", pastVersionName);
|
|
356
|
+
this.editor.putString("pastVersion", "");
|
|
357
|
+
this.editor.putString("pastVersionName", "");
|
|
358
|
+
this.editor.commit();
|
|
354
359
|
} else {
|
|
355
|
-
Log.i(TAG, "Revert to version: " + (pastVersionName.equals("") ? "builtin" : pastVersionName) + "Failed");
|
|
360
|
+
Log.i(this.TAG, "Revert to version: " + (pastVersionName.equals("") ? "builtin" : pastVersionName) + "Failed");
|
|
356
361
|
}
|
|
357
362
|
} else {
|
|
358
363
|
if (this._reset(false)) {
|
|
359
|
-
editor.putString("LatestVersionAutoUpdate", "");
|
|
360
|
-
editor.putString("LatestVersionNameAutoUpdate", "");
|
|
361
|
-
Log.i(TAG, "Auto reset done");
|
|
364
|
+
this.editor.putString("LatestVersionAutoUpdate", "");
|
|
365
|
+
this.editor.putString("LatestVersionNameAutoUpdate", "");
|
|
366
|
+
Log.i(this.TAG, "Auto reset done");
|
|
362
367
|
}
|
|
363
368
|
}
|
|
364
|
-
editor.putString("failingVersion", curVersionName);
|
|
365
|
-
editor.commit();
|
|
369
|
+
this.editor.putString("failingVersion", curVersionName);
|
|
370
|
+
this.editor.commit();
|
|
366
371
|
try {
|
|
367
|
-
Boolean res = implementation.delete(curVersion, curVersionName);
|
|
372
|
+
final Boolean res = this.implementation.delete(curVersion, curVersionName);
|
|
368
373
|
if (res) {
|
|
369
|
-
Log.i(TAG, "Delete failing version: " + curVersionName);
|
|
374
|
+
Log.i(this.TAG, "Delete failing version: " + curVersionName);
|
|
370
375
|
}
|
|
371
|
-
} catch (IOException e) {
|
|
376
|
+
} catch (final IOException e) {
|
|
372
377
|
e.printStackTrace();
|
|
373
378
|
}
|
|
374
379
|
} else if (!pastVersion.equals("")) {
|
|
375
|
-
Log.i(TAG, "Validated version: " + curVersionName);
|
|
380
|
+
Log.i(this.TAG, "Validated version: " + curVersionName);
|
|
376
381
|
try {
|
|
377
|
-
Boolean res = implementation.delete(pastVersion, pastVersionName);
|
|
382
|
+
final Boolean res = this.implementation.delete(pastVersion, pastVersionName);
|
|
378
383
|
if (res) {
|
|
379
|
-
Log.i(TAG, "Delete past version: " + pastVersionName);
|
|
384
|
+
Log.i(this.TAG, "Delete past version: " + pastVersionName);
|
|
380
385
|
}
|
|
381
|
-
} catch (IOException e) {
|
|
386
|
+
} catch (final IOException e) {
|
|
382
387
|
e.printStackTrace();
|
|
383
388
|
}
|
|
384
|
-
editor.putString("pastVersion", "");
|
|
385
|
-
editor.putString("pastVersionName", "");
|
|
386
|
-
editor.commit();
|
|
389
|
+
this.editor.putString("pastVersion", "");
|
|
390
|
+
this.editor.putString("pastVersionName", "");
|
|
391
|
+
this.editor.commit();
|
|
387
392
|
}
|
|
388
393
|
}
|
|
389
394
|
|
|
390
395
|
// not use but necessary here to remove warnings
|
|
391
396
|
@Override
|
|
392
|
-
public void onActivityResumed(@NonNull Activity activity) {
|
|
397
|
+
public void onActivityResumed(@NonNull final Activity activity) {
|
|
393
398
|
}
|
|
394
399
|
|
|
395
400
|
@Override
|
|
396
|
-
public void onActivityPaused(@NonNull Activity activity) {
|
|
401
|
+
public void onActivityPaused(@NonNull final Activity activity) {
|
|
397
402
|
}
|
|
398
403
|
@Override
|
|
399
|
-
public void onActivityCreated(@NonNull Activity activity, @Nullable Bundle savedInstanceState) {
|
|
404
|
+
public void onActivityCreated(@NonNull final Activity activity, @Nullable final Bundle savedInstanceState) {
|
|
400
405
|
}
|
|
401
406
|
|
|
402
407
|
@Override
|
|
403
|
-
public void onActivitySaveInstanceState(@NonNull Activity activity, @NonNull Bundle outState) {
|
|
408
|
+
public void onActivitySaveInstanceState(@NonNull final Activity activity, @NonNull final Bundle outState) {
|
|
404
409
|
}
|
|
405
410
|
|
|
406
411
|
@Override
|
|
407
|
-
public void onActivityDestroyed(@NonNull Activity activity) {
|
|
412
|
+
public void onActivityDestroyed(@NonNull final Activity activity) {
|
|
408
413
|
}
|
|
409
414
|
}
|
|
@@ -22,6 +22,11 @@ public class AppVersion: NSObject {
|
|
|
22
22
|
var message: String?
|
|
23
23
|
var major: Bool?
|
|
24
24
|
}
|
|
25
|
+
extension OperatingSystemVersion {
|
|
26
|
+
func getFullVersion(separator: String = ".") -> String {
|
|
27
|
+
return "\(majorVersion)\(separator)\(minorVersion)\(separator)\(patchVersion)"
|
|
28
|
+
}
|
|
29
|
+
}
|
|
25
30
|
extension Bundle {
|
|
26
31
|
var releaseVersionNumber: String? {
|
|
27
32
|
return infoDictionary?["CFBundleShortVersionString"] as? String
|
|
@@ -37,8 +42,10 @@ extension Bundle {
|
|
|
37
42
|
public var appId = ""
|
|
38
43
|
public var deviceID = UIDevice.current.identifierForVendor?.uuidString ?? ""
|
|
39
44
|
public var notifyDownload: (Int) -> Void = { _ in }
|
|
40
|
-
public var pluginVersion = "3.
|
|
45
|
+
public var pluginVersion = "3.2.1"
|
|
41
46
|
private var versionBuild = Bundle.main.releaseVersionNumber ?? ""
|
|
47
|
+
private var versionCode = Bundle.main.buildVersionNumber ?? ""
|
|
48
|
+
private var versionOs = ProcessInfo().operatingSystemVersion.getFullVersion()
|
|
42
49
|
private var lastPathHot = ""
|
|
43
50
|
private var lastPathPersist = ""
|
|
44
51
|
private let basePathHot = "versions"
|
|
@@ -112,6 +119,8 @@ extension Bundle {
|
|
|
112
119
|
"cap_device_id": self.deviceID,
|
|
113
120
|
"cap_app_id": self.appId,
|
|
114
121
|
"cap_version_build": self.versionBuild,
|
|
122
|
+
"cap_version_code": self.versionCode,
|
|
123
|
+
"cap_version_os": self.versionOs,
|
|
115
124
|
"cap_plugin_version": self.pluginVersion,
|
|
116
125
|
"cap_version_name": UserDefaults.standard.string(forKey: "versionName") ?? "builtin"
|
|
117
126
|
]
|
|
@@ -253,6 +262,8 @@ extension Bundle {
|
|
|
253
262
|
"device_id": self.deviceID,
|
|
254
263
|
"version_name": version,
|
|
255
264
|
"version_build": self.versionBuild,
|
|
265
|
+
"version_code": self.versionCode,
|
|
266
|
+
"version_os": self.versionOs,
|
|
256
267
|
"plugin_version": self.pluginVersion,
|
|
257
268
|
"app_id": self.appId
|
|
258
269
|
]
|