Skip to content

Commit 486044d

Browse files
committed
support for JITStreamer-EB, fix #34
1 parent 2639af1 commit 486044d

14 files changed

Lines changed: 303 additions & 71 deletions

LCSharedUtils.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
+ (NSString *)appGroupID;
66
+ (NSURL*) appGroupPath;
77
+ (NSString *)certificatePassword;
8-
+ (BOOL)askForJIT;
98
+ (BOOL)launchToGuestApp;
109
+ (BOOL)launchToGuestAppWithURL:(NSURL *)url;
1110
+ (void)setWebPageUrlForNextLaunch:(NSString*)urlString;

LCSharedUtils.m

Lines changed: 7 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -93,41 +93,6 @@ + (BOOL)launchToGuestApp {
9393
return NO;
9494
}
9595

96-
+ (BOOL)askForJIT {
97-
NSString *urlScheme;
98-
NSString *tsPath = [NSString stringWithFormat:@"%@/../_TrollStore", NSBundle.mainBundle.bundlePath];
99-
if (!access(tsPath.UTF8String, F_OK)) {
100-
urlScheme = @"apple-magnifier://enable-jit?bundle-id=%@";
101-
NSURL *launchURL = [NSURL URLWithString:[NSString stringWithFormat:urlScheme, NSBundle.mainBundle.bundleIdentifier]];
102-
UIApplication *application = [NSClassFromString(@"UIApplication") sharedApplication];
103-
if ([application canOpenURL:launchURL]) {
104-
[application openURL:launchURL options:@{} completionHandler:nil];
105-
[LCSharedUtils launchToGuestApp];
106-
return YES;
107-
}
108-
} else {
109-
NSUserDefaults* groupUserDefaults = [[NSUserDefaults alloc] initWithSuiteName:[self appGroupID]];
110-
111-
NSString* sideJITServerAddress = [groupUserDefaults objectForKey:@"LCSideJITServerAddress"];
112-
NSString* deviceUDID = [groupUserDefaults objectForKey:@"LCDeviceUDID"];
113-
if (!sideJITServerAddress || !deviceUDID) {
114-
return NO;
115-
}
116-
NSString* launchJITUrlStr = [NSString stringWithFormat: @"%@/%@/%@", sideJITServerAddress, deviceUDID, NSBundle.mainBundle.bundleIdentifier];
117-
NSURLSession* session = [NSURLSession sharedSession];
118-
NSURL* launchJITUrl = [NSURL URLWithString:launchJITUrlStr];
119-
NSURLRequest* req = [[NSURLRequest alloc] initWithURL:launchJITUrl];
120-
NSURLSessionDataTask *task = [session dataTaskWithRequest:req completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
121-
if(error) {
122-
NSLog(@"[LC] failed to contact SideJITServer: %@", error);
123-
}
124-
}];
125-
[task resume];
126-
127-
}
128-
return NO;
129-
}
130-
13196
+ (BOOL)launchToGuestAppWithURL:(NSURL *)url {
13297
NSURLComponents* components = [NSURLComponents componentsWithURL:url resolvingAgainstBaseURL:NO];
13398
if(![components.host isEqualToString:@"livecontainer-launch"]) return NO;
@@ -294,6 +259,13 @@ + (void)moveSharedAppFolderBack {
294259
}
295260
// move all apps in shared folder back
296261
NSArray<NSString *> * sharedDataFoldersToMove = [fm contentsOfDirectoryAtPath:sharedAppDataFolderPath error:&error];
262+
263+
// something went wrong with app group
264+
if(!appGroupFolder && sharedDataFoldersToMove.count > 0) {
265+
[lcUserDefaults setObject:@"LiveContainer was unable to move the data of shared app back because LiveContainer cannot access app group. Please check JITLess diagnose page in LiveContainer settings for more information." forKey:@"error"];
266+
return;
267+
}
268+
297269
for(int i = 0; i < [sharedDataFoldersToMove count]; ++i) {
298270
NSString* destPath = [appGroupFolder.path stringByAppendingPathComponent:[NSString stringWithFormat:@"Data/Application/%@", sharedDataFoldersToMove[i]]];
299271
if([fm fileExistsAtPath:destPath]) {

LiveContainerSwiftUI/LCAppBanner.swift

Lines changed: 44 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ struct LCAppBanner : View {
104104
}
105105

106106
}
107+
.buttonStyle(BasicButtonStyle())
107108
.padding()
108109
.frame(idealWidth: 70)
109110
.frame(height: 32)
@@ -203,14 +204,8 @@ struct LCAppBanner : View {
203204
} label: {
204205
Label("lc.appBanner.uninstall".loc, systemImage: "trash")
205206
}
206-
207207
}
208-
209208
}
210-
211-
212-
213-
214209
}
215210

