diff --git a/sm_osx.xcodeproj/project.pbxproj b/sm_osx.xcodeproj/project.pbxproj index f1be597..2fd2833 100644 --- a/sm_osx.xcodeproj/project.pbxproj +++ b/sm_osx.xcodeproj/project.pbxproj @@ -415,7 +415,7 @@ CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; COMBINE_HIDPI_IMAGES = YES; - CURRENT_PROJECT_VERSION = 6; + CURRENT_PROJECT_VERSION = 7; DEAD_CODE_STRIPPING = YES; DEVELOPMENT_ASSET_PATHS = "\"sm_osx/Preview Content\""; DEVELOPMENT_TEAM = 25RK3JMVLT; @@ -431,7 +431,7 @@ "@executable_path/../Frameworks", ); MACOSX_DEPLOYMENT_TARGET = 13.0; - MARKETING_VERSION = 1.3.0.4; + MARKETING_VERSION = 1.3.0.5; ONLY_ACTIVE_ARCH = NO; PRODUCT_BUNDLE_IDENTIFIER = "com.CubingStudios.sm-osx"; PRODUCT_NAME = "$(TARGET_NAME)"; @@ -449,7 +449,7 @@ CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; COMBINE_HIDPI_IMAGES = YES; - CURRENT_PROJECT_VERSION = 6; + CURRENT_PROJECT_VERSION = 7; DEAD_CODE_STRIPPING = YES; DEVELOPMENT_ASSET_PATHS = "\"sm_osx/Preview Content\""; DEVELOPMENT_TEAM = 25RK3JMVLT; @@ -465,7 +465,7 @@ "@executable_path/../Frameworks", ); MACOSX_DEPLOYMENT_TARGET = 13.0; - MARKETING_VERSION = 1.3.0.4; + MARKETING_VERSION = 1.3.0.5; ONLY_ACTIVE_ARCH = NO; PRODUCT_BUNDLE_IDENTIFIER = "com.CubingStudios.sm-osx"; PRODUCT_NAME = "$(TARGET_NAME)"; diff --git a/sm_osx/CompilationView.swift b/sm_osx/CompilationView.swift index 08afb8c..b5f12e4 100644 --- a/sm_osx/CompilationView.swift +++ b/sm_osx/CompilationView.swift @@ -21,6 +21,7 @@ struct CompilationView: View { @ObservedObject var addingRepo = AddingRepo.shared @AppStorage("compilationAppearence") var compilationAppearence = CompilationAppearence.compact let task = Process() + let pipe = Pipe() var body: some View { VStack { @@ -102,7 +103,14 @@ struct CompilationView: View { }.padding(.bottom) } else { Button("Cancel") { - log = "Canceling" + if task.isRunning { + task.terminate() + } + + shell.shell("cd ~/SM64Repos && rm -rf \(execPath)", false) + shell.shell("cd ~/SM64Repos && rm -rf \(repo)", false) + + dismiss.callAsFunction() }.padding(.bottom) } } @@ -112,7 +120,14 @@ struct CompilationView: View { Spacer() Button("Cancel") { - log = "Canceling" + if task.isRunning { + task.terminate() + } + + shell.shell("cd ~/SM64Repos && rm -rf \(execPath)", false) + shell.shell("cd ~/SM64Repos && rm -rf \(repo)", false) + + dismiss.callAsFunction() }.padding([.bottom, .trailing]) } } @@ -136,16 +151,15 @@ struct CompilationView: View { task.executableURL = URL(fileURLWithPath: "/bin/zsh") task.arguments = ["-cl", "cd ~/SM64Repos && rm -rf \(execPath) && cd ~/; \(compileCommands)"] - let pipe = Pipe() task.standardOutput = pipe task.standardError = pipe let outHandle = pipe.fileHandleForReading - + outHandle.readabilityHandler = { pipe in if let line = String(data: pipe.availableData, encoding: String.Encoding.utf8) { let number = CharacterSet.decimalDigits let letters = CharacterSet.letters - + totalLog.append(line) print(line) @@ -158,8 +172,110 @@ struct CompilationView: View { log = line } } - - if log.contains("sm_osx: Finishing Up") { + + if log.contains("sm_osx: Done") { + task.terminate() + + compilationStatus = .finished + + if shell.shell("ls ~/SM64Repos/\(execPath)/sm64.us.f3dex2e | echo y", true) == "y\n" && repo != .moon64 { + + let content = UNMutableNotificationContent() + content.title = "Build Finished Successfully" + content.subtitle = "The repo \(repo) has finished building successfully." + content.sound = UNNotificationSound.default + + let trigger = UNTimeIntervalNotificationTrigger(timeInterval: 0.0001, repeats: false) + + let request = UNNotificationRequest(identifier: UUID().uuidString, content: content, trigger: trigger) + + UNUserNotificationCenter.current().add(request) + + compilesSucess = true + + if doLauncher { + + let launcherRepo = LauncherRepos(context: moc) + + launcherRepo.title = "\(repo)" + launcherRepo.isEditing = false + launcherRepo.path = "~/SM64Repos/\(execPath)/sm64.us.f3dex2e" + launcherRepo.args = "" + launcherRepo.id = UUID() + + do { + try moc.save() + + reloadMenuBarLauncher = true + } + catch { + print(error) + } + } + + dismiss.callAsFunction() + } + else if shell.shell("ls ~/SM64Repos/\(execPath)/moon64.us.f3dex2e | echo y", true) == "y\n" { + + let content = UNMutableNotificationContent() + content.title = "Build Finished Successfully" + content.subtitle = "The build \(repo) has finished successfully." + content.sound = UNNotificationSound.default + + let trigger = UNTimeIntervalNotificationTrigger(timeInterval: 0.0001, repeats: false) + + let request = UNNotificationRequest(identifier: UUID().uuidString, content: content, trigger: trigger) + + UNUserNotificationCenter.current().add(request) + + compilesSucess = true + + if doLauncher { + + let launcherRepo = LauncherRepos(context: moc) + + launcherRepo.title = "\(repo)" + launcherRepo.isEditing = false + launcherRepo.path = "~/SM64Repos/\(execPath)/moon64.us.f3dex2e" + launcherRepo.args = "" + launcherRepo.id = UUID() + + do { + try moc.save() + + reloadMenuBarLauncher = true + } + catch { + print(error) + } + } + + dismiss.callAsFunction() + } + else { + + let content = UNMutableNotificationContent() + content.title = "Build Failed" + content.subtitle = "The build \(repo) has failed." + content.sound = UNNotificationSound.default + + let trigger = UNTimeIntervalNotificationTrigger(timeInterval: 0.0001, repeats: false) + + let request = UNNotificationRequest(identifier: UUID().uuidString, content: content, trigger: trigger) + + UNUserNotificationCenter.current().add(request) + + compilesSucess = false + + height = 575 + + shell.shell("cd ~/SM64Repos && rm -rf \(execPath)", false) + shell.shell("cd ~/SM64Repos && rm -rf \(repo)", false) + } + + outHandle.readabilityHandler = nil + } + else if log.contains("sm_osx: Finishing Up") { compilationStatus = .finishingUp } else if log.contains("sm_osx: Compiling Now") { @@ -180,109 +296,6 @@ struct CompilationView: View { } else { print("Error decoding data: \(pipe.availableData)") } - - if outHandle.availableData.count == 0 { - task.terminate() - - compilationStatus = .finished - - if shell.shell("ls ~/SM64Repos/\(execPath)/sm64.us.f3dex2e | echo y", true) == "y\n" && repo != .moon64 { - - let content = UNMutableNotificationContent() - content.title = "Build Finished Successfully" - content.subtitle = "The repo \(repo) has finished building successfully." - content.sound = UNNotificationSound.default - - let trigger = UNTimeIntervalNotificationTrigger(timeInterval: 0.0001, repeats: false) - - let request = UNNotificationRequest(identifier: UUID().uuidString, content: content, trigger: trigger) - - UNUserNotificationCenter.current().add(request) - - compilesSucess = true - - if doLauncher { - - let launcherRepo = LauncherRepos(context: moc) - - launcherRepo.title = "\(repo)" - launcherRepo.isEditing = false - launcherRepo.path = "~/SM64Repos/\(execPath)/sm64.us.f3dex2e" - launcherRepo.args = "" - launcherRepo.id = UUID() - - do { - try moc.save() - - reloadMenuBarLauncher = true - } - catch { - print(error) - } - } - - dismiss.callAsFunction() - } - else if shell.shell("ls ~/SM64Repos/\(execPath)/moon64.us.f3dex2e | echo y", true) == "y\n" { - - let content = UNMutableNotificationContent() - content.title = "Build Finished Successfully" - content.subtitle = "The build \(repo) has finished successfully." - content.sound = UNNotificationSound.default - - let trigger = UNTimeIntervalNotificationTrigger(timeInterval: 0.0001, repeats: false) - - let request = UNNotificationRequest(identifier: UUID().uuidString, content: content, trigger: trigger) - - UNUserNotificationCenter.current().add(request) - - compilesSucess = true - - if doLauncher { - - let launcherRepo = LauncherRepos(context: moc) - - launcherRepo.title = "\(repo)" - launcherRepo.isEditing = false - launcherRepo.path = "~/SM64Repos/\(execPath)/moon64.us.f3dex2e" - launcherRepo.args = "" - launcherRepo.id = UUID() - - do { - try moc.save() - - reloadMenuBarLauncher = true - } - catch { - print(error) - } - } - - dismiss.callAsFunction() - } - else { - - let content = UNMutableNotificationContent() - content.title = "Build Failed" - content.subtitle = "The build \(repo) has failed." - content.sound = UNNotificationSound.default - - let trigger = UNTimeIntervalNotificationTrigger(timeInterval: 0.0001, repeats: false) - - let request = UNNotificationRequest(identifier: UUID().uuidString, content: content, trigger: trigger) - - UNUserNotificationCenter.current().add(request) - - compilesSucess = false - - height = 575 - - shell.shell("cd ~/SM64Repos && rm -rf \(execPath)", false) - shell.shell("cd ~/SM64Repos && rm -rf \(repo)", false) - } - } - - outHandle.stopReadingIfPassedEOF() } try? task.run() @@ -301,15 +314,8 @@ struct CompilationView: View { height = 575 } } - }.onChange(of: log) { _ in - if log == "Canceling" { - task.terminate() - - shell.shell("cd ~/SM64Repos && rm -rf \(execPath)", false) - shell.shell("cd ~/SM64Repos && rm -rf \(repo)", false) - - dismiss.callAsFunction() - } + }.onDisappear { + pipe.fileHandleForReading.readabilityHandler = nil } } } diff --git a/sm_osx/GlobalFunctions.swift b/sm_osx/GlobalFunctions.swift index 550bf6b..53b5d4d 100644 --- a/sm_osx/GlobalFunctions.swift +++ b/sm_osx/GlobalFunctions.swift @@ -49,3 +49,11 @@ class AddingRepo: ObservableObject { static let shared = AddingRepo() var isCompiling = false } + +extension DispatchQueue { + static func background(delay: Double = 0.0, background: @escaping () -> Void) { + DispatchQueue.global(qos: .background).async { + background() + } + } +}