Skip to content

Commit

Permalink
feat: add resetWhenUpdate system
Browse files Browse the repository at this point in the history
  • Loading branch information
riderx committed Mar 28, 2022
1 parent c889b76 commit 17b0326
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ You have 3 ways possible :
Join the [discord](https://discord.gg/VnYRvBfgA6) to get help.

## Documentation
I maintain a more user friendly [documentation](https://doc.capgo.app).
I maintain a more user friendly and complete [documentation](https://doc.capgo.app) in notion site.

## install plugin

```bash
npm install cordova-updater
npm install capacitor-updater
npx cap sync
```

Expand Down
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 String autoUpdateUrl = null;
private Boolean disableAutoUpdateUnderNative = false;
private Boolean disableAutoUpdateToMajor = false;
private Boolean resetWhenUpdate = false;


@Override
Expand All @@ -48,8 +49,19 @@ public void load() {
if (this.autoUpdateUrl == null || this.autoUpdateUrl.equals("")) return;
disableAutoUpdateUnderNative = getConfig().getBoolean("disableAutoUpdateUnderNative", false);
disableAutoUpdateToMajor = getConfig().getBoolean("disableAutoUpdateBreaking", false);
resetWhenUpdate = getConfig().getBoolean("resetWhenUpdate", false);
Application application = (Application) this.getContext().getApplicationContext();
application.registerActivityLifecycleCallbacks(this);
if (resetWhenUpdate) {
String LatestVersionNative = prefs.getString("LatestVersionNative", "");
if (!LatestVersionNative.equals("") && Bundle.main.buildVersionNumber.major > LatestVersionNative.major) {
this._reset(false);
editor.putString("LatestVersionAutoUpdate", "");
editor.putString("LatestVersionNameAutoUpdate", "");
}
editor.putString("LatestVersionNative", Bundle.main.buildVersionNumber);
editor.commit();
}
onActivityStarted(getActivity());
}

Expand Down
11 changes: 11 additions & 0 deletions ios/Plugin/CapacitorUpdaterPlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public class CapacitorUpdaterPlugin: CAPPlugin {
private var statsUrl = ""
private var disableAutoUpdateUnderNative = false;
private var disableAutoUpdateToMajor = false;
private var resetWhenUpdate = false;

override public func load() {
autoUpdateUrl = getConfigValue("autoUpdateUrl") as? String ?? ""
Expand All @@ -26,9 +27,19 @@ public class CapacitorUpdaterPlugin: CAPPlugin {
if (autoUpdateUrl == "") { return }
disableAutoUpdateUnderNative = getConfigValue("disableAutoUpdateUnderNative") as? Bool ?? false
disableAutoUpdateToMajor = getConfigValue("disableAutoUpdateBreaking") as? Bool ?? false
resetWhenUpdate = getConfigValue("resetWhenUpdate") as? Bool ?? false
let nc = NotificationCenter.default
nc.addObserver(self, selector: #selector(appMovedToBackground), name: UIApplication.didEnterBackgroundNotification, object: nil)
nc.addObserver(self, selector: #selector(appMovedToForeground), name: UIApplication.willEnterForegroundNotification, object: nil)
if (resetWhenUpdate) {
let LatestVersionNative = UserDefaults.standard.string(forKey: "LatestVersionNative") ?? ""
if (LatestVersionNative != "" && Bundle.main.buildVersionNumber.major > LatestVersionNative.major) {
self._reset(toAutoUpdate: false)
UserDefaults.standard.set("", forKey: "LatestVersionAutoUpdate")
UserDefaults.standard.set("", forKey: "LatestVersionNameAutoUpdate")
}
UserDefaults.standard.set( Bundle.main.buildVersionNumber, forKey: "LatestVersionNative")
}
self.appMovedToForeground()
}

Expand Down

0 comments on commit 17b0326

Please sign in to comment.