capacitor-ota 1.0.6 → 1.0.8

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.
@@ -106,6 +106,9 @@ declare class OtaUpdateElement extends HTMLElement {
106
106
  show(): void;
107
107
  hide(): void;
108
108
  connectedCallback(): void;
109
+ private lastStatus;
110
+ private onStateChange;
111
+ private updateProgress;
109
112
  private getProgressOffset;
110
113
  private render;
111
114
  private renderContent;
@@ -119,25 +119,8 @@ var OtaUpdater = class {
119
119
  });
120
120
  this.emit("downloadStart", { version });
121
121
  if (!isNativePlatform()) {
122
- for (let i = 0; i <= 100; i += 5) {
123
- this.setState({ progress: i });
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;
122
+ this.setState({ status: "idle" });
123
+ return false;
141
124
  }
142
125
  try {
143
126
  const url = `${this.config.staticUrl}/updates/${this.config.appId}.json`;
@@ -181,13 +164,8 @@ var OtaUpdater = class {
181
164
  }
182
165
  }
183
166
  async apply() {
167
+ if (!isNativePlatform()) return;
184
168
  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
169
  if (!this.downloadedBundle) {
192
170
  const error = "No downloaded bundle";
193
171
  this.setState({
@@ -619,9 +597,25 @@ var OtaUpdateElement = class extends HTMLElement {
619
597
  }
620
598
  connectedCallback() {
621
599
  const ota = getOtaUpdater();
622
- if (ota) ota.on("stateChange", () => this.render());
600
+ if (ota) ota.on("stateChange", (state) => this.onStateChange(state));
623
601
  this.render();
624
602
  }
603
+ lastStatus = "";
604
+ onStateChange(state) {
605
+ if (state.status === "downloading" && this.lastStatus === "downloading") this.updateProgress(state.progress);
606
+ else {
607
+ this.lastStatus = state.status;
608
+ this.render();
609
+ }
610
+ }
611
+ updateProgress(progress) {
612
+ const circumference = 2 * Math.PI * 45;
613
+ const offset = circumference - circumference * progress / 100;
614
+ const progressBar = this.shadow.querySelector(".progress-bar");
615
+ const progressPercent = this.shadow.querySelector(".progress-percent");
616
+ if (progressBar) progressBar.style.strokeDashoffset = String(offset);
617
+ if (progressPercent) progressPercent.textContent = String(progress);
618
+ }
625
619
  getProgressOffset(progress) {
626
620
  const circumference = 2 * Math.PI * 45;
627
621
  return circumference - circumference * progress / 100;
@@ -742,6 +736,7 @@ function registerOtaUpdateElement() {
742
736
  //#region src/index.ts
743
737
  async function initOtaUpdate(config) {
744
738
  const ota = createOtaUpdater(config);
739
+ if (!isNativePlatform()) return ota;
745
740
  if (config.showUI !== false) {
746
741
  registerOtaUpdateElement();
747
742
  const element = document.createElement("ota-update");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "capacitor-ota",
3
- "version": "1.0.6",
3
+ "version": "1.0.8",
4
4
  "type": "module",
5
5
  "main": "dist/src/index.mjs",
6
6
  "types": "dist/src/index.d.mts",