@capgo/capacitor-updater 5.3.25 → 5.3.29

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -14,7 +14,6 @@ import android.content.SharedPreferences;
14
14
  import android.content.pm.PackageInfo;
15
15
  import android.content.pm.PackageManager;
16
16
  import android.os.Build;
17
- import android.os.Handler;
18
17
  import android.util.Log;
19
18
  import com.android.volley.toolbox.Volley;
20
19
  import com.getcapacitor.CapConfig;
@@ -56,7 +55,7 @@ public class CapacitorUpdaterPlugin extends Plugin {
56
55
  private static final String channelUrlDefault =
57
56
  "https://api.capgo.app/channel_self";
58
57
 
59
- private final String PLUGIN_VERSION = "5.3.25";
58
+ private final String PLUGIN_VERSION = "5.3.29";
60
59
  private static final String DELAY_CONDITION_PREFERENCES = "";
61
60
 
62
61
  private SharedPreferences.Editor editor;
@@ -157,15 +156,25 @@ public class CapacitorUpdaterPlugin extends Plugin {
157
156
  );
158
157
  return;
159
158
  }
160
-
161
159
  final CapConfig config = CapConfig.loadDefault(this.getActivity());
162
- this.implementation.appId = config.getString("appId", "");
160
+ this.implementation.appId =
161
+ InternalUtils.getPackageName(
162
+ getContext().getPackageManager(),
163
+ getContext().getPackageName()
164
+ );
165
+ this.implementation.appId =
166
+ config.getString("appId", this.implementation.appId);
163
167
  this.implementation.appId =
164
168
  this.getConfig().getString("appId", this.implementation.appId);
165
- if ("".equals(implementation.appId)) {
166
- Log.i(CapacitorUpdater.TAG, "appId: " + implementation.appId);
167
- throw new RuntimeException("appId is required");
169
+ if (
170
+ this.implementation.appId == null || "".equals(this.implementation.appId)
171
+ ) {
172
+ // crash the app
173
+ throw new RuntimeException(
174
+ "appId is missing in capacitor.config.json or plugin config, and cannot be retrieved from the native app, please add it globally or in the plugin config"
175
+ );
168
176
  }
177
+ Log.i(CapacitorUpdater.TAG, "appId: " + implementation.appId);
169
178
  this.implementation.privateKey =
170
179
  this.getConfig().getString("privateKey", defaultPrivateKey);
171
180
  this.implementation.statsUrl =
@@ -0,0 +1,42 @@
1
+ package ee.forgr.capacitor_updater;
2
+
3
+ import android.content.pm.PackageInfo;
4
+ import android.content.pm.PackageManager;
5
+ import android.os.Build;
6
+
7
+ public class InternalUtils {
8
+
9
+ public static String getPackageName(PackageManager pm, String packageName) {
10
+ try {
11
+ PackageInfo pinfo = getPackageInfoInternal(pm, packageName, 0);
12
+ return (pinfo != null) ? pinfo.packageName : null;
13
+ } catch (PackageManager.NameNotFoundException e) {
14
+ // Exception is handled internally, and null is returned to indicate the package name could not be retrieved
15
+ return null;
16
+ }
17
+ }
18
+
19
+ private static PackageInfo getPackageInfoInternal(
20
+ PackageManager pm,
21
+ String packageName,
22
+ long flags
23
+ ) throws PackageManager.NameNotFoundException {
24
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
25
+ return pm.getPackageInfo(
26
+ packageName,
27
+ PackageManager.PackageInfoFlags.of(flags)
28
+ );
29
+ } else {
30
+ return getPackageInfoLegacy(pm, packageName, (int) flags);
31
+ }
32
+ }
33
+
34
+ @SuppressWarnings("deprecation")
35
+ private static PackageInfo getPackageInfoLegacy(
36
+ PackageManager pm,
37
+ String packageName,
38
+ int flags
39
+ ) throws PackageManager.NameNotFoundException {
40
+ return pm.getPackageInfo(packageName, flags);
41
+ }
42
+ }
@@ -15,7 +15,7 @@ import Version
15
15
  @objc(CapacitorUpdaterPlugin)
16
16
  public class CapacitorUpdaterPlugin: CAPPlugin {
17
17
  public var implementation = CapacitorUpdater()
18
- private let PLUGIN_VERSION: String = "5.3.25"
18
+ private let PLUGIN_VERSION: String = "5.3.29"
19
19
  static let updateUrlDefault = "https://api.capgo.app/updates"
20
20
  static let statsUrlDefault = "https://api.capgo.app/stats"
21
21
  static let channelUrlDefault = "https://api.capgo.app/channel_self"
@@ -71,15 +71,13 @@ public class CapacitorUpdaterPlugin: CAPPlugin {
71
71
  implementation.notifyDownload = notifyDownload
72
72
  implementation.PLUGIN_VERSION = self.PLUGIN_VERSION
73
73
  let config = (self.bridge?.viewController as? CAPBridgeViewController)?.instanceDescriptor().legacyConfig
74
- if config?["appId"] != nil {
75
- implementation.appId = config?["appId"] as! String
76
- }
74
+ implementation.appId = Bundle.main.infoDictionary?["CFBundleIdentifier"] as? String ?? ""
75
+ implementation.appId = config?["appId"] as? String ?? implementation.appId
77
76
  implementation.appId = getConfig().getString("appId", implementation.appId)!
78
77
  if implementation.appId == "" {
79
- print("\(self.implementation.TAG) appId is empty")
80
- // crash the app
81
- fatalError("appId is empty")
78
+ fatalError("appId is missing in capacitor.config.json or plugin config, and cannot be retrieved from the native app, please add it globally or in the plugin config")
82
79
  }
80
+ print("\(self.implementation.TAG) appId \(implementation.appId)")
83
81
  implementation.statsUrl = getConfig().getString("statsUrl", CapacitorUpdaterPlugin.statsUrlDefault)!
84
82
  implementation.channelUrl = getConfig().getString("channelUrl", CapacitorUpdaterPlugin.channelUrlDefault)!
85
83
  if resetWhenUpdate {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@capgo/capacitor-updater",
3
- "version": "5.3.25",
4
- "packageManager": "pnpm@8.10.0",
3
+ "version": "5.3.29",
4
+ "packageManager": "pnpm@8.10.2",
5
5
  "license": "MPL-2.0",
6
6
  "description": "Live update for capacitor apps",
7
7
  "main": "dist/plugin.cjs.js",