@@ -21,6 +21,7 @@ struct CompilationView: View {
2121 @ObservedObject var addingRepo = AddingRepo . shared
2222 @AppStorage ( " compilationAppearence " ) var compilationAppearence = CompilationAppearence . compact
2323 let task = Process ( )
24+ let pipe = Pipe ( )
2425
2526 var body : some View {
2627 VStack {
@@ -102,7 +103,14 @@ struct CompilationView: View {
102103 } . padding ( . bottom)
103104 } else {
104105 Button ( " Cancel " ) {
105- log = " Canceling "
106+ if task. isRunning {
107+ task. terminate ( )
108+ }
109+
110+ shell. shell ( " cd ~/SM64Repos && rm -rf \( execPath) " , false )
111+ shell. shell ( " cd ~/SM64Repos && rm -rf \( repo) " , false )
112+
113+ dismiss. callAsFunction ( )
106114 } . padding ( . bottom)
107115 }
108116 }
@@ -112,7 +120,14 @@ struct CompilationView: View {
112120 Spacer ( )
113121
114122 Button ( " Cancel " ) {
115- log = " Canceling "
123+ if task. isRunning {
124+ task. terminate ( )
125+ }
126+
127+ shell. shell ( " cd ~/SM64Repos && rm -rf \( execPath) " , false )
128+ shell. shell ( " cd ~/SM64Repos && rm -rf \( repo) " , false )
129+
130+ dismiss. callAsFunction ( )
116131 } . padding ( [ . bottom, . trailing] )
117132 }
118133 }
@@ -136,16 +151,15 @@ struct CompilationView: View {
136151 task. executableURL = URL ( fileURLWithPath: " /bin/zsh " )
137152 task. arguments = [ " -cl " , " cd ~/SM64Repos && rm -rf \( execPath) && cd ~/; \( compileCommands) " ]
138153
139- let pipe = Pipe ( )
140154 task. standardOutput = pipe
141155 task. standardError = pipe
142156 let outHandle = pipe. fileHandleForReading
143-
157+
144158 outHandle. readabilityHandler = { pipe in
145159 if let line = String ( data: pipe. availableData, encoding: String . Encoding. utf8) {
146160 let number = CharacterSet . decimalDigits
147161 let letters = CharacterSet . letters
148-
162+
149163 totalLog. append ( line)
150164
151165 print ( line)
@@ -158,8 +172,110 @@ struct CompilationView: View {
158172 log = line
159173 }
160174 }
161-
162- if log. contains ( " sm_osx: Finishing Up " ) {
175+
176+ if log. contains ( " sm_osx: Done " ) {
177+ task. terminate ( )
178+
179+ compilationStatus = . finished
180+
181+ if shell. shell ( " ls ~/SM64Repos/ \( execPath) /sm64.us.f3dex2e | echo y " , true ) == " y \n " && repo != . moon64 {
182+
183+ let content = UNMutableNotificationContent ( )
184+ content. title = " Build Finished Successfully "
185+ content. subtitle = " The repo \( repo) has finished building successfully. "
186+ content. sound = UNNotificationSound . default
187+
188+ let trigger = UNTimeIntervalNotificationTrigger ( timeInterval: 0.0001 , repeats: false )
189+
190+ let request = UNNotificationRequest ( identifier: UUID ( ) . uuidString, content: content, trigger: trigger)
191+
192+ UNUserNotificationCenter . current ( ) . add ( request)
193+
194+ compilesSucess = true
195+
196+ if doLauncher {
197+
198+ let launcherRepo = LauncherRepos ( context: moc)
199+
200+ launcherRepo. title = " \( repo) "
201+ launcherRepo. isEditing = false
202+ launcherRepo. path = " ~/SM64Repos/ \( execPath) /sm64.us.f3dex2e "
203+ launcherRepo. args = " "
204+ launcherRepo. id = UUID ( )
205+
206+ do {
207+ try moc. save ( )
208+
209+ reloadMenuBarLauncher = true
210+ }
211+ catch {
212+ print ( error)
213+ }
214+ }
215+
216+ dismiss. callAsFunction ( )
217+ }
218+ else if shell. shell ( " ls ~/SM64Repos/ \( execPath) /moon64.us.f3dex2e | echo y " , true ) == " y \n " {
219+
220+ let content = UNMutableNotificationContent ( )
221+ content. title = " Build Finished Successfully "
222+ content. subtitle = " The build \( repo) has finished successfully. "
223+ content. sound = UNNotificationSound . default
224+
225+ let trigger = UNTimeIntervalNotificationTrigger ( timeInterval: 0.0001 , repeats: false )
226+
227+ let request = UNNotificationRequest ( identifier: UUID ( ) . uuidString, content: content, trigger: trigger)
228+
229+ UNUserNotificationCenter . current ( ) . add ( request)
230+
231+ compilesSucess = true
232+
233+ if doLauncher {
234+
235+ let launcherRepo = LauncherRepos ( context: moc)
236+
237+ launcherRepo. title = " \( repo) "
238+ launcherRepo. isEditing = false
239+ launcherRepo. path = " ~/SM64Repos/ \( execPath) /moon64.us.f3dex2e "
240+ launcherRepo. args = " "
241+ launcherRepo. id = UUID ( )
242+
243+ do {
244+ try moc. save ( )
245+
246+ reloadMenuBarLauncher = true
247+ }
248+ catch {
249+ print ( error)
250+ }
251+ }
252+
253+ dismiss. callAsFunction ( )
254+ }
255+ else {
256+
257+ let content = UNMutableNotificationContent ( )
258+ content. title = " Build Failed "
259+ content. subtitle = " The build \( repo) has failed. "
260+ content. sound = UNNotificationSound . default
261+
262+ let trigger = UNTimeIntervalNotificationTrigger ( timeInterval: 0.0001 , repeats: false )
263+
264+ let request = UNNotificationRequest ( identifier: UUID ( ) . uuidString, content: content, trigger: trigger)
265+
266+ UNUserNotificationCenter . current ( ) . add ( request)
267+
268+ compilesSucess = false
269+
270+ height = 575
271+
272+ shell. shell ( " cd ~/SM64Repos && rm -rf \( execPath) " , false )
273+ shell. shell ( " cd ~/SM64Repos && rm -rf \( repo) " , false )
274+ }
275+
276+ outHandle. readabilityHandler = nil
277+ }
278+ else if log. contains ( " sm_osx: Finishing Up " ) {
163279 compilationStatus = . finishingUp
164280 }
165281 else if log. contains ( " sm_osx: Compiling Now " ) {
@@ -180,109 +296,6 @@ struct CompilationView: View {
180296 } else {
181297 print ( " Error decoding data: \( pipe. availableData) " )
182298 }
183-
184- if outHandle. availableData. count == 0 {
185- task. terminate ( )
186-
187- compilationStatus = . finished
188-
189- if shell. shell ( " ls ~/SM64Repos/ \( execPath) /sm64.us.f3dex2e | echo y " , true ) == " y \n " && repo != . moon64 {
190-
191- let content = UNMutableNotificationContent ( )
192- content. title = " Build Finished Successfully "
193- content. subtitle = " The repo \( repo) has finished building successfully. "
194- content. sound = UNNotificationSound . default
195-
196- let trigger = UNTimeIntervalNotificationTrigger ( timeInterval: 0.0001 , repeats: false )
197-
198- let request = UNNotificationRequest ( identifier: UUID ( ) . uuidString, content: content, trigger: trigger)
199-
200- UNUserNotificationCenter . current ( ) . add ( request)
201-
202- compilesSucess = true
203-
204- if doLauncher {
205-
206- let launcherRepo = LauncherRepos ( context: moc)
207-
208- launcherRepo. title = " \( repo) "
209- launcherRepo. isEditing = false
210- launcherRepo. path = " ~/SM64Repos/ \( execPath) /sm64.us.f3dex2e "
211- launcherRepo. args = " "
212- launcherRepo. id = UUID ( )
213-
214- do {
215- try moc. save ( )
216-
217- reloadMenuBarLauncher = true
218- }
219- catch {
220- print ( error)
221- }
222- }
223-
224- dismiss. callAsFunction ( )
225- }
226- else if shell. shell ( " ls ~/SM64Repos/ \( execPath) /moon64.us.f3dex2e | echo y " , true ) == " y \n " {
227-
228- let content = UNMutableNotificationContent ( )
229- content. title = " Build Finished Successfully "
230- content. subtitle = " The build \( repo) has finished successfully. "
231- content. sound = UNNotificationSound . default
232-
233- let trigger = UNTimeIntervalNotificationTrigger ( timeInterval: 0.0001 , repeats: false )
234-
235- let request = UNNotificationRequest ( identifier: UUID ( ) . uuidString, content: content, trigger: trigger)
236-
237- UNUserNotificationCenter . current ( ) . add ( request)
238-
239- compilesSucess = true
240-
241- if doLauncher {
242-
243- let launcherRepo = LauncherRepos ( context: moc)
244-
245- launcherRepo. title = " \( repo) "
246- launcherRepo. isEditing = false
247- launcherRepo. path = " ~/SM64Repos/ \( execPath) /moon64.us.f3dex2e "
248- launcherRepo. args = " "
249- launcherRepo. id = UUID ( )
250-
251- do {
252- try moc. save ( )
253-
254- reloadMenuBarLauncher = true
255- }
256- catch {
257- print ( error)
258- }
259- }
260-
261- dismiss. callAsFunction ( )
262- }
263- else {
264-
265- let content = UNMutableNotificationContent ( )
266- content. title = " Build Failed "
267- content. subtitle = " The build \( repo) has failed. "
268- content. sound = UNNotificationSound . default
269-
270- let trigger = UNTimeIntervalNotificationTrigger ( timeInterval: 0.0001 , repeats: false )
271-
272- let request = UNNotificationRequest ( identifier: UUID ( ) . uuidString, content: content, trigger: trigger)
273-
274- UNUserNotificationCenter . current ( ) . add ( request)
275-
276- compilesSucess = false
277-
278- height = 575
279-
280- shell. shell ( " cd ~/SM64Repos && rm -rf \( execPath) " , false )
281- shell. shell ( " cd ~/SM64Repos && rm -rf \( repo) " , false )
282- }
283- }
284-
285- outHandle. stopReadingIfPassedEOF ( )
286299 }
287300
288301 try ? task. run ( )
@@ -301,15 +314,8 @@ struct CompilationView: View {
301314 height = 575
302315 }
303316 }
304- } . onChange ( of: log) { _ in
305- if log == " Canceling " {
306- task. terminate ( )
307-
308- shell. shell ( " cd ~/SM64Repos && rm -rf \( execPath) " , false )
309- shell. shell ( " cd ~/SM64Repos && rm -rf \( repo) " , false )
310-
311- dismiss. callAsFunction ( )
312- }
317+ } . onDisappear {
318+ pipe. fileHandleForReading. readabilityHandler = nil
313319 }
314320 }
315321}
0 commit comments