Skip to content

Commit

Permalink
users can mark app as JIT needed
Browse files Browse the repository at this point in the history
  • Loading branch information
hugeBlack committed Sep 10, 2024
1 parent cb2dd17 commit 1ddcbbe
Show file tree
Hide file tree
Showing 19 changed files with 177 additions and 34 deletions.
1 change: 1 addition & 0 deletions LCSharedUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
@interface LCSharedUtils : NSObject
+ (NSString *)appGroupID;
+ (NSString *)certificatePassword;
+ (BOOL)askForJIT;
+ (BOOL)launchToGuestApp;
+ (BOOL)launchToGuestAppWithURL:(NSURL *)url;
+ (void)setWebPageUrlForNextLaunch:(NSString*)urlString;
Expand Down
18 changes: 17 additions & 1 deletion LCSharedUtils.m
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,22 @@ + (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=%@";
} else {
urlScheme = @"sidestore://sidejit-enable?bid=%@";
}
NSURL *launchURL = [NSURL URLWithString:[NSString stringWithFormat:urlScheme, NSBundle.mainBundle.bundleIdentifier]];
if ([UIApplication.sharedApplication canOpenURL:launchURL]) {
[UIApplication.sharedApplication openURL:launchURL options:@{} completionHandler:nil];
return YES;
}
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 @@ -176,7 +192,7 @@ + (void)movePreferencesFromPath:(NSString*) plistLocationFrom toPath:(NSString*)

