revert + version

This commit is contained in:
Dusk 2025-03-31 13:03:32 +08:00
parent 834d2c7d5d
commit 7cc57548d4
7 changed files with 115 additions and 48 deletions

View file

@ -10,14 +10,75 @@ import Network
import em_proxy
import UniformTypeIdentifiers
let fileManager = FileManager.default
let one_time_hardcoded_version = "1.0.0"
func httpGet(_ urlString: String, result: @escaping (String?) -> Void){
if let url = URL(string: urlString) {
let task = URLSession.shared.dataTask(with: url) { data, response, error in
if let error = error {
print("Error: \(error.localizedDescription)")
return
}
if let data = data, let httpResponse = response as? HTTPURLResponse {
if httpResponse.statusCode == 200 {
print("Response: \(httpResponse.statusCode)")
if let DataString = String(data: data, encoding: .utf8) {
result(DataString)
}
} else {
print("Received non-200 status code: \(httpResponse.statusCode)")
}
}
}
task.resume()
}
}
func UpdateRetrieval() -> Bool{
let fileURL = URL.documentsDirectory.appendingPathComponent("version.txt")
if !fileManager.fileExists(atPath: fileURL.path) {
do {
try one_time_hardcoded_version.write(to: fileURL, atomically: true, encoding: .utf8)
print("Wrote to file successfully")
} catch {
print("Error writing to file: \(error)")
}
}
let ver = try! String(contentsOfFile: fileURL.path)
let urlString = "https://raw.githubusercontent.com/0-Blu/StikJIT/refs/heads/main/version.txt"
var res = false;
httpGet(urlString) { result in
if (ver != result){
res = true;
}
}
return res;
}
@main
struct HeartbeatApp: App {
@State private var isLoading = true
@State private var isPairing = false
@State private var heartBeat = false
@State private var error: Int32? = nil
@State private var show_error = false
@State private var error_string = ""
@State private var show_alert = false
@State private var alert_string = ""
@State private var alert_title = ""
@StateObject private var mount = MountingProgress.shared
let urls: [String] = [
@ -35,11 +96,34 @@ struct HeartbeatApp: App {
]
init() {
newVerCheck()
let fixMethod = class_getInstanceMethod(UIDocumentPickerViewController.self, #selector(UIDocumentPickerViewController.fix_init(forOpeningContentTypes:asCopy:)))!
let origMethod = class_getInstanceMethod(UIDocumentPickerViewController.self, #selector(UIDocumentPickerViewController.init(forOpeningContentTypes:asCopy:)))!
method_exchangeImplementations(origMethod, fixMethod)
}
func newVerCheck() {
let currentDate = Calendar.current.startOfDay(for: Date())
let VUA = UserDefaults.standard.object(forKey: "VersionUpdateAlert") as? Date ?? Date.distantPast
if currentDate > Calendar.current.startOfDay(for: VUA) {
if (UpdateRetrieval()){
alert_title = "Update Avaliable!"
let urlString = "https://raw.githubusercontent.com/0-Blu/StikJIT/refs/heads/main/version.txt"
httpGet(urlString) { result in
alert_string = "Update to: v" + result!
}
show_alert = true
}
UserDefaults.standard.set(currentDate, forKey: "VersionUpdateAlert")
}
}
var body: some Scene {
WindowGroup {
if isLoading {
@ -130,8 +214,9 @@ struct HeartbeatApp: App {
if !fileManager.fileExists(atPath: destinationURL.path) {
downloadFile(from: urlString, to: destinationURL){ result in
if (result != ""){
error_string = "[Download DDI Error]: " + result
show_error = true
alert_title = "An Error has Occurred"
alert_string = "[Download DDI Error]: " + result
show_alert = true
}
}
@ -140,10 +225,10 @@ struct HeartbeatApp: App {
}
}
.alert("An Error Occurred", isPresented: $show_error) {
.alert(alert_title, isPresented: $show_alert) {
Button("OK", role: .cancel) { }
} message: {
Text(error_string)
Text(alert_title)
}
}
}

View file

@ -15,7 +15,7 @@ extension UIDocumentPickerViewController {
}
struct HomeView: View {
@Binding var is_lc: Bool
@AppStorage("username") private var username = "User"
@AppStorage("customBackgroundColor") private var customBackgroundColorHex: String = Color.primaryBackground.toHex() ?? "#000000"
@AppStorage("autoQuitAfterEnablingJIT") private var doAutoQuitAfterEnablingJIT = false
@ -34,9 +34,7 @@ struct HomeView: View {
@State private var viewDidAppeared = false
@State private var pendingBundleIdToEnableJIT : String? = nil
init(is_lc: Binding<Bool>? = nil) {
self._is_lc = is_lc ?? .constant(false)
}
var body: some View {
ZStack {
@ -271,7 +269,7 @@ struct HomeView: View {
DispatchQueue.global(qos: .background).async {
let success = JITEnableContext.shared.debugApp(withBundleID: bundleID,isLC: is_lc, logger: { message in
let success = JITEnableContext.shared.debugApp(withBundleID: bundleID, logger: { message in
if let message = message {
// Log messages from the JIT process

View file

@ -260,21 +260,7 @@ struct SettingsView: View {
self.mounted = isMounted()
}
}
SettingsCard {
VStack(alignment: .leading, spacing: 20) {
Text("Misclaneous Settings")
.font(.headline)
.foregroundColor(.primary)
.padding(.bottom, 4)
Toggle("Enable In-LiveContainer JIT", isOn: $is_lc)
.padding()
HomeView(is_lc: $is_lc)
}
.padding(.vertical, 20)
.padding(.horizontal, 16)
}
// About section

View file

@ -16,7 +16,7 @@ typedef void (^LogFunc)(NSString *message);
@property (class, readonly)JITEnableContext* shared;
- (IdevicePairingFile*)getPairingFileWithError:(NSError**)error;
- (void)startHeartbeatWithCompletionHandler:(HeartbeatCompletionHandler)completionHandler logger:(LogFunc)logger;
- (BOOL)debugAppWithBundleID:(NSString*)bundleID isLC:(BOOL)isLC logger:(LogFunc)logger;
- (BOOL)debugAppWithBundleID:(NSString*)bundleID logger:(LogFunc)logger;
- (NSDictionary<NSString*, NSString*>*)getAppListWithError:(NSError**)error;
- (UIImage*)getAppIconWithBundleId:(NSString*)bundleId error:(NSError**)error;
@end

View file

@ -105,7 +105,7 @@ JITEnableContext* sharedJITContext = nil;
}, [self createCLogger:logger]);
}
- (BOOL)debugAppWithBundleID:(NSString*)bundleID isLC:(BOOL)isLC logger:(LogFunc)logger {
- (BOOL)debugAppWithBundleID:(NSString*)bundleID logger:(LogFunc)logger {
if(!provider) {
if(logger) {
@ -117,7 +117,7 @@ JITEnableContext* sharedJITContext = nil;
return debug_app(provider, [bundleID UTF8String], [self createCLogger:logger], (bool)(isLC)) == 0;
return debug_app(provider, [bundleID UTF8String], [self createCLogger:logger] ) == 0;
}

View file

@ -18,7 +18,7 @@
#include "jit.h"
int debug_app(TcpProviderHandle* tcp_provider, const char *bundle_id, LogFuncC logger,bool isLC) {
int debug_app(TcpProviderHandle* tcp_provider, const char *bundle_id, LogFuncC logger) {
// Initialize logger
idevice_init_logger(Debug, Disabled, NULL);
IdeviceErrorCode err = IdeviceSuccess;
@ -142,25 +142,23 @@ int debug_app(TcpProviderHandle* tcp_provider, const char *bundle_id, LogFuncC l
xpc_service_free(debug_service);
return 1;
}
if(!isLC){
// Launch application
err = process_control_launch_app(process_control, bundle_id, NULL, 0, NULL, 0,
true, false, &pid);
if (err != IdeviceSuccess) {
logger("Failed to launch app: %d", err);
process_control_free(process_control);
remote_server_free(remote_server);
xpc_service_free(pc_service);
xpc_service_free(debug_service);
return 1;
}
logger("Successfully launched app with PID: %" PRIu64 "", pid);
} else {
pid = getpid();
// Launch application
err = process_control_launch_app(process_control, bundle_id, NULL, 0, NULL, 0,
true, false, &pid);
if (err != IdeviceSuccess) {
logger("Failed to launch app: %d", err);
process_control_free(process_control);
remote_server_free(remote_server);
xpc_service_free(pc_service);
xpc_service_free(debug_service);
return 1;
}
logger("Successfully launched app with PID: %" PRIu64 "", pid);
// Disable memory limit for PID
err = process_control_disable_memory_limit(process_control, pid);
if (err != IdeviceSuccess) {

View file

@ -11,6 +11,6 @@
#include "idevice.h"
typedef void (^LogFuncC)(const char* message, ...);
int debug_app(TcpProviderHandle* provider, const char *bundle_id, LogFuncC logger, bool isLC);
int debug_app(TcpProviderHandle* provider, const char *bundle_id, LogFuncC logger);
#endif /* JIT_H */