Skip to content

Commit

Permalink
fix: android direct update
Browse files Browse the repository at this point in the history
  • Loading branch information
riderx committed Aug 16, 2023
1 parent 12640fb commit c556475
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ public class CapacitorUpdater {
public RequestQueue requestQueue;

public File documentsDir;
public Boolean directUpdate = false;
public Activity activity;
public String PLUGIN_VERSION = "";
public String versionBuild = "";
Expand Down Expand Up @@ -369,7 +370,11 @@ public void finishDownload(
ret.put("bundle", next.toJSON());
CapacitorUpdater.this.notifyListeners("updateAvailable", ret);
if (setNext) {
this.setNextBundle(next.getId());
if (this.directUpdate) {
this.set(next);
} else {
this.setNextBundle(next.getId());
}
}
} catch (IOException e) {
e.printStackTrace();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ public class CapacitorUpdaterPlugin
private Boolean resetWhenUpdate = true;
private Thread backgroundTask;
private Boolean taskRunning = false;
private Boolean directUpdate = false;

private Boolean isPreviousMainActivity = true;

Expand Down Expand Up @@ -113,7 +112,7 @@ public void notifyListeners(final String id, final JSObject res) {
this.implementation.versionCode = Integer.toString(pInfo.versionCode);
this.implementation.requestQueue =
Volley.newRequestQueue(this.getContext());
this.directUpdate = this.getConfig().getBoolean("directUpdate", false);
this.implementation.directUpdate = this.getConfig().getBoolean("directUpdate", false);
this.currentVersionNative =
new Version(this.getConfig().getString("version", pInfo.versionName));
} catch (final PackageManager.NameNotFoundException e) {
Expand Down Expand Up @@ -921,7 +920,7 @@ public void run() {
CapacitorUpdater.TAG,
"Latest bundle already exists and download is NOT required. Update will occur next time app moves to background."
);
if (CapacitorUpdaterPlugin.this.directUpdate) {
if (CapacitorUpdaterPlugin.this.implementation.directUpdate) {
CapacitorUpdaterPlugin.this.implementation.set(
latest
);
Expand Down
10 changes: 5 additions & 5 deletions ios/Plugin/CapacitorUpdaterPlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -527,10 +527,10 @@ public class CapacitorUpdaterPlugin: CAPPlugin {
}
let latestVersionName = res.version
if latestVersionName != "" && current.getVersionName() != latestVersionName {
let latest = self.implementation.getBundleInfoByVersionName(version: latestVersionName)
var next = self.implementation.getBundleInfoByVersionName(version: latestVersionName)
do {
print("\(self.implementation.TAG) New bundle: \(latestVersionName) found. Current is: \(current.getVersionName()). Update will occur next time app moves to background.")
let next = self.implementation.getBundleInfoByVersionName(version: latestVersionName)
var next = self.implementation.getBundleInfoByVersionName(version: latestVersionName)
if next == nil || ((next?.isDeleted()) != nil) {
if (next?.isDeleted()) != nil {
print("\(self.implementation.TAG) Latest bundle already exists and will be deleted, download will overwrite it.")
Expand All @@ -541,7 +541,7 @@ public class CapacitorUpdaterPlugin: CAPPlugin {
print("\(self.implementation.TAG) Failed to delete failed bundle: \(next!.toString())")
}
}
let next = try self.implementation.download(url: downloadUrl, version: latestVersionName, sessionKey: sessionKey)
next = try self.implementation.download(url: downloadUrl, version: latestVersionName, sessionKey: sessionKey)
}
guard let next = next else {
print("\(self.implementation.TAG) Error downloading file")
Expand All @@ -567,8 +567,8 @@ public class CapacitorUpdaterPlugin: CAPPlugin {
throw ObjectSavableError.checksum
}
if self.directUpdate {
self.implementation.set(bundle: next)
self._reload()
_ = self.implementation.set(bundle: next)
_ = self._reload()
} else {
self.notifyListeners("updateAvailable", data: ["bundle": next.toJSON()])
_ = self.implementation.setNextBundle(next: next.getId())
Expand Down

0 comments on commit c556475

Please sign in to comment.