forked from github/CopilotForXcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclipboard.txt
More file actions
70 lines (59 loc) · 2.15 KB
/
clipboard.txt
File metadata and controls
70 lines (59 loc) · 2.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import SwiftUI
struct ContentView: View {
@State private var output = "Ready to uninstall Copilot for Xcode.\n"
@State private var isRunning = false
@State private var dryRun = true
var body: some View {
VStack(spacing: 20) {
Text("Copilot for Xcode Uninstaller")
.font(.title2)
Toggle("Dry Run (Preview Only)", isOn: $dryRun)
.padding(.horizontal)
ScrollView {
Text(output)
.frame(maxWidth: .infinity, alignment: .leading)
.padding()
.background(Color(.systemGray6))
.cornerRadius(8)
}
.frame(height: 300)
Button(action: runScript) {
Text(isRunning ? "Running..." : "Uninstall")
.frame(maxWidth: .infinity)
}
.disabled(isRunning)
.buttonStyle(.borderedProminent)
.padding(.horizontal)
Spacer()
}
.padding()
.frame(width: 500, height: 400)
}
func runScript() {
isRunning = true
output += "\nStarting \(dryRun ? "dry run" : "uninstall")...\n"
guard let scriptPath = Bundle.main.path(forResource: "uninstall-app", ofType: "sh") else {
output += "Script not found.\n"
isRunning = false
return
}
let command = dryRun ? "\(scriptPath) --dry-run" : "\(scriptPath)"
let appleScript = """
do shell script "\(command)" with administrator privileges
"""
DispatchQueue.global(qos: .userInitiated).async {
if let scriptObject = NSAppleScript(source: appleScript) {
var error: NSDictionary?
let result = scriptObject.executeAndReturnError(&error)
DispatchQueue.main.async {
if let error = error {
output += "Error: \(error)\n"
} else {
output += result.stringValue ?? "Completed.\n"
}
isRunning = false
}
}
}
}
}