Skip to content

Commit

Permalink
support for JITStreamer-EB, fix #34
Browse files Browse the repository at this point in the history
  • Loading branch information
hugeBlack committed Jan 31, 2025
1 parent 2639af1 commit 486044d
Show file tree
Hide file tree
Showing 14 changed files with 303 additions and 71 deletions.
1 change: 0 additions & 1 deletion LCSharedUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
+ (NSString *)appGroupID;
+ (NSURL*) appGroupPath;
+ (NSString *)certificatePassword;
+ (BOOL)askForJIT;
+ (BOOL)launchToGuestApp;
+ (BOOL)launchToGuestAppWithURL:(NSURL *)url;
+ (void)setWebPageUrlForNextLaunch:(NSString*)urlString;
Expand Down
42 changes: 7 additions & 35 deletions LCSharedUtils.m
Original file line number Diff line number Diff line change
Expand Up @@ -93,41 +93,6 @@ + (BOOL)launchToGuestApp {
return NO;
}

+ (BOOL)askForJIT {
NSString *urlScheme;
NSString *tsPath = [NSString stringWithFormat:@"%@/../_TrollStore", NSBundle.mainBundle.bundlePath];
if (!access(tsPath.UTF8String, F_OK)) {
urlScheme = @"apple-magnifier://enable-jit?bundle-id=%@";
NSURL *launchURL = [NSURL URLWithString:[NSString stringWithFormat:urlScheme, NSBundle.mainBundle.bundleIdentifier]];
UIApplication *application = [NSClassFromString(@"UIApplication") sharedApplication];
if ([application canOpenURL:launchURL]) {
[application openURL:launchURL options:@{} completionHandler:nil];
[LCSharedUtils launchToGuestApp];
return YES;
}
} else {
NSUserDefaults* groupUserDefaults = [[NSUserDefaults alloc] initWithSuiteName:[self appGroupID]];

NSString* sideJITServerAddress = [groupUserDefaults objectForKey:@"LCSideJITServerAddress"];
NSString* deviceUDID = [groupUserDefaults objectForKey:@"LCDeviceUDID"];
if (!sideJITServerAddress || !deviceUDID) {
return NO;
}
NSString* launchJITUrlStr = [NSString stringWithFormat: @"%@/%@/%@", sideJITServerAddress, deviceUDID, NSBundle.mainBundle.bundleIdentifier];
NSURLSession* session = [NSURLSession sharedSession];
NSURL* launchJITUrl = [NSURL URLWithString:launchJITUrlStr];
NSURLRequest* req = [[NSURLRequest alloc] initWithURL:launchJITUrl];
NSURLSessionDataTask *task = [session dataTaskWithRequest:req completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
if(error) {
NSLog(@"[LC] failed to contact SideJITServer: %@", error);
}
}];
[task resume];

}
return NO;
}

+ (BOOL)launchToGuestAppWithURL:(NSURL *)url {
NSURLComponents* components = [NSURLComponents componentsWithURL:url resolvingAgainstBaseURL:NO];
if(![components.host isEqualToString:@"livecontainer-launch"]) return NO;
Expand Down Expand Up @@ -294,6 +259,13 @@ + (void)moveSharedAppFolderBack {
}
// move all apps in shared folder back
NSArray<NSString *> * sharedDataFoldersToMove = [fm contentsOfDirectoryAtPath:sharedAppDataFolderPath error:&error];

// something went wrong with app group
if(!appGroupFolder && sharedDataFoldersToMove.count > 0) {
[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"];
return;
}

for(int i = 0; i < [sharedDataFoldersToMove count]; ++i) {
NSString* destPath = [appGroupFolder.path stringByAppendingPathComponent:[NSString stringWithFormat:@"Data/Application/%@", sharedDataFoldersToMove[i]]];
if([fm fileExistsAtPath:destPath]) {
Expand Down
61 changes: 44 additions & 17 deletions LiveContainerSwiftUI/LCAppBanner.swift
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ struct LCAppBanner : View {
}

}
.buttonStyle(BasicButtonStyle())
.padding()
.frame(idealWidth: 70)
.frame(height: 32)
Expand Down Expand Up @@ -203,14 +204,8 @@ struct LCAppBanner : View {
} label: {
Label("lc.appBanner.uninstall".loc, systemImage: "trash")
}

}

}




}

