diff --git a/JavaApp/src/main/java/net/kdt/pojavlaunch/uikit/AccountJNI.java b/JavaApp/src/main/java/net/kdt/pojavlaunch/uikit/AccountJNI.java index 01b36cbe..9977a22d 100644 --- a/JavaApp/src/main/java/net/kdt/pojavlaunch/uikit/AccountJNI.java +++ b/JavaApp/src/main/java/net/kdt/pojavlaunch/uikit/AccountJNI.java @@ -6,9 +6,9 @@ import net.kdt.pojavlaunch.value.MinecraftAccount; public class AccountJNI { public static final int TYPE_SELECTACC = 0; - public static final int TYPE_MICROSOFT = 0; - public static final int TYPE_MOJANG = 0; - public static final int TYPE_OFFLINE = 0; + public static final int TYPE_MICROSOFT = 1; + public static final int TYPE_MOJANG = 2; + public static final int TYPE_OFFLINE = 3; public static volatile MinecraftAccount CURRENT_ACCOUNT; diff --git a/Natives/LoginViewController.m b/Natives/LoginViewController.m index 36b48231..d2464517 100644 --- a/Natives/LoginViewController.m +++ b/Natives/LoginViewController.m @@ -6,18 +6,32 @@ #include "utils.h" +#define TYPE_SELECTACC 0 +#define TYPE_MICROSOFT 1 +#define TYPE_MOJANG 2 +#define TYPE_OFFLINE 3 + void loginAccount(LoginViewController *controller, int type, char* username_c, char* password_c) { JNIEnv *env; - (*runtimeJavaVMPtr)->GetEnv(runtimeJavaVMPtr, (void**) &env, JNI_VERSION_1_4); + (*runtimeJavaVMPtr)->AttachCurrentThread(runtimeJavaVMPtr, &env, NULL); jstring username = (*env)->NewStringUTF(env, username_c); jstring password = (*env)->NewStringUTF(env, password_c); jclass clazz = (*env)->FindClass(env, "net/kdt/pojavlaunch/uikit/AccountJNI"); - jmethodID method = (*env)->GetStaticMethodID(env, clazz, "loginAccount", "(ILjava/lang/String;Ljava/lang/String)Z"); + assert(clazz); + + jmethodID method = (*env)->GetStaticMethodID(env, clazz, "loginAccount", "(ILjava/lang/String;Ljava/lang/String;)Z"); + assert(method); + jboolean result = (*env)->CallStaticBooleanMethod(env, clazz, method, type, username, password); + + (*runtimeJavaVMPtr)->DetachCurrentThread(runtimeJavaVMPtr); + if (result == JNI_TRUE) { - [controller enterLauncher]; + dispatch_async(dispatch_get_main_queue(), ^{ + [controller enterLauncher]; + }); } } @@ -99,8 +113,56 @@ void loginAccount(LoginViewController *controller, int type, char* username_c, c } } +- (void)loginUsername:(int)type { + UIAlertController *controller = [UIAlertController alertControllerWithTitle: @"Login" + message: @(type == TYPE_MOJANG ? + "Account type: Mojang" : "Account type: Offline") + preferredStyle:UIAlertControllerStyleAlert]; + [controller addTextFieldWithConfigurationHandler:^(UITextField *textField) { + if (type == TYPE_MOJANG) { + textField.placeholder = @"Email or username"; + } else { + textField.placeholder = @"Username"; + } + textField.clearButtonMode = UITextFieldViewModeWhileEditing; + textField.borderStyle = UITextBorderStyleRoundedRect; + }]; + if (type == TYPE_MOJANG) { + [controller addTextFieldWithConfigurationHandler:^(UITextField *textField) { + textField.placeholder = @"Password"; + textField.clearButtonMode = UITextFieldViewModeWhileEditing; + textField.borderStyle = UITextBorderStyleRoundedRect; + textField.secureTextEntry = YES; + }]; + } + [controller addAction:[UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) { + NSArray *textFields = controller.textFields; + UITextField *usernameField = textFields[0]; + + const char *username = [usernameField.text UTF8String]; + if (type == TYPE_MOJANG) { + UITextField *passwordField = textFields[1]; + const char *password = [passwordField.text UTF8String]; + dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^(void){ + loginAccount(self, TYPE_MOJANG, username, password); + }); + } else { + if (usernameField.text.length < 3 || usernameField.text.length > 16) { + controller.message = @"Username must be at least 3 characters and maximum 16 characters"; + [self presentViewController:controller animated:YES completion:nil]; + } else { + dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^(void){ + loginAccount(self, TYPE_OFFLINE, username, ""); + }); + } + } + }]]; + [controller addAction:[UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:nil]]; + [self presentViewController:controller animated:YES completion:nil]; +} + - (void)loginMojang { - [self enterLauncher]; + [self loginUsername:TYPE_MOJANG]; } - (void)loginMicrosoft { @@ -108,25 +170,10 @@ void loginAccount(LoginViewController *controller, int type, char* username_c, c } - (void)loginOffline { - [self enterLauncher]; + [self loginUsername:TYPE_OFFLINE]; } - (void)loginAccount { -/* - UIViewController *controller = [[UIViewController alloc] init]; - UITableView *alertTableView; -alertTableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, 300, 300)]; - alertTableView.delegate = self; - alertTableView.dataSource = self; - alertTableView.tableFooterView = [[UIView alloc]initWithFrame:CGRectZero]; - [alertTableView setSeparatorStyle:UITableViewCellSeparatorStyleSingleLine]; - [controller.view addSubview:alertTableView]; - [controller.view bringSubviewToFront:alertTableView]; - [controller.view setUserInteractionEnabled:YES]; - [alertTableView setUserInteractionEnabled:YES]; - [alertTableView setAllowsSelection:YES]; -*/ - LoginListViewController *vc = [[LoginListViewController alloc] init]; [self.navigationController pushViewController:vc animated:YES]; } @@ -158,6 +205,7 @@ NSMutableArray *accountList; [accountList removeAllObjects]; } + // List accounts DIR *d; struct dirent *dir; d = opendir("/var/mobile/Documents/.pojavlauncher/accounts"); @@ -181,12 +229,7 @@ NSMutableArray *accountList; int width = (int) roundf(screenBounds.size.width); int height = (int) roundf(screenBounds.size.height) - self.navigationController.navigationBar.frame.size.height; - // self.view.frame = CGRectMake(width / 6, height / 6, width - width / 3, height); - - // UITableView *tableView = [[UITableView alloc]initWithFrame:self.view.frame]; - // tableView.tableFooterView = [[UIView alloc]initWithFrame:CGRectZero]; [self.tableView setSeparatorStyle:UITableViewCellSeparatorStyleSingleLine]; - // [self.view addSubview:tableView]; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section @@ -214,7 +257,12 @@ NSMutableArray *accountList; - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath { if (editingStyle == UITableViewCellEditingStyleDelete) { - // delete + NSString *str = [accountList objectAtIndex:indexPath.row]; + char accPath[1024]; + sprintf(accPath, "/var/mobile/Documents/.pojavlauncher/accounts/%s.json", [str UTF8String]); + remove(accPath); + [accountList removeObjectAtIndex:indexPath.row]; + [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade]; } } diff --git a/Natives/SurfaceViewController.m b/Natives/SurfaceViewController.m index a0e2011c..4f66de99 100644 --- a/Natives/SurfaceViewController.m +++ b/Natives/SurfaceViewController.m @@ -211,9 +211,9 @@ BOOL shouldTriggerClick = NO; } else { NSString *newText = [inputView.text substringFromIndex:2]; int charLength = [newText length]; - char *charText = [newText UTF8String]; + //char16_t *charText = [newText UTF16String]; for (int i = 0; i < charLength; i++) { - Java_org_lwjgl_glfw_CallbackBridge_nativeSendCharMods(NULL, NULL, (jchar) charText[i], /* mods */ 0); + Java_org_lwjgl_glfw_CallbackBridge_nativeSendCharMods(NULL, NULL, (jchar) [newText characterAtIndex:i] /* charText[i] */, /* mods */ 0); } } diff --git a/Natives/ios_uikit_bridge.m b/Natives/ios_uikit_bridge.m index ca211450..14d8056b 100644 --- a/Natives/ios_uikit_bridge.m +++ b/Natives/ios_uikit_bridge.m @@ -46,7 +46,8 @@ dispatch_async(dispatch_get_main_queue(), ^{ jboolean UIKit_updateProgress(float progress, const char* message) { dispatch_async(dispatch_get_main_queue(), ^{ install_progress_bar.progress = progress; - install_progress_text.text = [NSString stringWithUTF8String:message]; + install_progress_text.text = [[NSString alloc] initWithUTF8String:message]; + // @(message); }); return skipDownloadAssets; }