Skip to content

Commit

Permalink
feat: send old_version_name when set version and reset
Browse files Browse the repository at this point in the history
  • Loading branch information
riderx committed Apr 12, 2024
1 parent ceddd5d commit e19ba30
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -687,9 +687,10 @@ public Boolean set(final String id) {
final File bundle = this.getBundleDirectory(id);
Log.i(TAG, "Setting next active bundle: " + id);
if (this.bundleExists(id)) {
var currentBundleName = this.getCurrentBundle().getVersionName();
this.setCurrentBundle(bundle);
this.setBundleStatus(id, BundleStatus.PENDING);
this.sendStats("set", newBundle.getVersionName());
this.sendStats("set", newBundle.getVersionName(), currentBundleName);
return true;
}
this.setBundleStatus(id, BundleStatus.ERROR);
Expand Down Expand Up @@ -745,11 +746,16 @@ public void setError(final BundleInfo bundle) {

public void reset(final boolean internal) {
Log.d(CapacitorUpdater.TAG, "reset: " + internal);
var currentBundleName = this.getCurrentBundle().getVersionName();
this.setCurrentBundle(new File("public"));
this.setFallbackBundle(null);
this.setNextBundle(null);
if (!internal) {
this.sendStats("reset", this.getCurrentBundle().getVersionName());
this.sendStats(
"reset",
this.getCurrentBundle().getVersionName(),
currentBundleName
);
}
}

Expand Down Expand Up @@ -1020,13 +1026,23 @@ public void sendStats(final String action) {
}

public void sendStats(final String action, final String versionName) {
this.sendStats(action, versionName, "");
}

public void sendStats(
final String action,
final String versionName,
final String oldVersionName
) {
String statsUrl = this.statsUrl;
if (statsUrl == null || statsUrl.isEmpty()) {
return;
}
JSONObject json;
try {
json = this.createInfoObject();
json.put("version_name", versionName);
json.put("old_version_name", oldVersionName);
json.put("action", action);
} catch (JSONException e) {
Log.e(TAG, "Error sendStats JSONException", e);
Expand Down
13 changes: 9 additions & 4 deletions ios/Plugin/CapacitorUpdater.swift
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ struct InfoObject: Codable {
let version_build: String?
let version_code: String?
let version_os: String?
let version_name: String?
var version_name: String?
var old_version_name: String?
let plugin_version: String?
let is_emulator: Bool?
let is_prod: Bool?
Expand Down Expand Up @@ -716,9 +717,10 @@ extension CustomError: LocalizedError {
return true
}
if bundleExists(id: id) {
let currentBundleName = self.getCurrentBundle().getVersionName()
self.setCurrentBundle(bundle: self.getBundleDirectory(id: id).path)
self.setBundleStatus(id: id, status: BundleStatus.PENDING)
self.sendStats(action: "set", versionName: newBundle.getVersionName())
self.sendStats(action: "set", versionName: newBundle.getVersionName(), oldVersionName: currentBundleName)
return true
}
self.setBundleStatus(id: id, status: BundleStatus.ERROR)
Expand All @@ -740,11 +742,12 @@ extension CustomError: LocalizedError {

public func reset(isInternal: Bool) {
print("\(self.TAG) reset: \(isInternal)")
let currentBundleName = self.getCurrentBundle().getVersionName()
self.setCurrentBundle(bundle: "")
self.setFallbackBundle(fallback: Optional<BundleInfo>.none)
_ = self.setNextBundle(next: Optional<String>.none)
if !isInternal {
self.sendStats(action: "reset")
self.sendStats(action: "reset", versionName: self.getCurrentBundle().getVersionName(), oldVersionName: currentBundleName)
}
}

Expand Down Expand Up @@ -882,7 +885,7 @@ extension CustomError: LocalizedError {
return getChannel
}

func sendStats(action: String, versionName: String? = nil) {
func sendStats(action: String, versionName: String? = nil, oldVersionName: String? = "") {
guard !statsUrl.isEmpty else {
return
}
Expand All @@ -891,6 +894,8 @@ extension CustomError: LocalizedError {

var parameters = createInfoObject()
parameters.action = action
parameters.version_name = versionName
parameters.old_version_name = oldVersionName

DispatchQueue.global(qos: .background).async {
let request = AF.request(
Expand Down

0 comments on commit e19ba30

Please sign in to comment.