capacitor-ota 1.0.8 → 1.0.10

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.
Files changed (2) hide show
  1. package/dist/src/index.mjs +13 -5
  2. package/package.json +2 -2
@@ -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) this.state.currentVersion = 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() {
@@ -65,7 +70,7 @@ var OtaUpdater = class {
65
70
  });
66
71
  try {
67
72
  const url = `${this.config.staticUrl}/updates/${this.config.appId}.json`;
68
- const response = await fetch(url, { cache: "no-store" });
73
+ const response = await fetch(url);
69
74
  if (!response.ok) {
70
75
  if (response.status === 404) {
71
76
  this.setState({ status: "idle" });
@@ -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
- if (compareVersions(data.version, this.state.currentVersion) > 0) {
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,
@@ -124,7 +131,7 @@ var OtaUpdater = class {
124
131
  }
125
132
  try {
126
133
  const url = `${this.config.staticUrl}/updates/${this.config.appId}.json`;
127
- const data = await (await fetch(url, { cache: "no-store" })).json();
134
+ const data = await (await fetch(url)).json();
128
135
  const { CapacitorUpdater } = await import("@capgo/capacitor-updater");
129
136
  const listener = await CapacitorUpdater.addListener("download", (event) => {
130
137
  this.setState({ progress: event.percent });
@@ -133,8 +140,9 @@ var OtaUpdater = class {
133
140
  version
134
141
  });
135
142
  });
143
+ const bundleUrl = data.url.startsWith("http") ? data.url : `${this.config.staticUrl}${data.url}`;
136
144
  const bundle = await CapacitorUpdater.download({
137
- url: data.url,
145
+ url: bundleUrl,
138
146
  version: data.version,
139
147
  checksum: data.checksum
140
148
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "capacitor-ota",
3
- "version": "1.0.8",
3
+ "version": "1.0.10",
4
4
  "type": "module",
5
5
  "main": "dist/src/index.mjs",
6
6
  "types": "dist/src/index.d.mts",
@@ -23,7 +23,7 @@
23
23
  "panel:dev": "vite dev --host",
24
24
  "panel:build": "vite build",
25
25
  "panel:preview": "vite preview",
26
- "build:web": "vite build && wrangler deploy",
26
+ "build:web": "vite build && npx wrangler --cwd .output/ deploy",
27
27
  "db:migrate": "wrangler d1 migrations apply ota-db --local",
28
28
  "db:migrate:remote": "wrangler d1 migrations apply ota-db --remote",
29
29
  "cli": "tsx cli/ota.ts"