capacitor-ota 1.0.7 → 1.0.9
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/dist/src/index.mjs +13 -27
- package/package.json +1 -1
package/dist/src/index.mjs
CHANGED
|
@@ -55,7 +55,12 @@ var OtaUpdater = class {
|
|
|
55
55
|
try {
|
|
56
56
|
const { CapacitorUpdater } = await import("@capgo/capacitor-updater");
|
|
57
57
|
const result = await CapacitorUpdater.notifyAppReady();
|
|
58
|
-
if (result?.bundle?.version)
|
|
58
|
+
if (result?.bundle?.version) {
|
|
59
|
+
const bundleVersion = result.bundle.version;
|
|
60
|
+
const nativeVersion = this.config.appVersion;
|
|
61
|
+
if (compareVersions(bundleVersion, nativeVersion) > 0) this.state.currentVersion = bundleVersion;
|
|
62
|
+
else this.state.currentVersion = nativeVersion;
|
|
63
|
+
}
|
|
59
64
|
} catch {}
|
|
60
65
|
}
|
|
61
66
|
async check() {
|
|
@@ -74,7 +79,9 @@ var OtaUpdater = class {
|
|
|
74
79
|
throw new Error(`HTTP ${response.status}`);
|
|
75
80
|
}
|
|
76
81
|
const data = await response.json();
|
|
77
|
-
|
|
82
|
+
const isNewer = compareVersions(data.version, this.state.currentVersion) > 0;
|
|
83
|
+
const isNewerThanNative = compareVersions(data.version, this.config.appVersion) > 0;
|
|
84
|
+
if (isNewer && isNewerThanNative) {
|
|
78
85
|
this.setState({ newVersion: data.version });
|
|
79
86
|
this.emit("updateAvailable", {
|
|
80
87
|
currentVersion: this.state.currentVersion,
|
|
@@ -119,25 +126,8 @@ var OtaUpdater = class {
|
|
|
119
126
|
});
|
|
120
127
|
this.emit("downloadStart", { version });
|
|
121
128
|
if (!isNativePlatform()) {
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
this.emit("downloadProgress", {
|
|
125
|
-
progress: i,
|
|
126
|
-
version
|
|
127
|
-
});
|
|
128
|
-
await new Promise((r) => setTimeout(r, 50));
|
|
129
|
-
}
|
|
130
|
-
this.downloadedBundle = {
|
|
131
|
-
id: "web-sim",
|
|
132
|
-
version
|
|
133
|
-
};
|
|
134
|
-
this.setState({ status: "ready" });
|
|
135
|
-
this.emit("downloadComplete", { version });
|
|
136
|
-
this.emit("updateReady", {
|
|
137
|
-
version,
|
|
138
|
-
bundleId: "web-sim"
|
|
139
|
-
});
|
|
140
|
-
return true;
|
|
129
|
+
this.setState({ status: "idle" });
|
|
130
|
+
return false;
|
|
141
131
|
}
|
|
142
132
|
try {
|
|
143
133
|
const url = `${this.config.staticUrl}/updates/${this.config.appId}.json`;
|
|
@@ -181,13 +171,8 @@ var OtaUpdater = class {
|
|
|
181
171
|
}
|
|
182
172
|
}
|
|
183
173
|
async apply() {
|
|
174
|
+
if (!isNativePlatform()) return;
|
|
184
175
|
this.setState({ status: "applying" });
|
|
185
|
-
if (!isNativePlatform()) {
|
|
186
|
-
await new Promise((r) => setTimeout(r, 500));
|
|
187
|
-
this.emit("updateApplied", { version: this.state.newVersion || "" });
|
|
188
|
-
window.location.reload();
|
|
189
|
-
return;
|
|
190
|
-
}
|
|
191
176
|
if (!this.downloadedBundle) {
|
|
192
177
|
const error = "No downloaded bundle";
|
|
193
178
|
this.setState({
|
|
@@ -758,6 +743,7 @@ function registerOtaUpdateElement() {
|
|
|
758
743
|
//#region src/index.ts
|
|
759
744
|
async function initOtaUpdate(config) {
|
|
760
745
|
const ota = createOtaUpdater(config);
|
|
746
|
+
if (!isNativePlatform()) return ota;
|
|
761
747
|
if (config.showUI !== false) {
|
|
762
748
|
registerOtaUpdateElement();
|
|
763
749
|
const element = document.createElement("ota-update");
|