@@ -17,18 +17,19 @@ struct LauncherView: View {
1717 @FetchRequest ( sortDescriptors: [ SortDescriptor ( \. title) ] ) var launcherRepos : FetchedResults < LauncherRepos >
1818 @State var existingRepo = URL ( string: " " )
1919 @State var repoTitle = " "
20- @State var currentVersion = " v1.1.6 \n "
20+ @State var currentVersion = " v1.1.7 \n "
2121 @State var updateAlert = false
2222 @State var latestVersion = " "
2323 @State var repoArgs = " "
2424 @State var crashStatus = false
2525 @State var crashLog = " "
2626 @State var readableCrashLog = " "
2727 @State var allowAddingRepos = true
28+ @State var beginLogging = false
2829 @AppStorage ( " firstLaunch " ) var firstLaunch = true
2930 @State var romURL = URL ( string: " " )
30- let sm64 : UTType = . init( filenameExtension: " f3dex2e " ) !
31- let rom : UTType = . init( filenameExtension: " z64 " ) !
31+ let sm64 : UTType = . init( filenameExtension: " f3dex2e " ) ?? UTType . unixExecutable
32+ let rom : UTType = . init( filenameExtension: " z64 " ) ?? UTType . unixExecutable
3233
3334 func launcherShell( _ command: String ) throws -> String {
3435 self . crashLog = " "
@@ -44,7 +45,7 @@ struct LauncherView: View {
4445 let outHandle = pipe. fileHandleForReading
4546 outHandle. waitForDataInBackgroundAndNotify ( )
4647
47- var obs1 : NSObjectProtocol !
48+ var obs1 : NSObjectProtocol ?
4849 obs1 = NotificationCenter . default. addObserver ( forName: Notification . Name. NSFileHandleDataAvailable, object: outHandle, queue: nil ) { notification -> Void in
4950 let data = outHandle. availableData
5051
@@ -63,7 +64,7 @@ struct LauncherView: View {
6364 }
6465 }
6566
66- var obs2 : NSObjectProtocol !
67+ var obs2 : NSObjectProtocol ?
6768 obs2 = NotificationCenter . default. addObserver ( forName: Process . didTerminateNotification, object: task, queue: nil ) { notification -> Void in
6869 print ( " terminated " )
6970
@@ -215,6 +216,23 @@ struct LauncherView: View {
215216 Image ( systemName: " trash " )
216217 }
217218
219+ Button ( action: {
220+
221+ for i in 0 ... launcherRepos. count - 1 {
222+ launcherRepos [ i] . isEditing = false
223+ }
224+
225+ print ( try ? launcherShell ( " \( LauncherRepo . path ?? " its broken " ) \( LauncherRepo . args ?? " " ) " ) )
226+
227+ beginLogging = true
228+
229+ print ( LauncherRepo . path ?? " " )
230+ } ) {
231+ Text ( " Log " )
232+
233+ Image ( systemName: " arrow.right.circle.fill " )
234+ }
235+
218236 Button ( action: {
219237
220238 for i in 0 ... launcherRepos. count - 1 {
@@ -246,8 +264,10 @@ struct LauncherView: View {
246264 if allowAddingRepos {
247265 Button ( action: {
248266
249- for i in 0 ... launcherRepos. count - 1 {
250- launcherRepos [ i] . isEditing = false
267+ if !launcherRepos. isEmpty {
268+ for i in 0 ... launcherRepos. count - 1 {
269+ launcherRepos [ i] . isEditing = false
270+ }
251271 }
252272
253273 romURL = showOpenPanelForRom ( )
@@ -274,8 +294,10 @@ struct LauncherView: View {
274294
275295 Button ( action: {
276296
277- for i in 0 ... launcherRepos. count - 1 {
278- launcherRepos [ i] . isEditing = false
297+ if !launcherRepos. isEmpty {
298+ for i in 0 ... launcherRepos. count - 1 {
299+ launcherRepos [ i] . isEditing = false
300+ }
279301 }
280302
281303 repoView = true
@@ -288,8 +310,10 @@ struct LauncherView: View {
288310
289311 Button ( " Add Existing Repo " ) {
290312
291- for i in 0 ... launcherRepos. count - 1 {
292- launcherRepos [ i] . isEditing = false
313+ if !launcherRepos. isEmpty {
314+ for i in 0 ... launcherRepos. count - 1 {
315+ launcherRepos [ i] . isEditing = false
316+ }
293317 }
294318
295319 existingRepo = showOpenPanel ( )
@@ -324,11 +348,11 @@ struct LauncherView: View {
324348 launcherRepos [ i] . isEditing = false
325349 }
326350
327- print ( try ! shell. shell ( " brew install make mingw-w64 gcc sdl2 pkg-config glew glfw3 libusb audiofile coreutils " ) )
351+ print ( try ? shell. shell ( " brew install make mingw-w64 gcc sdl2 pkg-config glew glfw3 libusb audiofile coreutils " ) )
328352
329353 print ( " its intel's turn nerd what an idiot man " )
330354
331- print ( try ! shell. intelShell ( " /usr/local/bin/brew install gcc gcc@9 sdl2 pkg-config glew glfw3 libusb audiofile coreutils " ) )
355+ print ( try ? shell. intelShell ( " /usr/local/bin/brew install gcc gcc@9 sdl2 pkg-config glew glfw3 libusb audiofile coreutils " ) )
332356
333357 let content = UNMutableNotificationContent ( )
334358 content. title = " Finished installing dependencies "
@@ -349,14 +373,24 @@ struct LauncherView: View {
349373 }
350374
351375 } . onAppear {
352- if try ! checkRom ( " ls ~/SM64Repos/baserom.us.z64 " ) {
353- allowAddingRepos = true
376+ do {
377+ if try checkRom ( " ls ~/SM64Repos/baserom.us.z64 " ) {
378+ allowAddingRepos = true
379+ }
380+ else {
381+ allowAddingRepos = false
382+ }
354383 }
355- else {
356- allowAddingRepos = false
384+ catch {
385+ print ( " Failed: \( error ) " )
357386 }
358387
359- latestVersion = try ! shell. shell ( " curl https://github.com/EmeraldLoc/sm_osx/releases/latest -s | grep -o 'v[0-9].[0-9].[0-9]*' | sort -u " )
388+ do {
389+ latestVersion = try shell. shell ( " curl https://github.com/EmeraldLoc/sm_osx/releases/latest -s | grep -o 'v[0-9].[0-9].[0-9]*' | sort -u " )
390+ }
391+ catch {
392+ print ( " Failed: \( error) " )
393+ }
360394
361395 print ( " Latest Version: \( latestVersion) , Current Version: \( currentVersion) " )
362396
@@ -382,7 +416,7 @@ struct LauncherView: View {
382416
383417 } . alert ( " An Update is Avalible " , isPresented: $updateAlert) {
384418 Button ( " Update " , role: . none) {
385- print ( try ! shell. shell ( " cd ~/Downloads && wget https://github.com/EmeraldLoc/sm_osx/releases/latest/download/sm_osx.zip && unzip sm_osx.zip && rm -rf sm_osx.zip /Applications/sm_osx.app && mv sm_osx.app /Applications && open /Applications/sm_osx.app " ) )
419+ print ( try ? shell. shell ( " cd ~/Downloads && wget https://github.com/EmeraldLoc/sm_osx/releases/latest/download/sm_osx.zip && unzip sm_osx.zip && rm -rf sm_osx.zip /Applications/sm_osx.app && mv sm_osx.app /Applications && open /Applications/sm_osx.app " ) )
386420
387421 exit ( 0 )
388422 }
@@ -400,6 +434,8 @@ struct LauncherView: View {
400434 readableCrashLog = crashLog
401435 }
402436 . onAppear {
437+ beginLogging = false
438+
403439 readableCrashLog = crashLog
404440 }
405441 }
@@ -410,6 +446,25 @@ struct LauncherView: View {
410446 crashStatus = false
411447 }
412448 } . frame ( minWidth: 350 , maxHeight: 350 )
449+ } . sheet ( isPresented: $beginLogging) {
450+ VStack {
451+ TextEditor ( text: $readableCrashLog)
452+ . frame ( minWidth: 350 , minHeight: 350 )
453+ . onChange ( of: readableCrashLog) { _ in
454+ readableCrashLog = crashLog
455+ } . onChange ( of: crashLog) { _ in
456+ readableCrashLog = crashLog
457+ }
458+ . onAppear {
459+ readableCrashLog = crashLog
460+ }
461+
462+ Spacer ( )
463+
464+ Button ( " Finish " ) {
465+ beginLogging = false
466+ }
467+ }
413468 }
414469 }
415470}
0 commit comments