Skip to content

Commit

Permalink
fix: revert change double folder
Browse files Browse the repository at this point in the history
  • Loading branch information
riderx committed May 1, 2024
1 parent 4c9b973 commit f0878a7
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 9 deletions.
31 changes: 24 additions & 7 deletions ios/Plugin/CapacitorUpdater.swift
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ extension CustomError: LocalizedError {
private let versionOs = UIDevice.current.systemVersion
private let documentsDir: URL = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first!
private let libraryDir: URL = FileManager.default.urls(for: .libraryDirectory, in: .userDomainMask).first!
private let bundleDirectoryHot: String = "versions"
private let DEFAULT_FOLDER: String = ""
private let bundleDirectory: String = "NoCloud/ionic_built_snapshots"
private let INFO_SUFFIX: String = "_info"
Expand Down Expand Up @@ -295,7 +296,8 @@ extension CustomError: LocalizedError {
return false
#endif
}
// Hot Reload path /var/mobile/Containers/Data/Application/8C0C07BE-0FD3-4FD4-B7DF-90A88E12B8C3/Library/NoCloud/ionic_built_snapshots/FOLDER
// Persistent path /var/mobile/Containers/Data/Application/8C0C07BE-0FD3-4FD4-B7DF-90A88E12B8C3/Library/NoCloud/ionic_built_snapshots/FOLDER
// Hot Reload path /var/mobile/Containers/Data/Application/8C0C07BE-0FD3-4FD4-B7DF-90A88E12B8C3/Documents/FOLDER
// Normal /private/var/containers/Bundle/Application/8C0C07BE-0FD3-4FD4-B7DF-90A88E12B8C3/App.app/public

private func prepareFolder(source: URL) throws {
Expand Down Expand Up @@ -582,7 +584,8 @@ extension CustomError: LocalizedError {
do {
try self.decryptFile(filePath: fileURL, sessionKey: sessionKey, version: version)
checksum = self.getChecksum(filePath: fileURL)
try self.saveDownloaded(sourceZip: fileURL, id: id, base: self.libraryDir.appendingPathComponent(self.bundleDirectory), notify: true)
try self.saveDownloaded(sourceZip: fileURL, id: id, base: self.documentsDir.appendingPathComponent(self.bundleDirectoryHot), notify: true)
try self.saveDownloaded(sourceZip: fileURL, id: id, base: self.libraryDir.appendingPathComponent(self.bundleDirectory), notify: false)
try self.deleteFolder(source: fileURL)
self.notifyDownload(id, 100)
} catch {
Expand Down Expand Up @@ -626,7 +629,7 @@ extension CustomError: LocalizedError {
}

public func list() -> [BundleInfo] {
let dest: URL = documentsDir.appendingPathComponent(bundleDirectory)
let dest: URL = documentsDir.appendingPathComponent(bundleDirectoryHot)
do {
let files: [String] = try FileManager.default.contentsOfDirectory(atPath: dest.path)
var res: [BundleInfo] = []
Expand All @@ -649,11 +652,17 @@ extension CustomError: LocalizedError {
print("\(self.TAG) Cannot delete \(id)")
return false
}
let destHot: URL = libraryDir.appendingPathComponent(bundleDirectory).appendingPathComponent(id)
let destHot: URL = documentsDir.appendingPathComponent(bundleDirectoryHot).appendingPathComponent(id)
let destPersist: URL = libraryDir.appendingPathComponent(bundleDirectory).appendingPathComponent(id)
do {
try FileManager.default.removeItem(atPath: destHot.path)
} catch {
print("\(self.TAG) Folder \(destHot.path), not removed.")
print("\(self.TAG) Hot Folder \(destHot.path), not removed.")
}
do {
try FileManager.default.removeItem(atPath: destPersist.path)
} catch {
print("\(self.TAG) Folder \(destPersist.path), not removed.")
return false
}
if removeInfo {
Expand All @@ -670,6 +679,10 @@ extension CustomError: LocalizedError {
return self.delete(id: id, removeInfo: true)
}

public func getPathHot(id: String) -> URL {
return documentsDir.appendingPathComponent(self.bundleDirectoryHot).appendingPathComponent(id)
}

public func getBundleDirectory(id: String) -> URL {
return libraryDir.appendingPathComponent(self.bundleDirectory).appendingPathComponent(id)
}
Expand All @@ -679,14 +692,18 @@ extension CustomError: LocalizedError {
}

private func bundleExists(id: String) -> Bool {
let destHot: URL = self.getBundleDirectory(id: id)
let destHot: URL = self.getPathHot(id: id)
let destHotPersist: URL = self.getBundleDirectory(id: id)
let indexHot: URL = destHot.appendingPathComponent("index.html")
let indexPersist: URL = destHotPersist.appendingPathComponent("index.html")
let bundleIndo: BundleInfo = self.getBundleInfo(id: id)
if
destHot.exist &&
destHot.isDirectory &&
!indexHot.isDirectory &&
destHotPersist.exist &&
destHotPersist.isDirectory &&
indexHot.exist &&
indexPersist.exist &&
!bundleIndo.isDeleted() {
return true
}
Expand Down
4 changes: 2 additions & 2 deletions ios/Plugin/CapacitorUpdaterPlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import Version
@objc(CapacitorUpdaterPlugin)
public class CapacitorUpdaterPlugin: CAPPlugin {
public var implementation = CapacitorUpdater()
private let PLUGIN_VERSION: String = "6.0.2"
private let PLUGIN_VERSION: String = "6.0.3"
static let updateUrlDefault = "https://api.capgo.app/updates"
static let statsUrlDefault = "https://api.capgo.app/stats"
static let channelUrlDefault = "https://api.capgo.app/channel_self"
Expand Down Expand Up @@ -247,7 +247,7 @@ public class CapacitorUpdaterPlugin: CAPPlugin {
if BundleInfo.ID_BUILTIN == id {
dest = Bundle.main.resourceURL!.appendingPathComponent("public")
} else {
dest = self.implementation.getBundleDirectory(id: id)
dest = self.implementation.getPathHot(id: id)
}
print("\(self.implementation.TAG) Reloading \(id)")
if let vc = bridge.viewController as? CAPBridgeViewController {
Expand Down

0 comments on commit f0878a7

Please sign in to comment.