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

Commit a334e1c

Browse files
authored
Refactor SignerView for improved functionality
1 parent f05a7ec commit a334e1c

File tree

1 file changed

+26
-23
lines changed

1 file changed

+26
-23
lines changed

Sources/prosign/views/SignerView.swift

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,16 @@ struct SignerView: View {
88
@State private var progressMessage = ""
99
@State private var showActivity = false
1010
@State private var activityURL: URL? = nil
11-
@State private var showPickerFor: PickerKind?
11+
@State private var showPickerFor: PickerKind? = nil
1212
@State private var selectedCertificateName: String? = nil
1313
@State private var hasSelectedCertificate: Bool = false
1414

1515
var body: some View {
1616
Form {
1717
Section(header: Text("Inputs")
18-
.font(.headline)
19-
.foregroundColor(.primary)
20-
.padding(.top, 8)) {
18+
.font(.headline)
19+
.foregroundColor(.primary)
20+
.padding(.top, 8)) {
2121
// IPA picker with icon and truncated file name
2222
HStack {
2323
Image(systemName: "doc.fill")
@@ -28,7 +28,9 @@ struct SignerView: View {
2828
.font(.caption)
2929
.lineLimit(1)
3030
.foregroundColor(.secondary)
31-
Button(action: { showPickerFor = .ipa }) {
31+
Button(action: {
32+
showPickerFor = .ipa
33+
}) {
3234
Text("Pick")
3335
.padding(.horizontal, 8)
3436
.padding(.vertical, 4)
@@ -37,7 +39,7 @@ struct SignerView: View {
3739
}
3840
}
3941
.padding(.vertical, 4)
40-
42+
4143
if hasSelectedCertificate, let name = selectedCertificateName {
4244
Text("The \(name) certificate will be used to sign the ipa file. If you wish to use a different certificate for signing, please select or add it to the certificates page.")
4345
.font(.subheadline)
@@ -49,6 +51,7 @@ struct SignerView: View {
4951
.padding(.vertical, 4)
5052
}
5153
}
54+
5255
Section {
5356
Button(action: runSign) {
5457
HStack {
@@ -69,10 +72,11 @@ struct SignerView: View {
6972
.animation(.easeInOut(duration: 0.2), value: isProcessing)
7073
}
7174
.padding(.vertical, 8)
75+
7276
Section(header: Text("Status")
73-
.font(.headline)
74-
.foregroundColor(.primary)
75-
.padding(.top, 8)) {
77+
.font(.headline)
78+
.foregroundColor(.primary)
79+
.padding(.top, 8)) {
7680
HStack {
7781
if isProcessing {
7882
ProgressView()
@@ -88,8 +92,10 @@ struct SignerView: View {
8892
.sheet(item: $showPickerFor, onDismiss: nil) { kind in
8993
DocumentPicker(kind: kind, onPick: { url in
9094
switch kind {
91-
case .ipa: ipa.url = url
92-
default: break
95+
case .ipa:
96+
ipa.url = url
97+
default:
98+
break
9399
}
94100
})
95101
}
@@ -105,18 +111,17 @@ struct SignerView: View {
105111
loadSelectedCertificate()
106112
}
107113
}
108-
114+
109115
private func loadSelectedCertificate() {
110116
guard let selectedFolder = UserDefaults.standard.string(forKey: "selectedCertificateFolder") else {
111117
hasSelectedCertificate = false
112118
return
113119
}
114-
115120
let certDir = CertificateFileManager.shared.certificatesDirectory.appendingPathComponent(selectedFolder)
116-
117121
do {
118122
if let nameData = try? Data(contentsOf: certDir.appendingPathComponent("name.txt")),
119-
let name = String(data: nameData, encoding: .utf8)?.trimmingCharacters(in: .whitespacesAndNewlines), !name.isEmpty {
123+
let name = String(data: nameData, encoding: .utf8)?.trimmingCharacters(in: .whitespacesAndNewlines),
124+
!name.isEmpty {
120125
selectedCertificateName = name
121126
} else {
122127
selectedCertificateName = "Custom Certificate"
@@ -127,39 +132,37 @@ struct SignerView: View {
127132
selectedCertificateName = nil
128133
}
129134
}
130-
135+
131136
func runSign() {
132137
guard let ipaURL = ipa.url else {
133138
progressMessage = "Pick IPA file first 😅"
134139
return
135140
}
136-
137141
guard let selectedFolder = UserDefaults.standard.string(forKey: "selectedCertificateFolder") else {
138142
progressMessage = "No certificate selected 😅"
139143
return
140144
}
141-
142145
let certDir = CertificateFileManager.shared.certificatesDirectory.appendingPathComponent(selectedFolder)
143146
let p12URL = certDir.appendingPathComponent("certificate.p12")
144147
let provURL = certDir.appendingPathComponent("profile.mobileprovision")
145148
let passwordURL = certDir.appendingPathComponent("password.txt")
146-
147-
guard FileManager.default.fileExists(atPath: p12URL.path),
148-
FileManager.default.fileExists(atPath: provURL.path) else {
149+
150+
guard FileManager.default.fileExists(atPath: p12URL.path), FileManager.default.fileExists(atPath: provURL.path) else {
149151
progressMessage = "Error loading certificate files 😅"
150152
return
151153
}
152-
154+
153155
let p12Password: String
154156
if let passwordData = try? Data(contentsOf: passwordURL),
155157
let passwordStr = String(data: passwordData, encoding: .utf8) {
156158
p12Password = passwordStr
157159
} else {
158160
p12Password = ""
159161
}
160-
162+
161163
isProcessing = true
162164
progressMessage = "Starting signing process..."
165+
163166
ProStoreTools.sign(
164167
ipaURL: ipaURL,
165168
p12URL: p12URL,

0 commit comments

Comments
 (0)