@@ -10,30 +10,52 @@ import SwiftUI
1010struct ContentView : View {
1111 @State private var isImporting = false
1212 @State private var alertMessage = " "
13+ @State private var alertTitle = " "
1314 @State private var showingAlert = false
1415 @State private var converting = false
16+ @State private var performCleanup = true
17+ @State private var statusText = " "
1518
1619 var body : some View {
1720 NavigationView {
1821 VStack {
19- ProgressView ( )
20- . padding ( )
21- . opacity ( converting ? 1 : 0 )
22- Button ( " Import .deb " , action: {
22+ HStack {
23+ if converting {
24+ ProgressView ( )
25+ . padding ( )
26+ }
27+ Text ( statusText)
28+ . foregroundColor ( . secondary)
29+ . font ( . caption)
30+ }
31+ Button ( " Convert .deb app " , action: {
2332 isImporting. toggle ( )
2433 } )
25- . padding ( 10 )
26- . background ( Color . blue)
27- . cornerRadius ( 8 )
28- . foregroundColor ( . white)
29- Text ( " By sourcelocation \n \n Credits: itsnebulalol, \n LebJe/ArArchiveKit, \n marmelroy/Zip, \n tsolomko/SWCompression " )
30- . foregroundColor ( Color . secondary)
31- . font ( . caption)
32- . multilineTextAlignment ( . center)
33-
34+ . padding ( 10 )
35+ . background ( Color . blue)
36+ . cornerRadius ( 8 )
37+ . foregroundColor ( . white)
38+ HStack ( alignment: . center) {
39+ Text ( " By sourcelocation " )
40+ . foregroundColor ( . secondary)
41+ . font ( . caption)
42+ Button {
43+ alert ( " \n Credits: itsnebulalol, \n LebJe/ArArchiveKit, \n marmelroy/Zip, \n tsolomko/SWCompression " , title: " Info " )
44+ } label: {
45+ Image ( systemName: " info.circle " )
46+ }
47+ }
48+ HStack {
49+ Text ( " Clean after running " )
50+ . font ( . body)
51+ Toggle ( " Cleanup " , isOn: $performCleanup)
52+ . labelsHidden ( )
53+ }
54+ . padding ( )
3455 }
3556 . navigationTitle ( " DebToIPA " )
3657 }
58+ . navigationViewStyle ( StackNavigationViewStyle ( ) )
3759 . fileImporter (
3860 isPresented: $isImporting,
3961 allowedContentTypes: [ . init( filenameExtension: " deb " ) !] ,
@@ -44,44 +66,52 @@ struct ContentView: View {
4466 }
4567 . alert ( isPresented: $showingAlert) {
4668 Alert (
47- title: Text ( " Error " ) ,
69+ title: Text ( alertTitle ) ,
4870 message: Text ( alertMessage)
4971 )
5072 }
5173 }
5274
5375 func convert( url: URL ) {
5476 converting = true
55- DispatchQueue . main . asyncAfter ( deadline : . now ( ) + 0.1 , execute : {
77+ DispatchQueue . global ( qos : . userInitiated ) . async {
5678 do {
5779 guard url. startAccessingSecurityScopedResource ( ) else { throw ConversionError . noPermission }
58- let ipa = try DebToIPA . convert ( url)
59- share ( ipa)
80+ let ipa = try DebToIPA . convert ( url, statusUpdate: { message in
81+ DispatchQueue . main. async {
82+ statusText = message
83+ }
84+ } )
85+ DispatchQueue . main. async {
86+ share ( ipa)
87+ }
6088 } catch let error {
61- print ( error)
62- if let convError = error as? ConversionError {
63- switch convError {
64- case . unsupportedApp:
65- alert ( " The .deb you imported is UNSUPPORTED and CANNOT be converted to .ipa, as it doesn't have Applications folder. " )
66- case . noDataFound:
67- alert ( " Data wasn't found in .deb. Are you sure the .deb you imported isn't corrupted? " )
68- case . noApplication:
69- alert ( " The .deb you imported is UNSUPPORTED and CANNOT be converted to .ipa, as it doesn't have a .app file inside it. " )
70- case . noPermission:
71- alert ( " No permission to view the file " )
72- case . unknownFiletypeInsideTar:
73- alert ( " Unknown filetype inside tar. This is a bug with the app. Please create an issue on Github with the name of tweak/app. Thanks! " )
74- case . unsupportedCompression:
75- alert ( " Unsupported compression. This is a bug with the app. Please create an issue on Github with the name of tweak/app. Thanks! " )
89+ DispatchQueue . main. async {
90+ print ( error)
91+ if let convError = error as? ConversionError {
92+ switch convError {
93+ case . unsupportedApp:
94+ alert ( " The .deb you imported is UNSUPPORTED and CANNOT be converted to .ipa, as it doesn't have Applications folder. " )
95+ case . noDataFound:
96+ alert ( " Data wasn't found in .deb. Are you sure the .deb you imported isn't corrupted? " )
97+ case . noApplication:
98+ alert ( " The .deb you imported is UNSUPPORTED and CANNOT be converted to .ipa, as it doesn't have a .app file inside it. " )
99+ case . noPermission:
100+ alert ( " No permission to view the file " )
101+ case . unknownFiletypeInsideTar:
102+ alert ( " Unknown filetype inside tar. This is a bug with the app. Please create an issue on Github with the name of tweak/app. Thanks! " )
103+ case . unsupportedCompression:
104+ alert ( " Unsupported compression. This is a bug with the app. Please create an issue on Github with the name of tweak/app. Thanks! " )
105+ }
106+ } else {
107+ alert ( " Unknown error. \n " + error. localizedDescription)
76108 }
77- } else {
78- alert ( " Unknown error. \n " + error. localizedDescription)
79109 }
80110 }
81111 url. stopAccessingSecurityScopedResource ( )
82112
83113 converting = false
84- } )
114+ }
85115 }
86116
87117 func share( _ url: URL ) {
@@ -91,14 +121,23 @@ struct ContentView: View {
91121 shareActivity. popoverPresentationController? . sourceView = vc. view
92122 shareActivity. popoverPresentationController? . sourceRect = CGRect ( x: UIScreen . main. bounds. width / 2 , y: UIScreen . main. bounds. height, width: 0 , height: 0 )
93123 shareActivity. popoverPresentationController? . permittedArrowDirections = UIPopoverArrowDirection . down
124+ shareActivity. completionWithItemsHandler = { ( type, completed, returnedItems, activityError) in
125+ if performCleanup {
126+ do {
127+ try DebToIPA . cleanup ( )
128+ } catch {
129+ alert ( " Cleanup failed. Reinstall is most likely needed. " + error. localizedDescription)
130+ }
131+ }
132+ }
94133 DispatchQueue . main. async {
95- vc. present ( shareActivity, animated: true , completion: {
96- } )
134+ vc. present ( shareActivity, animated: true )
97135 }
98136 }
99137 }
100138
101- func alert( _ message: String ) {
139+ func alert( _ message: String , title: String = " Error " ) {
140+ alertTitle = title
102141 alertMessage = message
103142 showingAlert. toggle ( )
104143 }
0 commit comments