22import Foundation
33import Combine
44
5+ // Import the signer module (assuming it exists)
6+ // If not, you'll need to define or import the signer
7+
58class DownloadSignManager : ObservableObject {
69 @Published var progress : Double = 0.0
710 @Published var status : String = " "
@@ -11,6 +14,9 @@ class DownloadSignManager: ObservableObject {
1114 private var downloadTask : URLSessionDownloadTask ?
1215 private var cancellables = Set < AnyCancellable > ( )
1316
17+ // Assuming signer is available - you might need to import it
18+ private let signer = Signer ( ) // Adjust based on your actual signer class
19+
1420 func downloadAndSign( app: AltApp ) {
1521 guard let downloadURL = app. downloadURL else {
1622 self . status = " No download URL available "
@@ -153,87 +159,95 @@ class DownloadSignManager: ObservableObject {
153159 }
154160 }
155161
156- private func signAndInstallIPA(
157- ipaURL: URL ,
158- p12URL: URL ,
159- provURL: URL ,
160- password: String ,
161- appName: String
162- ) {
163- DispatchQueue . main. async {
164- self . status = " Starting signing process... "
165- self . progress = 0.5
166- self . isProcessing = true
167- }
168-
169- signer. sign (
170- ipaURL: ipaURL,
171- p12URL: p12URL,
172- provURL: provURL,
173- p12Password: password,
174- progressUpdate: { [ weak self] status, progress in
175- DispatchQueue . main. async {
176- let overallProgress = 0.5 + ( progress * 0.5 )
177- self ? . progress = overallProgress
178- let percent = Int ( overallProgress * 100 )
179- self ? . status = " \( status) ( \( percent) %) "
180- }
181- } ,
182- completion: { [ weak self] result in
183- guard let self else { return }
162+ private func signAndInstallIPA(
163+ ipaURL: URL ,
164+ p12URL: URL ,
165+ provURL: URL ,
166+ password: String ,
167+ appName: String
168+ ) {
169+ DispatchQueue . main. async {
170+ self . status = " Starting signing process... "
171+ self . progress = 0.5
172+ self . isProcessing = true
173+ }
184174
185- switch result {
186- case . success( let signedIPAURL) :
175+ // Assuming signer.sign method exists
176+ // You'll need to adjust this based on your actual signer implementation
177+ signer. sign (
178+ ipaURL: ipaURL,
179+ p12URL: p12URL,
180+ provURL: provURL,
181+ p12Password: password,
182+ progressUpdate: { [ weak self] status, progress in
187183 DispatchQueue . main. async {
188- self . progress = 1.0
189- self . status = " ✅ Successfully signed IPA! Installing app now... "
190- self . showSuccess = true
184+ let overallProgress = 0.5 + ( progress * 0.5 )
185+ self ? . progress = overallProgress
186+ let percent = Int ( overallProgress * 100 )
187+ self ? . status = " \( status) ( \( percent) %) "
191188 }
189+ } ,
190+ completion: { [ weak self] result in
191+ guard let self = self else { return }
192192
193- // Create a view model for installation progress
194- // inside your Task after signing completes
195- let stream = installAppWithStatusStream ( from: signedIPAURL)
196-
197- Task {
198- do {
199- for try await status in stream {
200- DispatchQueue . main. async {
201- switch status {
202- case . idle: break
203- case . uploading( let pct) , . installing( let pct) :
204- self . progress = Double ( pct) / 100.0
205- self . status = status. pretty
206- case . success:
207- self . status = status. pretty
208- case . failure( let msg) :
209- self . status = status. pretty
210- case . message( let text) :
211- self . status = text
212- }
213- }
214- }
215- } catch {
216- DispatchQueue . main. async {
217- self . status = " ❌ Install failed: \( error. localizedDescription) "
218- self . isProcessing = false
219- }
220- }
221- }
193+ switch result {
194+ case . success( let signedIPAURL) :
195+ DispatchQueue . main. async {
196+ self . progress = 1.0
197+ self . status = " ✅ Successfully signed IPA! Installing app now... "
198+ self . showSuccess = true
199+ }
222200
201+ // Install the signed IPA
202+ let stream = installAppWithStatusStream ( from: signedIPAURL)
223203
224- // Clean up original downloaded IPA
225- try ? FileManager . default. removeItem ( at: ipaURL)
204+ Task {
205+ do {
206+ for try await status in stream {
207+ DispatchQueue . main. async {
208+ switch status {
209+ case . idle:
210+ break
211+ case . uploading( let pct) , . installing( let pct) :
212+ self . progress = Double ( pct) / 100.0
213+ self . status = status. pretty
214+ case . success:
215+ self . status = status. pretty
216+ // Optional: Delay resetting to show success
217+ DispatchQueue . main. asyncAfter ( deadline: . now( ) + 2 ) {
218+ self . isProcessing = false
219+ self . showSuccess = false
220+ self . progress = 0.0
221+ }
222+ case . failure( let msg) :
223+ self . status = status. pretty
224+ self . isProcessing = false
225+ case . message( let text) :
226+ self . status = text
227+ }
228+ }
229+ }
230+ } catch {
231+ DispatchQueue . main. async {
232+ self . status = " ❌ Install failed: \( error. localizedDescription) "
233+ self . isProcessing = false
234+ }
235+ }
236+ }
226237
227- case . failure( let error) :
228- DispatchQueue . main. async {
229- self . status = " ❌ Signing failed: \( error. localizedDescription) "
230- self . isProcessing = false
238+ // Clean up original downloaded IPA
231239 try ? FileManager . default. removeItem ( at: ipaURL)
240+
241+ case . failure( let error) :
242+ DispatchQueue . main. async {
243+ self . status = " ❌ Signing failed: \( error. localizedDescription) "
244+ self . isProcessing = false
245+ try ? FileManager . default. removeItem ( at: ipaURL)
246+ }
232247 }
233248 }
234- }
235- )
236- }
249+ )
250+ }
237251
238252 func cancel( ) {
239253 downloadTask? . cancel ( )
@@ -253,4 +267,4 @@ Task {
253267 }
254268 return appFolder
255269 }
256- }
270+ }
0 commit comments