From 1af09ca02dc4a7eb296d9a67ccdfb0321e55fec2 Mon Sep 17 00:00:00 2001 From: Duy Tran Khanh Date: Thu, 17 Nov 2022 21:46:38 +0700 Subject: [PATCH] Tweak NSLocalizedString; Keep split display mode Tweak NSLocalizedString to return English if not yet localized. Keep Split display mode between rotations. New debug option: skip JIT wait, for #423 --- Natives/AccountListViewController.m | 4 +- ...CustomControlsViewController+UndoManager.m | 19 ++--- Natives/CustomControlsViewController.m | 78 +++++++++--------- Natives/JavaLauncher.m | 2 +- Natives/LauncherMenuViewController.m | 15 ++-- Natives/LauncherNavigationController.m | 26 +++--- Natives/LauncherPrefGameDirViewController.m | 21 ++--- Natives/LauncherPreferences.m | 1 + Natives/LauncherPreferencesViewController.m | 46 ++++++----- Natives/LauncherSplitViewController.m | 28 +++---- Natives/LoginViewController.m | 80 +++++++++---------- .../SurfaceViewController+ExternalDisplay.m | 2 +- Natives/SurfaceViewController+LogView.m | 9 ++- Natives/SurfaceViewController+Navigation.m | 9 ++- Natives/SurfaceViewController.m | 5 +- Natives/authenticator/BaseAuthenticator.m | 2 +- .../authenticator/MicrosoftAuthenticator.m | 16 ++-- Natives/en.lproj/Localizable.strings | 2 + Natives/ios_uikit_bridge.m | 2 +- Natives/utils.h | 1 + Natives/utils.m | 15 ++++ 21 files changed, 207 insertions(+), 176 deletions(-) diff --git a/Natives/AccountListViewController.m b/Natives/AccountListViewController.m index a2ff0d6e..08fcd3ff 100644 --- a/Natives/AccountListViewController.m +++ b/Natives/AccountListViewController.m @@ -63,9 +63,9 @@ if ([selected[@"username"] hasPrefix:@"Demo."]) { // Remove the prefix "Demo." cell.textLabel.text = [selected[@"username"] substringFromIndex:5]; - cell.detailTextLabel.text = NSLocalizedString(@"login.option.demo", nil); + cell.detailTextLabel.text = localize(@"login.option.demo", nil); } else if (selected[@"xboxGamertag"] == nil) { - cell.detailTextLabel.text = NSLocalizedString(@"login.option.local", nil); + cell.detailTextLabel.text = localize(@"login.option.local", nil); } else { // Display the Xbox gamertag for online accounts cell.detailTextLabel.text = selected[@"xboxGamertag"]; diff --git a/Natives/CustomControlsViewController+UndoManager.m b/Natives/CustomControlsViewController+UndoManager.m index ac8b6968..891378e3 100644 --- a/Natives/CustomControlsViewController+UndoManager.m +++ b/Natives/CustomControlsViewController+UndoManager.m @@ -1,6 +1,7 @@ #import "CustomControlsViewController.h" #import "customcontrols/ControlDrawer.h" #import "customcontrols/ControlLayout.h" +#import "utils.h" @implementation CustomControlsViewController(UndoManager) @@ -8,7 +9,7 @@ NSUndoManager *undo = self.undoManager; if ([button isKindOfClass:[ControlSubButton class]]) { - undo.actionName = NSLocalizedString(@"custom_controls.button_menu.add_subbutton", nil); + undo.actionName = localize(@"custom_controls.button_menu.add_subbutton", nil); [self.ctrlView addSubview:button]; ControlDrawer *drawer = ((ControlSubButton *)button).parentDrawer; @@ -16,7 +17,7 @@ [drawer.drawerData[@"buttonProperties"] insertObject:button.properties atIndex:index.intValue]; [drawer syncButtons]; } else if ([button isKindOfClass:[ControlDrawer class]]) { - undo.actionName = NSLocalizedString(@"custom_controls.control_menu.add_drawer", nil); + undo.actionName = localize(@"custom_controls.control_menu.add_drawer", nil); for (ControlSubButton *subButton in ((ControlDrawer *)button).buttons) { [self.ctrlView addSubview:subButton]; @@ -24,14 +25,14 @@ [self.cc_dictionary[@"mDrawerDataList"] insertObject:((ControlDrawer *)button).drawerData atIndex:index.intValue]; [self.ctrlView addSubview:button]; } else { - undo.actionName = NSLocalizedString(@"custom_controls.control_menu.add_button", nil); + undo.actionName = localize(@"custom_controls.control_menu.add_button", nil); [self.cc_dictionary[@"mControlDataList"] insertObject:button.properties atIndex:index.intValue]; [self.ctrlView addSubview:button]; } [[undo prepareWithInvocationTarget:self] doRemoveButton:button]; if (undo.isUndoing) { - undo.actionName = NSLocalizedString(@"Remove", nil); + undo.actionName = localize(@"Remove", nil); } } @@ -58,14 +59,14 @@ NSUndoManager *undo = self.undoManager; [[undo prepareWithInvocationTarget:self] undoRemoveButton:button atIndex:index]; if (!undo.isUndoing) { - undo.actionName = NSLocalizedString(@"Remove", nil); + undo.actionName = localize(@"Remove", nil); } } - (void)undoRemoveButton:(ControlButton *)button atIndex:(NSNumber *)index { NSUndoManager *undo = self.undoManager; if (!undo.isUndoing) { - undo.actionName = NSLocalizedString(@"Remove", nil); + undo.actionName = localize(@"Remove", nil); } [self doAddButton:button atIndex:index]; } @@ -76,9 +77,9 @@ [[undo prepareWithInvocationTarget:self] doMoveOrResizeButton:button from:to to:from]; if (!undo.isUndoing) { if (CGSizeEqualToSize(from.size, to.size)) { - undo.actionName = NSLocalizedString(@"Move", nil); + undo.actionName = localize(@"Move", nil); } else { - undo.actionName = NSLocalizedString(@"Resize", nil); + undo.actionName = localize(@"Resize", nil); } } @@ -94,7 +95,7 @@ NSUndoManager *undo = self.undoManager; [[undo prepareWithInvocationTarget:self] doUpdateButton:button from:to to:from]; if (!undo.isUndoing) { - undo.actionName = NSLocalizedString(@"Edit", nil); + undo.actionName = localize(@"Edit", nil); } for (NSString *key in to) { diff --git a/Natives/CustomControlsViewController.m b/Natives/CustomControlsViewController.m index 9a5294f8..3953321b 100644 --- a/Natives/CustomControlsViewController.m +++ b/Natives/CustomControlsViewController.m @@ -51,7 +51,7 @@ NSMutableArray *keyCodeMap, *keyValueMap; guideLabel.numberOfLines = 0; guideLabel.textAlignment = NSTextAlignmentCenter; guideLabel.textColor = UIColor.whiteColor; - guideLabel.text = NSLocalizedString(@"custom_controls.hint", nil); + guideLabel.text = localize(@"custom_controls.hint", nil); [self.view addSubview:guideLabel]; self.ctrlView = [[ControlLayout alloc] initWithFrame:CGRectFromString(getPreference(@"control_safe_area"))]; @@ -244,23 +244,23 @@ NSMutableArray *keyCodeMap, *keyValueMap; UIMenuController *menuController = [UIMenuController sharedMenuController]; if (![sender.view isKindOfClass:[ControlButton class]]) { - UIMenuItem *actionExit = [[UIMenuItem alloc] initWithTitle:NSLocalizedString(@"custom_controls.control_menu.exit", nil) action:@selector(actionMenuExit)]; - UIMenuItem *actionSave = [[UIMenuItem alloc] initWithTitle:NSLocalizedString(@"custom_controls.control_menu.save", nil) action:@selector(actionMenuSave)]; - UIMenuItem *actionLoad = [[UIMenuItem alloc] initWithTitle:NSLocalizedString(@"custom_controls.control_menu.load", nil) action:@selector(actionMenuLoad)]; - UIMenuItem *actionSetDef = [[UIMenuItem alloc] initWithTitle:NSLocalizedString(@"custom_controls.control_menu.make_default", nil) action:@selector(actionMenuSetDef)]; - UIMenuItem *actionSafeArea = [[UIMenuItem alloc] initWithTitle:NSLocalizedString(@"custom_controls.control_menu.safe_area", nil) action:@selector(actionMenuSafeArea)]; - UIMenuItem *actionAddButton = [[UIMenuItem alloc] initWithTitle:NSLocalizedString(@"custom_controls.control_menu.add_button", nil) action:@selector(actionMenuAddButton)]; - UIMenuItem *actionAddDrawer = [[UIMenuItem alloc] initWithTitle:NSLocalizedString(@"custom_controls.control_menu.add_drawer", nil) action:@selector(actionMenuAddDrawer)]; + UIMenuItem *actionExit = [[UIMenuItem alloc] initWithTitle:localize(@"custom_controls.control_menu.exit", nil) action:@selector(actionMenuExit)]; + UIMenuItem *actionSave = [[UIMenuItem alloc] initWithTitle:localize(@"custom_controls.control_menu.save", nil) action:@selector(actionMenuSave)]; + UIMenuItem *actionLoad = [[UIMenuItem alloc] initWithTitle:localize(@"custom_controls.control_menu.load", nil) action:@selector(actionMenuLoad)]; + UIMenuItem *actionSetDef = [[UIMenuItem alloc] initWithTitle:localize(@"custom_controls.control_menu.make_default", nil) action:@selector(actionMenuSetDef)]; + UIMenuItem *actionSafeArea = [[UIMenuItem alloc] initWithTitle:localize(@"custom_controls.control_menu.safe_area", nil) action:@selector(actionMenuSafeArea)]; + UIMenuItem *actionAddButton = [[UIMenuItem alloc] initWithTitle:localize(@"custom_controls.control_menu.add_button", nil) action:@selector(actionMenuAddButton)]; + UIMenuItem *actionAddDrawer = [[UIMenuItem alloc] initWithTitle:localize(@"custom_controls.control_menu.add_drawer", nil) action:@selector(actionMenuAddDrawer)]; [menuController setMenuItems:@[actionExit, actionSave, actionLoad, actionSetDef, actionSafeArea, actionAddButton, actionAddDrawer]]; CGPoint point = [sender locationInView:sender.view]; self.selectedPoint = CGRectMake(point.x, point.y, 1.0, 1.0); } else { - UIMenuItem *actionEdit = [[UIMenuItem alloc] initWithTitle:NSLocalizedString(@"Edit", nil) action:@selector(actionMenuBtnEdit)]; - UIMenuItem *actionCopy = [[UIMenuItem alloc] initWithTitle:NSLocalizedString(@"Copy", nil) action:@selector(actionMenuBtnCopy)]; - UIMenuItem *actionDelete = [[UIMenuItem alloc] initWithTitle:NSLocalizedString(@"Remove", nil) action:@selector(actionMenuBtnDelete)]; + UIMenuItem *actionEdit = [[UIMenuItem alloc] initWithTitle:localize(@"Edit", nil) action:@selector(actionMenuBtnEdit)]; + UIMenuItem *actionCopy = [[UIMenuItem alloc] initWithTitle:localize(@"Copy", nil) action:@selector(actionMenuBtnCopy)]; + UIMenuItem *actionDelete = [[UIMenuItem alloc] initWithTitle:localize(@"Remove", nil) action:@selector(actionMenuBtnDelete)]; if ([sender.view isKindOfClass:[ControlDrawer class]]) { - UIMenuItem *actionAddSubButton = [[UIMenuItem alloc] initWithTitle:NSLocalizedString(@"custom_controls.button_menu.add_subbutton", nil) action:@selector(actionMenuAddSubButton)]; + UIMenuItem *actionAddSubButton = [[UIMenuItem alloc] initWithTitle:localize(@"custom_controls.button_menu.add_subbutton", nil) action:@selector(actionMenuAddSubButton)]; [menuController setMenuItems:@[actionEdit, /* actionCopy, */ actionDelete, actionAddSubButton]]; } else { [menuController setMenuItems:@[actionEdit, /* actionCopy, */ actionDelete]]; @@ -286,8 +286,8 @@ NSMutableArray *keyCodeMap, *keyValueMap; } - (void)actionMenuSaveWithExit:(BOOL)exit { - UIAlertController *controller = [UIAlertController alertControllerWithTitle: NSLocalizedString(@"custom_controls.control_menu.save", nil) - message:exit?NSLocalizedString(@"custom_controls.control_menu.exit.warn", nil):@"" + UIAlertController *controller = [UIAlertController alertControllerWithTitle: localize(@"custom_controls.control_menu.save", nil) + message:exit?localize(@"custom_controls.control_menu.exit.warn", nil):@"" preferredStyle:UIAlertControllerStyleAlert]; [controller addTextFieldWithConfigurationHandler:^(UITextField *textField) { textField.placeholder = @"Name"; @@ -295,22 +295,22 @@ NSMutableArray *keyCodeMap, *keyValueMap; textField.clearButtonMode = UITextFieldViewModeWhileEditing; textField.borderStyle = UITextBorderStyleRoundedRect; }]; - [controller addAction:[UIAlertAction actionWithTitle:NSLocalizedString(@"OK", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) { + [controller addAction:[UIAlertAction actionWithTitle:localize(@"OK", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) { NSArray *textFields = controller.textFields; UITextField *field = textFields[0]; if ([field.text isEqualToString:@"default"]) { - controller.message = NSLocalizedString(@"custom_controls.control_menu.save.error.default", nil); + controller.message = localize(@"custom_controls.control_menu.save.error.default", nil); [self presentViewController:controller animated:YES completion:nil]; } else { NSError *error; NSData *jsonData = [NSJSONSerialization dataWithJSONObject:self.cc_dictionary options:NSJSONWritingPrettyPrinted error:&error]; if (jsonData == nil) { - showDialog(self, NSLocalizedString(@"custom_controls.control_menu.save.error.json", nil), error.localizedDescription); + showDialog(self, localize(@"custom_controls.control_menu.save.error.json", nil), error.localizedDescription); return; } BOOL success = [jsonData writeToFile:[NSString stringWithFormat:@"%s/controlmap/%@.json", getenv("POJAV_HOME"), field.text] options:NSDataWritingAtomic error:&error]; if (!success) { - showDialog(self, NSLocalizedString(@"custom_controls.control_menu.save.error.write", nil), error.localizedDescription); + showDialog(self, localize(@"custom_controls.control_menu.save.error.write", nil), error.localizedDescription); return; } @@ -323,11 +323,11 @@ NSMutableArray *keyCodeMap, *keyValueMap; } }]]; if (exit) { - [controller addAction:[UIAlertAction actionWithTitle:NSLocalizedString(@"custom_controls.control_menu.discard_changes", nil) style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) { + [controller addAction:[UIAlertAction actionWithTitle:localize(@"custom_controls.control_menu.discard_changes", nil) style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) { [self dismissViewControllerAnimated:YES completion:nil]; }]]; } - [controller addAction:[UIAlertAction actionWithTitle:NSLocalizedString(@"Cancel", nil) style:UIAlertActionStyleCancel handler:nil]]; + [controller addAction:[UIAlertAction actionWithTitle:localize(@"Cancel", nil) style:UIAlertActionStyleCancel handler:nil]]; [self presentViewController:controller animated:YES completion:nil]; } @@ -463,9 +463,9 @@ NSMutableArray *keyCodeMap, *keyValueMap; } - (void)actionMenuBtnDelete { - UIAlertController *alert = [UIAlertController alertControllerWithTitle:((ControlButton *)self.currentGesture.view).currentTitle message:NSLocalizedString(@"custom_controls.button_menu.remove", nil) preferredStyle:UIAlertControllerStyleAlert]; - UIAlertAction *cancel = [UIAlertAction actionWithTitle:NSLocalizedString(@"Cancel", nil) style:UIAlertActionStyleCancel handler:nil]; - UIAlertAction *ok = [UIAlertAction actionWithTitle:NSLocalizedString(@"OK", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) { + UIAlertController *alert = [UIAlertController alertControllerWithTitle:((ControlButton *)self.currentGesture.view).currentTitle message:localize(@"custom_controls.button_menu.remove", nil) preferredStyle:UIAlertControllerStyleAlert]; + UIAlertAction *cancel = [UIAlertAction actionWithTitle:localize(@"Cancel", nil) style:UIAlertActionStyleCancel handler:nil]; + UIAlertAction *ok = [UIAlertAction actionWithTitle:localize(@"OK", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) { self.resizeView.hidden = YES; ControlButton *button = (ControlButton *)self.currentGesture.view; [self doRemoveButton:button]; @@ -816,17 +816,17 @@ CGFloat currentY; // Property: Name - UILabel *labelName = [self addLabel:NSLocalizedString(@"custom_controls.button_edit.name", nil)]; + UILabel *labelName = [self addLabel:localize(@"custom_controls.button_edit.name", nil)]; self.editName = [[UITextField alloc] initWithFrame:CGRectMake(labelName.frame.size.width + 5.0, currentY, width - labelName.frame.size.width - 5.0, labelName.frame.size.height)]; [self.editName addTarget:self.editName action:@selector(resignFirstResponder) forControlEvents:UIControlEventEditingDidEndOnExit]; - self.editName.placeholder = NSLocalizedString(@"custom_controls.button_edit.name", nil); + self.editName.placeholder = localize(@"custom_controls.button_edit.name", nil); self.editName.text = self.targetButton.properties[@"name"]; [self.scrollView addSubview:self.editName]; if (![self.targetButton isKindOfClass:[ControlSubButton class]]) { // Property: Size currentY += labelName.frame.size.height + 12.0; - UILabel *labelSize = [self addLabel:NSLocalizedString(@"custom_controls.button_edit.size", nil)]; + UILabel *labelSize = [self addLabel:localize(@"custom_controls.button_edit.size", nil)]; // width / 2.0 + (labelSize.frame.size.width + 4.0) / 2.0 CGFloat editSizeWidthValue = (width - labelSize.frame.size.width) / 2 - labelSize.frame.size.height / 2; UILabel *labelSizeX = [[UILabel alloc] initWithFrame:CGRectMake(labelSize.frame.size.width + editSizeWidthValue, labelSize.frame.origin.y, labelSize.frame.size.height, labelSize.frame.size.height)]; @@ -852,7 +852,7 @@ CGFloat currentY; currentY += labelName.frame.size.height + 12.0; if (![self.targetButton isKindOfClass:[ControlDrawer class]]) { // Property: Mapping - UILabel *labelMapping = [self addLabel:NSLocalizedString(@"custom_controls.button_edit.mapping", nil)]; + UILabel *labelMapping = [self addLabel:localize(@"custom_controls.button_edit.mapping", nil)]; self.editMapping = [[UITextView alloc] initWithFrame:CGRectMake(0,0,1,1)]; self.editMapping.text = @"\n\n\n"; @@ -876,7 +876,7 @@ CGFloat currentY; } else { // Property: Orientation self.arrOrientation = @[@"DOWN", @"LEFT", @"UP", @"RIGHT", @"FREE"]; - UILabel *labelOrientation = [self addLabel:NSLocalizedString(@"custom_controls.button_edit.orientation", nil)]; + UILabel *labelOrientation = [self addLabel:localize(@"custom_controls.button_edit.orientation", nil)]; self.ctrlOrientation = [[UISegmentedControl alloc] initWithItems:self.arrOrientation]; self.ctrlOrientation.frame = CGRectMake(labelOrientation.frame.size.width + 5.0, currentY - 5.0, width - labelOrientation.frame.size.width - 5.0, 30.0); self.ctrlOrientation.selectedSegmentIndex = [self.arrOrientation indexOfObject: @@ -887,7 +887,7 @@ CGFloat currentY; // Property: Toggleable - UILabel *labelToggleable = [self addLabel:NSLocalizedString(@"custom_controls.button_edit.toggleable", nil)]; + UILabel *labelToggleable = [self addLabel:localize(@"custom_controls.button_edit.toggleable", nil)]; self.switchToggleable = [[UISwitch alloc] initWithFrame:CGRectMake(width - 62.0, currentY - 5.0, 50.0, 30)]; [self.switchToggleable setOn:[self.targetButton.properties[@"isToggle"] boolValue] animated:NO]; [self.scrollView addSubview:self.switchToggleable]; @@ -895,7 +895,7 @@ CGFloat currentY; // Property: Mouse pass currentY += labelName.frame.size.height + 12.0; - UILabel *labelMousePass = [self addLabel:NSLocalizedString(@"custom_controls.button_edit.mouse_pass", nil)]; + UILabel *labelMousePass = [self addLabel:localize(@"custom_controls.button_edit.mouse_pass", nil)]; self.switchMousePass = [[UISwitch alloc] initWithFrame:CGRectMake(width - 62.0, currentY - 5.0, 50.0, 30)]; [self.switchMousePass setOn:[self.targetButton.properties[@"passThruEnabled"] boolValue]]; [self.scrollView addSubview:self.switchMousePass]; @@ -903,7 +903,7 @@ CGFloat currentY; // Property: Swipeable currentY += labelName.frame.size.height + 12.0; - UILabel *labelSwipeable = [self addLabel:NSLocalizedString(@"custom_controls.button_edit.swipeable", nil)]; + UILabel *labelSwipeable = [self addLabel:localize(@"custom_controls.button_edit.swipeable", nil)]; self.switchSwipeable = [[UISwitch alloc] initWithFrame:CGRectMake(width - 62.0, currentY - 5.0, 50.0, 30)]; [self.switchSwipeable setOn:[self.targetButton.properties[@"isSwipeable"] boolValue]]; [self.scrollView addSubview:self.switchSwipeable]; @@ -911,7 +911,7 @@ CGFloat currentY; // Property: Background color currentY += labelName.frame.size.height + 12.0; - UILabel *labelBGColor = [self addLabel:NSLocalizedString(@"custom_controls.button_edit.bg_color", nil)]; + UILabel *labelBGColor = [self addLabel:localize(@"custom_controls.button_edit.bg_color", nil)]; if(@available(iOS 14.0, *)) { self.colorWellINTBackground = [[UIColorWell alloc] initWithFrame:CGRectMake(width - 42.0, currentY - 5.0, 30.0, 30.0)]; self.colorWellINTBackground.selectedColor = self.targetButton.backgroundColor; @@ -932,7 +932,7 @@ CGFloat currentY; // Property: Stroke width currentY += labelName.frame.size.height + 12.0; - UILabel *labelStrokeWidth = [self addLabel:NSLocalizedString(@"custom_controls.button_edit.stroke_width", nil)]; + UILabel *labelStrokeWidth = [self addLabel:localize(@"custom_controls.button_edit.stroke_width", nil)]; self.sliderStrokeWidth = [[DBNumberedSlider alloc] initWithFrame:CGRectMake(labelStrokeWidth.frame.size.width + 5.0, currentY - 5.0, width - labelStrokeWidth.frame.size.width - 5.0, 30.0)]; self.sliderStrokeWidth.continuous = YES; self.sliderStrokeWidth.maximumValue = 100; @@ -944,7 +944,7 @@ CGFloat currentY; // Property: Stroke color currentY += labelName.frame.size.height + 12.0; - UILabel *labelStrokeColor = [self addLabel:NSLocalizedString(@"custom_controls.button_edit.stroke_color", nil)]; + UILabel *labelStrokeColor = [self addLabel:localize(@"custom_controls.button_edit.stroke_color", nil)]; if(@available(iOS 14.0, *)) { self.colorWellINTStroke = [[UIColorWell alloc] initWithFrame:CGRectMake(width - 42.0, currentY - 5.0, 30.0, 30.0)]; self.colorWellINTStroke.selectedColor = [[UIColor alloc] initWithCGColor:self.targetButton.layer.borderColor]; @@ -960,7 +960,7 @@ CGFloat currentY; // Property: Corner radius currentY += labelName.frame.size.height + 12.0; - UILabel *labelCornerRadius = [self addLabel:NSLocalizedString(@"custom_controls.button_edit.corner_radius", nil)]; + UILabel *labelCornerRadius = [self addLabel:localize(@"custom_controls.button_edit.corner_radius", nil)]; self.sliderCornerRadius = [[DBNumberedSlider alloc] initWithFrame:CGRectMake(labelCornerRadius.frame.size.width + 5.0, currentY - 5.0, width - labelCornerRadius.frame.size.width - 5.0, 30.0)]; self.sliderCornerRadius.continuous = NO; self.sliderCornerRadius.maximumValue = 100; @@ -972,7 +972,7 @@ CGFloat currentY; // Property: Button Opacity currentY += labelName.frame.size.height + 12.0; - UILabel *labelOpacity = [self addLabel:NSLocalizedString(@"custom_controls.button_edit.opacity", nil)]; + UILabel *labelOpacity = [self addLabel:localize(@"custom_controls.button_edit.opacity", nil)]; self.sliderOpacity = [[DBNumberedSlider alloc] initWithFrame:CGRectMake(labelOpacity.frame.size.width + 5.0, currentY - 5.0, width - labelOpacity.frame.size.width - 5.0, 30.0)]; self.sliderOpacity.continuous = NO; self.sliderOpacity.minimumValue = 1; @@ -987,7 +987,7 @@ CGFloat currentY; [((ControlSubButton *)self.targetButton).parentDrawer.drawerData[@"orientation"] isEqualToString:@"FREE"]) { // Property: Dynamic position currentY += labelName.frame.size.height + 12.0; - UILabel *labelDynamicPos = [self addLabel:NSLocalizedString(@"custom_controls.button_edit.dynamic_position", nil)]; + UILabel *labelDynamicPos = [self addLabel:localize(@"custom_controls.button_edit.dynamic_position", nil)]; self.switchDynamicPos = [[UISwitch alloc] initWithFrame:CGRectMake(width - 62.0, currentY - 5.0, 50.0, 30)]; self.switchDynamicPos.tag = TAG_SWITCH_DYNAMICPOS; [self.switchDynamicPos setOn:[self.targetButton.properties[@"isDynamicBtn"] boolValue] animated:NO]; @@ -997,7 +997,7 @@ CGFloat currentY; // Property: Dynamic X-axis currentY += labelName.frame.size.height + 12.0; - UILabel *labelDynamicX = [self addLabel:NSLocalizedString(@"custom_controls.button_edit.dynamic_x", nil)]; + UILabel *labelDynamicX = [self addLabel:localize(@"custom_controls.button_edit.dynamic_x", nil)]; self.editDynamicX = [[UITextField alloc] initWithFrame:CGRectMake(labelDynamicX.frame.size.width + 5.0, currentY, width - labelDynamicX.frame.size.width - 5.0, labelDynamicX.frame.size.height)]; [self.editDynamicX addTarget:self.editDynamicX action:@selector(resignFirstResponder) forControlEvents:UIControlEventEditingDidEndOnExit]; self.editDynamicX.text = self.targetButton.properties[@"dynamicX"]; @@ -1006,7 +1006,7 @@ CGFloat currentY; // Property: Dynamic Y-axis currentY += labelName.frame.size.height + 12.0; - UILabel *labelDynamicY = [self addLabel:NSLocalizedString(@"custom_controls.button_edit.dynamic_y", nil)]; + UILabel *labelDynamicY = [self addLabel:localize(@"custom_controls.button_edit.dynamic_y", nil)]; self.editDynamicY = [[UITextField alloc] initWithFrame:CGRectMake(labelDynamicY.frame.size.width + 5.0, currentY, width - labelDynamicY.frame.size.width - 5.0, labelDynamicY.frame.size.height)]; [self.editDynamicY addTarget:self.editDynamicY action:@selector(resignFirstResponder) forControlEvents:UIControlEventEditingDidEndOnExit]; self.editDynamicY.text = self.targetButton.properties[@"dynamicY"]; diff --git a/Natives/JavaLauncher.m b/Natives/JavaLauncher.m index dfdcb580..5bbddc33 100644 --- a/Natives/JavaLauncher.m +++ b/Natives/JavaLauncher.m @@ -114,7 +114,7 @@ NSString* environmentFailsafes(int minVersion) { } if (javaHome == nil) { - showDialog(currentVC(), NSLocalizedString(@"Error", nil), [NSString stringWithFormat:@"Minecraft %@ requires Java %d in order to run. Please install it first.", getPreference(@"selected_version"), minVersion]); + showDialog(currentVC(), localize(@"Error", nil), [NSString stringWithFormat:@"Minecraft %@ requires Java %d in order to run. Please install it first.", getPreference(@"selected_version"), minVersion]); } return javaHome; diff --git a/Natives/LauncherMenuViewController.m b/Natives/LauncherMenuViewController.m index 6f9128a1..c7058f4e 100644 --- a/Natives/LauncherMenuViewController.m +++ b/Natives/LauncherMenuViewController.m @@ -5,6 +5,7 @@ #import "LauncherPreferencesViewController.h" #import "UIButton+AFNetworking.h" #import "UIImageView+AFNetworking.h" +#import "utils.h" @interface LauncherMenuViewController () { } @@ -22,8 +23,8 @@ [[LauncherNewsViewController alloc] init], [[LauncherPreferencesViewController alloc] init] ]; - self.options[0].title = NSLocalizedString(@"News", nil); - self.options[1].title = NSLocalizedString(@"Settings", nil); + self.options[0].title = localize(@"News", nil); + self.options[1].title = localize(@"Settings", nil); //@[@"News", @"Development Console", @"Crash logs"]; self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone; @@ -46,6 +47,9 @@ [self updateAccountInfo]; [self tableView:self.tableView didSelectRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]]; + + // Put a close button, as iOS does not have a dedicated back button + self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"❌" style:UIBarButtonItemStyleDone target:self.splitViewController action:@selector(dismissViewController)]; } - (void)viewWillAppear:(BOOL)animated { @@ -90,9 +94,6 @@ selected.navigationItem.leftBarButtonItem = self.splitViewController.displayModeButtonItem; selected.navigationItem.leftItemsSupplementBackButton = true; } - - // Put a close button, as iOS does not have a dedicated back button - self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"❌" style:UIBarButtonItemStyleDone target:self.splitViewController action:@selector(dismissViewController)]; } - (void)selectAccount:(UIButton *)sender { @@ -120,9 +121,9 @@ id subtitle; if (isDemo) { // Remove the prefix "Demo." - subtitle = NSLocalizedString(@"login.option.demo", nil); + subtitle = localize(@"login.option.demo", nil); } else if (selected[@"xboxGamertag"] == nil) { - subtitle = NSLocalizedString(@"login.option.local", nil); + subtitle = localize(@"login.option.local", nil); } else { // Display the Xbox gamertag for online accounts subtitle = selected[@"xboxGamertag"]; diff --git a/Natives/LauncherNavigationController.m b/Natives/LauncherNavigationController.m index dda5e676..bbf17155 100644 --- a/Natives/LauncherNavigationController.m +++ b/Natives/LauncherNavigationController.m @@ -44,11 +44,11 @@ int versionSelectedAt = 0; UIToolbar *versionPickToolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0.0, 0.0, self.view.frame.size.width, 44.0)]; UISegmentedControl *versionTypeControl = [[UISegmentedControl alloc] initWithItems:@[ - NSLocalizedString(@"Installed", nil), - NSLocalizedString(@"Releases", nil), - NSLocalizedString(@"Snapshot", nil), - NSLocalizedString(@"Old-beta", nil), - NSLocalizedString(@"Old-alpha", nil) + localize(@"Installed", nil), + localize(@"Releases", nil), + localize(@"Snapshot", nil), + localize(@"Old-beta", nil), + localize(@"Old-alpha", nil) ]]; versionTypeControl.selectedSegmentIndex = [getPreference(@"selected_version_type") intValue]; [versionTypeControl addTarget:self action:@selector(changeVersionType:) forControlEvents:UIControlEventValueChanged]; @@ -73,7 +73,7 @@ int versionSelectedAt = 0; self.buttonInstall = [UIButton buttonWithType:UIButtonTypeSystem]; setButtonPointerInteraction(self.buttonInstall); self.buttonInstall.enabled = NO; - [self.buttonInstall setTitle:NSLocalizedString(@"Play", nil) forState:UIControlStateNormal]; + [self.buttonInstall setTitle:localize(@"Play", nil) forState:UIControlStateNormal]; self.buttonInstall.autoresizingMask = AUTORESIZE_MASKS; self.buttonInstall.backgroundColor = [UIColor colorWithRed:54/255.0 green:176/255.0 blue:48/255.0 alpha:1.0]; self.buttonInstall.layer.cornerRadius = 5; @@ -84,7 +84,7 @@ int versionSelectedAt = 0; UIButton *buttonCustomControls = [UIButton buttonWithType:UIButtonTypeSystem]; setButtonPointerInteraction(buttonCustomControls); - [buttonCustomControls setTitle:NSLocalizedString(@"launcher.menu.custom_controls", nil) forState:UIControlStateNormal]; + [buttonCustomControls setTitle:localize(@"launcher.menu.custom_controls", nil) forState:UIControlStateNormal]; buttonCustomControls.autoresizingMask = AUTORESIZE_MASKS; buttonCustomControls.frame = CGRectMake(0, self.toolbar.frame.size.height/2, splitWidth, self.toolbar.frame.size.height/2); [buttonCustomControls addTarget:self action:@selector(enterCustomControls) forControlEvents:UIControlEventTouchUpInside]; @@ -92,7 +92,7 @@ int versionSelectedAt = 0; UIButton *buttonInstallJar = [UIButton buttonWithType:UIButtonTypeSystem]; setButtonPointerInteraction(buttonInstallJar); - [buttonInstallJar setTitle:NSLocalizedString(@"launcher.menu.install_jar", nil) forState:UIControlStateNormal]; + [buttonInstallJar setTitle:localize(@"launcher.menu.install_jar", nil) forState:UIControlStateNormal]; buttonInstallJar.autoresizingMask = AUTORESIZE_MASKS; buttonInstallJar.frame = CGRectMake(splitWidth*2, self.toolbar.frame.size.height/2, splitWidth, self.toolbar.frame.size.height/2); [buttonInstallJar addTarget:self action:@selector(enterModInstaller) forControlEvents:UIControlEventTouchUpInside]; @@ -278,15 +278,19 @@ int versionSelectedAt = 0; if (isJITEnabled()) { handler(); return; + } else if ([getPreference(@"debug_skip_wait_jit") boolValue]) { + NSLog(@"Debug option skipped waiting for JIT. Java might not work."); + handler(); + return; } CADisplayLink *displayLink = [CADisplayLink displayLinkWithTarget:self selector:@selector(tickJIT)]; - UIAlertController* alert = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"launcher.wait_jit.title", nil) - message:NSLocalizedString(@"launcher.wait_jit.message", nil) + UIAlertController* alert = [UIAlertController alertControllerWithTitle:localize(@"launcher.wait_jit.title", nil) + message:localize(@"launcher.wait_jit.message", nil) preferredStyle:UIAlertControllerStyleAlert]; /* TODO: - UIAlertAction *cancel = [UIAlertAction actionWithTitle:NSLocalizedString(@"Cancel", nil) style:UIAlertActionStyleCancel handler:^{ + UIAlertAction *cancel = [UIAlertAction actionWithTitle:localize(@"Cancel", nil) style:UIAlertActionStyleCancel handler:^{ }]; [alert addAction:cancel]; diff --git a/Natives/LauncherPrefGameDirViewController.m b/Natives/LauncherPrefGameDirViewController.m index 0488b036..cb52d450 100644 --- a/Natives/LauncherPrefGameDirViewController.m +++ b/Natives/LauncherPrefGameDirViewController.m @@ -3,6 +3,7 @@ #import "LauncherPrefGameDirViewController.h" #import "TOInsetGroupedTableView.h" #import "ios_uikit_bridge.h" +#import "utils.h" @interface LauncherPrefGameDirViewController () @property(nonatomic) NSMutableArray *array; @@ -13,7 +14,7 @@ - (void)viewDidLoad { [super viewDidLoad]; - [self setTitle:NSLocalizedString(@"preference.title.game_directory", nil)]; + [self setTitle:localize(@"preference.title.game_directory", nil)]; self.array = [[NSMutableArray alloc] init]; [self.array addObject:@"default"]; @@ -87,7 +88,7 @@ viewForFooterInSection:(NSInteger)section view.autocorrectionType = UITextAutocorrectionTypeNo; view.autocapitalizationType = UITextAutocapitalizationTypeNone; view.delegate = self; - view.placeholder = NSLocalizedString(@"preference.multidir.add_directory", nil); + view.placeholder = localize(@"preference.multidir.add_directory", nil); view.returnKeyType = UIReturnKeyDone; return view; } @@ -168,7 +169,7 @@ viewForFooterInSection:(NSInteger)section menuItems = @[open]; } else { UIAction *rename = [UIAction - actionWithTitle:NSLocalizedString(@"Rename", nil) + actionWithTitle:localize(@"Rename", nil) image:[UIImage systemImageNamed:@"pencil"] identifier:nil handler:^(UIAction *action) { @@ -178,7 +179,7 @@ viewForFooterInSection:(NSInteger)section ]; UIAction *delete = [UIAction - actionWithTitle:NSLocalizedString(@"Delete", nil) + actionWithTitle:localize(@"Delete", nil) image:[UIImage systemImageNamed:@"trash"] identifier:nil handler:^(UIAction *action) { @@ -219,12 +220,12 @@ viewForFooterInSection:(NSInteger)section - (void)actionDeleteAtIndexPath:(NSIndexPath *)indexPath { UITableViewCell *view = [self.tableView cellForRowAtIndexPath:indexPath]; - NSString *title = NSLocalizedString(@"preference.title.confirm", nil); - NSString *message = [NSString stringWithFormat:NSLocalizedString(@"preference.title.confirm.delete_game_directory", nil), self.array[indexPath.row]]; + NSString *title = localize(@"preference.title.confirm", nil); + NSString *message = [NSString stringWithFormat:localize(@"preference.title.confirm.delete_game_directory", nil), self.array[indexPath.row]]; UIAlertController *confirmAlert = [UIAlertController alertControllerWithTitle:title message:message preferredStyle:UIAlertControllerStyleActionSheet]; confirmAlert.popoverPresentationController.sourceView = view; confirmAlert.popoverPresentationController.sourceRect = view.bounds; - UIAlertAction *ok = [UIAlertAction actionWithTitle:NSLocalizedString(@"OK", nil) style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) { + UIAlertAction *ok = [UIAlertAction actionWithTitle:localize(@"OK", nil) style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) { NSString *directory = [NSString stringWithFormat:@"%s/instances/%@", getenv("POJAV_HOME"), self.array[indexPath.row]]; NSError *error; if([NSFileManager.defaultManager removeItemAtPath:directory error:&error]) { @@ -235,10 +236,10 @@ viewForFooterInSection:(NSInteger)section [self.array removeObjectAtIndex:indexPath.row]; [self.tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade]; } else { - showDialog(self, NSLocalizedString(@"Error", nil), error.localizedDescription); + showDialog(self, localize(@"Error", nil), error.localizedDescription); } }]; - UIAlertAction *cancel = [UIAlertAction actionWithTitle:NSLocalizedString(@"Cancel", nil) style:UIAlertActionStyleCancel handler:nil]; + UIAlertAction *cancel = [UIAlertAction actionWithTitle:localize(@"Cancel", nil) style:UIAlertActionStyleCancel handler:nil]; [confirmAlert addAction:cancel]; [confirmAlert addAction:ok]; [self presentViewController:confirmAlert animated:YES completion:nil]; @@ -288,7 +289,7 @@ viewForFooterInSection:(NSInteger)section if (!isFooterView) { sender.text = sender.placeholder; } - showDialog(self, NSLocalizedString(@"Error", nil), error.localizedDescription); + showDialog(self, localize(@"Error", nil), error.localizedDescription); } } diff --git a/Natives/LauncherPreferences.m b/Natives/LauncherPreferences.m index ef10f293..0d46caf6 100644 --- a/Natives/LauncherPreferences.m +++ b/Natives/LauncherPreferences.m @@ -139,6 +139,7 @@ void loadPreferences(BOOL reset) { setDefaultValueForPref(prefDict, @"unsupported_warn_counter", @(0)); // Debug settings + setDefaultValueForPref(debugPrefDict, @"debug_skip_wait_jit", @NO); setDefaultValueForPref(debugPrefDict, @"debug_ipad_ui", @(UIDevice.currentDevice.userInterfaceIdiom == UIUserInterfaceIdiomPad)); setDefaultValueForPref(debugPrefDict, @"debug_show_layout_bounds", @NO); setDefaultValueForPref(debugPrefDict, @"debug_show_layout_overlap", @NO); diff --git a/Natives/LauncherPreferencesViewController.m b/Natives/LauncherPreferencesViewController.m index 23db43ea..16a43751 100644 --- a/Natives/LauncherPreferencesViewController.m +++ b/Natives/LauncherPreferencesViewController.m @@ -7,7 +7,7 @@ #import "LauncherPrefGameDirViewController.h" #import "TOInsetGroupedTableView.h" -#include "utils.h" +#import "utils.h" typedef void(^CreateView)(UITableViewCell *, NSString *, NSDictionary *); @@ -112,10 +112,10 @@ typedef void(^CreateView)(UITableViewCell *, NSString *, NSDictionary *); @ RENDERER_NAME_VK_ZINK ], @"pickList": @[ - NSLocalizedString(@"preference.title.renderer.auto", nil), - NSLocalizedString(@"preference.title.renderer.gl4es", nil), - NSLocalizedString(@"preference.title.renderer.tinygl4angle", nil), - NSLocalizedString(@"preference.title.renderer.zink", nil) + localize(@"preference.title.renderer.auto", nil), + localize(@"preference.title.renderer.gl4es", nil), + localize(@"preference.title.renderer.tinygl4angle", nil), + localize(@"preference.title.renderer.zink", nil) ] }, @{@"key": @"resolution", @@ -213,6 +213,12 @@ typedef void(^CreateView)(UITableViewCell *, NSString *, NSDictionary *); } ], @[ // Debug settings - only recommended for developer use + @{@"key": @"debug_skip_wait_jit", + @"hasDetail": @YES, + @"icon": @"forward", + @"type": self.typeSwitch, + @"enableCondition": whenNotInGame + }, @{@"key": @"debug_ipad_ui", @"hasDetail": @YES, @"icon": @"ipad", @@ -241,7 +247,7 @@ typedef void(^CreateView)(UITableViewCell *, NSString *, NSDictionary *); if (@available(iOS 13.0, *)) { helpButton = [[UIBarButtonItem alloc] initWithImage:[UIImage systemImageNamed:@"questionmark.circle"] style:UIBarButtonItemStyleDone target:self action:@selector(toggleDetailVisibility)]; } else { - helpButton = [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"Help", nil) style:UIBarButtonItemStyleDone target:self action:@selector(toggleDetailVisibility)]; + helpButton = [[UIBarButtonItem alloc] initWithTitle:localize(@"Help", nil) style:UIBarButtonItemStyleDone target:self action:@selector(toggleDetailVisibility)]; } self.navigationItem.rightBarButtonItems = @[helpButton]; } @@ -280,7 +286,7 @@ typedef void(^CreateView)(UITableViewCell *, NSString *, NSDictionary *); } - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section { - return NSLocalizedString(([NSString stringWithFormat:@"preference.section.%@", self.prefSections[section]]), nil); + return localize(([NSString stringWithFormat:@"preference.section.%@", self.prefSections[section]]), nil); } - (NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section { @@ -335,9 +341,9 @@ typedef void(^CreateView)(UITableViewCell *, NSString *, NSDictionary *); cell.imageView.tintColor = destructive ? UIColor.systemRedColor : nil; cell.imageView.image = [UIImage systemImageNamed:item[@"icon"]]; } - cell.textLabel.text = NSLocalizedString(([NSString stringWithFormat:@"preference.title.%@", key]), nil); + cell.textLabel.text = localize(([NSString stringWithFormat:@"preference.title.%@", key]), nil); if ([item[@"hasDetail"] boolValue] && self.prefDetailVisible) { - cell.detailTextLabel.text = NSLocalizedString(([NSString stringWithFormat:@"preference.detail.%@", key]), nil); + cell.detailTextLabel.text = localize(([NSString stringWithFormat:@"preference.detail.%@", key]), nil); } else if (cellStyle != UITableViewCellStyleValue1) { cell.detailTextLabel.text = nil; } @@ -375,7 +381,7 @@ typedef void(^CreateView)(UITableViewCell *, NSString *, NSDictionary *); view.autocapitalizationType = UITextAutocapitalizationTypeNone; view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleLeftMargin; view.delegate = weakSelf; - view.placeholder = NSLocalizedString(([NSString stringWithFormat:@"preference.placeholder.%@", key]), nil); + view.placeholder = localize(([NSString stringWithFormat:@"preference.placeholder.%@", key]), nil); view.returnKeyType = UIReturnKeyDone; view.text = getPreference(key); view.textAlignment = NSTextAlignmentRight; @@ -417,7 +423,7 @@ typedef void(^CreateView)(UITableViewCell *, NSString *, NSDictionary *); UIAlertController *alert = [UIAlertController alertControllerWithTitle:title message:message preferredStyle:UIAlertControllerStyleActionSheet]; alert.popoverPresentationController.sourceView = view; alert.popoverPresentationController.sourceRect = view.bounds; - UIAlertAction *ok = [UIAlertAction actionWithTitle:NSLocalizedString(@"OK", nil) style:UIAlertActionStyleCancel handler:nil]; + UIAlertAction *ok = [UIAlertAction actionWithTitle:localize(@"OK", nil) style:UIAlertActionStyleCancel handler:nil]; [alert addAction:ok]; [self presentViewController:alert animated:YES completion:nil]; } @@ -436,8 +442,8 @@ typedef void(^CreateView)(UITableViewCell *, NSString *, NSDictionary *); setPreference(warnKey, @NO); } - NSString *message = NSLocalizedString(([NSString stringWithFormat:@"preference.warn.%@", key]), nil); - [self showAlertOnView:view title:NSLocalizedString(@"Warning", nil) message:message]; + NSString *message = localize(([NSString stringWithFormat:@"preference.warn.%@", key]), nil); + [self showAlertOnView:view title:localize(@"Warning", nil) message:message]; } } @@ -532,7 +538,7 @@ typedef void(^CreateView)(UITableViewCell *, NSString *, NSDictionary *); picker.popoverPresentationController.sourceView = cell; picker.popoverPresentationController.sourceRect = cell.bounds; - UIAlertAction *cancel = [UIAlertAction actionWithTitle:NSLocalizedString(@"Cancel", nil) style:UIAlertActionStyleCancel handler:nil]; + UIAlertAction *cancel = [UIAlertAction actionWithTitle:localize(@"Cancel", nil) style:UIAlertActionStyleCancel handler:nil]; [picker addAction:cancel]; [self presentViewController:picker animated:YES completion:nil]; @@ -545,15 +551,15 @@ typedef void(^CreateView)(UITableViewCell *, NSString *, NSDictionary *); if ([item[@"showConfirmPrompt"] boolValue]) { BOOL destructive = [item[@"destructive"] boolValue]; - NSString *title = NSLocalizedString(@"preference.title.confirm", nil); - NSString *message = NSLocalizedString(([NSString stringWithFormat:@"preference.title.confirm.%@", key]), nil); + NSString *title = localize(@"preference.title.confirm", nil); + NSString *message = localize(([NSString stringWithFormat:@"preference.title.confirm.%@", key]), nil); UIAlertController *confirmAlert = [UIAlertController alertControllerWithTitle:title message:message preferredStyle:UIAlertControllerStyleActionSheet]; confirmAlert.popoverPresentationController.sourceView = view; confirmAlert.popoverPresentationController.sourceRect = view.bounds; - UIAlertAction *ok = [UIAlertAction actionWithTitle:NSLocalizedString(@"OK", nil) style:destructive?UIAlertActionStyleDestructive:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) { + UIAlertAction *ok = [UIAlertAction actionWithTitle:localize(@"OK", nil) style:destructive?UIAlertActionStyleDestructive:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) { [self tableView:tableView invokeActionAtIndexPath:indexPath]; }]; - UIAlertAction *cancel = [UIAlertAction actionWithTitle:NSLocalizedString(@"Cancel", nil) style:UIAlertActionStyleCancel handler:nil]; + UIAlertAction *cancel = [UIAlertAction actionWithTitle:localize(@"Cancel", nil) style:UIAlertActionStyleCancel handler:nil]; [confirmAlert addAction:cancel]; [confirmAlert addAction:ok]; [self presentViewController:confirmAlert animated:YES completion:nil]; @@ -572,8 +578,8 @@ typedef void(^CreateView)(UITableViewCell *, NSString *, NSDictionary *); } UIView *view = [self.tableView cellForRowAtIndexPath:indexPath]; - NSString *title = NSLocalizedString(([NSString stringWithFormat:@"preference.title.done.%@", key]), nil); - //NSString *message = NSLocalizedString(([NSString stringWithFormat:@"preference.message.done.%@", key]), nil); + NSString *title = localize(([NSString stringWithFormat:@"preference.title.done.%@", key]), nil); + //NSString *message = localize(([NSString stringWithFormat:@"preference.message.done.%@", key]), nil); [self showAlertOnView:view title:title message:nil]; } diff --git a/Natives/LauncherSplitViewController.m b/Natives/LauncherSplitViewController.m index c293781e..46cfc859 100644 --- a/Natives/LauncherSplitViewController.m +++ b/Natives/LauncherSplitViewController.m @@ -13,24 +13,14 @@ [super viewDidLoad]; UIApplication.sharedApplication.idleTimerDisabled = YES; setViewBackgroundColor(self.view); + self.delegate = self; + [self changeDisplayModeForSize:self.view.frame.size]; LauncherMenuViewController *masterVc = [[LauncherMenuViewController alloc] init]; LauncherNavigationController *detailVc = [[LauncherNavigationController alloc] init]; detailVc.toolbarHidden = NO; - BOOL isPortrait = self.view.frame.size.height > self.view.frame.size.width; - self.preferredDisplayMode = isPortrait ? - UISplitViewControllerDisplayModeOneOverSecondary : - UISplitViewControllerDisplayModeOneBesideSecondary; - if (@available(iOS 14.0, tvOS 14.0, *)) { - self.preferredSplitBehavior = isPortrait ? - UISplitViewControllerSplitBehaviorOverlay : - UISplitViewControllerSplitBehaviorTile; - } - - self.presentsWithGesture = YES; - self.viewControllers = @[[[UINavigationController alloc] initWithRootViewController:masterVc], detailVc]; } @@ -45,12 +35,18 @@ - (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id)coordinator { [super viewWillTransitionToSize:size withTransitionCoordinator:coordinator]; + [self changeDisplayModeForSize:size]; +} - self.preferredDisplayMode = size.height > size.width ? - UISplitViewControllerDisplayModeOneOverSecondary : - UISplitViewControllerDisplayModeOneBesideSecondary; +- (void)changeDisplayModeForSize:(CGSize)size { + BOOL isPortrait = size.height > size.width; + if (self.preferredDisplayMode == 0 || self.displayMode != UISplitViewControllerDisplayModeSecondaryOnly) { + self.preferredDisplayMode = isPortrait ? + UISplitViewControllerDisplayModeOneOverSecondary : + UISplitViewControllerDisplayModeOneBesideSecondary; + } if (@available(iOS 14.0, tvOS 14.0, *)) { - self.preferredSplitBehavior = size.height > size.width ? + self.preferredSplitBehavior = isPortrait ? UISplitViewControllerSplitBehaviorOverlay : UISplitViewControllerSplitBehaviorTile; } diff --git a/Natives/LoginViewController.m b/Natives/LoginViewController.m index 8d421e18..4f8e1932 100644 --- a/Natives/LoginViewController.m +++ b/Natives/LoginViewController.m @@ -45,8 +45,8 @@ extern NSMutableDictionary *prefDict; CGFloat rawHeight = self.view.frame.size.height; if(roundf([[NSProcessInfo processInfo] physicalMemory] / 1048576) < 1900 && [getPreference(@"unsupported_warn_counter") intValue] == 0) { - UIAlertController *RAMAlert = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"login.warn.title.a7", nil) message:NSLocalizedString(@"login.warn.message.a7", nil) preferredStyle:UIAlertControllerStyleAlert]; - UIAlertAction *ok = [UIAlertAction actionWithTitle:NSLocalizedString(@"OK", nil) style:UIAlertActionStyleCancel handler:nil]; + UIAlertController *RAMAlert = [UIAlertController alertControllerWithTitle:localize(@"login.warn.title.a7", nil) message:localize(@"login.warn.message.a7", nil) preferredStyle:UIAlertControllerStyleAlert]; + UIAlertAction *ok = [UIAlertAction actionWithTitle:localize(@"OK", nil) style:UIAlertActionStyleCancel handler:nil]; [self presentViewController:RAMAlert animated:YES completion:nil]; [RAMAlert addAction:ok]; } @@ -59,8 +59,8 @@ extern NSMutableDictionary *prefDict; } if(!getenv("POJAV_DETECTEDJB") && [getPreference(@"ram_unjb_warn") boolValue] == YES && [getPreference(@"auto_ram") boolValue] == NO) { - UIAlertController *ramalert = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"login.warn.title.ram_unjb", nil) message:NSLocalizedString(@"login.warn.message.ram_unjb", nil) preferredStyle:UIAlertControllerStyleAlert]; - UIAlertAction *ok = [UIAlertAction actionWithTitle:NSLocalizedString(@"OK", nil) style:UIAlertActionStyleCancel handler:nil]; + UIAlertController *ramalert = [UIAlertController alertControllerWithTitle:localize(@"login.warn.title.ram_unjb", nil) message:localize(@"login.warn.message.ram_unjb", nil) preferredStyle:UIAlertControllerStyleAlert]; + UIAlertAction *ok = [UIAlertAction actionWithTitle:localize(@"OK", nil) style:UIAlertActionStyleCancel handler:nil]; [self presentViewController:ramalert animated:YES completion:nil]; [ramalert addAction:ok]; setPreference(@"ram_unjb_warn", @NO); @@ -91,7 +91,7 @@ extern NSMutableDictionary *prefDict; target:self action:@selector(latestLogShare)], // There's no better way to put both title+icon for both iOS 12 and 13+, so do this [[UIBarButtonItem alloc] - initWithTitle:NSLocalizedString(@"login.menu.sendlogs", nil) + initWithTitle:localize(@"login.menu.sendlogs", nil) style:UIBarButtonItemStyleDone target:self action:@selector(latestLogShare)] ]; @@ -100,7 +100,7 @@ extern NSMutableDictionary *prefDict; UIButton *button_login = [UIButton buttonWithType:UIButtonTypeSystem]; setButtonPointerInteraction(button_login); - [button_login setTitle:NSLocalizedString(@"Sign in", nil) forState:UIControlStateNormal]; + [button_login setTitle:localize(@"Sign in", nil) forState:UIControlStateNormal]; button_login.autoresizingMask = AUTORESIZE_BTN; button_login.frame = CGRectMake(frame.origin.x - frame.size.width - 20, (height - 80.0), (width - widthSplit * 2.0) / 2, 40.0); if([date isEqualToString:@"06-29"] || [date isEqualToString:@"06-30"] || [date isEqualToString:@"07-01"]) { @@ -112,11 +112,11 @@ extern NSMutableDictionary *prefDict; [button_login setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; [button_login addTarget:self action:@selector(accountType:) forControlEvents:UIControlEventTouchUpInside]; if(@available (iOS 14.0, *)) { - UIAction *option1 = [UIAction actionWithTitle:NSLocalizedString(@"login.option.microsoft", nil) image:nil identifier:nil + UIAction *option1 = [UIAction actionWithTitle:localize(@"login.option.microsoft", nil) image:nil identifier:nil handler:^(__kindof UIAction * _Nonnull action) {[self loginMicrosoft];}]; - UIAction *option3 = [UIAction actionWithTitle:NSLocalizedString(@"login.option.demo", nil) image:nil identifier:nil + UIAction *option3 = [UIAction actionWithTitle:localize(@"login.option.demo", nil) image:nil identifier:nil handler:^(__kindof UIAction * _Nonnull action) {[self loginDemo:button_login];}]; - UIAction *option4 = [UIAction actionWithTitle:NSLocalizedString(@"login.option.local", nil) image:nil identifier:nil + UIAction *option4 = [UIAction actionWithTitle:localize(@"login.option.local", nil) image:nil identifier:nil handler:^(__kindof UIAction * _Nonnull action) {[self loginOffline:button_login];}]; UIMenu *menu = [UIMenu menuWithTitle:@"" image:nil identifier:nil options:UIMenuOptionsDisplayInline children:@[option4, option3, option1]]; @@ -132,7 +132,7 @@ extern NSMutableDictionary *prefDict; UIButton *button_accounts = [UIButton buttonWithType:UIButtonTypeSystem]; setButtonPointerInteraction(button_accounts); - [button_accounts setTitle:NSLocalizedString(@"Accounts", nil) forState:UIControlStateNormal]; + [button_accounts setTitle:localize(@"Accounts", nil) forState:UIControlStateNormal]; button_accounts.autoresizingMask = AUTORESIZE_BTN; button_accounts.frame = CGRectMake(frame.origin.x + frame.size.width + 20, (height - 80.0), (width - widthSplit * 2.0) / 2, 40.0); if([date isEqualToString:@"06-29"] || [date isEqualToString:@"06-30"] || [date isEqualToString:@"07-01"]) { @@ -162,7 +162,7 @@ extern NSMutableDictionary *prefDict; if (!getEntitlementValue(@"dynamic-codesigning")) { if (isJITEnabled()) { - self.title = NSLocalizedString(@"login.jit.enabled", nil); + self.title = localize(@"login.jit.enabled", nil); } else { [self enableJITWithJitStreamer]; } @@ -187,10 +187,10 @@ extern NSMutableDictionary *prefDict; // UIMenu } else { UIAlertController *fullAlert = [UIAlertController alertControllerWithTitle:@"Let's get you signed in." message:@"What account do you use to log into Minecraft?" preferredStyle:UIAlertControllerStyleActionSheet]; - UIAlertAction *microsoft = [UIAlertAction actionWithTitle:NSLocalizedString(@"login.option.microsoft", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {[self loginMicrosoft];}]; - UIAlertAction *offline = [UIAlertAction actionWithTitle:NSLocalizedString(@"login.option.local", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {[self loginOffline:sender];}]; - UIAlertAction *demo = [UIAlertAction actionWithTitle:NSLocalizedString(@"login.option.demo", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {[self loginDemo:sender];}]; - UIAlertAction *cancel = [UIAlertAction actionWithTitle:NSLocalizedString(NSLocalizedString(@"Cancel", nil), nil) style:UIAlertActionStyleCancel handler:nil]; + UIAlertAction *microsoft = [UIAlertAction actionWithTitle:localize(@"login.option.microsoft", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {[self loginMicrosoft];}]; + UIAlertAction *offline = [UIAlertAction actionWithTitle:localize(@"login.option.local", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {[self loginOffline:sender];}]; + UIAlertAction *demo = [UIAlertAction actionWithTitle:localize(@"login.option.demo", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {[self loginDemo:sender];}]; + UIAlertAction *cancel = [UIAlertAction actionWithTitle:localize(localize(@"Cancel", nil), nil) style:UIAlertActionStyleCancel handler:nil]; [self setPopoverProperties:fullAlert.popoverPresentationController sender:sender]; [self presentViewController:fullAlert animated:YES completion:nil]; [fullAlert addAction:microsoft]; @@ -222,7 +222,7 @@ extern NSMutableDictionary *prefDict; if (auth == nil) return; if (type != TYPE_OFFLINE && !shouldDismiss) { - [self displayProgress:NSLocalizedString(@"login.progress.title", nil)]; + [self displayProgress:localize(@"login.progress.title", nil)]; } id callback = ^(BOOL success) { @@ -267,12 +267,12 @@ extern NSMutableDictionary *prefDict; NSString *outError = [components[1] stringByReplacingOccurrencesOfString:@"&error_description=" withString:@": "]; outError = [outError stringByRemovingPercentEncoding]; - showDialog(self, NSLocalizedString(@"Error", nil), outError); + showDialog(self, localize(@"Error", nil), outError); } } } else { if (error.code != ASWebAuthenticationSessionErrorCodeCanceledLogin) { - showDialog(self, NSLocalizedString(@"Error", nil), error.localizedDescription); + showDialog(self, localize(@"Error", nil), error.localizedDescription); } } }]; @@ -283,48 +283,48 @@ extern NSMutableDictionary *prefDict; } if ([self.authVC start] == NO) { - showDialog(self, NSLocalizedString(@"Error", nil), @"Unable to open Safari"); + showDialog(self, localize(@"Error", nil), @"Unable to open Safari"); } } - (void)loginOffline:(UIButton *)sender { if ([getPreference(@"local_warn") boolValue] == YES) { - UIAlertController *offlineAlert = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"login.warn.title.localmode", nil) message:NSLocalizedString(@"login.warn.message.localmode", nil) preferredStyle:UIAlertControllerStyleActionSheet]; + UIAlertController *offlineAlert = [UIAlertController alertControllerWithTitle:localize(@"login.warn.title.localmode", nil) message:localize(@"login.warn.message.localmode", nil) preferredStyle:UIAlertControllerStyleActionSheet]; [self setPopoverProperties:offlineAlert.popoverPresentationController sender:sender]; - UIAlertAction *ok = [UIAlertAction actionWithTitle:NSLocalizedString(@"OK", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {[self loginOffline:sender];}]; - UIAlertAction *cancel = [UIAlertAction actionWithTitle:NSLocalizedString(@"Cancel", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {[self accountType:sender];}]; + UIAlertAction *ok = [UIAlertAction actionWithTitle:localize(@"OK", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {[self loginOffline:sender];}]; + UIAlertAction *cancel = [UIAlertAction actionWithTitle:localize(@"Cancel", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {[self accountType:sender];}]; [self presentViewController:offlineAlert animated:YES completion:nil]; [offlineAlert addAction:ok]; [offlineAlert addAction:cancel]; setPreference(@"local_warn", @NO); } else { - UIAlertController *controller = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"Sign in", nil) message:NSLocalizedString(@"login.option.local", nil) preferredStyle:UIAlertControllerStyleAlert]; + UIAlertController *controller = [UIAlertController alertControllerWithTitle:localize(@"Sign in", nil) message:localize(@"login.option.local", nil) preferredStyle:UIAlertControllerStyleAlert]; [controller addTextFieldWithConfigurationHandler:^(UITextField *textField) { - textField.placeholder = NSLocalizedString(@"login.alert.field.username", nil); + textField.placeholder = localize(@"login.alert.field.username", nil); textField.clearButtonMode = UITextFieldViewModeWhileEditing; textField.borderStyle = UITextBorderStyleRoundedRect; }]; - [controller addAction:[UIAlertAction actionWithTitle:NSLocalizedString(@"OK", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) { + [controller addAction:[UIAlertAction actionWithTitle:localize(@"OK", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) { NSArray *textFields = controller.textFields; UITextField *usernameField = textFields[0]; if (usernameField.text.length < 3 || usernameField.text.length > 16) { - controller.message = NSLocalizedString(@"login.error.username.outOfRange", nil); + controller.message = localize(@"login.error.username.outOfRange", nil); [self presentViewController:controller animated:YES completion:nil]; } else { [self loginAccountInput:TYPE_OFFLINE data:usernameField.text]; } }]]; - [controller addAction:[UIAlertAction actionWithTitle:NSLocalizedString(@"Cancel", nil) style:UIAlertActionStyleCancel handler:nil]]; + [controller addAction:[UIAlertAction actionWithTitle:localize(@"Cancel", nil) style:UIAlertActionStyleCancel handler:nil]]; [self presentViewController:controller animated:YES completion:nil]; } } - (void)loginDemo:(UIButton *)sender { if ([getPreference(@"demo_warn") boolValue] == YES) { - UIAlertController *offlineAlert = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"login.warn.title.demomode", nil) message:NSLocalizedString(@"login.warn.message.demomode", nil) preferredStyle:UIAlertControllerStyleActionSheet]; + UIAlertController *offlineAlert = [UIAlertController alertControllerWithTitle:localize(@"login.warn.title.demomode", nil) message:localize(@"login.warn.message.demomode", nil) preferredStyle:UIAlertControllerStyleActionSheet]; [self setPopoverProperties:offlineAlert.popoverPresentationController sender:sender]; - UIAlertAction *ok = [UIAlertAction actionWithTitle:NSLocalizedString(@"OK", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {[self loginMicrosoft];}]; - UIAlertAction *cancel = [UIAlertAction actionWithTitle:NSLocalizedString(@"Cancel", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {[self accountType:sender];}]; + UIAlertAction *ok = [UIAlertAction actionWithTitle:localize(@"OK", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {[self loginMicrosoft];}]; + UIAlertAction *cancel = [UIAlertAction actionWithTitle:localize(@"Cancel", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {[self accountType:sender];}]; [self presentViewController:offlineAlert animated:YES completion:nil]; [offlineAlert addAction:ok]; [offlineAlert addAction:cancel]; @@ -356,25 +356,25 @@ extern NSMutableDictionary *prefDict; - (void)enableJITWithAltJIT { - self.title = NSLocalizedString(@"login.jit.start.AltKit", nil); + self.title = localize(@"login.jit.start.AltKit", nil); [ALTServerManager.sharedManager startDiscovering]; [ALTServerManager.sharedManager autoconnectWithCompletionHandler:^(ALTServerConnection *connection, NSError *error) { if (error) { NSLog(@"[AltKit] Could not auto-connect to server. %@", error); - self.title = NSLocalizedString(@"login.jit.fail.AltKit", nil); + self.title = localize(@"login.jit.fail.AltKit", nil); return; } [connection enableUnsignedCodeExecutionWithCompletionHandler:^(BOOL success, NSError *error) { if (success) { NSLog(@"[AltKit] Successfully enabled JIT compilation!"); [ALTServerManager.sharedManager stopDiscovering]; - self.title = NSLocalizedString(@"login.jit.enabled", nil); + self.title = localize(@"login.jit.enabled", nil); self.navigationItem.leftBarButtonItem = nil; } else { NSLog(@"[AltKit] Could not enable JIT compilation. %@", error); - self.title = NSLocalizedString(@"login.jit.fail.AltKit", nil); + self.title = localize(@"login.jit.fail.AltKit", nil); self.navigationItem.leftBarButtonItem = nil; - showDialog(self, NSLocalizedString(@"Error", nil), error.description); + showDialog(self, localize(@"Error", nil), error.description); } [connection disconnect]; }]; @@ -383,7 +383,7 @@ extern NSMutableDictionary *prefDict; - (void)enableJITWithJitStreamer { - [self displayProgress:NSLocalizedString(@"login.jit.checking", nil)]; + [self displayProgress:localize(@"login.jit.checking", nil)]; // TODO: customizable address NSString *address = getPreference(@"jitstreamer_server"); @@ -396,7 +396,7 @@ extern NSMutableDictionary *prefDict; [manager GET:[NSString stringWithFormat:@"http://%@/version", address] parameters:nil headers:nil progress:nil success:^(NSURLSessionDataTask *task, NSData *response) { NSString *version = [[NSString alloc] initWithData:response encoding:NSUTF8StringEncoding]; NSLog(@"Found JitStreamer %@", version); - self.title = NSLocalizedString(@"login.jit.found.JitStreamer", nil); + self.title = localize(@"login.jit.found.JitStreamer", nil); manager.requestSerializer.timeoutInterval = 0; manager.responseSerializer = AFJSONResponseSerializer.serializer; void(^handleResponse)(NSURLSessionDataTask *task, id response) = ^void(NSURLSessionDataTask *task, id response){ @@ -411,12 +411,12 @@ extern NSMutableDictionary *prefDict; responseDict = response; } if ([responseDict[@"success"] boolValue]) { - self.title = NSLocalizedString(@"login.jit.enabled", nil); + self.title = localize(@"login.jit.enabled", nil); self.navigationItem.leftBarButtonItem = nil; } else { - self.title = [NSString stringWithFormat:NSLocalizedString(@"login.jit.fail.JitStreamer", nil), responseDict[@"message"]]; + self.title = [NSString stringWithFormat:localize(@"login.jit.fail.JitStreamer", nil), responseDict[@"message"]]; self.navigationItem.leftBarButtonItem = nil; - showDialog(self, NSLocalizedString(@"Error", nil), responseDict[@"message"]); + showDialog(self, localize(@"Error", nil), responseDict[@"message"]); [self enableJITWithAltJIT]; } }; diff --git a/Natives/SurfaceViewController+ExternalDisplay.m b/Natives/SurfaceViewController+ExternalDisplay.m index fe62d509..addd4473 100644 --- a/Natives/SurfaceViewController+ExternalDisplay.m +++ b/Natives/SurfaceViewController+ExternalDisplay.m @@ -13,7 +13,7 @@ noteLabel.numberOfLines = 0; noteLabel.textAlignment = NSTextAlignmentCenter; noteLabel.textColor = UIColor.whiteColor; - noteLabel.text = NSLocalizedString(@"game.note.airplay", nil); + noteLabel.text = localize(@"game.note.airplay", nil); [self.touchView addSubview:noteLabel]; UIWindow *secondWindow = currentWindowInScene(1); diff --git a/Natives/SurfaceViewController+LogView.m b/Natives/SurfaceViewController+LogView.m index 6c49e219..af194b4e 100644 --- a/Natives/SurfaceViewController+LogView.m +++ b/Natives/SurfaceViewController+LogView.m @@ -1,4 +1,5 @@ #import "SurfaceViewController.h" +#import "utils.h" static BOOL fatalErrorOccurred; @@ -47,14 +48,14 @@ static NSMutableArray* logLines; UIAlertController *alert = [UIAlertController alertControllerWithTitle:nil message:line preferredStyle:UIAlertControllerStyleActionSheet]; alert.popoverPresentationController.sourceView = cell; alert.popoverPresentationController.sourceRect = cell.bounds; - UIAlertAction *share = [UIAlertAction actionWithTitle:NSLocalizedString(NSLocalizedString(@"Share", nil), nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) { + UIAlertAction *share = [UIAlertAction actionWithTitle:localize(localize(@"Share", nil), nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) { UIView *navigationBar = vc.logOutputView.subviews[1]; UIActivityViewController *activityVC = [[UIActivityViewController alloc] initWithActivityItems:@[line] applicationActivities:nil]; activityVC.popoverPresentationController.sourceView = navigationBar; activityVC.popoverPresentationController.sourceRect = navigationBar.bounds; [vc presentViewController:activityVC animated:YES completion:nil]; }]; - UIAlertAction *cancel = [UIAlertAction actionWithTitle:NSLocalizedString(@"Cancel", nil) style:UIAlertActionStyleCancel handler:nil]; + UIAlertAction *cancel = [UIAlertAction actionWithTitle:localize(@"Cancel", nil) style:UIAlertActionStyleCancel handler:nil]; [alert addAction:share]; [alert addAction:cancel]; [vc presentViewController:alert animated:YES completion:nil]; @@ -84,7 +85,7 @@ static int logCharPerLine; ]; UINavigationBar* navigationBar = [[UINavigationBar alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 44)]; navigationBar.items = @[navigationItem]; - navigationBar.topItem.title = NSLocalizedString(@"game.menu.log_output", nil); + navigationBar.topItem.title = localize(@"game.menu.log_output", nil); [navigationBar sizeToFit]; navigationBar.autoresizingMask = UIViewAutoresizingFlexibleWidth; @@ -189,7 +190,7 @@ static int logCharPerLine; // Cleanup navigation bar UINavigationBar *navigationBar = instance.logOutputView.subviews[1]; navigationBar.topItem.title = [NSString stringWithFormat: - NSLocalizedString(@"game.title.exit_code", nil), code]; + localize(@"game.title.exit_code", nil), code]; navigationBar.items[0].leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAction target:instance action:@selector(actionShareLatestlog)]; diff --git a/Natives/SurfaceViewController+Navigation.m b/Natives/SurfaceViewController+Navigation.m index 21dc3d8c..314d4b35 100644 --- a/Natives/SurfaceViewController+Navigation.m +++ b/Natives/SurfaceViewController+Navigation.m @@ -1,5 +1,6 @@ #import "LauncherPreferencesViewController.h" #import "SurfaceViewController.h" +#import "utils.h" @implementation SurfaceViewController(Navigation) @@ -90,13 +91,13 @@ static CGPoint lastCenterPoint; - (void)actionForceClose { UIAlertController* alert = [UIAlertController alertControllerWithTitle:nil - message:NSLocalizedString(@"game.menu.confirm.force_close", nil) + message:localize(@"game.menu.confirm.force_close", nil) preferredStyle:UIAlertControllerStyleAlert]; - UIAlertAction* cancelAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"Cancel", nil) style:UIAlertActionStyleDefault handler:nil]; + UIAlertAction* cancelAction = [UIAlertAction actionWithTitle:localize(@"Cancel", nil) style:UIAlertActionStyleDefault handler:nil]; [alert addAction:cancelAction]; - UIAlertAction* okAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"OK", nil) style:UIAlertActionStyleDestructive handler:^(UIAlertAction * action) { + UIAlertAction* okAction = [UIAlertAction actionWithTitle:localize(@"OK", nil) style:UIAlertActionStyleDestructive handler:^(UIAlertAction * action) { [UIView animateWithDuration:0.4 delay:0 options:UIViewAnimationOptionCurveEaseIn animations:^{ self.rootView.center = CGPointMake(self.rootView.bounds.size.width/-2, self.rootView.center.y); self.menuView.frame = CGRectMake(self.view.frame.size.width, 0, 0, 0); @@ -135,7 +136,7 @@ static CGPoint lastCenterPoint; cell.backgroundColor = UIColor.groupTableViewBackgroundColor; } - cell.textLabel.text = NSLocalizedString(self.menuArray[indexPath.row], nil); + cell.textLabel.text = localize(self.menuArray[indexPath.row], nil); return cell; } diff --git a/Natives/SurfaceViewController.m b/Natives/SurfaceViewController.m index 0ae44e5e..f234e37e 100644 --- a/Natives/SurfaceViewController.m +++ b/Natives/SurfaceViewController.m @@ -344,7 +344,7 @@ BOOL slideableHotbar; self.cc_dictionary = parseJSONFromFile(controlFilePath); if (self.cc_dictionary[@"error"] != nil) { - showDialog(self, NSLocalizedString(@"Error", nil), [NSString stringWithFormat:@"Could not open %@: %@", controlFilePath, [self.cc_dictionary[@"error"] localizedDescription]]); + showDialog(self, localize(@"Error", nil), [NSString stringWithFormat:@"Could not open %@: %@", controlFilePath, [self.cc_dictionary[@"error"] localizedDescription]]); return; } @@ -398,6 +398,7 @@ BOOL slideableHotbar; [self viewWillTransitionToSize_LogView:frame]; [self viewWillTransitionToSize_Navigation:frame]; + // Update custom controls button position CGRect ctrlFrame = CGRectFromString(getPreference(@"control_safe_area")); CGSize screenSize = UIScreen.mainScreen.bounds.size; if (size.width < screenSize.width || size.height < screenSize.height) { @@ -415,7 +416,7 @@ BOOL slideableHotbar; } } } completion:^(id _Nonnull context) { - [self updateSavedResolution]; + virtualMouseFrame = self.mousePointerView.frame; }]; [super viewWillTransitionToSize:size withTransitionCoordinator:coordinator]; } diff --git a/Natives/authenticator/BaseAuthenticator.m b/Natives/authenticator/BaseAuthenticator.m index a135f86c..7eb00ba2 100644 --- a/Natives/authenticator/BaseAuthenticator.m +++ b/Natives/authenticator/BaseAuthenticator.m @@ -21,7 +21,7 @@ static BaseAuthenticator *current = nil; + (id)loadSavedName:(NSString *)name { NSMutableDictionary *authData = parseJSONFromFile([NSString stringWithFormat:@"%s/accounts/%@.json", getenv("POJAV_HOME"), name]); if (authData[@"error"] != nil) { - showDialog(currentVC(), NSLocalizedString(@"Error", nil), ((NSError *)authData[@"error"]).localizedDescription); + showDialog(currentVC(), localize(@"Error", nil), ((NSError *)authData[@"error"]).localizedDescription); return nil; } if ([authData[@"accessToken"] length] < 5) { diff --git a/Natives/authenticator/MicrosoftAuthenticator.m b/Natives/authenticator/MicrosoftAuthenticator.m index 4647254c..e15c7596 100644 --- a/Natives/authenticator/MicrosoftAuthenticator.m +++ b/Natives/authenticator/MicrosoftAuthenticator.m @@ -8,7 +8,7 @@ typedef void(^XSTSCallback)(NSString *xsts, NSString *uhs); @implementation MicrosoftAuthenticator - (void)acquireAccessToken:(NSString *)authcode refresh:(BOOL)refresh callback:(Callback)callback { - currentVC().title = NSLocalizedString(@"login.msa.progress.acquireAccessToken", nil); + currentVC().title = localize(@"login.msa.progress.acquireAccessToken", nil); NSDictionary *data = @{ @"client_id": @"00000000402b5328", @@ -30,7 +30,7 @@ typedef void(^XSTSCallback)(NSString *xsts, NSString *uhs); } - (void)acquireXBLToken:(NSString *)accessToken callback:(Callback)callback { - currentVC().title = NSLocalizedString(@"login.msa.progress.acquireXBLToken", nil); + currentVC().title = localize(@"login.msa.progress.acquireXBLToken", nil); NSDictionary *data = @{ @"Properties": @{ @@ -76,7 +76,7 @@ typedef void(^XSTSCallback)(NSString *xsts, NSString *uhs); } - (void)acquireXSTSFor:(NSString *)replyingParty token:(NSString *)xblToken callback:(XSTSCallback)callback { - currentVC().title = NSLocalizedString(@"login.msa.progress.acquireXSTS", nil); + currentVC().title = localize(@"login.msa.progress.acquireXSTS", nil); NSDictionary *data = @{ @"Properties": @{ @@ -118,13 +118,13 @@ typedef void(^XSTSCallback)(NSString *xsts, NSString *uhs); break; } NSLog(@"[MSA] Error: %@", errorString); - showDialog(currentVC(), NSLocalizedString(@"Error", nil), NSLocalizedString(errorString, nil)); + showDialog(currentVC(), localize(@"Error", nil), localize(errorString, nil)); }]; } - (void)acquireXboxProfile:(NSString *)xblUhs xstsToken:(NSString *)xblXsts callback:(Callback)callback { - currentVC().title = NSLocalizedString(@"login.msa.progress.acquireXboxProfile", nil); + currentVC().title = localize(@"login.msa.progress.acquireXboxProfile", nil); NSDictionary *headers = @{ @"x-xbl-contract-version": @"2", @@ -144,7 +144,7 @@ typedef void(^XSTSCallback)(NSString *xsts, NSString *uhs); } - (void)acquireMinecraftToken:(NSString *)xblUhs xstsToken:(NSString *)xblXsts callback:(Callback)callback { - currentVC().title = NSLocalizedString(@"login.msa.progress.acquireMCToken", nil); + currentVC().title = localize(@"login.msa.progress.acquireMCToken", nil); NSDictionary *data = @{ @"identityToken": [NSString stringWithFormat:@"XBL3.0 x=%@;%@", xblUhs, xblXsts] @@ -165,7 +165,7 @@ typedef void(^XSTSCallback)(NSString *xsts, NSString *uhs); - (void)checkMCProfile:(NSString *)mcAccessToken callback:(Callback)callback { self.authData[@"expiresAt"] = @((long)[NSDate.date timeIntervalSince1970] + 86400); - currentVC().title = NSLocalizedString(@"login.msa.progress.checkMCProfile", nil); + currentVC().title = localize(@"login.msa.progress.checkMCProfile", nil); NSDictionary *headers = @{ @"Authorization": [NSString stringWithFormat:@"Bearer %@", mcAccessToken] @@ -193,7 +193,7 @@ typedef void(^XSTSCallback)(NSString *xsts, NSString *uhs); self.authData[@"profileId"] = @"00000000-0000-0000-0000-000000000000"; self.authData[@"username"] = [NSString stringWithFormat:@"Demo.%@", self.authData[@"xboxGamertag"]]; - showDialog(currentVC(), NSLocalizedString(@"Notice", nil), NSLocalizedString(@"login.msa.notice.demomode", nil)); + showDialog(currentVC(), localize(@"Notice", nil), localize(@"login.msa.notice.demomode", nil)); callback([super saveChanges]); return; } diff --git a/Natives/en.lproj/Localizable.strings b/Natives/en.lproj/Localizable.strings index da33b645..8c181844 100644 --- a/Natives/en.lproj/Localizable.strings +++ b/Natives/en.lproj/Localizable.strings @@ -197,6 +197,8 @@ "preference.title.custom_env" = "Environment variables"; "preference.detail.custom_env" = "This option is under construction."; +"preference.title.debug_skip_wait_jit" = "Skip \"Waiting for JIT\" dialog"; +"preference.detail.debug_skip_wait_jit" = "This does not allow you to launch without JIT, instead this skips debugger check, because check fails on certain jailbreaks."; "preference.title.debug_ipad_ui" = "Unlock iPadOS UI"; "preference.detail.debug_ipad_ui" = "Unlock iPad-exclusive UI (alert, keyboard, etc.) if enabled or iPhone UI if disabled."; "preference.title.debug_show_layout_bounds" = "Show layout bounds"; diff --git a/Natives/ios_uikit_bridge.m b/Natives/ios_uikit_bridge.m index d58cbe42..89768de7 100644 --- a/Natives/ios_uikit_bridge.m +++ b/Natives/ios_uikit_bridge.m @@ -26,7 +26,7 @@ void internal_showDialog(UIViewController *viewController, NSString* title, NSSt message:message preferredStyle:UIAlertControllerStyleAlert]; //text.dataDetectorTypes = UIDataDetectorTypeLink; - UIAlertAction* okAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"OK", nil) style:UIAlertActionStyleDefault handler:nil]; + UIAlertAction* okAction = [UIAlertAction actionWithTitle:localize(@"OK", nil) style:UIAlertActionStyleDefault handler:nil]; [alert addAction:okAction]; [currentVC() presentViewController:alert animated:YES completion:nil]; diff --git a/Natives/utils.h b/Natives/utils.h index 1baaee9a..bcab0d12 100644 --- a/Natives/utils.h +++ b/Natives/utils.h @@ -85,6 +85,7 @@ UIWindow* currentWindow(); UIWindow* currentWindowInScene(BOOL external); UIViewController* currentVC(); +NSString* localize(NSString* key, NSString* comment); NSMutableDictionary* parseJSONFromFile(NSString *path); NSError* saveJSONToFile(NSDictionary *dict, NSString *path); diff --git a/Natives/utils.m b/Natives/utils.m index 5f1ecc01..88c0d339 100644 --- a/Natives/utils.m +++ b/Natives/utils.m @@ -51,6 +51,21 @@ NSError* saveJSONToFile(NSDictionary *dict, NSString *path) { return nil; } +NSString* localize(NSString* key, NSString* comment) { + NSString *value = NSLocalizedString(key, nil); + if (![NSLocale.preferredLanguages[0] isEqualToString:@"en"] && [value isEqualToString:key]) { + NSString* path = [NSBundle.mainBundle pathForResource:@"en" ofType:@"lproj"]; + NSBundle* languageBundle = [NSBundle bundleWithPath:path]; + value = [languageBundle localizedStringForKey:key value:nil table:nil]; + + if ([value isEqualToString:key]) { + value = [[NSBundle bundleWithIdentifier:@"com.apple.UIKit"] localizedStringForKey:key value:nil table:nil]; + } + } + + return value; +} + CGFloat MathUtils_dist(CGFloat x1, CGFloat y1, CGFloat x2, CGFloat y2) { const CGFloat x = (x2 - x1); const CGFloat y = (y2 - y1);