Skip to content

Commit

Permalink
fix: remove call when not necessary
Browse files Browse the repository at this point in the history
  • Loading branch information
riderx committed Apr 8, 2022
1 parent ff2ba75 commit 6d01411
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
14 changes: 9 additions & 5 deletions ios/Plugin/CapacitorUpdater.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ extension URL {
}
}
struct AppVersionDec: Decodable {
let version: String
let url: String
let version: String?
let url: String?
let message: String?
let major: Bool?
}
Expand Down Expand Up @@ -76,17 +76,20 @@ extension Bundle {
}
}

private func moveFolder(source: URL, dest: URL) {
private func unflatFolder(source: URL, dest: URL) -> Bool {
let index = source.appendingPathComponent("index.html")
do {
let files = try FileManager.default.contentsOfDirectory(atPath: source.path)
if (files.count == 1 && source.appendingPathComponent(files[0]).isDirectory && !FileManager.default.fileExists(atPath: index.path)) {
try FileManager.default.moveItem(at: source.appendingPathComponent(files[0]), to: dest)
return true
} else {
try FileManager.default.moveItem(at: source, to: dest)
return false
}
} catch {
print("✨ Capacitor-updater: File not moved. source: \(source.path) dest: \(dest.path)")
return true
}
}

Expand All @@ -95,8 +98,9 @@ extension Bundle {
let destHot = base.appendingPathComponent(version)
let destUnZip = documentsUrl.appendingPathComponent(randomString(length: 10))
SSZipArchive.unzipFile(atPath: sourceZip.path, toDestination: destUnZip.path)
moveFolder(source: destUnZip, dest: destHot)
deleteFolder(source: destUnZip)
if (unflatFolder(source: destUnZip, dest: destHot)) {
deleteFolder(source: destUnZip)
}
}

@objc public func getLatest(url: URL) -> AppVersion? {
Expand Down
2 changes: 1 addition & 1 deletion ios/Plugin/CapacitorUpdaterPlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ public class CapacitorUpdaterPlugin: CAPPlugin {
return
}
guard let downloadUrl = URL(string: res?.url ?? "") else {
print("✨ Capacitor-updater: \(res?.message ?? "Unknow error")")
print("✨ Capacitor-updater: Error \(res?.message ?? "Unknow error")")
if (res?.major == true) {
self.notifyListeners("majorAvailable", data: ["version": res?.version ?? "0.0.0"])
}
Expand Down

0 comments on commit 6d01411

Please sign in to comment.