capacitor-ota 1.0.6 → 1.0.7

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;
@@ -619,9 +619,25 @@ var OtaUpdateElement = class extends HTMLElement {
619
619
  }
620
620
  connectedCallback() {
621
621
  const ota = getOtaUpdater();
622
- if (ota) ota.on("stateChange", () => this.render());
622
+ if (ota) ota.on("stateChange", (state) => this.onStateChange(state));
623
623
  this.render();
624
624
  }
625
+ lastStatus = "";
626
+ onStateChange(state) {
627
+ if (state.status === "downloading" && this.lastStatus === "downloading") this.updateProgress(state.progress);
628
+ else {
629
+ this.lastStatus = state.status;
630
+ this.render();
631
+ }
632
+ }
633
+ updateProgress(progress) {
634
+ const circumference = 2 * Math.PI * 45;
635
+ const offset = circumference - circumference * progress / 100;
636
+ const progressBar = this.shadow.querySelector(".progress-bar");
637
+ const progressPercent = this.shadow.querySelector(".progress-percent");
638
+ if (progressBar) progressBar.style.strokeDashoffset = String(offset);
639
+ if (progressPercent) progressPercent.textContent = String(progress);
640
+ }
625
641
  getProgressOffset(progress) {
626
642
  const circumference = 2 * Math.PI * 45;
627
643
  return circumference - circumference * progress / 100;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "capacitor-ota",
3
- "version": "1.0.6",
3
+ "version": "1.0.7",
4
4
  "type": "module",
5
5
  "main": "dist/src/index.mjs",
6
6
  "types": "dist/src/index.d.mts",