2023-10-13 21:37:34 -04:00
|
|
|
#import <UIKit/UIKit.h>
|
2023-10-19 14:05:34 -04:00
|
|
|
#import <WebKit/WKNavigationDelegate.h>
|
2023-10-16 10:16:21 -04:00
|
|
|
#import <WebKit/WKUIDelegate.h>
|
2023-10-13 21:37:34 -04:00
|
|
|
#import <WebKit/WKWebView.h>
|
|
|
|
#import <WebKit/WKWebViewConfiguration.h>
|
|
|
|
|
2023-10-15 12:55:25 -04:00
|
|
|
#include <libgen.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
void tf_run_thread_start(const char* zip_path);
|
|
|
|
|
2024-02-15 18:35:01 -05:00
|
|
|
@interface ViewController : UIViewController <WKUIDelegate, WKNavigationDelegate>
|
|
|
|
@property (strong, nonatomic) WKWebView* web_view;
|
2023-10-19 14:05:34 -04:00
|
|
|
@property bool initial_load_complete;
|
2023-10-13 21:37:34 -04:00
|
|
|
@end
|
|
|
|
|
2023-10-19 14:05:34 -04:00
|
|
|
static void _start_initial_load(WKWebView* web_view)
|
|
|
|
{
|
|
|
|
[web_view loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://localhost:12345/"]]];
|
|
|
|
}
|
|
|
|
|
2023-10-16 10:16:21 -04:00
|
|
|
@implementation ViewController : UIViewController
|
2023-10-13 21:37:34 -04:00
|
|
|
- (void)viewDidLoad
|
|
|
|
{
|
|
|
|
[super viewDidLoad];
|
|
|
|
WKWebViewConfiguration* configuration = [[WKWebViewConfiguration alloc] init];
|
|
|
|
self.web_view = [[WKWebView alloc] initWithFrame:self.view.frame configuration:configuration];
|
2023-10-16 10:16:21 -04:00
|
|
|
self.web_view.UIDelegate = self;
|
2023-10-19 14:05:34 -04:00
|
|
|
self.web_view.navigationDelegate = self;
|
2023-10-21 14:32:23 -04:00
|
|
|
self.web_view.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
|
2023-10-13 21:37:34 -04:00
|
|
|
[self.view addSubview:self.web_view];
|
2023-10-19 14:05:34 -04:00
|
|
|
_start_initial_load(self.web_view);
|
|
|
|
}
|
|
|
|
|
2024-02-15 18:35:01 -05:00
|
|
|
- (void)webView:(WKWebView*)webView didFinishNavigation:(WKNavigation*)navigation
|
2023-10-19 14:05:34 -04:00
|
|
|
{
|
|
|
|
self.initial_load_complete = true;
|
|
|
|
}
|
|
|
|
|
2024-02-15 18:35:01 -05:00
|
|
|
- (void)webView:(WKWebView*)webView didFailProvisionalNavigation:(WKNavigation*)navigation withError:(NSError*)error
|
2023-10-19 14:05:34 -04:00
|
|
|
{
|
|
|
|
if (!self.initial_load_complete)
|
|
|
|
{
|
|
|
|
_start_initial_load(self.web_view);
|
|
|
|
}
|
2023-10-13 21:37:34 -04:00
|
|
|
}
|
2023-10-16 10:16:21 -04:00
|
|
|
|
2024-02-15 18:35:01 -05:00
|
|
|
- (void)webView:(WKWebView*)webView
|
|
|
|
runJavaScriptConfirmPanelWithMessage:(NSString*)message
|
|
|
|
initiatedByFrame:(WKFrameInfo*)frame
|
|
|
|
completionHandler:(void (^)(BOOL result))completionHandler
|
2023-10-16 10:16:21 -04:00
|
|
|
{
|
2024-02-15 18:35:01 -05:00
|
|
|
UIAlertController* alertController = [UIAlertController alertControllerWithTitle:message message:nil preferredStyle:UIAlertControllerStyleAlert];
|
|
|
|
[alertController addAction:[UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction* action) { completionHandler(true); }]];
|
|
|
|
[alertController addAction:[UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction* action) { completionHandler(false); }]];
|
|
|
|
[self presentViewController:alertController animated:YES completion:^ {}];
|
2023-10-16 10:16:21 -04:00
|
|
|
}
|
|
|
|
|
2024-02-15 18:35:01 -05:00
|
|
|
- (void)webView:(WKWebView*)webView runJavaScriptAlertPanelWithMessage:(NSString*)message initiatedByFrame:(WKFrameInfo*)frame completionHandler:(void (^)(void))completionHandler
|
2023-10-16 10:16:21 -04:00
|
|
|
{
|
2024-02-15 18:35:01 -05:00
|
|
|
UIAlertController* alertController = [UIAlertController alertControllerWithTitle:message message:nil preferredStyle:UIAlertControllerStyleAlert];
|
|
|
|
[alertController addAction:[UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction* action) { completionHandler(); }]];
|
|
|
|
[self presentViewController:alertController animated:YES completion:^ {}];
|
2023-10-16 10:16:21 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-02-15 18:35:01 -05:00
|
|
|
- (void)webView:(WKWebView*)webView
|
|
|
|
runJavaScriptTextInputPanelWithPrompt:(NSString*)prompt
|
|
|
|
defaultText:(NSString*)defaultText
|
|
|
|
initiatedByFrame:(WKFrameInfo*)frame
|
|
|
|
completionHandler:(void (^)(NSString*))completionHandler
|
2023-10-16 10:16:21 -04:00
|
|
|
{
|
2024-02-15 18:35:01 -05:00
|
|
|
NSString* sender = [NSString stringWithFormat:@"%@", self.web_view.URL.host];
|
2023-10-16 10:16:21 -04:00
|
|
|
|
2024-02-15 18:35:01 -05:00
|
|
|
UIAlertController* alertController = [UIAlertController alertControllerWithTitle:prompt message:sender preferredStyle:UIAlertControllerStyleAlert];
|
|
|
|
[alertController addTextFieldWithConfigurationHandler:^(UITextField* textField) {
|
|
|
|
textField.placeholder = defaultText;
|
|
|
|
textField.text = defaultText;
|
2023-10-16 10:16:21 -04:00
|
|
|
}];
|
2024-02-15 18:35:01 -05:00
|
|
|
[alertController addAction:[UIAlertAction actionWithTitle:@"OK"
|
|
|
|
style:UIAlertActionStyleDefault
|
|
|
|
handler:^(UIAlertAction* action) {
|
|
|
|
NSString* input = ((UITextField*)alertController.textFields.firstObject).text;
|
|
|
|
completionHandler(input);
|
|
|
|
}]];
|
|
|
|
[alertController addAction:[UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction* action) { completionHandler(nil); }]];
|
|
|
|
[self presentViewController:alertController animated:YES completion:^ {}];
|
2023-10-16 10:16:21 -04:00
|
|
|
}
|
2023-10-13 21:37:34 -04:00
|
|
|
@end
|
|
|
|
|
2024-02-15 18:35:01 -05:00
|
|
|
@interface AppDelegate : UIResponder <UIApplicationDelegate>
|
|
|
|
@property (strong, nonatomic) UIWindow* window;
|
2023-10-13 21:37:34 -04:00
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation AppDelegate
|
2024-02-15 18:35:01 -05:00
|
|
|
- (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions
|
2023-10-13 21:37:34 -04:00
|
|
|
{
|
|
|
|
self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
|
|
|
|
ViewController* view_controller = [[ViewController alloc] init];
|
|
|
|
self.window.rootViewController = view_controller;
|
|
|
|
[self.window makeKeyAndVisible];
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
@end
|
|
|
|
|
|
|
|
int main(int argc, char* argv[])
|
|
|
|
{
|
2023-10-15 12:55:25 -04:00
|
|
|
NSFileManager* file_manager = [NSFileManager defaultManager];
|
|
|
|
NSString* library_directory = [NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES) objectAtIndex:0];
|
|
|
|
[file_manager changeCurrentDirectoryPath:library_directory];
|
|
|
|
size_t path_length = strlen(argv[0]) - strlen(basename(argv[0]));
|
|
|
|
size_t length = path_length + strlen("data.zip");
|
|
|
|
char* zip_path = alloca(length + 1);
|
|
|
|
snprintf(zip_path, length + 1, "%.*sdata.zip", (int)path_length, argv[0]);
|
|
|
|
tf_run_thread_start(zip_path);
|
2023-10-13 21:37:34 -04:00
|
|
|
return UIApplicationMain(argc, argv, nil, @"AppDelegate");
|
|
|
|
}
|