Skip to content

Commit

Permalink
feat: add os version in metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
riderx committed Apr 22, 2022
1 parent b87c21c commit 664d992
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import android.content.SharedPreferences;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.os.Build;
import android.util.Log;

import com.android.volley.AuthFailureError;
Expand Down Expand Up @@ -60,6 +61,7 @@ public boolean accept(File f, String name) {
private final CapacitorUpdaterPlugin plugin;
private String versionBuild = "";
private String versionCode = "";
private String versionOs = "";
private String TAG = "Capacitor-updater";
private Context context;
private String basePathHot = "versions";
Expand All @@ -84,6 +86,7 @@ public CapacitorUpdater (Context context) throws PackageManager.NameNotFoundExce
this.plugin = new CapacitorUpdaterPlugin();
this.prefs = context.getSharedPreferences("CapWebViewSettings", Activity.MODE_PRIVATE);
this.editor = prefs.edit();
this.versionOs = Build.VERSION.RELEASE;
this.deviceID = Secure.getString(context.getContentResolver(), Secure.ANDROID_ID);
PackageInfo pInfo = context.getPackageManager().getPackageInfo(context.getPackageName(), 0);
this.versionBuild = pInfo.versionName;
Expand All @@ -94,6 +97,7 @@ public CapacitorUpdater (Context context, CapacitorUpdaterPlugin plugin) throws
this.plugin = plugin;
this.prefs = context.getSharedPreferences("CapWebViewSettings", Activity.MODE_PRIVATE);
this.editor = prefs.edit();
this.versionOs = Build.VERSION.RELEASE;
this.deviceID = Secure.getString(context.getContentResolver(), Secure.ANDROID_ID);
PackageInfo pInfo = context.getPackageManager().getPackageInfo(context.getPackageName(), 0);
this.versionBuild = pInfo.versionName;
Expand Down Expand Up @@ -301,36 +305,38 @@ public void getLatest(String url, Callback callback) {
String appId = this.appId;
String versionBuild = this.versionBuild;
String versionCode = this.versionCode;
String versionOs = this.versionOs;
String pluginVersion = this.pluginVersion;
String versionName = getVersionName().equals("") ? "builtin" : getVersionName();
StringRequest stringRequest = new StringRequest(Request.Method.GET, url,
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
try {
JSONObject jsonObject = new JSONObject(response);
callback.callback(jsonObject);
} catch (JSONException e) {
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
try {
JSONObject jsonObject = new JSONObject(response);
callback.callback(jsonObject);
} catch (JSONException e) {
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Log.e(TAG, "Error getting Latest" + error);
}
}) {
}) {
@Override
public Map<String, String> getHeaders() throws AuthFailureError {
Map<String, String> params = new HashMap<String, String>();
params.put("cap_platform", "android");
params.put("cap_device_id", deviceID);
params.put("cap_app_id", appId);
params.put("cap_version_build", versionBuild);
params.put("cap_version_code", versionCode);
params.put("cap_version_name", versionName);
params.put("cap_plugin_version", pluginVersion);
return params;
Map<String, String> params = new HashMap<String, String>();
params.put("cap_platform", "android");
params.put("cap_device_id", deviceID);
params.put("cap_app_id", appId);
params.put("cap_version_build", versionBuild);
params.put("cap_version_code", versionCode);
params.put("cap_version_os", versionOs);
params.put("cap_version_name", versionName);
params.put("cap_plugin_version", pluginVersion);
return params;
}
};
RequestQueue requestQueue = Volley.newRequestQueue(this.context);
Expand All @@ -345,7 +351,7 @@ public String getVersionName() {
return prefs.getString("versionName", "");
}

public void reset() {
public void reset() {
String version = prefs.getString("versionName", "");
this.sendStats("reset", version);
editor.putString("lastPathHot", "public");
Expand All @@ -367,6 +373,7 @@ public void sendStats(String action, String version) {
json.put("device_id", this.deviceID);
json.put("version_build", this.versionBuild);
json.put("version_code", this.versionCode);
json.put("version_os", this.versionOs);
json.put("plugin_version", this.pluginVersion);
json.put("app_id", this.appId);
jsonString = json.toString();
Expand Down
8 changes: 8 additions & 0 deletions ios/Plugin/CapacitorUpdater.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ public class AppVersion: NSObject {
var message: String?
var major: Bool?
}
extension OperatingSystemVersion {
func getFullVersion(separator: String = ".") -> String {
return "\(majorVersion)\(separator)\(minorVersion)\(separator)\(patchVersion)"
}
}
extension Bundle {
var releaseVersionNumber: String? {
return infoDictionary?["CFBundleShortVersionString"] as? String
Expand All @@ -40,6 +45,7 @@ extension Bundle {
public var pluginVersion = "3.0.10"
private var versionBuild = Bundle.main.releaseVersionNumber ?? ""
private var versionCode = Bundle.main.buildVersionNumber ?? ""
private var versionOs = ProcessInfo().operatingSystemVersion.getFullVersion()
private var lastPathHot = ""
private var lastPathPersist = ""
private let basePathHot = "versions"
Expand Down Expand Up @@ -114,6 +120,7 @@ extension Bundle {
"cap_app_id": self.appId,
"cap_version_build": self.versionBuild,
"cap_version_code": self.versionCode,
"cap_version_os": self.versionOs,
"cap_plugin_version": self.pluginVersion,
"cap_version_name": UserDefaults.standard.string(forKey: "versionName") ?? "builtin"
]
Expand Down Expand Up @@ -256,6 +263,7 @@ extension Bundle {
"version_name": version,
"version_build": self.versionBuild,
"version_code": self.versionCode,
"version_os": self.versionOs,
"plugin_version": self.pluginVersion,
"app_id": self.appId
]
Expand Down

0 comments on commit 664d992

Please sign in to comment.