Skip to content

Commit

Permalink
fix: build issue ios
Browse files Browse the repository at this point in the history
  • Loading branch information
riderx committed Jul 1, 2022
1 parent 5a66d19 commit fe02774
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 66 deletions.
14 changes: 14 additions & 0 deletions ios/Plugin/CapacitorUpdater.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,20 @@ public class AppVersion: NSObject {
var message: String?
var major: Bool?
}

extension AppVersion {
func toDict() -> [String:Any] {
var dict = [String:Any]()
let otherSelf = Mirror(reflecting: self)
for child in otherSelf.children {
if let key = child.label {
dict[key] = child.value
}
}
return dict
}
}

extension OperatingSystemVersion {
func getFullVersion(separator: String = ".") -> String {
return "\(majorVersion)\(separator)\(minorVersion)\(separator)\(patchVersion)"
Expand Down
19 changes: 10 additions & 9 deletions ios/Plugin/CapacitorUpdaterPlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public class CapacitorUpdaterPlugin: CAPPlugin {
print("\(self.implementation.TAG) Cannot get version native \(currentVersionNative)")
}
if (LatestVersionNative != "0.0.0" && currentVersionNative.major > LatestVersionNative.major) {
_ = self._reset(toAutoUpdate: false)
_ = self._reset(toLastSuccessful: false)
UserDefaults.standard.set("", forKey: "LatestVersionAutoUpdate")
UserDefaults.standard.set("", forKey: "LatestVersionNameAutoUpdate")
let res = implementation.list()
Expand Down Expand Up @@ -189,8 +189,8 @@ public class CapacitorUpdaterPlugin: CAPPlugin {
}

@objc func getLatest(_ call: CAPPluginCall) {
let res = self.implementation.getLatest(url: url)
call.resolve(res)
let res = self.implementation.getLatest(url: URL(string: self.updateUrl)!)
call.resolve((res?.toDict())!)
}

@objc func _reset(toLastSuccessful: Bool) -> Bool {
Expand All @@ -200,7 +200,7 @@ public class CapacitorUpdaterPlugin: CAPPlugin {
let fallback: BundleInfo = self.implementation.getFallbackVersion()
if (toLastSuccessful && !fallback.isBuiltin()) {
print("\(self.implementation.TAG) Resetting to: \(fallback.toString())")
return self.implementation.set(fallback) && self._reload()
return self.implementation.set(bundle: fallback) && self._reload()
}
self.implementation.reset()
vc.setServerBasePath(path: "")
Expand All @@ -215,7 +215,7 @@ public class CapacitorUpdaterPlugin: CAPPlugin {
}

@objc func reset(_ call: CAPPluginCall) {
let toAutoUpdate = call.getBool("toLastSuccessful") ?? false
let toLastSuccessful = call.getBool("toLastSuccessful") ?? false
if (self._reset(toLastSuccessful: toLastSuccessful)) {
return call.resolve()
}
Expand Down Expand Up @@ -277,7 +277,7 @@ public class CapacitorUpdaterPlugin: CAPPlugin {
if(BundleStatus.SUCCESS.localizedString != current.getStatus()) {
print("\(self.implementation.TAG) notifyAppReady was not called, roll back current bundle: \(current.toString())")
self.implementation.rollback(bundle: current)
let res = self._reset(toAutoUpdate: true)
let res = self._reset(toLastSuccessful: true)
if (!res) {
return
}
Expand All @@ -297,15 +297,16 @@ public class CapacitorUpdaterPlugin: CAPPlugin {
print("\(self.implementation.TAG) No result found in \(self.updateUrl)")
return
}
if (res?.message) {
print("\(self.implementation.TAG) message \(res.message)")
if ((res?.message) != nil) {
print("\(self.implementation.TAG) message \(res!.message ?? "")")
if (res?.major == true) {
self.notifyListeners("majorAvailable", data: ["version": res?.version ?? "0.0.0"])
}
return
}
guard let downloadUrl = URL(string: res?.url ?? "") else {
print("\(self.implementation.TAG) Error no url or wrong format")
return
}
let current = self.implementation.getCurrentBundle()
let latestVersionName = res?.version
Expand Down Expand Up @@ -389,7 +390,7 @@ public class CapacitorUpdaterPlugin: CAPPlugin {
print("\(self.implementation.TAG) Revert to bundle: \(fallback.toString()) Failed!")
}
} else {
if (self._reset(toAutoUpdate: false)) {
if (self._reset(toLastSuccessful: false)) {
print("\(self.implementation.TAG) Reverted to 'builtin' bundle.")
}
}
Expand Down
58 changes: 1 addition & 57 deletions ios/Plugin/ObjectPreferences.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,60 +38,4 @@ extension UserDefaults: ObjectSavable {
throw ObjectSavableError.unableToDecode
}
}
}

//
//// MARK: - Methods
//public extension UserDefaults {
// /// SwifterSwift: get object from UserDefaults by using subscript.
// ///
// /// - Parameter key: key in the current user's defaults database.
// subscript(key: String) -> Any? {
// get {
// return object(forKey: key)
// }
// set {
// set(newValue, forKey: key)
// }
// }
//
// /// SwifterSwift: Float from UserDefaults.
// ///
// /// - Parameter key: key to find float for.
// /// - Returns: Float object for key (if exists).
// func float(forKey key: String) -> Float? {
// return object(forKey: key) as? Float
// }
//
// /// SwifterSwift: Date from UserDefaults.
// ///
// /// - Parameter key: key to find date for.
// /// - Returns: Date object for key (if exists).
// func date(forKey key: String) -> Date? {
// return object(forKey: key) as? Date
// }
//
// /// SwifterSwift: Retrieves a Codable object from UserDefaults.
// ///
// /// - Parameters:
// /// - type: Class that conforms to the Codable protocol.
// /// - key: Identifier of the object.
// /// - decoder: Custom JSONDecoder instance. Defaults to `JSONDecoder()`.
// /// - Returns: Codable object for key (if exists).
// func object<T: Codable>(_ type: T.Type, with key: String, usingDecoder decoder: JSONDecoder = JSONDecoder()) -> T? {
// guard let data = value(forKey: key) as? Data else { return nil }
// return try? decoder.decode(type.self, from: data)
// }
//
// /// SwifterSwift: Allows storing of Codable objects to UserDefaults.
// ///
// /// - Parameters:
// /// - object: Codable object to store.
// /// - key: Identifier of the object.
// /// - encoder: Custom JSONEncoder instance. Defaults to `JSONEncoder()`.
// func set<T: Codable>(object: T, forKey key: String, usingEncoder encoder: JSONEncoder = JSONEncoder()) {
// let data = try? encoder.encode(object)
// set(data, forKey: key)
// }
//}
//
}

0 comments on commit fe02774

Please sign in to comment.