Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
EmeraldLoc committed May 2, 2023
2 parents 7aa8b51 + c3c295b commit 4abd34e
Show file tree
Hide file tree
Showing 3 changed files with 137 additions and 123 deletions.
8 changes: 4 additions & 4 deletions sm_osx.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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)";
Expand All @@ -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;
Expand All @@ -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)";
Expand Down
244 changes: 125 additions & 119 deletions sm_osx/CompilationView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
}
}
Expand All @@ -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])
}
}
Expand All @@ -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)
Expand All @@ -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") {
Expand All @@ -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()
Expand All @@ -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
}
}
}
8 changes: 8 additions & 0 deletions sm_osx/GlobalFunctions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}
}

0 comments on commit 4abd34e

Please sign in to comment.