Skip to content

Commit 3220514

Browse files
committed
Merge branch 'feature/altkit' into master
2 parents 7fd0f08 + b527a17 commit 3220514

File tree

5 files changed

+133
-5
lines changed

5 files changed

+133
-5
lines changed

Platform/Shared/ContentView.swift

+4
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,11 @@ struct ContentView: View {
115115
#if !WITH_QEMU_TCI
116116
if !Main.jitAvailable {
117117
data.busyWork {
118+
#if canImport(AltKit)
119+
try data.startAltJIT()
120+
#else
118121
throw NSLocalizedString("Your version of iOS does not support running VMs while unmodified. You must either run UTM while jailbroken or with a remote debugger attached.", comment: "ContentView")
122+
#endif
119123
}
120124
}
121125
#endif

Platform/UTMData.swift

+53-4
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ import AppKit
2020
#else
2121
import UIKit
2222
#endif
23+
#if canImport(AltKit)
24+
import AltKit
25+
#endif
2326

2427
@available(iOS 14, macOS 11, *)
2528
struct AlertMessage: Identifiable {
@@ -69,8 +72,11 @@ class UTMData: ObservableObject {
6972
fileManager.urls(for: .documentDirectory, in: .userDomainMask)[0]
7073
}
7174

75+
private var busyQueue: DispatchQueue
76+
7277
init() {
7378
let defaults = UserDefaults.standard
79+
self.busyQueue = DispatchQueue(label: "UTM Busy Queue", qos: .userInitiated)
7480
self.showSettingsModal = false
7581
self.showNewVMSheet = false
7682
self.busy = false
@@ -525,10 +531,10 @@ class UTMData: ObservableObject {
525531
}
526532

527533
func busyWork(_ work: @escaping () throws -> Void) {
528-
DispatchQueue.main.async {
529-
self.busy = true
530-
}
531-
DispatchQueue.global(qos: .userInitiated).async {
534+
busyQueue.async {
535+
DispatchQueue.main.async {
536+
self.busy = true
537+
}
532538
defer {
533539
DispatchQueue.main.async {
534540
self.busy = false
@@ -602,4 +608,47 @@ class UTMData: ObservableObject {
602608
tryClickAtPoint(point: point, button: button)
603609
#endif
604610
}
611+
612+
// MARK: - AltKit
613+
614+
#if canImport(AltKit)
615+
func startAltJIT() throws {
616+
let event = DispatchSemaphore(value: 0)
617+
var connectError: Error?
618+
DispatchQueue.main.async {
619+
ServerManager.shared.autoconnect { result in
620+
switch result
621+
{
622+
case .failure(let error):
623+
logger.error("Could not auto-connect to server. \(error.localizedDescription)")
624+
connectError = error
625+
event.signal()
626+
case .success(let connection):
627+
connection.enableUnsignedCodeExecution { result in
628+
switch result
629+
{
630+
case .failure(let error):
631+
logger.error("Could not enable JIT compilation. \(error.localizedDescription)")
632+
connectError = error
633+
case .success:
634+
logger.debug("Successfully enabled JIT compilation!")
635+
}
636+
637+
connection.disconnect()
638+
event.signal()
639+
}
640+
}
641+
}
642+
ServerManager.shared.startDiscovering()
643+
}
644+
defer {
645+
ServerManager.shared.stopDiscovering()
646+
}
647+
if event.wait(timeout: .now() + 10) == .timedOut {
648+
throw NSLocalizedString("Cannot find AltServer for JIT enable. You cannot run VMs until JIT is enabled.", comment: "UTMData")
649+
} else if let error = connectError {
650+
throw NSLocalizedString("AltJIT error: \(error.localizedDescription)", comment: "UTMData")
651+
}
652+
}
653+
#endif
605654
}

Platform/iOS/Info.plist

+8
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
33
<plist version="1.0">
44
<dict>
5+
<key>ALTDeviceID</key>
6+
<string>None</string>
57
<key>CFBundleDevelopmentRegion</key>
68
<string>$(DEVELOPMENT_LANGUAGE)</string>
79
<key>CFBundleDocumentTypes</key>
@@ -57,6 +59,12 @@
5759
<key>NSAllowsArbitraryLoads</key>
5860
<true/>
5961
</dict>
62+
<key>NSBonjourServices</key>
63+
<array>
64+
<string>_altserver._tcp</string>
65+
</array>
66+
<key>NSLocalNetworkUsageDescription</key>
67+
<string>UTM uses the local network to find and communicate with AltServer.</string>
6068
<key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
6169
<string>VM background access requires location services. Location data will never leave the device.</string>
6270
<key>NSLocationAlwaysUsageDescription</key>

UTM.xcodeproj/project.pbxproj

+25-1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@
4646
8401FD71269BEB2B00265F0D /* main.c in Sources */ = {isa = PBXBuildFile; fileRef = CE6B240A25F1F3CE0020D43E /* main.c */; };
4747
8401FD72269BEB3000265F0D /* Bootstrap.c in Sources */ = {isa = PBXBuildFile; fileRef = CE0DF17125A80B6300A51894 /* Bootstrap.c */; };
4848
8401FD7A269BECE200265F0D /* QEMULauncher.app in Embed Launcher */ = {isa = PBXBuildFile; fileRef = 8401FD62269BE9C500265F0D /* QEMULauncher.app */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; };
49+
B329049C270FE136002707AC /* AltKit in Frameworks */ = {isa = PBXBuildFile; productRef = B329049B270FE136002707AC /* AltKit */; };
50+
B3DDF57226E9BBA300CE47F0 /* AltKit in Frameworks */ = {isa = PBXBuildFile; productRef = B3DDF57126E9BBA300CE47F0 /* AltKit */; };
4951
CE020BA324AEDC7C00B44AB6 /* UTMData.swift in Sources */ = {isa = PBXBuildFile; fileRef = CE020BA224AEDC7C00B44AB6 /* UTMData.swift */; };
5052
CE020BA424AEDC7C00B44AB6 /* UTMData.swift in Sources */ = {isa = PBXBuildFile; fileRef = CE020BA224AEDC7C00B44AB6 /* UTMData.swift */; };
5153
CE020BA724AEDEF000B44AB6 /* Logging in Frameworks */ = {isa = PBXBuildFile; productRef = CE020BA624AEDEF000B44AB6 /* Logging */; };
@@ -2116,6 +2118,7 @@
21162118
CE2D933724AD46670059923A /* libgstplayback.a in Frameworks */,
21172119
CE2D933824AD46670059923A /* libgstadder.a in Frameworks */,
21182120
CE2D933A24AD46670059923A /* libgstaudiorate.a in Frameworks */,
2121+
B3DDF57226E9BBA300CE47F0 /* AltKit in Frameworks */,
21192122
CE2D933B24AD46670059923A /* libgstvideofilter.a in Frameworks */,
21202123
CE2D933C24AD46670059923A /* libgstapp.a in Frameworks */,
21212124
CE2D933D24AD46670059923A /* libgstgio.a in Frameworks */,
@@ -2130,6 +2133,7 @@
21302133
CE2D934524AD46670059923A /* gthread-2.0.0.framework in Frameworks */,
21312134
CE2D934624AD46670059923A /* gstrtp-1.0.0.framework in Frameworks */,
21322135
CE2D934724AD46670059923A /* gstriff-1.0.0.framework in Frameworks */,
2136+
B329049C270FE136002707AC /* AltKit in Frameworks */,
21332137
CEA9058F25FC6A1400801E7C /* usbredirhost.1.framework in Frameworks */,
21342138
CE2D934924AD46670059923A /* gstreamer-1.0.0.framework in Frameworks */,
21352139
CE2D934B24AD46670059923A /* json-glib-1.0.0.framework in Frameworks */,
@@ -3193,6 +3197,7 @@
31933197
CE020BA624AEDEF000B44AB6 /* Logging */,
31943198
CE93759824BB821F0074066F /* IQKeyboardManagerSwift */,
31953199
83993291272F68550059355F /* ZIPFoundation */,
3200+
B329049B270FE136002707AC /* AltKit */,
31963201
);
31973202
productName = UTM;
31983203
productReference = CE2D93BE24AD46670059923A /* UTM.app */;
@@ -3328,6 +3333,7 @@
33283333
CE020BA524AEDEF000B44AB6 /* XCRemoteSwiftPackageReference "swift-log" */,
33293334
CE93759724BB821F0074066F /* XCRemoteSwiftPackageReference "IQKeyboardManager" */,
33303335
8399328E272F4A400059355F /* XCRemoteSwiftPackageReference "ZIPFoundation" */,
3336+
B329049A270FE136002707AC /* XCRemoteSwiftPackageReference "AltKit" */,
33313337
);
33323338
productRefGroup = CE550BCA225947990063E575 /* Products */;
33333339
projectDirPath = "";
@@ -4914,6 +4920,14 @@
49144920
minimumVersion = 0.9.9;
49154921
};
49164922
};
4923+
B329049A270FE136002707AC /* XCRemoteSwiftPackageReference "AltKit" */ = {
4924+
isa = XCRemoteSwiftPackageReference;
4925+
repositoryURL = "https://github.com/utmapp/AltKit.git";
4926+
requirement = {
4927+
branch = main;
4928+
kind = branch;
4929+
};
4930+
};
49174931
CE020BA524AEDEF000B44AB6 /* XCRemoteSwiftPackageReference "swift-log" */ = {
49184932
isa = XCRemoteSwiftPackageReference;
49194933
repositoryURL = "https://github.com/apple/swift-log";
@@ -4943,7 +4957,7 @@
49434957
repositoryURL = "https://github.com/hackiftekhar/IQKeyboardManager.git";
49444958
requirement = {
49454959
kind = upToNextMajorVersion;
4946-
minimumVersion = 6.5.5;
4960+
minimumVersion = 6.5.6;
49474961
};
49484962
};
49494963
/* End XCRemoteSwiftPackageReference section */
@@ -4964,6 +4978,16 @@
49644978
package = 8399328E272F4A400059355F /* XCRemoteSwiftPackageReference "ZIPFoundation" */;
49654979
productName = ZIPFoundation;
49664980
};
4981+
B329049B270FE136002707AC /* AltKit */ = {
4982+
isa = XCSwiftPackageProductDependency;
4983+
package = B329049A270FE136002707AC /* XCRemoteSwiftPackageReference "AltKit" */;
4984+
productName = AltKit;
4985+
};
4986+
B3DDF57126E9BBA300CE47F0 /* AltKit */ = {
4987+
isa = XCSwiftPackageProductDependency;
4988+
package = B3DDF57026E9BBA300CE47F0 /* XCRemoteSwiftPackageReference "AltKit" */;
4989+
productName = AltKit;
4990+
};
49674991
CE020BA624AEDEF000B44AB6 /* Logging */ = {
49684992
isa = XCSwiftPackageProductDependency;
49694993
package = CE020BA524AEDEF000B44AB6 /* XCRemoteSwiftPackageReference "swift-log" */;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
{
2+
"object": {
3+
"pins": [
4+
{
5+
"package": "AltKit",
6+
"repositoryURL": "https://github.com/utmapp/AltKit.git",
7+
"state": {
8+
"branch": "main",
9+
"revision": "71ec1d505cbb7cb53dc16c7c98cb94c93953f3ff",
10+
"version": null
11+
}
12+
},
13+
{
14+
"package": "IQKeyboardManagerSwift",
15+
"repositoryURL": "https://github.com/hackiftekhar/IQKeyboardManager.git",
16+
"state": {
17+
"branch": null,
18+
"revision": "4dc6bc7d1c9747bd0c261c8c055903f9fdef91f7",
19+
"version": "6.5.6"
20+
}
21+
},
22+
{
23+
"package": "swift-log",
24+
"repositoryURL": "https://github.com/apple/swift-log",
25+
"state": {
26+
"branch": null,
27+
"revision": "5d66f7ba25daf4f94100e7022febf3c75e37a6c7",
28+
"version": "1.4.2"
29+
}
30+
},
31+
{
32+
"package": "ZIPFoundation",
33+
"repositoryURL": "https://github.com/weichsel/ZIPFoundation.git",
34+
"state": {
35+
"branch": null,
36+
"revision": "cf10bbff6ac3b873e97b36b9784c79866a051a8e",
37+
"version": "0.9.12"
38+
}
39+
}
40+
]
41+
},
42+
"version": 1
43+
}

0 commit comments

Comments
 (0)