Skip to content

Commit

Permalink
fix: stats use config appId
Browse files Browse the repository at this point in the history
  • Loading branch information
riderx committed Mar 2, 2022
1 parent b231264 commit f0b1cfb
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ interface Callback {
public class CapacitorUpdater {
private String TAG = "Capacitor-updater";
public String statsUrl = "";
public String appId = "";

private Context context;
private String basePathHot = "versions";
Expand Down Expand Up @@ -285,7 +286,7 @@ public void sendStats(String action, String version) {
json.put("device_id", android_id);
json.put("version_name", version);
json.put("version_build", pInfo.versionName);
json.put("app_id", pInfo.packageName);
json.put("app_id", this.appId);
jsonString = json.toString();
} catch (Exception ex) {
Log.e(TAG, "Error get stats", ex);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.getcapacitor.CapConfig;
import com.getcapacitor.JSArray;
import com.getcapacitor.JSObject;
import com.getcapacitor.Plugin;
import com.getcapacitor.PluginCall;
import com.getcapacitor.PluginMethod;
import com.getcapacitor.annotation.CapacitorPlugin;
import com.getcapacitor.util.JSONUtils;

import org.json.JSONException;

Expand All @@ -35,8 +37,9 @@ public void load() {
this.prefs = this.getContext().getSharedPreferences("CapWebViewSettings", Activity.MODE_PRIVATE);
this.editor = prefs.edit();
implementation = new CapacitorUpdater(this.getContext());
implementation.statsUrl = getConfig().getString("statsUrl");
implementation.statsUrl = implementation.statsUrl == "" ? "https://capgo.app/api/stats" : implementation.statsUrl;
CapConfig config = CapConfig.loadDefault(getActivity());
implementation.appId = config.getString("appId", "");
implementation.statsUrl = getConfig().getString("statsUrl", "https://capgo.app/api/stats");
this.autoUpdateUrl = getConfig().getString("autoUpdateUrl");
if (this.autoUpdateUrl == null || this.autoUpdateUrl.equals("")) return;
Application application = (Application) this.getContext().getApplicationContext();
Expand Down
12 changes: 6 additions & 6 deletions ios/Plugin/CapacitorUpdater.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ extension Bundle {
@objc public class CapacitorUpdater: NSObject {

public var statsUrl = ""
public var appId = ""
private var versionBuild = Bundle.main.buildVersionNumber ?? ""
private var deviceID = UIDevice.current.identifierForVendor?.uuidString ?? ""
private var lastPathHot = ""
private var lastPathPersist = ""
private let basePathHot = "versions"
Expand Down Expand Up @@ -213,17 +216,14 @@ extension Bundle {
@objc func sendStats(action: String, version: String) {
if (statsUrl == "") { return }
DispatchQueue.main.async {
let deviceID = UIDevice.current.identifierForVendor!.uuidString
let versionBuild = Bundle.main.buildVersionNumber ?? ""
let bundleIdentifier = Bundle.main.bundleIdentifier ?? ""
_ = Just.post(self.statsUrl,
json: [
"platform": "ios",
"action": action,
"device_id": deviceID,
"device_id": self.deviceID,
"version_name": version,
"version_build": versionBuild,
"app_id": bundleIdentifier
"version_build": self.versionBuild,
"app_id": self.appId
]
)
print("✨ Capacitor-updater: Stats send for " + action + ", version " + version)
Expand Down
5 changes: 5 additions & 0 deletions ios/Plugin/CapacitorUpdaterPlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ public class CapacitorUpdaterPlugin: CAPPlugin {

override public func load() {
autoUpdateUrl = getConfigValue("autoUpdateUrl") as? String ?? ""
implementation.appId = Bundle.main.bundleIdentifier ?? ""
let config = (self.bridge?.viewController as? CAPBridgeViewController)?.instanceDescriptor().legacyConfig
if (config?["appId"] != nil) {
implementation.appId = config?["appId"] as! String
}
implementation.statsUrl = getConfigValue("statsUrl") as? String ?? "https://capgo.app/api/stats"
if (autoUpdateUrl == "") { return }
let nc = NotificationCenter.default
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "capacitor-updater",
"version": "1.3.13",
"version": "1.3.14",
"license": "AGPL-3.0-only",
"description": "Download app update from url",
"main": "dist/plugin.cjs.js",
Expand Down

0 comments on commit f0b1cfb

Please sign in to comment.