Skip to content

Commit

Permalink
improve UX and mem usage
Browse files Browse the repository at this point in the history
  • Loading branch information
rA9stuff committed Jun 25, 2023
1 parent 5d2c83b commit dcfa3ec
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 9 deletions.
3 changes: 2 additions & 1 deletion LeetDown_M/LeetDownMain.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@
@property (assign) IBOutlet NSTextField *percentage;
- (int) discoverDevices;
- (void)updateStatus:(NSString*)text color:(NSColor*)color1;

// Declare a property for your custom NSWindow instance
@property (strong, nonatomic) NSAlert *alert;
@end

@protocol USBDeviceDetectedDelegate <NSObject>
Expand Down
40 changes: 33 additions & 7 deletions LeetDown_M/LeetDownMain.mm
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ @implementation ViewController
bool pwned = false;
bool restoreStarted = false;
double uzip_progress = 0;
NSString *ECID = NULL;
bool discoverStateEnded = false;

LDD *dfuDevPtr = new LDD; // initialize it with defualt constructor first, since we only need ECID not to be NULL to connect to device

Expand Down Expand Up @@ -473,13 +475,16 @@ - (void)bootchainUploadManager:(NSString*)filename reconnect:(bool)reconnect {
return;
}
dispatch_async(dispatch_get_main_queue(), ^{
[self updateStatus:@"Device got lost, reconnect the USB cable to your mac to resume the upload process" color:[NSColor yellowColor]];
[self showAlert:@"DFU device got lost" content:@"Please reconnect the USB cable to your Mac. LeetDown will automatically continue when it detects a device"];
});
int i = 0;
while (dfuDevPtr -> openConnection(5) != 0) {
printf("reconnect attempt %i\n", i);
i++;
}
dispatch_async(dispatch_get_main_queue(), ^{
[self dismissAlert];
});
dfuDevPtr -> setAllDeviceInfo();
[self bootchainUploadManager:filename reconnect:false];

Expand Down Expand Up @@ -533,7 +538,7 @@ - (void)infoLog:(NSString*)text color:(NSColor*)color1 {
});
}

int supported = 0;


- (int) PrintDevInfo {

Expand Down Expand Up @@ -564,10 +569,11 @@ - (int) PrintDevInfo {
return 0;
}

NSString *ECID = NULL;
static bool discoverStateEnded = false;


- (int) discoverDevices {

static bool supported = false;

if (discoverStateEnded) {
dispatch_async(dispatch_get_main_queue(), ^{
Expand Down Expand Up @@ -976,8 +982,10 @@ - (IBAction)downgradeButtonAct:(id)sender {
if ([self exploitDevice] != 0) {
return;
}
//dfuDevPtr -> openConnection(5); // now reconnect to device
//dfuDevPtr -> setAllDeviceInfo(); // set the rest
if (dfuDevPtr -> getClient() == NULL) {
dfuDevPtr -> openConnection(5); // now reconnect to device
dfuDevPtr -> setAllDeviceInfo(); // set the rest
}
}

dispatch_async(dispatch_get_main_queue(), ^(){
Expand Down Expand Up @@ -1086,6 +1094,24 @@ - (void)redirectLogToDocuments {
freopen([pathForLog cStringUsingEncoding:NSASCIIStringEncoding],"a+",stdout);
}

- (void)showAlert:(NSString*)title content:(NSString*)content {

self.alert = [[NSAlert alloc] init];
[self.alert setMessageText:title];
[self.alert setInformativeText:content];
[self.alert addButtonWithTitle:@"OK"];
NSButton *button = [[self.alert buttons] objectAtIndex:0];
[button setHidden:YES];
[self.alert beginSheetModalForWindow:self.view.window completionHandler:^(NSModalResponse returnCode) {

}];
}

- (void)dismissAlert {
[self.view.window endSheet:self.alert.window];
}



- (void)viewDidLoad {
[super viewDidLoad];
Expand Down Expand Up @@ -1114,7 +1140,7 @@ - (void)viewDidLoad {
[_uselessIndicator setIndeterminate:YES];
[_uselessIndicator setUsesThreadedAnimation:YES];
[self updateStatus:@"Waiting for a device in DFU Mode\n" color:[NSColor whiteColor]];

}

@end
9 changes: 8 additions & 1 deletion nightly_changes.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,11 @@ improve unzip progress view
improve memory usage
rebrand PlistUtils (formerly plistModifier)
fix leetdown bootlogo on A7
bump version to 2.3 rc (A6 and A7 ready)
bump version to 2.3 rc (A6 and A7 ready)

==================================
25 Jun 2023

add NSAlert for reconnect request
improve memory usage

0 comments on commit dcfa3ec

Please sign in to comment.