-
Notifications
You must be signed in to change notification settings - Fork 0
/
Apps.swift
59 lines (50 loc) · 1.63 KB
/
Apps.swift
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
//
// apps.swift
// deldos
//
// Created by Mikhail on 10.08.2024.
//
import SwiftUI
struct Apps: View {
@State private var commandInput: String = ""
var body: some View {
VStack {
Text("Type apps name")
TextField("Enter command", text: $commandInput)
.textFieldStyle(RoundedBorderTextFieldStyle())
.padding()
Button(action: {
self.sendCommand()
}) {
Text("Send Command")
.padding()
.background(Color.blue)
.foregroundColor(.white)
.cornerRadius(8)
}
.padding()
}
}
func sendCommand() {
guard let url = URL(string: "\(Constants.serverIP)/execute_command") else { return }
var request = URLRequest(url: url)
request.httpMethod = "POST"
request.addValue("application/json", forHTTPHeaderField: "Content-Type")
// Форматируем команду
let command = "open -a \(commandInput)"
let jsonData = try? JSONSerialization.data(withJSONObject: ["command": command])
let task = URLSession.shared.uploadTask(with: request, from: jsonData) { data, response, error in
guard let data = data, error == nil else {
print("Ошибка: \(error?.localizedDescription ?? "Unknown error")")
return
}
print(String(data: data, encoding: .utf8) ?? "")
}
task.resume()
}
}
struct Apps_Previews: PreviewProvider {
static var previews: some View {
Apps()
}
}