216211
.alert("lc.appBanner.confirmUninstallTitle".loc, isPresented: $appRemovalAlert.show) {
@@ -237,17 +232,11 @@ struct LCAppBanner : View {
237232
} message: {
238233
Text("lc.appBanner.deleteDataMsg \(appInfo.displayName()!)")
239234
}
240-
.alert("lc.appBanner.waitForJitTitle".loc, isPresented: $jitAlert.show) {
241-
Button {
242-
jitAlert.close(result: true)
243-
} label: {
244-
Text("lc.appBanner.jitLaunchNow".loc)
245-
}
246-
Button("lc.common.cancel", role: .cancel) {
247-
jitAlert.close(result: false)
248-
}
249-
} message: {
250-
Text("lc.appBanner.waitForJitMsg".loc)
235+
.sheet(isPresented: $jitAlert.show, onDismiss: {
236+
NSLog("[LC] onDismiss")
237+
jitAlert.close(result: false)
238+
}) {
239+
JITEnablingModal
251240
}
252241

253242
.alert("lc.common.error".loc, isPresented: $errorShow){
@@ -262,6 +251,44 @@ struct LCAppBanner : View {
262251

263252
}
264253

254+
var JITEnablingModal : some View {
255+
NavigationView {
256+
VStack{
257+
Text("lc.appBanner.waitForJitMsg".loc)
258+
ScrollViewReader { proxy in
259+
ScrollView {
260+
Text(model.jitLog)
261+
.font(.system(size: 12).monospaced())
262+
.fixedSize(horizontal: false, vertical: false)
263+
.textSelection(.enabled)
264+
Spacer()
265+
.id(0)
266+
}
267+
.onAppear {
268+
proxy.scrollTo(0)
269+
}
270+
}
271+
.padding()
272+
}
273+
.navigationTitle("lc.appBanner.waitForJitTitle".loc)
274+
.navigationBarTitleDisplayMode(.inline)
275+
.toolbar {
276+
ToolbarItem(placement: .topBarLeading) {
277+
Button("lc.common.cancel".loc, role: .cancel) {
278+
jitAlert.close(result: false)
279+
}
280+
}
281+
ToolbarItem(placement: .topBarTrailing) {
282+
Button {
283+
jitAlert.close(result: true)
284+
} label: {
285+
Text("lc.appBanner.jitLaunchNow".loc)
286+
}
287+
}
288+
}
289+
}
290+
}
291+
265292
func handleOnAppear() {
266293
model.jitAlert = jitAlert
267294
}

LiveContainerSwiftUI/LCAppListView.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -578,6 +578,16 @@ struct LCAppListView : View, LCAppBannerDelegate, LCAppModelDelegate {
578578
return
579579
}
580580

581+
if !installUrl.startAccessingSecurityScopedResource() {
582+
errorInfo = "lc.appList.ipaAccessError".loc
583+
errorShow = true
584+
return
585+
}
586+
587+
defer {
588+
installUrl.stopAccessingSecurityScopedResource()
589+
}
590+
581591
do {
582592
try await installIpaFile(installUrl)
583593
} catch {

LiveContainerSwiftUI/LCAppModel.swift

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ class LCAppModel: ObservableObject, Hashable {
3333
@Published var supportedLanaguages : [String]?
3434

3535
var jitAlert : YesNoHelper? = nil
36+
@Published var jitLog : String = ""
3637

3738
var delegate : LCAppModelDelegate?
3839

@@ -208,10 +209,16 @@ class LCAppModel: ObservableObject, Hashable {
208209
}
209210

210211
func jitLaunch() async {
211-
LCUtils.askForJIT()
212+
jitLog = ""
213+
let enableJITTask = Task {
214+
let _ = await LCUtils.askForJIT { newMsg in
215+
self.jitLog += "\(newMsg)\n"
216+
}
212217

218+
}
213219
guard let result = await jitAlert?.open(), result else {
214220
UserDefaults.standard.removeObject(forKey: "selected")
221+
enableJITTask.cancel()
215222
return
216223
}
217224
LCUtils.launchToGuestApp()

LiveContainerSwiftUI/LCSettingsView.swift

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ enum PatchChoice {
1414
case archiveOnly
1515
}
1616

17+
enum JITEnablerType : Int {
18+
case SideJITServer = 0
19+
case JITStreamerEB = 1
20+
}
21+
1722
struct LCSettingsView: View {
1823
@State var errorShow = false
1924
@State var errorInfo = ""
@@ -46,6 +51,7 @@ struct LCSettingsView: View {
4651

4752
@State var sideJITServerAddress : String
4853
@State var deviceUDID: String
54+
@State var JITEnabler: JITEnablerType = .SideJITServer
4955

5056
@State var isSideStore : Bool = true
5157

@@ -93,6 +99,8 @@ struct LCSettingsView: View {
9399
} else {
94100
_deviceUDID = State(initialValue: "")
95101
}
102+
_JITEnabler = State(initialValue: JITEnablerType(rawValue: LCUtils.appGroupUserDefault.integer(forKey: "LCJITEnablerType"))!)
103+
96104
_strictHiding = State(initialValue: LCUtils.appGroupUserDefault.bool(forKey: "LCStrictHiding"))
97105

98106
}
@@ -188,15 +196,24 @@ struct LCSettingsView: View {
188196
HStack {
189197
Text("lc.settings.JitAddress".loc)
190198
Spacer()
191-
TextField("http://x.x.x.x:8080", text: $sideJITServerAddress)
199+
TextField(JITEnabler == .SideJITServer ? "http://x.x.x.x:8080" : "http://[fd00::]:9172", text: $sideJITServerAddress)
192200
.multilineTextAlignment(.trailing)
193201
}
194-
HStack {
195-
Text("lc.settings.JitUDID".loc)
196-
Spacer()
197-
TextField("", text: $deviceUDID)
198-
.multilineTextAlignment(.trailing)
202+
if JITEnabler == .SideJITServer {
203+
HStack {
204+
Text("lc.settings.JitUDID".loc)
205+
Spacer()
206+
TextField("", text: $deviceUDID)
207+
.multilineTextAlignment(.trailing)
208+
}
209+
}
210+
Picker(selection: $JITEnabler) {
211+
Text("SideJITServer/JITStreamer 2.0").tag(JITEnablerType.SideJITServer)
212+
Text("JitStreamer-EB").tag(JITEnablerType.JITStreamerEB)
213+
} label: {
214+
Text("lc.settings.jitEnabler".loc)
199215
}
216+
200217
} header: {
201218
Text("JIT")
202219
} footer: {
@@ -513,6 +530,9 @@ struct LCSettingsView: View {
513530
.onChange(of: sideJITServerAddress) { newValue in
514531
saveAppGroupItem(key: "LCSideJITServerAddress", val: newValue)
515532
}
533+
.onChange(of: JITEnabler) { newValue in
534+
saveAppGroupItem(key: "LCJITEnablerType", val: newValue.rawValue)
535+
}
516536
.onChange(of: defaultSigner) { newValue in
517537
saveAppGroupItem(key: "LCDefaultSigner", val: newValue.rawValue)
518538
}

LiveContainerSwiftUI/LCUtils.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ NSString* getLCEntitlementXML(void);
3434
+ (NSData *)certificateData;
3535
+ (NSString *)certificatePassword;
3636

37-
+ (BOOL)askForJIT;
3837
+ (BOOL)launchToGuestApp;
3938
+ (BOOL)launchToGuestAppWithURL:(NSURL *)url;
4039

LiveContainerSwiftUI/LCUtils.m

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,6 @@ + (BOOL)launchToGuestApp {
6262
return [LCSharedUtilsClass launchToGuestApp];
6363
}
6464

65-
+ (BOOL)askForJIT {
66-
return [LCSharedUtilsClass askForJIT];
67-
}
68-
6965
+ (BOOL)launchToGuestAppWithURL:(NSURL *)url {
7066
return [LCSharedUtilsClass launchToGuestAppWithURL:url];
7167
}

LiveContainerSwiftUI/Localizable.xcstrings

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2956,6 +2956,23 @@
29562956
}
29572957
}
29582958
},
2959+
"lc.settings.jitEnabler" : {
2960+
"extractionState" : "manual",
2961+
"localizations" : {
2962+
"en" : {
2963+
"stringUnit" : {
2964+
"state" : "translated",
2965+
"value" : "JIT Enabler"
2966+
}
2967+
},
2968+
"zh_CN" : {
2969+
"stringUnit" : {
2970+
"state" : "translated",
2971+
"value" : "JIT启用工具"
2972+
}
2973+
}
2974+
}
2975+
},
29592976
"lc.settings.jitLess" : {
29602977
"extractionState" : "manual",
29612978
"localizations" : {

0 commit comments

Comments
 (0)