Skip to content

Commit

Permalink
feat: add currentNative to get current
Browse files Browse the repository at this point in the history
  • Loading branch information
riderx committed Apr 6, 2022
1 parent 75af960 commit 962ec3d
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public class CapacitorUpdaterPlugin extends Plugin implements Application.Activi
private static final String autoUpdateUrlDefault = "https://capgo.app/api/auto_update";
private static final String statsUrlDefault = "https://capgo.app/api/stats";
private String autoUpdateUrl = "";
private String currentVersionNative = "";
private Boolean autoUpdate = false;
private Boolean disableAutoUpdateUnderNative = false;
private Boolean disableAutoUpdateToMajor = false;
Expand All @@ -56,6 +57,13 @@ public void load() {
resetWhenUpdate = getConfig().getBoolean("resetWhenUpdate", false);
Application application = (Application) this.getContext().getApplicationContext();
application.registerActivityLifecycleCallbacks(this);
try {
PackageInfo pInfo = this.getContext().getPackageManager().getPackageInfo(this.getContext().getPackageName(), 0);
currentVersionNative = pInfo.versionName;
} catch (Exception ex) {
Log.e(TAG, "Error get currentVersionNative", ex);
return;
}
if (resetWhenUpdate) {
Version LatestVersionNative = new Version(prefs.getString("LatestVersionNative", ""));
try {
Expand Down Expand Up @@ -197,6 +205,7 @@ public void current(PluginCall call) {
JSObject ret = new JSObject();
String current = pathHot.length() >= 10 ? pathHot.substring(pathHot.length() - 10) : "builtin";
ret.put("current", current);
ret.put("currentNative", currentVersionNative);
call.resolve(ret);
}

Expand Down
2 changes: 2 additions & 0 deletions ios/Plugin/CapacitorUpdaterPlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,10 @@ public class CapacitorUpdaterPlugin: CAPPlugin {
@objc func current(_ call: CAPPluginCall) {
let pathHot = implementation.getLastPathHot()
let current = pathHot.count >= 10 ? pathHot.suffix(10) : "builtin"
let currentVersionNative = Bundle.main.buildVersionNumber ?? "0.0.0"
call.resolve([
"current": current
"currentNative": currentVersionNative
])
}

Expand Down
6 changes: 3 additions & 3 deletions src/definitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,10 @@ export interface CapacitorUpdaterPlugin {
*/
reset(options?:{ toAutoUpdate?: boolean }): Promise<void>;
/**
* Get the current version, if none are set it returns `builtin`
* @returns {Promise<{ current: string }>} an Promise with the current version name
* Get the current version, if none are set it returns `builtin`, currentNative is the original version install on the device
* @returns {Promise<{ current: string, currentNative: string }>} an Promise with the current version name
*/
current(): Promise<{ current: string }>;
current(): Promise<{ current: string, currentNative: string }>;
/**
* Reload the view
* @returns {Promise<void>} an Promise resolved when the view is reloaded
Expand Down

0 comments on commit 962ec3d

Please sign in to comment.