Skip to content
This repository was archived by the owner on Mar 7, 2026. It is now read-only.

Commit 089d27d

Browse files
authored
Fix bug
1 parent 940b851 commit 089d27d

2 files changed

Lines changed: 61 additions & 57 deletions

File tree

Sources/prostore/signing/DownloadSignManager.swift

Lines changed: 47 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -153,56 +153,57 @@ class DownloadSignManager: ObservableObject {
153153
}
154154
}
155155

156-
private func signIPA(ipaURL: URL, p12URL: URL, provURL: URL, password: String, appName: String) {
157-
DispatchQueue.main.async {
158-
self.status = "Starting signing process..."
159-
self.progress = 0.5
160-
}
161-
162-
signer.sign(
163-
ipaURL: ipaURL,
164-
p12URL: p12URL,
165-
provURL: provURL,
166-
p12Password: password,
167-
progressUpdate: { [weak self] status, progress in
168-
DispatchQueue.main.async {
169-
// Convert from 0-1 range within signing phase to 0.5-1.0 overall range
170-
let overallProgress = 0.5 + (progress * 0.5)
171-
self?.progress = overallProgress
172-
let percent = Int(overallProgress * 100)
173-
self?.status = "\(status) (\(percent)%)"
174-
}
175-
},
176-
completion: { [weak self] result in
177-
DispatchQueue.main.async {
178-
switch result {
179-
case .success(let signedIPAURL):
180-
self?.progress = 1.0
181-
self?.status = "✅ Successfully signed! Saved to: \(signedIPAURL.lastPathComponent)"
182-
self?.showSuccess = true
183-
184-
// Hide progress bar after 3 seconds
185-
DispatchQueue.main.asyncAfter(deadline: .now() + 3) {
186-
self?.isProcessing = false
187-
self?.showSuccess = false
188-
self?.progress = 0.0
189-
self?.status = ""
190-
}
191-
192-
// Clean up original downloaded IPA
193-
try? FileManager.default.removeItem(at: ipaURL)
194-
195-
case .failure(let error):
196-
self?.status = "❌ Signing failed: \(error.localizedDescription)"
156+
private func signIPA(ipaURL: URL, p12URL: URL, provURL: URL, password: String, appName: String) {
157+
DispatchQueue.main.async {
158+
self.status = "Starting signing process..."
159+
self.progress = 0.5
160+
}
161+
162+
signer.sign(
163+
ipaURL: ipaURL,
164+
p12URL: p12URL,
165+
provURL: provURL,
166+
p12Password: password,
167+
progressUpdate: { [weak self] status, progress in
168+
DispatchQueue.main.async {
169+
// progress is already in the range 0.0-1.0 for the signing phase
170+
// We need to map it to 0.5-1.0 overall
171+
let overallProgress = 0.5 + (progress * 0.5)
172+
self?.progress = overallProgress
173+
let percent = Int(overallProgress * 100)
174+
self?.status = "\(status) (\(percent)%)"
175+
}
176+
},
177+
completion: { [weak self] result in
178+
DispatchQueue.main.async {
179+
switch result {
180+
case .success(let signedIPAURL):
181+
self?.progress = 1.0
182+
self?.status = "✅ Successfully signed! Saved to: \(signedIPAURL.lastPathComponent)"
183+
self?.showSuccess = true
184+
185+
// Hide progress bar after 3 seconds
186+
DispatchQueue.main.asyncAfter(deadline: .now() + 3) {
197187
self?.isProcessing = false
198-
199-
// Clean up temp files
200-
try? FileManager.default.removeItem(at: ipaURL)
188+
self?.showSuccess = false
189+
self?.progress = 0.0
190+
self?.status = ""
201191
}
192+
193+
// Clean up original downloaded IPA
194+
try? FileManager.default.removeItem(at: ipaURL)
195+
196+
case .failure(let error):
197+
self?.status = "❌ Signing failed: \(error.localizedDescription)"
198+
self?.isProcessing = false
199+
200+
// Clean up temp files
201+
try? FileManager.default.removeItem(at: ipaURL)
202202
}
203203
}
204-
)
205-
}
204+
}
205+
)
206+
}
206207

207208
func cancel() {
208209
downloadTask?.cancel()

Sources/prostore/signing/signer.swift

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,11 @@ fileprivate class SigningManager {
7272
to: inputsDir
7373
)
7474
progressUpdate("Unzipping IPA 🔓", 0.25)
75-
try extractIPA(ipaURL: localIPA, to: workDir, progressUpdate: { status, progress in
76-
progressUpdate(status, 0.25 + (progress * 0.25))
75+
try extractIPA(ipaURL: localIPA, to: workDir, progressUpdate: { progress in
76+
// Convert 0.0-1.0 progress to 0.25-0.5 range
77+
let overallProgress = 0.25 + (progress * 0.25)
78+
let pct = Int(progress * 100)
79+
progressUpdate("Unzipping IPA 🔓 (\(pct)%)", overallProgress)
7780
})
7881
let payloadDir = workDir.appendingPathComponent("Payload")
7982
let appDir = try findAppBundle(in: payloadDir)
@@ -104,8 +107,11 @@ fileprivate class SigningManager {
104107
from: workDir,
105108
originalIPAURL: ipaURL,
106109
outputDir: tmpRoot,
107-
progressUpdate: { status, progress in
108-
progressUpdate(status, 0.75 + (progress * 0.25))
110+
progressUpdate: { progress in
111+
// Convert 0.0-1.0 progress to 0.75-1.0 range
112+
let overallProgress = 0.75 + (progress * 0.25)
113+
let pct = Int(progress * 100)
114+
progressUpdate("Zipping signed IPA 📦 (\(pct)%)", overallProgress)
109115
}
110116
)
111117
completion(.success(signedIPAURL))
@@ -150,13 +156,12 @@ fileprivate class SigningManager {
150156
static func extractIPA(
151157
ipaURL: URL,
152158
to workDir: URL,
153-
progressUpdate: @escaping (String, Double) -> Void
159+
progressUpdate: @escaping (Double) -> Void
154160
) throws {
155161
let fm = FileManager.default
156162
let progress = Progress()
157163
let observation = progress.observe(\Progress.fractionCompleted) { prog, _ in
158-
let pct = Int(prog.fractionCompleted * 100)
159-
progressUpdate("Unzipping IPA 🔓 (\(pct)%)", prog.fractionCompleted)
164+
progressUpdate(prog.fractionCompleted)
160165
}
161166
defer {
162167
observation.invalidate()
@@ -180,16 +185,14 @@ fileprivate class SigningManager {
180185
from workDir: URL,
181186
originalIPAURL: URL,
182187
outputDir: URL,
183-
progressUpdate: @escaping (String, Double) -> Void
188+
progressUpdate: @escaping (Double) -> Void
184189
) throws -> URL {
185190
let fm = FileManager.default
186-
let originalBase = originalIPAURL.deletingPathExtension().lastPathComponent
187191
let finalFileName = "signed_\(UUID().uuidString).ipa"
188192
let signedIpa = outputDir.appendingPathComponent(finalFileName)
189193
let progress = Progress()
190194
let observation = progress.observe(\Progress.fractionCompleted) { prog, _ in
191-
let pct = Int(prog.fractionCompleted * 100)
192-
progressUpdate("Zipping signed IPA 📦 (\(pct)%)", prog.fractionCompleted)
195+
progressUpdate(prog.fractionCompleted)
193196
}
194197
defer {
195198
observation.invalidate()

0 commit comments

Comments
 (0)