Skip to content

Commit

Permalink
fix: android update
Browse files Browse the repository at this point in the history
  • Loading branch information
riderx committed Aug 17, 2023
1 parent e3d1d93 commit bbd4c50
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,10 @@ void notifyDownload(final String id, final int percent) {
return;
}

void directUpdateFinish(final BundleInfo latest) {
return;
}

void notifyListeners(final String id, final JSObject res) {
return;
}
Expand Down Expand Up @@ -371,7 +375,7 @@ public void finishDownload(
CapacitorUpdater.this.notifyListeners("updateAvailable", ret);
if (setNext) {
if (this.directUpdate) {
this.set(next);
CapacitorUpdater.this.directUpdateFinish(next);
} else {
this.setNextBundle(next.getId());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,11 @@ public void notifyDownload(final String id, final int percent) {
CapacitorUpdaterPlugin.this.notifyDownload(id, percent);
}

@Override
public void directUpdateFinish(final BundleInfo latest) {
CapacitorUpdaterPlugin.this.directUpdateFinish(latest);
}

@Override
public void notifyListeners(final String id, final JSObject res) {
CapacitorUpdaterPlugin.this.notifyListeners(id, res);
Expand Down Expand Up @@ -168,6 +173,14 @@ public void notifyListeners(final String id, final JSObject res) {
application.registerActivityLifecycleCallbacks(this);
}

private void directUpdateFinish(final BundleInfo latest) {
final JSObject ret = new JSObject();
ret.put("bundle", latest.toJSON());
CapacitorUpdaterPlugin.this.implementation.set(latest);
CapacitorUpdaterPlugin.this._reload();
CapacitorUpdaterPlugin.this.notifyListeners("appReady", ret);
}

private void cleanupObsoleteVersions() {
try {
final Version previous = new Version(
Expand Down Expand Up @@ -877,6 +890,10 @@ public void run() {
"noNeedUpdate",
retNoNeed
);
CapacitorUpdaterPlugin.this.notifyListeners(
"appReady",
retNoNeed
);
return;
}

Expand All @@ -893,6 +910,11 @@ public void run() {
"noNeedUpdate",
retNoNeed
);
CapacitorUpdaterPlugin.this.notifyListeners(
"appReady",
retNoNeed
);
return;
}
final String latestVersionName = res.getString("version");

Expand All @@ -906,6 +928,8 @@ public void run() {
latestVersionName
);
if (latest != null) {
final JSObject ret = new JSObject();
ret.put("bundle", latest.toJSON());
if (latest.isErrorStatus()) {
Log.e(
CapacitorUpdater.TAG,
Expand All @@ -917,6 +941,10 @@ public void run() {
"noNeedUpdate",
retNoNeed
);
CapacitorUpdaterPlugin.this.notifyListeners(
"appReady",
ret
);
return;
}
if (latest.isDownloaded()) {
Expand All @@ -932,15 +960,7 @@ public void run() {
latest
);
CapacitorUpdaterPlugin.this._reload();
final JSObject ret = new JSObject();
ret.put("bundle", latest.toJSON());
CapacitorUpdaterPlugin.this.notifyListeners(
"appReady",
ret
);
} else {
final JSObject ret = new JSObject();
ret.put("bundle", latest.toJSON());
CapacitorUpdaterPlugin.this.notifyListeners(
"updateAvailable",
ret
Expand All @@ -949,6 +969,10 @@ public void run() {
latest.getId()
);
}
CapacitorUpdaterPlugin.this.notifyListeners(
"appReady",
ret
);
return;
}
if (latest.isDeleted()) {
Expand Down Expand Up @@ -978,6 +1002,10 @@ public void run() {
);
}
}
CapacitorUpdaterPlugin.this.notifyListeners(
"appReady",
ret
);
}

new Thread(
Expand Down Expand Up @@ -1032,6 +1060,10 @@ public void run() {
"noNeedUpdate",
retNoNeed
);
CapacitorUpdaterPlugin.this.notifyListeners(
"appReady",
ret
);
}
}
}
Expand Down

0 comments on commit bbd4c50

Please sign in to comment.