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

Commit 638c2a7

Browse files
authored
Remove the annyo stuff
1 parent b163eb7 commit 638c2a7

2 files changed

Lines changed: 52 additions & 46 deletions

File tree

Lines changed: 41 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,52 @@
1+
// installAppStream.swift
12
import Foundation
23
import Combine
34
import IDeviceSwift
45

5-
public func installAppWithStatus(from ipaURL: URL, viewModel: InstallerViewModel) async throws {
6-
var cancellables = Set<AnyCancellable>()
6+
public func installAppWithStatusStream(from ipaURL: URL) -> AsyncThrowingStream<InstallerStatusViewModel.InstallerStatus, Error> {
7+
AsyncThrowingStream { continuation in
8+
// create a local view model for the InstallationProxy internals
9+
let localVM = InstallerStatusViewModel()
10+
var cancellables = Set<AnyCancellable>()
711

8-
viewModel.$uploadProgress
9-
.sink { progress in
10-
DispatchQueue.main.async {
11-
let percent = Int(progress * 100)
12-
viewModel.status = .uploading(percent: percent)
13-
viewModel.progress = 0.5 + (progress * 0.25)
12+
// Observe progress and forward into the AsyncStream
13+
localVM.$uploadProgress
14+
.sink { progress in
15+
let pct = Int(progress * 100)
16+
continuation.yield(.uploading(percent: pct))
1417
}
15-
}
16-
.store(in: &cancellables)
18+
.store(in: &cancellables)
1719

18-
viewModel.$installProgress
19-
.sink { progress in
20-
DispatchQueue.main.async {
21-
let percent = Int(progress * 100)
22-
viewModel.status = .installing(percent: percent)
23-
viewModel.progress = 0.75 + (progress * 0.25)
20+
localVM.$installProgress
21+
.sink { progress in
22+
let pct = Int(progress * 100)
23+
continuation.yield(.installing(percent: pct))
2424
}
25-
}
26-
.store(in: &cancellables)
25+
.store(in: &cancellables)
2726

28-
// DON'T reassign viewModel.status inside a sink on viewModel.$status —
29-
// that just creates a loop. If you want to react to status changes elsewhere,
30-
// observe it and map to UI strings there.
27+
// Optionally map other status changes
28+
localVM.$status
29+
.sink { status in
30+
continuation.yield(status)
31+
}
32+
.store(in: &cancellables)
3133

32-
let installer = InstallationProxy(viewModel: viewModel)
33-
try await installer.install(at: ipaURL)
34+
Task {
35+
do {
36+
let installer = InstallationProxy(viewModel: localVM)
37+
try await installer.install(at: ipaURL)
38+
continuation.yield(.success)
39+
continuation.finish()
40+
} catch {
41+
// forward failure as an enum + error finishing
42+
continuation.yield(.failure(message: error.localizedDescription))
43+
continuation.finish(throwing: error)
44+
}
45+
}
46+
47+
// on stream termination, cancel Combine sinks
48+
continuation.onTermination = { @Sendable _ in
49+
cancellables.forEach { $0.cancel() }
50+
}
51+
}
3452
}

Sources/prostore/signing/DownloadSignManager.swift

Lines changed: 11 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -191,39 +191,26 @@ private func signAndInstallIPA(
191191
}
192192

193193
// Create a view model for installation progress
194-
// Create a view model for installation progress
195-
let installerViewModel = InstallerViewModel()
194+
// inside your Task after signing completes
195+
let stream = installAppWithStatusStream(from: signedIPAURL)
196196

197197
Task {
198198
do {
199-
try await installAppWithStatus(from: signedIPAURL, viewModel: installerViewModel)
200-
201-
// Observe the viewModel status to update your UI
202-
installerViewModel.$status
203-
.receive(on: DispatchQueue.main)
204-
.sink { status in
199+
for try await status in stream {
200+
DispatchQueue.main.async {
205201
switch status {
206-
case .idle:
207-
break
208-
case .uploading(let percent), .installing(let percent):
209-
self.progress = Double(percent) / 100.0
202+
case .idle: break
203+
case .uploading(let pct), .installing(let pct):
204+
self.progress = Double(pct) / 100.0
210205
self.status = status.pretty
211206
case .success:
212-
self.status = InstallerViewModel.InstallerStatus.success.pretty
213-
case .failure(let message):
214-
self.status = InstallerViewModel.InstallerStatus.failure(message: message).pretty
207+
self.status = status.pretty
208+
case .failure(let msg):
209+
self.status = status.pretty
215210
case .message(let text):
216211
self.status = text
217212
}
218213
}
219-
.store(in: &self.cancellables)
220-
221-
// Hide the bar 3 seconds after install is complete
222-
DispatchQueue.main.asyncAfter(deadline: .now() + 3) {
223-
self.isProcessing = false
224-
self.showSuccess = false
225-
self.progress = 0.0
226-
self.status = ""
227214
}
228215
} catch {
229216
DispatchQueue.main.async {
@@ -233,6 +220,7 @@ Task {
233220
}
234221
}
235222

223+
236224
// Clean up original downloaded IPA
237225
try? FileManager.default.removeItem(at: ipaURL)
238226

0 commit comments

Comments
 (0)