Skip to content

Commit 66fb136

Browse files
authored
Merge pull request #43 from wynwxst/main
Adding Version Functionality + Revert LC
2 parents 87c58cf + 80945fe commit 66fb136

7 files changed

Lines changed: 140 additions & 49 deletions

File tree

StikJIT/StikJITApp.swift

Lines changed: 113 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,95 @@ import Network
1010
import em_proxy
1111
import UniformTypeIdentifiers
1212

13+
let fileManager = FileManager.default
14+
15+
16+
17+
func httpGet(_ urlString: String, result: @escaping (String?) -> Void){
18+
if let url = URL(string: urlString) {
19+
20+
21+
let task = URLSession.shared.dataTask(with: url) { data, response, error in
22+
23+
24+
if let error = error {
25+
print("Error: \(error.localizedDescription)")
26+
result(nil)
27+
return
28+
}
29+
30+
31+
if let data = data, let httpResponse = response as? HTTPURLResponse {
32+
33+
34+
if httpResponse.statusCode == 200 {
35+
print("Response: \(httpResponse.statusCode)")
36+
37+
38+
if let DataString = String(data: data, encoding: .utf8) {
39+
result(DataString)
40+
}
41+
} else {
42+
print("Received non-200 status code: \(httpResponse.statusCode)")
43+
}
44+
}
45+
}
46+
47+
48+
task.resume()
49+
}
50+
}
51+
52+
func UpdateRetrieval() -> Bool{
53+
let fileURL = URL.documentsDirectory.appendingPathComponent("version.txt")
54+
if !fileManager.fileExists(atPath: fileURL.path) {
55+
56+
let urlString = "https://raw.githubusercontent.com/0-Blu/StikJIT/refs/heads/main/version.txt"
57+
var FileContent: String = "";
58+
59+
httpGet(urlString) { result in
60+
if let fc = result {
61+
FileContent = fc
62+
}
63+
64+
}
65+
if (FileContent == ""){
66+
do {
67+
try FileContent.write(to: fileURL, atomically: true, encoding: .utf8)
68+
69+
print("Wrote to file successfully")
70+
} catch {
71+
print("Error writing to file: \(error)")
72+
}
73+
} else {
74+
print("Failed to get version.txt, will try again later.")
75+
}
76+
}
77+
let ver = try! String(contentsOfFile: fileURL.path)
78+
let urlString = "https://raw.githubusercontent.com/0-Blu/StikJIT/refs/heads/main/version.txt"
79+
var res = false
80+
httpGet(urlString) { result in
81+
if let fc = result {
82+
if (ver != fc){
83+
res = true
84+
}
85+
} // if nil then request failed so we won't throw an error
86+
87+
}
88+
return res
89+
90+
91+
}
92+
1393
@main
1494
struct HeartbeatApp: App {
1595
@State private var isLoading = true
1696
@State private var isPairing = false
1797
@State private var heartBeat = false
1898
@State private var error: Int32? = nil
19-
@State private var show_error = false
20-
@State private var error_string = ""
99+
@State private var show_alert = false
100+
@State private var alert_string = ""
101+
@State private var alert_title = ""
21102
@StateObject private var mount = MountingProgress.shared
22103

23104
let urls: [String] = [
@@ -35,11 +116,36 @@ struct HeartbeatApp: App {
35116
]
36117

37118
init() {
119+
newVerCheck()
38120
let fixMethod = class_getInstanceMethod(UIDocumentPickerViewController.self, #selector(UIDocumentPickerViewController.fix_init(forOpeningContentTypes:asCopy:)))!
39121
let origMethod = class_getInstanceMethod(UIDocumentPickerViewController.self, #selector(UIDocumentPickerViewController.init(forOpeningContentTypes:asCopy:)))!
40122
method_exchangeImplementations(origMethod, fixMethod)
41123
}
124+
func newVerCheck() {
125+
let currentDate = Calendar.current.startOfDay(for: Date())
42126

127+
128+
let VUA = UserDefaults.standard.object(forKey: "VersionUpdateAlert") as? Date ?? Date.distantPast
129+
130+
131+
if currentDate > Calendar.current.startOfDay(for: VUA) {
132+
133+
if (UpdateRetrieval()){
134+
alert_title = "Update Avaliable!"
135+
let urlString = "https://raw.githubusercontent.com/0-Blu/StikJIT/refs/heads/main/version.txt"
136+
httpGet(urlString) { result in
137+
if result == nil { return }
138+
alert_string = "Update to: version \(result!)!"
139+
show_alert = true
140+
}
141+
142+
143+
}
144+
145+
146+
UserDefaults.standard.set(currentDate, forKey: "VersionUpdateAlert")
147+
}
148+
}
43149
var body: some Scene {
44150
WindowGroup {
45151
if isLoading {
@@ -122,8 +228,9 @@ struct HeartbeatApp: App {
122228
if !fileManager.fileExists(atPath: destinationURL.path) {
123229
downloadFile(from: urlString, to: destinationURL){ result in
124230
if (result != ""){
125-
error_string = "[Download DDI Error]: " + result
126-
show_error = true
231+
alert_title = "An Error has Occurred"
232+
alert_string = "[Download DDI Error]: " + result
233+
show_alert = true
127234
}
128235

129236
}
@@ -132,10 +239,10 @@ struct HeartbeatApp: App {
132239
}
133240

134241
}
135-
.alert("An Error Occurred", isPresented: $show_error) {
242+
.alert(alert_title, isPresented: $show_alert) {
136243
Button("OK", role: .cancel) { }
137244
} message: {
138-
Text(error_string)
245+
Text(alert_title)
139246
}
140247
}
141248
}

StikJIT/Views/HomeView.swift

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ extension UIDocumentPickerViewController {
1515
}
1616

1717
struct HomeView: View {
18-
@Binding var is_lc: Bool
18+
1919
@AppStorage("username") private var username = "User"
2020
@AppStorage("customBackgroundColor") private var customBackgroundColorHex: String = Color.primaryBackground.toHex() ?? "#000000"
2121
@AppStorage("autoQuitAfterEnablingJIT") private var doAutoQuitAfterEnablingJIT = false
@@ -34,9 +34,7 @@ struct HomeView: View {
3434
@State private var viewDidAppeared = false
3535
@State private var pendingBundleIdToEnableJIT : String? = nil
3636

37-
init(is_lc: Binding<Bool>? = nil) {
38-
self._is_lc = is_lc ?? .constant(false)
39-
}
37+
4038

4139
var body: some View {
4240
ZStack {
@@ -271,7 +269,7 @@ struct HomeView: View {
271269

272270
DispatchQueue.global(qos: .background).async {
273271

274-
let success = JITEnableContext.shared.debugApp(withBundleID: bundleID,isLC: is_lc, logger: { message in
272+
let success = JITEnableContext.shared.debugApp(withBundleID: bundleID, logger: { message in
275273

276274
if let message = message {
277275
// Log messages from the JIT process

StikJIT/Views/SettingsView.swift

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -260,21 +260,7 @@ struct SettingsView: View {
260260
self.mounted = isMounted()
261261
}
262262
}
263-
SettingsCard {
264-
VStack(alignment: .leading, spacing: 20) {
265-
Text("Misclaneous Settings")
266-
.font(.headline)
267-
.foregroundColor(.primary)
268-
.padding(.bottom, 4)
269-
270-
Toggle("Enable In-LiveContainer JIT", isOn: $is_lc)
271-
.padding()
272-
273-
HomeView(is_lc: $is_lc)
274-
}
275-
.padding(.vertical, 20)
276-
.padding(.horizontal, 16)
277-
}
263+
278264

279265

280266
// About section
@@ -426,7 +412,9 @@ struct SettingsView: View {
426412
// Version info should now come after System Logs
427413
HStack {
428414
Spacer()
429-
Text("Version 1.1 • iOS \(UIDevice.current.systemVersion)")
415+
let fileURL = URL.documentsDirectory.appendingPathComponent("version.txt")
416+
let ver = (try? String(contentsOfFile: fileURL.path)) ?? "-"
417+
Text("Version \(ver) • iOS \(UIDevice.current.systemVersion)")
430418
.font(.footnote)
431419
.foregroundColor(.secondary.opacity(0.8))
432420
Spacer()

StikJIT/idevice/JITEnableContext.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ typedef void (^LogFunc)(NSString *message);
1616
@property (class, readonly)JITEnableContext* shared;
1717
- (IdevicePairingFile*)getPairingFileWithError:(NSError**)error;
1818
- (void)startHeartbeatWithCompletionHandler:(HeartbeatCompletionHandler)completionHandler logger:(LogFunc)logger;
19-
- (BOOL)debugAppWithBundleID:(NSString*)bundleID isLC:(BOOL)isLC logger:(LogFunc)logger;
19+
- (BOOL)debugAppWithBundleID:(NSString*)bundleID logger:(LogFunc)logger;
2020
- (NSDictionary<NSString*, NSString*>*)getAppListWithError:(NSError**)error;
2121
- (UIImage*)getAppIconWithBundleId:(NSString*)bundleId error:(NSError**)error;
2222
@end

StikJIT/idevice/JITEnableContext.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ - (void)startHeartbeatWithCompletionHandler:(HeartbeatCompletionHandler)completi
105105
}, [self createCLogger:logger]);
106106
}
107107

108-
- (BOOL)debugAppWithBundleID:(NSString*)bundleID isLC:(BOOL)isLC logger:(LogFunc)logger {
108+
- (BOOL)debugAppWithBundleID:(NSString*)bundleID logger:(LogFunc)logger {
109109

110110
if(!provider) {
111111
if(logger) {
@@ -117,7 +117,7 @@ - (BOOL)debugAppWithBundleID:(NSString*)bundleID isLC:(BOOL)isLC logger:(LogFunc
117117

118118

119119

120-
return debug_app(provider, [bundleID UTF8String], [self createCLogger:logger], (bool)(isLC)) == 0;
120+
return debug_app(provider, [bundleID UTF8String], [self createCLogger:logger] ) == 0;
121121

122122
}
123123

StikJIT/idevice/jit.c

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
#include "jit.h"
2020

21-
int debug_app(TcpProviderHandle* tcp_provider, const char *bundle_id, LogFuncC logger,bool isLC) {
21+
int debug_app(TcpProviderHandle* tcp_provider, const char *bundle_id, LogFuncC logger) {
2222
// Initialize logger
2323
idevice_init_logger(Debug, Disabled, NULL);
2424
IdeviceErrorCode err = IdeviceSuccess;
@@ -142,25 +142,23 @@ int debug_app(TcpProviderHandle* tcp_provider, const char *bundle_id, LogFuncC l
142142
xpc_service_free(debug_service);
143143
return 1;
144144
}
145-
if(!isLC){
146-
147-
// Launch application
148-
149-
err = process_control_launch_app(process_control, bundle_id, NULL, 0, NULL, 0,
150-
true, false, &pid);
151-
if (err != IdeviceSuccess) {
152-
logger("Failed to launch app: %d", err);
153-
process_control_free(process_control);
154-
remote_server_free(remote_server);
155-
xpc_service_free(pc_service);
156-
xpc_service_free(debug_service);
157-
return 1;
158-
}
145+
159146

160-
logger("Successfully launched app with PID: %" PRIu64 "", pid);
161-
} else {
162-
pid = getpid();
147+
// Launch application
148+
149+
err = process_control_launch_app(process_control, bundle_id, NULL, 0, NULL, 0,
150+
true, false, &pid);
151+
if (err != IdeviceSuccess) {
152+
logger("Failed to launch app: %d", err);
153+
process_control_free(process_control);
154+
remote_server_free(remote_server);
155+
xpc_service_free(pc_service);
156+
xpc_service_free(debug_service);
157+
return 1;
163158
}
159+
160+
logger("Successfully launched app with PID: %" PRIu64 "", pid);
161+
164162
// Disable memory limit for PID
165163
err = process_control_disable_memory_limit(process_control, pid);
166164
if (err != IdeviceSuccess) {

StikJIT/idevice/jit.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@
1111
#include "idevice.h"
1212

1313
typedef void (^LogFuncC)(const char* message, ...);
14-
int debug_app(TcpProviderHandle* provider, const char *bundle_id, LogFuncC logger, bool isLC);
14+
int debug_app(TcpProviderHandle* provider, const char *bundle_id, LogFuncC logger);
1515

1616
#endif /* JIT_H */

0 commit comments

Comments
 (0)