From 7cc57548d4634e2d81ff9fad34e883a93c39ef38 Mon Sep 17 00:00:00 2001 From: Dusk Date: Mon, 31 Mar 2025 13:03:32 +0800 Subject: [PATCH] revert + version --- StikJIT/StikJITApp.swift | 97 ++++++++++++++++++++++++++++-- StikJIT/Views/HomeView.swift | 8 +-- StikJIT/Views/SettingsView.swift | 16 +---- StikJIT/idevice/JITEnableContext.h | 2 +- StikJIT/idevice/JITEnableContext.m | 4 +- StikJIT/idevice/jit.c | 34 +++++------ StikJIT/idevice/jit.h | 2 +- 7 files changed, 115 insertions(+), 48 deletions(-) diff --git a/StikJIT/StikJITApp.swift b/StikJIT/StikJITApp.swift index 367a508..4c6ca8b 100644 --- a/StikJIT/StikJITApp.swift +++ b/StikJIT/StikJITApp.swift @@ -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) } } } diff --git a/StikJIT/Views/HomeView.swift b/StikJIT/Views/HomeView.swift index 806a4ae..39bedbf 100644 --- a/StikJIT/Views/HomeView.swift +++ b/StikJIT/Views/HomeView.swift @@ -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? = 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 diff --git a/StikJIT/Views/SettingsView.swift b/StikJIT/Views/SettingsView.swift index 8c38d67..8d8a56e 100644 --- a/StikJIT/Views/SettingsView.swift +++ b/StikJIT/Views/SettingsView.swift @@ -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 diff --git a/StikJIT/idevice/JITEnableContext.h b/StikJIT/idevice/JITEnableContext.h index 0fdf4a1..a3d1870 100644 --- a/StikJIT/idevice/JITEnableContext.h +++ b/StikJIT/idevice/JITEnableContext.h @@ -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*)getAppListWithError:(NSError**)error; - (UIImage*)getAppIconWithBundleId:(NSString*)bundleId error:(NSError**)error; @end diff --git a/StikJIT/idevice/JITEnableContext.m b/StikJIT/idevice/JITEnableContext.m index 527c33f..04ffa15 100644 --- a/StikJIT/idevice/JITEnableContext.m +++ b/StikJIT/idevice/JITEnableContext.m @@ -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; } diff --git a/StikJIT/idevice/jit.c b/StikJIT/idevice/jit.c index c7cf0ce..b657b34 100644 --- a/StikJIT/idevice/jit.c +++ b/StikJIT/idevice/jit.c @@ -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) { diff --git a/StikJIT/idevice/jit.h b/StikJIT/idevice/jit.h index 8f3b8f3..c42f2fc 100644 --- a/StikJIT/idevice/jit.h +++ b/StikJIT/idevice/jit.h @@ -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 */