[fm moveItemAtPath:fromPlistPath toPath:toPlistPath error:&error1];
if(error1) {
NSLog(@"[NMSL] error1 = %@", error1.description);
NSLog(@"[LC] error1 = %@", error1.description);
}

}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"colors" : [
{
"color" : {
"color-space" : "srgb",
"components" : {
"alpha" : "1.000",
"blue" : "190",
"green" : "82",
"red" : "130"
}
},
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
97 changes: 93 additions & 4 deletions LiveContainerSwiftUI/LCAppBanner.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ struct LCAppBanner : View {
var delegate: LCAppBannerDelegate

@State var uiIsShared : Bool
@State var uiIsJITNeeded : Bool

@Binding var appDataFolders: [String]
@Binding var tweakFolders: [String]
Expand Down Expand Up @@ -47,6 +48,10 @@ struct LCAppBanner : View {
@State private var confirmMoveToPrivateDoc = false
@State private var confirmMoveToPrivateDocContinuation : CheckedContinuation<Void, Never>? = nil

@State private var enablingJITShow = false
@State private var confirmEnablingJIT = false
@State private var confirmEnablingJITContinuation : CheckedContinuation<Void, Never>? = nil

@State private var errorShow = false
@State private var errorInfo = ""

Expand All @@ -55,6 +60,7 @@ struct LCAppBanner : View {
@State private var isAppRunning = false

@State private var observer : NSKeyValueObservation?
@EnvironmentObject private var bundleIDToLaunchModel : BundleIDToLaunchModel

init(appInfo: LCAppInfo, delegate: LCAppBannerDelegate, appDataFolders: Binding<[String]>, tweakFolders: Binding<[String]>) {
_appInfo = State(initialValue: appInfo)
Expand All @@ -67,7 +73,7 @@ struct LCAppBanner : View {
_uiPickerTweakFolder = _uiTweakFolder

_uiIsShared = State(initialValue: appInfo.isShared)

_uiIsJITNeeded = State(initialValue: appInfo.isJITNeeded())
}

var body: some View {
Expand All @@ -89,6 +95,13 @@ struct LCAppBanner : View {
Capsule().fill(Color("BadgeColor"))
)
}
if uiIsJITNeeded {
Text("JIT").font(.system(size: 8)).bold().padding(2)
.frame(width: 30, height:16)
.background(
Capsule().fill(Color("JITBadgeColor"))
)
}
}

Text("\(appInfo.version()) - \(appInfo.bundleIdentifier())").font(.system(size: 12)).foregroundColor(Color("FontColor"))
Expand Down Expand Up @@ -147,6 +160,23 @@ struct LCAppBanner : View {
} label: {
Label("Convert to Shared App", systemImage: "arrowshape.turn.up.left")
}
Button {
Task { await toggleJITNeeded()}
} label: {
if uiIsJITNeeded {
Label("Don't Need JIT", systemImage: "bolt.slash")
} else {
Label("Mark as JIT Needed", systemImage: "bolt")
}

}

Button {
copyLaunchUrl()
} label: {
Label("Copy Launch Url", systemImage: "link")
}

Menu(content: {
Button {
Task{ await createFolder() }
Expand Down Expand Up @@ -201,6 +231,13 @@ struct LCAppBanner : View {
setTweakFolder(folderName: newValue)
}
})
.onChange(of: bundleIDToLaunchModel.bundleIdToLaunch, perform: { newValue in
Task { await handleURLSchemeLaunch() }
})

.onAppear() {
Task { await handleURLSchemeLaunch() }
}

.alert("Confirm Uninstallation", isPresented: $confirmAppRemovalShow) {
Button(role: .destructive) {
Expand Down Expand Up @@ -272,16 +309,36 @@ struct LCAppBanner : View {
renameFolerContinuation?.resume()
}
)
.alert("Enabling JIT", isPresented: $enablingJITShow) {
Button {
self.confirmEnablingJIT = true
self.confirmEnablingJITContinuation?.resume()
} label: {
Text("Launch Now")
}
Button("Cancel", role: .cancel) {
self.confirmEnablingJIT = false
self.confirmEnablingJITContinuation?.resume()
}
} message: {
Text("Please use your favourite way to enable jit for current LiveContainer.")
}

.alert("Error", isPresented: $errorShow) {
Button("OK", action: {
})
} message: {
Text(errorInfo)
}


}

func handleURLSchemeLaunch() async {
if self.appInfo.relativeBundlePath == bundleIDToLaunchModel.bundleIdToLaunch {
await runApp()
}
}

func runApp() async {
if let runningLC = LCUtils.getAppRunningLCScheme(bundleId: self.appInfo.relativeBundlePath) {
let openURL = URL(string: "\(runningLC)://livecontainer-launch?bundle-name=\(self.appInfo.relativeBundlePath!)")!
Expand Down Expand Up @@ -324,7 +381,12 @@ struct LCAppBanner : View {
return
} else {
UserDefaults.standard.set(self.appInfo.relativeBundlePath, forKey: "selected")
LCUtils.launchToGuestApp()
if appInfo.isJITNeeded() {
await self.jitLaunch()
} else {
LCUtils.launchToGuestApp()
}

}
self.isAppRunning = false

Expand Down Expand Up @@ -524,7 +586,34 @@ struct LCAppBanner : View {
}

}


func toggleJITNeeded() async {
if appInfo.isJITNeeded() {
appInfo.setIsJITNeeded(false)
uiIsJITNeeded = false
} else {
appInfo.setIsJITNeeded(true)
uiIsJITNeeded = true
}
}

func jitLaunch() async {
LCUtils.askForJIT()

await withCheckedContinuation { c in
self.confirmEnablingJITContinuation = c
enablingJITShow = true
}
if confirmEnablingJIT {
LCUtils.launchToGuestApp()
} else {
UserDefaults.standard.removeObject(forKey: "selected")
}
}

func copyLaunchUrl() {
UIPasteboard.general.string = "livecontainer://livecontainer-launch?bundle-name=\(appInfo.relativeBundlePath!)"
}


}
2 changes: 1 addition & 1 deletion LiveContainerSwiftUI/LCAppListView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ struct LCAppListView : View, LCAppBannerDelegate {
@State var installOptionContinuation : CheckedContinuation<Void, Never>? = nil

@State var webViewOpened = false
@State var webViewURL : URL = URL(string: "https://www.google.com")!
@State var webViewURL : URL = URL(string: "about:blank")!
@State private var webViewUrlInputOpened = false
@State private var webViewUrlInputContent = ""
@State private var webViewUrlInputContinuation : CheckedContinuation<Void, Never>? = nil
Expand Down
1 change: 1 addition & 0 deletions LiveContainerSwiftUI/LCSwiftBridge.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@
@interface LCSwiftBridge : NSObject
+ (UIViewController * _Nonnull)getRootVC;
+ (void)openWebPageWithUrlStr:(NSURL* _Nonnull)url;
+ (void)launchAppWithBundleId:(NSString* _Nonnull)bundleId;
@end
4 changes: 4 additions & 0 deletions LiveContainerSwiftUI/LCSwiftBridge.m
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,8 @@ + (void)openWebPageWithUrlStr:(NSString* _Nonnull)urlStr {
[LCObjcBridge openWebPageWithUrlStr:urlStr];
}

+ (void)launchAppWithBundleId:(NSString* _Nonnull)bundleId {
[LCObjcBridge launchAppWithBundleId:bundleId];
}

@end
1 change: 1 addition & 0 deletions LiveContainerSwiftUI/LCTabView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ struct LCTabView: View {
}.onAppear() {
checkLastLaunchError()
}
.environmentObject(DataManager.shared.bundleIDToLaunchModel)
}

func checkLastLaunchError() {
Expand Down
3 changes: 1 addition & 2 deletions LiveContainerSwiftUI/LCWebView.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
//
// SwiftUIView.swift
// nmsl
//
// Created by s s on 2024/8/23.
//
Expand Down Expand Up @@ -131,7 +130,7 @@ struct LCWebView: View {

let encodedUrl = Data(url.absoluteString.utf8).base64EncodedString()
if let urlToOpen = URL(string: "\(runningLC)://livecontainer-launch?bundle-name=\(bundleId)&open-url=\(encodedUrl)"), UIApplication.shared.canOpenURL(urlToOpen) {
NSLog("[NMSL] urlToOpen = \(urlToOpen.absoluteString)")
NSLog("[LC] urlToOpen = \(urlToOpen.absoluteString)")
UIApplication.shared.open(urlToOpen)
isPresent = false
return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
/* Begin PBXBuildFile section */
173564C92C76FE3500C6C918 /* LCAppListView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 173564BC2C76FE3500C6C918 /* LCAppListView.swift */; };
173564CA2C76FE3500C6C918 /* LCTabView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 173564BD2C76FE3500C6C918 /* LCTabView.swift */; };
173564CB2C76FE3500C6C918 /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 173564BE2C76FE3500C6C918 /* Preview Assets.xcassets */; };
173564CC2C76FE3500C6C918 /* LCTweaksView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 173564C02C76FE3500C6C918 /* LCTweaksView.swift */; };
173564CD2C76FE3500C6C918 /* LCSettingsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 173564C12C76FE3500C6C918 /* LCSettingsView.swift */; };
173564CE2C76FE3500C6C918 /* Makefile in Sources */ = {isa = PBXBuildFile; fileRef = 173564C32C76FE3500C6C918 /* Makefile */; };
Expand All @@ -25,7 +24,6 @@
/* Begin PBXFileReference section */
173564BC2C76FE3500C6C918 /* LCAppListView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LCAppListView.swift; sourceTree = "<group>"; };
173564BD2C76FE3500C6C918 /* LCTabView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LCTabView.swift; sourceTree = "<group>"; };
173564BE2C76FE3500C6C918 /* Preview Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = "Preview Assets.xcassets"; sourceTree = "<group>"; };
173564C02C76FE3500C6C918 /* LCTweaksView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LCTweaksView.swift; sourceTree = "<group>"; };
173564C12C76FE3500C6C918 /* LCSettingsView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LCSettingsView.swift; sourceTree = "<group>"; };
173564C22C76FE3500C6C918 /* LCSwiftBridge.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LCSwiftBridge.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -66,22 +64,13 @@
173564C32C76FE3500C6C918 /* Makefile */,
173564C62C76FE3500C6C918 /* ObjcBridge.swift */,
178B4C3F2C7766A300DD1F74 /* LiveContainerSwiftUI-Bridging-Header.h */,
173564BF2C76FE3500C6C918 /* Preview Content */,
178B4C3D2C77654400DD1F74 /* Shared.swift */,
173564C22C76FE3500C6C918 /* LCSwiftBridge.h */,
173564C42C76FE3500C6C918 /* LCSwiftBridge.m */,
);
name = LiveContainerSwiftUI;
sourceTree = "<group>";
};
173564BF2C76FE3500C6C918 /* Preview Content */ = {
isa = PBXGroup;
children = (
173564BE2C76FE3500C6C918 /* Preview Assets.xcassets */,
);
path = "Preview Content";
sourceTree = "<group>";
};
17B9B8842C760678009D079E = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -195,7 +184,6 @@
buildActionMask = 2147483647;
files = (
173564D32C76FE3500C6C918 /* Assets.xcassets in Resources */,
173564CB2C76FE3500C6C918 /* Preview Assets.xcassets in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
4 changes: 4 additions & 0 deletions LiveContainerSwiftUI/ObjcBridge.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ import SwiftUI
}
}

@objc public static func launchApp(bundleId: String) {
DataManager.shared.bundleIDToLaunchModel.bundleIdToLaunch = bundleId
}

@objc public static func getRootVC() -> UIViewController {
let rootView = LCTabView()
let rootVC = UIHostingController(rootView: rootView)
Expand Down

This file was deleted.

10 changes: 10 additions & 0 deletions LiveContainerSwiftUI/Shared.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,16 @@ struct LCPath {
}
}

class BundleIDToLaunchModel: ObservableObject {
@Published var bundleIdToLaunch: String = ""
}

class DataManager {
static let shared = DataManager()
let bundleIDToLaunchModel = BundleIDToLaunchModel()
}


extension String: LocalizedError {
public var errorDescription: String? { return self }
}
Expand Down
1 change: 1 addition & 0 deletions LiveContainerUI/LCAppDelegateSwiftUI.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
@interface LCSwiftBridge : NSObject
+ (UIViewController * _Nonnull)getRootVC;
+ (void)openWebPageWithUrlStr:(NSString* _Nonnull)urlStr;
+ (void)launchAppWithBundleId:(NSString* _Nonnull)bundleId;
@end

@interface LCAppDelegateSwiftUI : UIResponder <UIApplicationDelegate>
Expand Down
9 changes: 2 additions & 7 deletions LiveContainerUI/LCAppDelegateSwiftUI.m
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,13 @@ - (BOOL)application:(UIApplication *)application openURL:(NSURL *)url options:(N
NSURLComponents* components = [NSURLComponents componentsWithURL:url resolvingAgainstBaseURL:NO];
for (NSURLQueryItem* queryItem in components.queryItems) {
if ([queryItem.name isEqualToString:@"bundle-name"]) {
NSString* runningLC = [NSClassFromString(@"LCSharedUtils") getAppRunningLCSchemeWithBundleId:queryItem.value];
if(runningLC) {
NSString* urlStr = [NSString stringWithFormat:@"%@://livecontainer-launch?bundle-name=%@", runningLC, queryItem.value];
[UIApplication.sharedApplication openURL:[NSURL URLWithString:urlStr] options:@{} completionHandler:nil];
return YES;
}
[NSClassFromString(@"LCSwiftBridge") launchAppWithBundleId:queryItem.value];
break;
}
}
}

return [LCUtils launchToGuestAppWithURL:url];
return NO;
}

@end
Loading

0 comments on commit 1ddcbbe

Please sign in to comment.