Skip to content

Commit

Permalink
- Fix pwndfu sub-checkboxes not becoming unchecked
Browse files Browse the repository at this point in the history
- Fix stop FutureRestore cancel on the popup enabling the button to start it again
- Add more checks to prevent two FutureRestore processes from running at the same time
- Code cleanup
- Fix GUI acting as if FutureRestore was killed when Stop button pressed, even if stop was cancelled
  • Loading branch information
CoocooFroggy committed Jul 29, 2021
1 parent f067d39 commit 6879111
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/main/java/FRUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public static boolean updateFRGUI(MainMenu mainMenuInstance) throws IOException,
JPanel mainMenuView = mainMenuInstance.getMainMenuView();

// If FutureRestore process is running, cancel early
if (!(FutureRestoreWorker.futureRestoreProcess == null || !FutureRestoreWorker.futureRestoreProcess.isAlive())) {
if (FutureRestoreWorker.futureRestoreProcess != null && FutureRestoreWorker.futureRestoreProcess.isAlive()) {
failUpdate("Can't update when FutureRestore is running!", mainMenuInstance, false);
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/FutureRestoreWorker.java
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ static void runFutureRestore(String futureRestoreFilePath, ArrayList<String> all
if (!hasRecoveryRestarted) {
hasRecoveryRestarted = true;
//Ensure current process is killed
if (futureRestoreProcess.isAlive())
if (FutureRestoreWorker.futureRestoreProcess != null && FutureRestoreWorker.futureRestoreProcess.isAlive())
futureRestoreProcess.destroy();
//Restart
new Thread(() -> {
Expand Down
43 changes: 31 additions & 12 deletions src/main/java/MainMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,10 @@ public MainMenu() {
justBootCheckBox.setSelected(false);
justBootCheckBox.setEnabled(false);
justBootLabel.setEnabled(false);

// Since we turn off the switches for pwndfu required items, also turn them off internally
optionNoIbssState = false;
optionJustBootState = false;
}
};
debugDCheckBox.addActionListener(optionsListener);
Expand All @@ -209,13 +213,22 @@ public MainMenu() {
justBootCheckBox.addActionListener(optionsListener);

startFutureRestoreButton.addActionListener(e -> {
//Ensure they have FutureRestore selected
// If FutureRestore is already running, just disable ourselves
if (FutureRestoreWorker.futureRestoreProcess != null && FutureRestoreWorker.futureRestoreProcess.isAlive()) {
SwingUtilities.invokeLater(() -> {
startFutureRestoreButton.setEnabled(false);
// Potentially make the button say unsafe again
});
return;
}

// Ensure they have FutureRestore selected
if (futureRestoreFilePath == null) {
JOptionPane.showMessageDialog(mainMenuView, "Please select a FutureRestore executable.", "No FutureRestore Selected", JOptionPane.ERROR_MESSAGE);
return;
}

//Ensure they actually selected a blob, IPSW, and buildmanifest if needed
// Ensure they actually selected a blob, IPSW, and buildmanifest if needed
if (blobFilePath == null) {
JOptionPane.showMessageDialog(mainMenuView, "Select a blob file.", "Error", JOptionPane.ERROR_MESSAGE);
return;
Expand Down Expand Up @@ -393,19 +406,25 @@ public MainMenu() {
stopFutureRestoreUnsafeButton.addActionListener(e -> {
Process futureRestoreProcess = FutureRestoreWorker.futureRestoreProcess;

if (futureRestoreProcess != null) {
if (futureRestoreProcess.isAlive()) {
int response = JOptionPane.showConfirmDialog(mainMenuView, "Are you sure you want to stop FutureRestore? This is considered unsafe if the device is currently restoring.", "Stop FutureRestore?", JOptionPane.YES_NO_OPTION);
if (response == JOptionPane.YES_OPTION) {
futureRestoreProcess.destroy();
messageToLog("FutureRestore process killed.");
}
boolean killed = false;
if (FutureRestoreWorker.futureRestoreProcess != null && FutureRestoreWorker.futureRestoreProcess.isAlive()) {
int response = JOptionPane.showConfirmDialog(mainMenuView, "Are you sure you want to stop FutureRestore? This is considered unsafe if the device is currently restoring.", "Stop FutureRestore?", JOptionPane.YES_NO_OPTION);
if (response == JOptionPane.YES_OPTION) {
futureRestoreProcess.destroy();
messageToLog("FutureRestore process killed.");
killed = true;
}
} else {
killed = true;
}

startFutureRestoreButton.setEnabled(true);
stopFutureRestoreUnsafeButton.setText("Stop FutureRestore");
currentTaskTextField.setText("");
if (killed) {
SwingUtilities.invokeLater(() -> {
startFutureRestoreButton.setEnabled(true);
stopFutureRestoreUnsafeButton.setText("Stop FutureRestore");
currentTaskTextField.setText("");
});
}
});

downloadFutureRestoreButton.addActionListener(event -> {
Expand Down

0 comments on commit 6879111

Please sign in to comment.