From 6dcd8eb07a99bf381c33c03879fe63d071efcf9c Mon Sep 17 00:00:00 2001 From: Selim Mustafaev Date: Thu, 18 May 2023 19:21:25 +0300 Subject: [PATCH] Selecting provisioning profile --- reSign.xcodeproj/project.pbxproj | 4 ++++ reSign/Views/FormButtonItem.swift | 23 +++++++++++++++++++++++ reSign/Views/Sign/SignView.swift | 22 ++++++++++++++++++++++ reSign/Views/Sign/SignViewModel.swift | 1 + 4 files changed, 50 insertions(+) create mode 100644 reSign/Views/FormButtonItem.swift diff --git a/reSign.xcodeproj/project.pbxproj b/reSign.xcodeproj/project.pbxproj index 1af9445..ff7efb5 100644 --- a/reSign.xcodeproj/project.pbxproj +++ b/reSign.xcodeproj/project.pbxproj @@ -7,6 +7,7 @@ objects = { /* Begin PBXBuildFile section */ + 63B2CF622A16641500B80D2F /* FormButtonItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = 63B2CF612A16641500B80D2F /* FormButtonItem.swift */; }; 7A064BE429DE107000C5D978 /* Category.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7A064BE329DE107000C5D978 /* Category.swift */; }; 7A064BE929DE18C700C5D978 /* SignInfoView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7A064BE829DE18C700C5D978 /* SignInfoView.swift */; }; 7A064BEB29DF5BB800C5D978 /* AppPackage.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7A064BEA29DF5BB800C5D978 /* AppPackage.swift */; }; @@ -29,6 +30,7 @@ /* End PBXBuildFile section */ /* Begin PBXFileReference section */ + 63B2CF612A16641500B80D2F /* FormButtonItem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FormButtonItem.swift; sourceTree = ""; }; 7A064BE329DE107000C5D978 /* Category.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Category.swift; sourceTree = ""; }; 7A064BE829DE18C700C5D978 /* SignInfoView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SignInfoView.swift; sourceTree = ""; }; 7A064BEA29DF5BB800C5D978 /* AppPackage.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppPackage.swift; sourceTree = ""; }; @@ -80,6 +82,7 @@ 7A064BE829DE18C700C5D978 /* SignInfoView.swift */, 7AF0C53A29F72151008D4084 /* PlistView.swift */, 7A9478022A0984D200EC7329 /* FormPickerItem.swift */, + 63B2CF612A16641500B80D2F /* FormButtonItem.swift */, ); path = Views; sourceTree = ""; @@ -228,6 +231,7 @@ 7AF0C53B29F72151008D4084 /* PlistView.swift in Sources */, 7AF0C51C29EF43CD008D4084 /* TreeItem.swift in Sources */, 7AF0C51829EDCF59008D4084 /* URL+ExtendedAttributes.swift in Sources */, + 63B2CF622A16641500B80D2F /* FormButtonItem.swift in Sources */, 7A064BEB29DF5BB800C5D978 /* AppPackage.swift in Sources */, 7A064BE929DE18C700C5D978 /* SignInfoView.swift in Sources */, 7AF0C54229FFBDB0008D4084 /* SignViewModel.swift in Sources */, diff --git a/reSign/Views/FormButtonItem.swift b/reSign/Views/FormButtonItem.swift new file mode 100644 index 0000000..58d7734 --- /dev/null +++ b/reSign/Views/FormButtonItem.swift @@ -0,0 +1,23 @@ +// +// FormButtonItem.swift +// reSign +// +// Created by Мустафаев Селим Мустафаевич on 18.05.2023. +// + +import SwiftUI + +struct FormButtonItem: View { + + let name: String + let buttonName: String + let onClick: () -> Void + + var body: some View { + HStack { + Text(name) + Spacer() + Button(buttonName, action: onClick) + } + } +} diff --git a/reSign/Views/Sign/SignView.swift b/reSign/Views/Sign/SignView.swift index aea1030..bdc7b89 100644 --- a/reSign/Views/Sign/SignView.swift +++ b/reSign/Views/Sign/SignView.swift @@ -6,6 +6,7 @@ // import SwiftUI +import UniformTypeIdentifiers struct SignView: View { @@ -19,10 +20,31 @@ struct SignView: View { FormPickerItem(name: "Signing Identity", options: viewModel.signingIdentities, selectedItem: $viewModel.selectedIdentity) + + if let profile = viewModel.provisioningProfileUrl { + FormTextItem(name: "Provisioning profile", + value: profile.path()) + } else { + FormButtonItem(name: "Provisioning profile", + buttonName: "Open", + onClick: openProvisioningProfile) + } } } .formStyle(.grouped) } + + func openProvisioningProfile() { + + let panel = NSOpenPanel() + panel.title = "Select provisioning profile" + panel.allowsMultipleSelection = false + panel.canChooseDirectories = false + panel.allowedContentTypes = [UTType("provisionprofile")].compactMap { $0 } + if panel.runModal() == .OK { + viewModel.provisioningProfileUrl = panel.url + } + } } struct SignView_Previews: PreviewProvider { diff --git a/reSign/Views/Sign/SignViewModel.swift b/reSign/Views/Sign/SignViewModel.swift index 6634153..21bdbc4 100644 --- a/reSign/Views/Sign/SignViewModel.swift +++ b/reSign/Views/Sign/SignViewModel.swift @@ -11,6 +11,7 @@ class SignViewModel: ObservableObject { @Published var signingIdentities: [String] = [] @Published var selectedIdentity: String = "" + @Published var provisioningProfileUrl: URL? init() { updateSigningIdentities()