@capgo/capacitor-updater 3.2.0 → 3.3.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 +4 -4
- package/android/src/main/java/ee/forgr/capacitor_updater/CapacitorUpdater.java +209 -212
- package/android/src/main/java/ee/forgr/capacitor_updater/CapacitorUpdaterPlugin.java +188 -182
- package/ios/Plugin/CapacitorUpdater.swift +63 -26
- package/ios/Plugin/CapacitorUpdaterPlugin.m +1 -0
- package/ios/Plugin/CapacitorUpdaterPlugin.swift +13 -9
- package/package.json +1 -1
|
@@ -5,13 +5,11 @@ import android.app.Application;
|
|
|
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;
|
|
9
8
|
import android.os.Bundle;
|
|
10
9
|
import android.util.Log;
|
|
11
10
|
|
|
12
11
|
import androidx.annotation.NonNull;
|
|
13
12
|
import androidx.annotation.Nullable;
|
|
14
|
-
import androidx.annotation.RequiresApi;
|
|
15
13
|
|
|
16
14
|
import com.getcapacitor.CapConfig;
|
|
17
15
|
import com.getcapacitor.JSArray;
|
|
@@ -29,107 +27,123 @@ import java.util.ArrayList;
|
|
|
29
27
|
|
|
30
28
|
@CapacitorPlugin(name = "CapacitorUpdater")
|
|
31
29
|
public class CapacitorUpdaterPlugin extends Plugin implements Application.ActivityLifecycleCallbacks {
|
|
32
|
-
private String
|
|
30
|
+
private static final String autoUpdateUrlDefault = "https://capgo.app/api/auto_update";
|
|
31
|
+
private static final String statsUrlDefault = "https://capgo.app/api/stats";
|
|
32
|
+
private final String TAG = "Capacitor-updater";
|
|
33
33
|
private CapacitorUpdater implementation;
|
|
34
|
+
|
|
34
35
|
private SharedPreferences prefs;
|
|
35
36
|
private SharedPreferences.Editor editor;
|
|
36
|
-
|
|
37
|
-
private static final String statsUrlDefault = "https://capgo.app/api/stats";
|
|
37
|
+
|
|
38
38
|
private String autoUpdateUrl = "";
|
|
39
39
|
private Version currentVersionNative;
|
|
40
40
|
private Boolean autoUpdate = false;
|
|
41
41
|
private Boolean resetWhenUpdate = true;
|
|
42
42
|
|
|
43
|
-
|
|
44
43
|
@Override
|
|
45
44
|
public void load() {
|
|
46
45
|
super.load();
|
|
47
46
|
this.prefs = this.getContext().getSharedPreferences("CapWebViewSettings", Activity.MODE_PRIVATE);
|
|
48
|
-
this.editor = prefs.edit();
|
|
47
|
+
this.editor = this.prefs.edit();
|
|
49
48
|
try {
|
|
50
|
-
implementation = new CapacitorUpdater(this.getContext()
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
49
|
+
this.implementation = new CapacitorUpdater(this.getContext()) {
|
|
50
|
+
@Override
|
|
51
|
+
public void notifyDownload(final int percent) {
|
|
52
|
+
this.notifyDownload(percent);
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
final PackageInfo pInfo = this.getContext().getPackageManager().getPackageInfo(this.getContext().getPackageName(), 0);
|
|
56
|
+
this.currentVersionNative = new Version(pInfo.versionName);
|
|
57
|
+
} catch (final PackageManager.NameNotFoundException e) {
|
|
58
|
+
Log.e(this.TAG, "Error instantiating implementation", e);
|
|
55
59
|
return;
|
|
56
|
-
} catch (Exception ex) {
|
|
57
|
-
Log.e(TAG, "Error
|
|
60
|
+
} catch (final Exception ex) {
|
|
61
|
+
Log.e(this.TAG, "Error getting current native app version", ex);
|
|
58
62
|
return;
|
|
59
63
|
}
|
|
60
|
-
CapConfig config = CapConfig.loadDefault(getActivity());
|
|
61
|
-
implementation.
|
|
62
|
-
implementation.
|
|
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", ""));
|
|
64
|
+
final CapConfig config = CapConfig.loadDefault(this.getActivity());
|
|
65
|
+
this.implementation.setAppId(config.getString("appId", ""));
|
|
66
|
+
this.implementation.setStatsUrl(this.getConfig().getString("statsUrl", statsUrlDefault));
|
|
67
|
+
this.autoUpdateUrl = this.getConfig().getString("autoUpdateUrl", autoUpdateUrlDefault);
|
|
68
|
+
this.autoUpdate = this.getConfig().getBoolean("autoUpdate", false);
|
|
69
|
+
this.resetWhenUpdate = this.getConfig().getBoolean("resetWhenUpdate", true);
|
|
70
|
+
if (this.resetWhenUpdate) {
|
|
71
|
+
final Version LatestVersionNative = new Version(this.prefs.getString("LatestVersionNative", ""));
|
|
68
72
|
try {
|
|
69
|
-
if (!LatestVersionNative.equals("") && currentVersionNative.getMajor() > LatestVersionNative.getMajor()) {
|
|
73
|
+
if (!LatestVersionNative.equals("") && this.currentVersionNative.getMajor() > LatestVersionNative.getMajor()) {
|
|
70
74
|
this._reset(false);
|
|
71
|
-
editor.putString("LatestVersionAutoUpdate", "");
|
|
72
|
-
editor.putString("LatestVersionNameAutoUpdate", "");
|
|
73
|
-
ArrayList<String> res = implementation.list();
|
|
75
|
+
this.editor.putString("LatestVersionAutoUpdate", "");
|
|
76
|
+
this.editor.putString("LatestVersionNameAutoUpdate", "");
|
|
77
|
+
final ArrayList<String> res = this.implementation.list();
|
|
74
78
|
for (int i = 0; i < res.size(); i++) {
|
|
75
79
|
try {
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
80
|
+
final String version = res.get(i);
|
|
81
|
+
this.implementation.delete(version, "");
|
|
82
|
+
Log.i(this.TAG, "Deleted obsolete version: " + version);
|
|
83
|
+
} catch (final IOException e) {
|
|
84
|
+
Log.e(CapacitorUpdaterPlugin.this.TAG, "error deleting version", e);
|
|
79
85
|
}
|
|
80
86
|
}
|
|
81
87
|
}
|
|
82
|
-
editor.putString("LatestVersionNative", currentVersionNative.toString());
|
|
83
|
-
editor.commit();
|
|
84
|
-
} catch (Exception ex) {
|
|
85
|
-
Log.e(
|
|
88
|
+
this.editor.putString("LatestVersionNative", this.currentVersionNative.toString());
|
|
89
|
+
this.editor.commit();
|
|
90
|
+
} catch (final Exception ex) {
|
|
91
|
+
Log.e(this.TAG, "Cannot get the current version " + ex.getMessage());
|
|
86
92
|
}
|
|
87
93
|
}
|
|
88
|
-
if (!autoUpdate || this.autoUpdateUrl.equals("")) return;
|
|
89
|
-
Application application = (Application) this.getContext().getApplicationContext();
|
|
94
|
+
if (!this.autoUpdate || this.autoUpdateUrl.equals("")) return;
|
|
95
|
+
final Application application = (Application) this.getContext().getApplicationContext();
|
|
90
96
|
application.registerActivityLifecycleCallbacks(this);
|
|
91
|
-
onActivityStarted(getActivity());
|
|
97
|
+
this.onActivityStarted(this.getActivity());
|
|
92
98
|
}
|
|
93
99
|
|
|
94
|
-
public void notifyDownload(int percent) {
|
|
95
|
-
JSObject ret = new JSObject();
|
|
100
|
+
public void notifyDownload(final int percent) {
|
|
101
|
+
final JSObject ret = new JSObject();
|
|
96
102
|
ret.put("percent", percent);
|
|
97
|
-
notifyListeners("download", ret);
|
|
103
|
+
this.notifyListeners("download", ret);
|
|
98
104
|
}
|
|
99
105
|
|
|
100
106
|
@PluginMethod
|
|
101
|
-
public void getId(PluginCall call) {
|
|
102
|
-
JSObject ret = new JSObject();
|
|
103
|
-
ret.put("id", implementation.
|
|
107
|
+
public void getId(final PluginCall call) {
|
|
108
|
+
final JSObject ret = new JSObject();
|
|
109
|
+
ret.put("id", this.implementation.getDeviceID());
|
|
104
110
|
call.resolve(ret);
|
|
105
111
|
}
|
|
106
112
|
|
|
107
113
|
@PluginMethod
|
|
108
|
-
public void
|
|
114
|
+
public void getPluginVersion(final PluginCall call) {
|
|
115
|
+
final JSObject ret = new JSObject();
|
|
116
|
+
ret.put("vrsion", this.implementation.pluginVersion);
|
|
117
|
+
call.resolve(ret);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
@PluginMethod
|
|
121
|
+
public void download(final PluginCall call) {
|
|
109
122
|
new Thread(new Runnable(){
|
|
110
123
|
@Override
|
|
111
124
|
public void run() {
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
JSObject ret = new JSObject();
|
|
116
|
-
ret.put("version",
|
|
125
|
+
try {
|
|
126
|
+
final String url = call.getString("url");
|
|
127
|
+
final String version = CapacitorUpdaterPlugin.this.implementation.download(url);
|
|
128
|
+
final JSObject ret = new JSObject();
|
|
129
|
+
ret.put("version", version);
|
|
117
130
|
call.resolve(ret);
|
|
118
|
-
}
|
|
119
|
-
|
|
131
|
+
} catch (final IOException e) {
|
|
132
|
+
Log.e(CapacitorUpdaterPlugin.this.TAG, "download failed", e);
|
|
133
|
+
call.reject("download failed", e);
|
|
120
134
|
}
|
|
121
135
|
}
|
|
122
136
|
}).start();
|
|
123
137
|
}
|
|
124
138
|
|
|
125
139
|
private boolean _reload() {
|
|
126
|
-
String pathHot = implementation.getLastPathHot();
|
|
140
|
+
final String pathHot = this.implementation.getLastPathHot();
|
|
127
141
|
this.bridge.setServerBasePath(pathHot);
|
|
128
142
|
return true;
|
|
129
143
|
}
|
|
130
|
-
|
|
144
|
+
|
|
131
145
|
@PluginMethod
|
|
132
|
-
public void reload(PluginCall call) {
|
|
146
|
+
public void reload(final PluginCall call) {
|
|
133
147
|
if (this._reload()) {
|
|
134
148
|
call.resolve();
|
|
135
149
|
} else {
|
|
@@ -138,10 +152,10 @@ public class CapacitorUpdaterPlugin extends Plugin implements Application.Activi
|
|
|
138
152
|
}
|
|
139
153
|
|
|
140
154
|
@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);
|
|
155
|
+
public void set(final PluginCall call) {
|
|
156
|
+
final String version = call.getString("version");
|
|
157
|
+
final String versionName = call.getString("versionName", version);
|
|
158
|
+
final Boolean res = this.implementation.set(version, versionName);
|
|
145
159
|
|
|
146
160
|
if (!res) {
|
|
147
161
|
call.reject("Update failed, version " + version + " doesn't exist");
|
|
@@ -151,38 +165,38 @@ public class CapacitorUpdaterPlugin extends Plugin implements Application.Activi
|
|
|
151
165
|
}
|
|
152
166
|
|
|
153
167
|
@PluginMethod
|
|
154
|
-
public void delete(PluginCall call) {
|
|
155
|
-
String version = call.getString("version");
|
|
168
|
+
public void delete(final PluginCall call) {
|
|
169
|
+
final String version = call.getString("version");
|
|
156
170
|
try {
|
|
157
|
-
Boolean res = implementation.delete(version, "");
|
|
171
|
+
final Boolean res = this.implementation.delete(version, "");
|
|
158
172
|
if (res) {
|
|
159
173
|
call.resolve();
|
|
160
174
|
} else {
|
|
161
175
|
call.reject("Delete failed, version " + version + " doesn't exist");
|
|
162
176
|
}
|
|
163
|
-
} catch(IOException ex) {
|
|
164
|
-
Log.e(
|
|
177
|
+
} catch(final IOException ex) {
|
|
178
|
+
Log.e(this.TAG, "An unexpected error occurred during deletion of folder. Message: " + ex.getMessage());
|
|
165
179
|
call.reject("An unexpected error occurred during deletion of folder.");
|
|
166
180
|
}
|
|
167
181
|
}
|
|
168
182
|
|
|
169
183
|
@PluginMethod
|
|
170
|
-
public void list(PluginCall call) {
|
|
171
|
-
ArrayList<String> res = implementation.list();
|
|
172
|
-
JSObject ret = new JSObject();
|
|
184
|
+
public void list(final PluginCall call) {
|
|
185
|
+
final ArrayList<String> res = this.implementation.list();
|
|
186
|
+
final JSObject ret = new JSObject();
|
|
173
187
|
ret.put("versions", new JSArray(res));
|
|
174
188
|
call.resolve(ret);
|
|
175
189
|
}
|
|
176
190
|
|
|
177
|
-
private boolean _reset(Boolean toAutoUpdate) {
|
|
178
|
-
String version = prefs.getString("LatestVersionAutoUpdate", "");
|
|
179
|
-
String versionName = prefs.getString("LatestVersionNameAutoUpdate", "");
|
|
191
|
+
private boolean _reset(final Boolean toAutoUpdate) {
|
|
192
|
+
final String version = this.prefs.getString("LatestVersionAutoUpdate", "");
|
|
193
|
+
final String versionName = this.prefs.getString("LatestVersionNameAutoUpdate", "");
|
|
180
194
|
if (toAutoUpdate && !version.equals("") && !versionName.equals("")) {
|
|
181
|
-
Boolean res = implementation.set(version, versionName);
|
|
195
|
+
final Boolean res = this.implementation.set(version, versionName);
|
|
182
196
|
return res && this._reload();
|
|
183
197
|
}
|
|
184
|
-
implementation.reset();
|
|
185
|
-
String pathHot = implementation.getLastPathHot();
|
|
198
|
+
this.implementation.reset();
|
|
199
|
+
final String pathHot = this.implementation.getLastPathHot();
|
|
186
200
|
if (this.bridge.getLocalServer() != null) {
|
|
187
201
|
// if the server is not ready yet, hot reload is not needed
|
|
188
202
|
this.bridge.setServerAssetPath(pathHot);
|
|
@@ -191,8 +205,8 @@ public class CapacitorUpdaterPlugin extends Plugin implements Application.Activi
|
|
|
191
205
|
}
|
|
192
206
|
|
|
193
207
|
@PluginMethod
|
|
194
|
-
public void reset(PluginCall call) {
|
|
195
|
-
Boolean toAutoUpdate = call.getBoolean("toAutoUpdate");
|
|
208
|
+
public void reset(final PluginCall call) {
|
|
209
|
+
final Boolean toAutoUpdate = call.getBoolean("toAutoUpdate", false);
|
|
196
210
|
if (this._reset(toAutoUpdate)) {
|
|
197
211
|
call.resolve();
|
|
198
212
|
return;
|
|
@@ -201,102 +215,94 @@ public class CapacitorUpdaterPlugin extends Plugin implements Application.Activi
|
|
|
201
215
|
}
|
|
202
216
|
|
|
203
217
|
@PluginMethod
|
|
204
|
-
public void versionName(PluginCall call) {
|
|
205
|
-
String name = implementation.getVersionName();
|
|
206
|
-
JSObject ret = new JSObject();
|
|
218
|
+
public void versionName(final PluginCall call) {
|
|
219
|
+
final String name = this.implementation.getVersionName();
|
|
220
|
+
final JSObject ret = new JSObject();
|
|
207
221
|
ret.put("versionName", name);
|
|
208
222
|
call.resolve(ret);
|
|
209
223
|
}
|
|
210
224
|
|
|
211
225
|
@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";
|
|
226
|
+
public void current(final PluginCall call) {
|
|
227
|
+
final String pathHot = this.implementation.getLastPathHot();
|
|
228
|
+
final JSObject ret = new JSObject();
|
|
229
|
+
final String current = pathHot.length() >= 10 ? pathHot.substring(pathHot.length() - 10) : "builtin";
|
|
216
230
|
ret.put("current", current);
|
|
217
|
-
ret.put("currentNative", currentVersionNative);
|
|
231
|
+
ret.put("currentNative", this.currentVersionNative);
|
|
218
232
|
call.resolve(ret);
|
|
219
233
|
}
|
|
220
234
|
|
|
221
235
|
@PluginMethod
|
|
222
|
-
public void notifyAppReady(PluginCall call) {
|
|
223
|
-
editor.putBoolean("notifyAppReady", true);
|
|
224
|
-
editor.commit();
|
|
236
|
+
public void notifyAppReady(final PluginCall call) {
|
|
237
|
+
this.editor.putBoolean("notifyAppReady", true);
|
|
238
|
+
this.editor.commit();
|
|
225
239
|
call.resolve();
|
|
226
240
|
}
|
|
227
241
|
|
|
228
242
|
@PluginMethod
|
|
229
|
-
public void delayUpdate(PluginCall call) {
|
|
230
|
-
editor.putBoolean("delayUpdate", true);
|
|
231
|
-
editor.commit();
|
|
243
|
+
public void delayUpdate(final PluginCall call) {
|
|
244
|
+
this.editor.putBoolean("delayUpdate", true);
|
|
245
|
+
this.editor.commit();
|
|
232
246
|
call.resolve();
|
|
233
247
|
}
|
|
234
248
|
|
|
235
249
|
@PluginMethod
|
|
236
|
-
public void cancelDelay(PluginCall call) {
|
|
237
|
-
editor.putBoolean("delayUpdate", false);
|
|
238
|
-
editor.commit();
|
|
250
|
+
public void cancelDelay(final PluginCall call) {
|
|
251
|
+
this.editor.putBoolean("delayUpdate", false);
|
|
252
|
+
this.editor.commit();
|
|
239
253
|
call.resolve();
|
|
240
254
|
}
|
|
241
255
|
|
|
242
256
|
@Override
|
|
243
|
-
public void onActivityStarted(@NonNull Activity activity) {
|
|
257
|
+
public void onActivityStarted(@NonNull final Activity activity) {
|
|
244
258
|
// disableRevert disableBreaking
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
PackageInfo pInfo = this.getContext().getPackageManager().getPackageInfo(this.getContext().getPackageName(), 0);
|
|
248
|
-
currentVersionNative = pInfo.versionName;
|
|
249
|
-
} catch (Exception ex) {
|
|
250
|
-
Log.e(TAG, "Error get stats", ex);
|
|
251
|
-
return;
|
|
252
|
-
}
|
|
253
|
-
Log.i(TAG, "Check for update in the server");
|
|
254
|
-
if (autoUpdateUrl.equals("")) return;
|
|
255
|
-
String finalCurrentVersionNative = currentVersionNative;
|
|
259
|
+
Log.i(this.TAG, "Check for update in the server");
|
|
260
|
+
if (this.autoUpdateUrl.equals("")) return;
|
|
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
|
|
285
|
+
final String url = (String) res.get("url");
|
|
286
|
+
final String dl = CapacitorUpdaterPlugin.this.implementation.download(url);
|
|
281
287
|
if (dl.equals("")) {
|
|
282
|
-
Log.i(TAG, "Download version: " + newVersion + " failed");
|
|
288
|
+
Log.i(CapacitorUpdaterPlugin.this.TAG, "Download version: " + newVersion + " failed");
|
|
283
289
|
return;
|
|
284
290
|
}
|
|
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 (
|
|
291
|
-
e.
|
|
291
|
+
Log.i(CapacitorUpdaterPlugin.this.TAG, "New version: " + newVersion + " found. Current is " + (currentVersion.equals("") ? "builtin" : currentVersion) + ", next backgrounding will trigger update");
|
|
292
|
+
CapacitorUpdaterPlugin.this.editor.putString("nextVersion", dl);
|
|
293
|
+
CapacitorUpdaterPlugin.this.editor.putString("nextVersionName", (String) res.get("version"));
|
|
294
|
+
CapacitorUpdaterPlugin.this.editor.commit();
|
|
295
|
+
CapacitorUpdaterPlugin.this.notifyListeners("updateAvailable", ret);
|
|
296
|
+
} catch (final Exception e) {
|
|
297
|
+
Log.e(CapacitorUpdaterPlugin.this.TAG, "error downloading file", e);
|
|
292
298
|
}
|
|
293
299
|
}
|
|
294
300
|
}).start();
|
|
295
301
|
} else {
|
|
296
|
-
Log.i(TAG, "No need to update, " + currentVersion + " is the latest");
|
|
302
|
+
Log.i(CapacitorUpdaterPlugin.this.TAG, "No need to update, " + currentVersion + " is the latest");
|
|
297
303
|
}
|
|
298
|
-
} catch (JSONException e) {
|
|
299
|
-
e.
|
|
304
|
+
} catch (final JSONException e) {
|
|
305
|
+
Log.e(CapacitorUpdaterPlugin.this.TAG, "error parsing JSON", e);
|
|
300
306
|
}
|
|
301
307
|
});
|
|
302
308
|
}
|
|
@@ -304,106 +310,106 @@ public class CapacitorUpdaterPlugin extends Plugin implements Application.Activi
|
|
|
304
310
|
}
|
|
305
311
|
|
|
306
312
|
@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();
|
|
313
|
+
public void onActivityStopped(@NonNull final Activity activity) {
|
|
314
|
+
final String pathHot = this.implementation.getLastPathHot();
|
|
315
|
+
Log.i(this.TAG, "Check for waiting update");
|
|
316
|
+
final String nextVersion = this.prefs.getString("nextVersion", "");
|
|
317
|
+
final Boolean delayUpdate = this.prefs.getBoolean("delayUpdate", false);
|
|
318
|
+
this.editor.putBoolean("delayUpdate", false);
|
|
319
|
+
this.editor.commit();
|
|
314
320
|
if (delayUpdate) {
|
|
315
|
-
Log.i(TAG, "Update delayed to next backgrounding");
|
|
321
|
+
Log.i(this.TAG, "Update delayed to next backgrounding");
|
|
316
322
|
return;
|
|
317
323
|
}
|
|
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();
|
|
324
|
+
final String nextVersionName = this.prefs.getString("nextVersionName", "");
|
|
325
|
+
final String pastVersion = this.prefs.getString("pastVersion", "");
|
|
326
|
+
final String pastVersionName = this.prefs.getString("pastVersionName", "");
|
|
327
|
+
final Boolean notifyAppReady = this.prefs.getBoolean("notifyAppReady", false);
|
|
328
|
+
final String tmpCurVersion = this.implementation.getLastPathHot();
|
|
329
|
+
final String curVersion = tmpCurVersion.substring(tmpCurVersion.lastIndexOf('/') +1);
|
|
330
|
+
final String curVersionName = this.implementation.getVersionName();
|
|
325
331
|
if (!nextVersion.equals("") && !nextVersionName.equals("")) {
|
|
326
|
-
Boolean res = implementation.set(nextVersion, nextVersionName);
|
|
332
|
+
final Boolean res = this.implementation.set(nextVersion, nextVersionName);
|
|
327
333
|
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();
|
|
334
|
+
Log.i(this.TAG, "Auto update to version: " + nextVersionName);
|
|
335
|
+
this.editor.putString("LatestVersionAutoUpdate", nextVersion);
|
|
336
|
+
this.editor.putString("LatestVersionNameAutoUpdate", nextVersionName);
|
|
337
|
+
this.editor.putString("nextVersion", "");
|
|
338
|
+
this.editor.putString("nextVersionName", "");
|
|
339
|
+
this.editor.putString("pastVersion", curVersion);
|
|
340
|
+
this.editor.putString("pastVersionName", curVersionName);
|
|
341
|
+
this.editor.putBoolean("notifyAppReady", false);
|
|
342
|
+
this.editor.commit();
|
|
337
343
|
} else {
|
|
338
|
-
Log.i(TAG, "Auto update to version: " + nextVersionName + "Failed");
|
|
344
|
+
Log.i(this.TAG, "Auto update to version: " + nextVersionName + "Failed");
|
|
339
345
|
}
|
|
340
346
|
} 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.");
|
|
347
|
+
Log.i(this.TAG, "notifyAppReady never trigger");
|
|
348
|
+
Log.i(this.TAG, "Version: " + curVersionName + ", is considered broken");
|
|
349
|
+
Log.i(this.TAG, "Will downgraded to version: " + (pastVersionName.equals("") ? "builtin" : pastVersionName) + " for next start");
|
|
350
|
+
Log.i(this.TAG, "Don't forget to trigger 'notifyAppReady()' in js code to validate a version.");
|
|
345
351
|
if (!pastVersion.equals("") && !pastVersionName.equals("")) {
|
|
346
|
-
Boolean res = implementation.set(pastVersion, pastVersionName);
|
|
352
|
+
final Boolean res = this.implementation.set(pastVersion, pastVersionName);
|
|
347
353
|
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();
|
|
354
|
+
Log.i(this.TAG, "Revert to version: " + (pastVersionName.equals("") ? "builtin" : pastVersionName));
|
|
355
|
+
this.editor.putString("LatestVersionAutoUpdate", pastVersion);
|
|
356
|
+
this.editor.putString("LatestVersionNameAutoUpdate", pastVersionName);
|
|
357
|
+
this.editor.putString("pastVersion", "");
|
|
358
|
+
this.editor.putString("pastVersionName", "");
|
|
359
|
+
this.editor.commit();
|
|
354
360
|
} else {
|
|
355
|
-
Log.i(TAG, "Revert to version: " + (pastVersionName.equals("") ? "builtin" : pastVersionName) + "Failed");
|
|
361
|
+
Log.i(this.TAG, "Revert to version: " + (pastVersionName.equals("") ? "builtin" : pastVersionName) + "Failed");
|
|
356
362
|
}
|
|
357
363
|
} else {
|
|
358
364
|
if (this._reset(false)) {
|
|
359
|
-
editor.putString("LatestVersionAutoUpdate", "");
|
|
360
|
-
editor.putString("LatestVersionNameAutoUpdate", "");
|
|
361
|
-
Log.i(TAG, "Auto reset done");
|
|
365
|
+
this.editor.putString("LatestVersionAutoUpdate", "");
|
|
366
|
+
this.editor.putString("LatestVersionNameAutoUpdate", "");
|
|
367
|
+
Log.i(this.TAG, "Auto reset done");
|
|
362
368
|
}
|
|
363
369
|
}
|
|
364
|
-
editor.putString("failingVersion", curVersionName);
|
|
365
|
-
editor.commit();
|
|
370
|
+
this.editor.putString("failingVersion", curVersionName);
|
|
371
|
+
this.editor.commit();
|
|
366
372
|
try {
|
|
367
|
-
Boolean res = implementation.delete(curVersion, curVersionName);
|
|
373
|
+
final Boolean res = this.implementation.delete(curVersion, curVersionName);
|
|
368
374
|
if (res) {
|
|
369
|
-
Log.i(TAG, "
|
|
375
|
+
Log.i(this.TAG, "Deleted failing version: " + curVersionName);
|
|
370
376
|
}
|
|
371
|
-
} catch (IOException e) {
|
|
372
|
-
e.
|
|
377
|
+
} catch (final IOException e) {
|
|
378
|
+
Log.e(CapacitorUpdaterPlugin.this.TAG, "error deleting version", e);
|
|
373
379
|
}
|
|
374
380
|
} else if (!pastVersion.equals("")) {
|
|
375
|
-
Log.i(TAG, "Validated version: " + curVersionName);
|
|
381
|
+
Log.i(this.TAG, "Validated version: " + curVersionName);
|
|
376
382
|
try {
|
|
377
|
-
Boolean res = implementation.delete(pastVersion, pastVersionName);
|
|
383
|
+
final Boolean res = this.implementation.delete(pastVersion, pastVersionName);
|
|
378
384
|
if (res) {
|
|
379
|
-
Log.i(TAG, "
|
|
385
|
+
Log.i(this.TAG, "Deleted past version: " + pastVersionName);
|
|
380
386
|
}
|
|
381
|
-
} catch (IOException e) {
|
|
382
|
-
e.
|
|
387
|
+
} catch (final IOException e) {
|
|
388
|
+
Log.e(CapacitorUpdaterPlugin.this.TAG, "error deleting version", e);
|
|
383
389
|
}
|
|
384
|
-
editor.putString("pastVersion", "");
|
|
385
|
-
editor.putString("pastVersionName", "");
|
|
386
|
-
editor.commit();
|
|
390
|
+
this.editor.putString("pastVersion", "");
|
|
391
|
+
this.editor.putString("pastVersionName", "");
|
|
392
|
+
this.editor.commit();
|
|
387
393
|
}
|
|
388
394
|
}
|
|
389
395
|
|
|
390
396
|
// not use but necessary here to remove warnings
|
|
391
397
|
@Override
|
|
392
|
-
public void onActivityResumed(@NonNull Activity activity) {
|
|
398
|
+
public void onActivityResumed(@NonNull final Activity activity) {
|
|
393
399
|
}
|
|
394
400
|
|
|
395
401
|
@Override
|
|
396
|
-
public void onActivityPaused(@NonNull Activity activity) {
|
|
402
|
+
public void onActivityPaused(@NonNull final Activity activity) {
|
|
397
403
|
}
|
|
398
404
|
@Override
|
|
399
|
-
public void onActivityCreated(@NonNull Activity activity, @Nullable Bundle savedInstanceState) {
|
|
405
|
+
public void onActivityCreated(@NonNull final Activity activity, @Nullable final Bundle savedInstanceState) {
|
|
400
406
|
}
|
|
401
407
|
|
|
402
408
|
@Override
|
|
403
|
-
public void onActivitySaveInstanceState(@NonNull Activity activity, @NonNull Bundle outState) {
|
|
409
|
+
public void onActivitySaveInstanceState(@NonNull final Activity activity, @NonNull final Bundle outState) {
|
|
404
410
|
}
|
|
405
411
|
|
|
406
412
|
@Override
|
|
407
|
-
public void onActivityDestroyed(@NonNull Activity activity) {
|
|
413
|
+
public void onActivityDestroyed(@NonNull final Activity activity) {
|
|
408
414
|
}
|
|
409
415
|
}
|