Skip to content

Commit

Permalink
fix: remove auto update logic from app
Browse files Browse the repository at this point in the history
  • Loading branch information
riderx committed Apr 7, 2022
1 parent 48d0d8b commit 38ad3de
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -253,15 +253,15 @@ public void run() {
String newVersion = (String) res.get("version");
JSObject ret = new JSObject();
ret.put("newVersion", newVersion);
String failingVersion = prefs.getString("failingVersion", "");
if (disableAutoUpdateUnderNative && new Version(newVersion).isHigherThan(finalCurrentVersionNative)) {
Log.i(TAG, "Cannot download revert, " + newVersion + " is lest than native version " + finalCurrentVersionNative);
}
else if (disableAutoUpdateToMajor && new Version(newVersion).getMajor() > new Version(currentVersion).getMajor()) {
Log.i(TAG, "Cannot download Major, " + newVersion + " is Breaking change from " + currentVersion);
notifyListeners("majorAvailable", ret);
if (res.get('message')) {
Log.i(TAG, "Capacitor-updater: " + (res.get('message') || "Unknow error"));
if (res.get('major') == true) {
notifyListeners("majorAvailable", ret);
}
return
}
else if (!newVersion.equals("") && !newVersion.equals(currentVersion) && !newVersion.equals(failingVersion)) {
String failingVersion = prefs.getString("failingVersion", "");
if (!newVersion.equals("") && !newVersion.equals(failingVersion)) {
new Thread(new Runnable(){
@Override
public void run() {
Expand Down
12 changes: 11 additions & 1 deletion ios/Plugin/CapacitorUpdater.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ extension URL {
struct AppVersionDec: Decodable {
let version: String
let url: String
let message: String
let major: Bool
}
public class AppVersion: NSObject {
var version: String = ""
Expand Down Expand Up @@ -109,10 +111,18 @@ extension Bundle {
request.validate().responseDecodable(of: AppVersionDec.self) { response in
switch response.result {
case .success:
if let url = response.value?.url, let version = response.value?.version {
if let url = response.value?.url {
latest.url = url
}
if let version = response.value?.version {
latest.version = version
}
if let major = response.value?.major {
latest.major = major
}
if let message = response.value?.message {
latest.message = message
}
case let .failure(error):
print("✨ Capacitor-updater: Error getting Latest", error )
}
Expand Down
17 changes: 5 additions & 12 deletions ios/Plugin/CapacitorUpdaterPlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -206,29 +206,22 @@ public class CapacitorUpdaterPlugin: CAPPlugin {
return
}
guard let downloadUrl = URL(string: res?.url ?? "") else {
print("✨ Capacitor-updater: \(res?.message || "Unknow error")")
if (res?.major == true) {
self.notifyListeners("majorAvailable", data: ["version": res?.version])
}
return
}
let currentVersion = self.implementation.getVersionName()
var failingVersion: Version = "0.0.0"
var currentVersionForCompare: Version = "0.0.0"
var newVersion: Version = "0.0.0"
var currentVersionNative: Version = "0.0.0"
do {
currentVersionForCompare = try Version(currentVersion == "" ? "0.0.0" : currentVersion)
newVersion = try Version(res?.version ?? "0.0.0")
currentVersionNative = try Version(Bundle.main.buildVersionNumber ?? "0.0.0")
failingVersion = try Version(UserDefaults.standard.string(forKey: "failingVersion") ?? "0.0.0")
} catch {
print("✨ Capacitor-updater: Cannot get version \(failingVersion) \(currentVersionForCompare) \(newVersion) \(currentVersionNative)")
}
if (self.disableAutoUpdateUnderNative && newVersion < currentVersionNative) {
print("✨ Capacitor-updater: Cannot download revert, \(newVersion) is lest than native version \(currentVersionNative)")
}
else if (self.disableAutoUpdateToMajor && newVersion.major > currentVersionNative.major) {
print("✨ Capacitor-updater: Cannot download Major, \(newVersion) is Breaking change from \(currentVersion)")
self.notifyListeners("majorAvailable", data: ["version": newVersion])
}
else if (newVersion != "0.0.0" && newVersion != currentVersionForCompare && newVersion != failingVersion) {
if (newVersion != "0.0.0" && newVersion != failingVersion) {
let dlOp = self.implementation.download(url: downloadUrl)
if let dl = dlOp {
print("✨ Capacitor-updater: New version: \(newVersion) found. Current is \(currentVersion == "" ? "builtin" : currentVersion), next backgrounding will trigger update")
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": "2.3.3",
"version": "3.0.0-beta.1",
"license": "AGPL-3.0-only",
"description": "OTA update for capacitor apps",
"main": "dist/plugin.cjs.js",
Expand Down

0 comments on commit 38ad3de

Please sign in to comment.