.alert("lc.appBanner.confirmUninstallTitle".loc, isPresented: $appRemovalAlert.show) {
Expand All @@ -237,17 +232,11 @@ struct LCAppBanner : View {
} message: {
Text("lc.appBanner.deleteDataMsg \(appInfo.displayName()!)")
}
.alert("lc.appBanner.waitForJitTitle".loc, isPresented: $jitAlert.show) {
Button {
jitAlert.close(result: true)
} label: {
Text("lc.appBanner.jitLaunchNow".loc)
}
Button("lc.common.cancel", role: .cancel) {
jitAlert.close(result: false)
}
} message: {
Text("lc.appBanner.waitForJitMsg".loc)
.sheet(isPresented: $jitAlert.show, onDismiss: {
NSLog("[LC] onDismiss")
jitAlert.close(result: false)
}) {
JITEnablingModal
}

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

}

var JITEnablingModal : some View {
NavigationView {
VStack{
Text("lc.appBanner.waitForJitMsg".loc)
ScrollViewReader { proxy in
ScrollView {
Text(model.jitLog)
.font(.system(size: 12).monospaced())
.fixedSize(horizontal: false, vertical: false)
.textSelection(.enabled)
Spacer()
.id(0)
}
.onAppear {
proxy.scrollTo(0)
}
}
.padding()
}
.navigationTitle("lc.appBanner.waitForJitTitle".loc)
.navigationBarTitleDisplayMode(.inline)
.toolbar {
ToolbarItem(placement: .topBarLeading) {
Button("lc.common.cancel".loc, role: .cancel) {
jitAlert.close(result: false)
}
}
ToolbarItem(placement: .topBarTrailing) {
Button {
jitAlert.close(result: true)
} label: {
Text("lc.appBanner.jitLaunchNow".loc)
}
}
}
}
}

func handleOnAppear() {
model.jitAlert = jitAlert
}
Expand Down
10 changes: 10 additions & 0 deletions LiveContainerSwiftUI/LCAppListView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -578,6 +578,16 @@ struct LCAppListView : View, LCAppBannerDelegate, LCAppModelDelegate {
return
}

if !installUrl.startAccessingSecurityScopedResource() {
errorInfo = "lc.appList.ipaAccessError".loc
errorShow = true
return
}

defer {
installUrl.stopAccessingSecurityScopedResource()
}

do {
try await installIpaFile(installUrl)
} catch {
Expand Down
9 changes: 8 additions & 1 deletion LiveContainerSwiftUI/LCAppModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class LCAppModel: ObservableObject, Hashable {
@Published var supportedLanaguages : [String]?

var jitAlert : YesNoHelper? = nil
@Published var jitLog : String = ""

var delegate : LCAppModelDelegate?

Expand Down Expand Up @@ -208,10 +209,16 @@ class LCAppModel: ObservableObject, Hashable {
}

func jitLaunch() async {
LCUtils.askForJIT()
jitLog = ""
let enableJITTask = Task {
let _ = await LCUtils.askForJIT { newMsg in
self.jitLog += "\(newMsg)\n"
}

}
guard let result = await jitAlert?.open(), result else {
UserDefaults.standard.removeObject(forKey: "selected")
enableJITTask.cancel()
return
}
LCUtils.launchToGuestApp()
Expand Down
32 changes: 26 additions & 6 deletions LiveContainerSwiftUI/LCSettingsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ enum PatchChoice {
case archiveOnly
}

enum JITEnablerType : Int {
case SideJITServer = 0
case JITStreamerEB = 1
}

struct LCSettingsView: View {
@State var errorShow = false
@State var errorInfo = ""
Expand Down Expand Up @@ -46,6 +51,7 @@ struct LCSettingsView: View {

@State var sideJITServerAddress : String
@State var deviceUDID: String
@State var JITEnabler: JITEnablerType = .SideJITServer

@State var isSideStore : Bool = true

Expand Down Expand Up @@ -93,6 +99,8 @@ struct LCSettingsView: View {
} else {
_deviceUDID = State(initialValue: "")
}
_JITEnabler = State(initialValue: JITEnablerType(rawValue: LCUtils.appGroupUserDefault.integer(forKey: "LCJITEnablerType"))!)

_strictHiding = State(initialValue: LCUtils.appGroupUserDefault.bool(forKey: "LCStrictHiding"))

}
Expand Down Expand Up @@ -188,15 +196,24 @@ struct LCSettingsView: View {
HStack {
Text("lc.settings.JitAddress".loc)
Spacer()
TextField("http://x.x.x.x:8080", text: $sideJITServerAddress)
TextField(JITEnabler == .SideJITServer ? "http://x.x.x.x:8080" : "http://[fd00::]:9172", text: $sideJITServerAddress)
.multilineTextAlignment(.trailing)
}
HStack {
Text("lc.settings.JitUDID".loc)
Spacer()
TextField("", text: $deviceUDID)
.multilineTextAlignment(.trailing)
if JITEnabler == .SideJITServer {
HStack {
Text("lc.settings.JitUDID".loc)
Spacer()
TextField("", text: $deviceUDID)
.multilineTextAlignment(.trailing)
}
}
Picker(selection: $JITEnabler) {
Text("SideJITServer/JITStreamer 2.0").tag(JITEnablerType.SideJITServer)
Text("JitStreamer-EB").tag(JITEnablerType.JITStreamerEB)
} label: {
Text("lc.settings.jitEnabler".loc)
}

} header: {
Text("JIT")
} footer: {
Expand Down Expand Up @@ -513,6 +530,9 @@ struct LCSettingsView: View {
.onChange(of: sideJITServerAddress) { newValue in
saveAppGroupItem(key: "LCSideJITServerAddress", val: newValue)
}
.onChange(of: JITEnabler) { newValue in
saveAppGroupItem(key: "LCJITEnablerType", val: newValue.rawValue)
}
.onChange(of: defaultSigner) { newValue in
saveAppGroupItem(key: "LCDefaultSigner", val: newValue.rawValue)
}
Expand Down
1 change: 0 additions & 1 deletion LiveContainerSwiftUI/LCUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ NSString* getLCEntitlementXML(void);
+ (NSData *)certificateData;
+ (NSString *)certificatePassword;

+ (BOOL)askForJIT;
+ (BOOL)launchToGuestApp;
+ (BOOL)launchToGuestAppWithURL:(NSURL *)url;

Expand Down
4 changes: 0 additions & 4 deletions LiveContainerSwiftUI/LCUtils.m
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,6 @@ + (BOOL)launchToGuestApp {
return [LCSharedUtilsClass launchToGuestApp];
}

+ (BOOL)askForJIT {
return [LCSharedUtilsClass askForJIT];
}

+ (BOOL)launchToGuestAppWithURL:(NSURL *)url {
return [LCSharedUtilsClass launchToGuestAppWithURL:url];
}
Expand Down
17 changes: 17 additions & 0 deletions LiveContainerSwiftUI/Localizable.xcstrings
Original file line number Diff line number Diff line change
Expand Up @@ -2956,6 +2956,23 @@
}
}
},
"lc.settings.jitEnabler" : {
"extractionState" : "manual",
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "JIT Enabler"
}
},
"zh_CN" : {
"stringUnit" : {
"state" : "translated",
"value" : "JIT启用工具"
}
}
}
},
"lc.settings.jitLess" : {
"extractionState" : "manual",
"localizations" : {
Expand Down
Loading

0 comments on commit 486044d

Please sign in to comment.