Skip to content

Commit 5f5aa92

Browse files
SwiftWindsairsquared
authored andcommitted
No longer require restarting app to start background, improve reading output of tsschecker, add Version class
1 parent e38ed6f commit 5f5aa92

File tree

11 files changed

+250
-85
lines changed

11 files changed

+250
-85
lines changed

.idea/modules/blobsaver_main.iml

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/modules/blobsaver_test.iml

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ macAppBundle {
6666
appName = 'blobsaver'
6767
dmgName = 'blobsaver-macos'
6868
volumeName = 'blobsaver-macos'
69+
bundleExtras.put("LSUIElement", "YES")
6970
}
7071

7172
launch4j { // Windows only, don't use this, use createWindowsInstaller

libs/libdockvisibility-1.0.1.jar

3.28 KB
Binary file not shown.

src/main/java/com/airsquared/blobsaver/Background.java

Lines changed: 20 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import java.awt.PopupMenu;
3535
import java.awt.SystemTray;
3636
import java.awt.TrayIcon;
37+
import java.awt.event.ActionListener;
3738
import java.io.File;
3839
import java.io.IOException;
3940
import java.util.ArrayList;
@@ -46,7 +47,6 @@
4647

4748
import static com.airsquared.blobsaver.Main.appPrefs;
4849
import static com.airsquared.blobsaver.Main.appVersion;
49-
import static com.airsquared.blobsaver.Main.primaryStage;
5050
import static com.airsquared.blobsaver.Shared.*;
5151

5252
class Background {
@@ -73,13 +73,13 @@ static void startBackground(boolean runOnlyOnce) {
7373
}
7474
ArrayList<String> presetsToSaveNames = new ArrayList<>();
7575
if (!presetsToSave.isEmpty()) {
76-
presetsToSave.forEach((preset) -> presetsToSaveNames.add(appPrefs.get("Name Preset" + preset, "")));
76+
presetsToSave.forEach(preset -> presetsToSaveNames.add(appPrefs.get("Name Preset" + preset, "")));
7777
} else {
7878
inBackground = false;
7979
return;
8080
}
8181
if (!runOnlyOnce && Platform.isFxApplicationThread()) {
82-
primaryStage.hide();
82+
Main.hideStage();
8383
Notification.Notifier.INSTANCE.setPopupLifetime(Duration.seconds(30));
8484
Notification.Notifier.INSTANCE.notifyInfo("Background process has started", "Check your system tray/status bar for\nthe icon."
8585
+ presetsToSaveNames.toString().substring(1, presetsToSaveNames.toString().length() - 1));
@@ -100,8 +100,9 @@ static void startBackground(boolean runOnlyOnce) {
100100
trayIcon = new TrayIcon(image, "blobsaver " + appVersion);
101101
trayIcon.setImageAutoSize(true);
102102

103+
ActionListener showListener = event -> Platform.runLater(Main::showStage);
103104
MenuItem openItem = new MenuItem("Open window");
104-
openItem.addActionListener((evt) -> Platform.runLater(Background::showStage));
105+
openItem.addActionListener(showListener);
105106
openItem.setFont(Font.decode(null).deriveFont(Font.BOLD)); // bold it
106107

107108
MenuItem exitItem = new MenuItem("Quit");
@@ -118,6 +119,7 @@ static void startBackground(boolean runOnlyOnce) {
118119
popup.add(breakpointItem);
119120
}
120121
trayIcon.setPopupMenu(popup);
122+
trayIcon.addActionListener(showListener);
121123

122124
// add the application tray icon to the system tray.
123125
try {
@@ -181,9 +183,9 @@ private static void saveBackgroundBlobs(int preset) {
181183
} catch (IOException e) {
182184
Notification notification = new Notification("Saving blobs failed", "Check your internet connection.\nIf it is working, click here to report this error.", Notification.ERROR_ICON);
183185
Notification.Notifier.INSTANCE.setPopupLifetime(Duration.minutes(1));
184-
Notification.Notifier.INSTANCE.setOnNotificationPressed((event) -> {
186+
Notification.Notifier.INSTANCE.setOnNotificationPressed(event -> {
185187
Notification.Notifier.INSTANCE.stop();
186-
showStage();
188+
Main.showStage();
187189
Alert alert = new Alert(Alert.AlertType.ERROR,
188190
"Saving blobs failed. Check your internet connection.\n\nIf your internet is working and you can connect to the website ipsw.me in your browser, please create a new issue on Github or PM me on Reddit. The log has been copied to your clipboard.",
189191
githubIssue, redditPM, ButtonType.OK);
@@ -207,9 +209,9 @@ private static void saveBackgroundBlobs(int preset) {
207209
} catch (IOException e) {
208210
Notification notification = new Notification("Saving blobs failed", "There was an error creating tsschecker. Click here to report this error.", Notification.ERROR_ICON);
209211
Notification.Notifier.INSTANCE.setPopupLifetime(Duration.minutes(1));
210-
Notification.Notifier.INSTANCE.setOnNotificationPressed((event) -> {
212+
Notification.Notifier.INSTANCE.setOnNotificationPressed(event -> {
211213
Notification.Notifier.INSTANCE.stop();
212-
showStage();
214+
Main.showStage();
213215
Alert alert = new Alert(Alert.AlertType.ERROR,
214216
"There was an error creating tsschecker.\n\nIf your internet is working and you can connect to apple.com in your browser, please create a new issue on Github or PM me on Reddit. The log has been copied to your clipboard.",
215217
githubIssue, redditPM, ButtonType.OK);
@@ -239,9 +241,9 @@ private static void saveBackgroundBlobs(int preset) {
239241
} catch (IOException e) {
240242
Notification notification = new Notification("Saving blobs failed", "There was an error starting tsschecker. Click here to report this error.", Notification.ERROR_ICON);
241243
Notification.Notifier.INSTANCE.setPopupLifetime(Duration.minutes(1));
242-
Notification.Notifier.INSTANCE.setOnNotificationPressed((event) -> {
244+
Notification.Notifier.INSTANCE.setOnNotificationPressed(event -> {
243245
Notification.Notifier.INSTANCE.stop();
244-
showStage();
246+
Main.showStage();
245247
Alert alert = new Alert(Alert.AlertType.ERROR,
246248
"There was an error getting the tsschecker result.\n\nPlease create a new issue on Github or PM me on Reddit. The log has been copied to your clipboard.",
247249
githubIssue, redditPM, ButtonType.OK);
@@ -259,12 +261,12 @@ private static void saveBackgroundBlobs(int preset) {
259261
} else {
260262
presetName = appPrefs.get("Name Preset" + preset, "");
261263
}
262-
if (tsscheckerLog.contains("Saved shsh blobs")) {
264+
if (containsIgnoreCase(tsscheckerLog, "Saved")) {
263265
Notification notification = new Notification("Successfully saved blobs for", "iOS " + version + " (" + presetName + ") in\n" + path, Notification.SUCCESS_ICON);
264266
Notification.Notifier.INSTANCE.setPopupLifetime(Duration.seconds(30));
265267
Notification.Notifier.INSTANCE.setOnNotificationPressed((event) -> {
266268
Notification.Notifier.INSTANCE.stop();
267-
showStage();
269+
Main.showStage();
268270
Alert alert = new Alert(Alert.AlertType.INFORMATION, "Successfully saved blobs in\n" + path, ButtonType.OK);
269271
alert.setTitle("Success");
270272
alert.setHeaderText("Success!");
@@ -276,12 +278,12 @@ private static void saveBackgroundBlobs(int preset) {
276278

277279
log("displayed message");
278280

279-
} else if (tsscheckerLog.contains("[Error] ERROR: TSS request failed: Could not resolve host:")) {
281+
} else if (containsIgnoreCase(tsscheckerLog, "[Error] ERROR: TSS request failed: Could not resolve host:")) {
280282
Notification notification = new Notification("Saving blobs failed", "Check your internet connection. If it is working, click here to report this error.", Notification.ERROR_ICON);
281283
Notification.Notifier.INSTANCE.setPopupLifetime(Duration.minutes(1));
282-
Notification.Notifier.INSTANCE.setOnNotificationPressed((event) -> {
284+
Notification.Notifier.INSTANCE.setOnNotificationPressed(event -> {
283285
Notification.Notifier.INSTANCE.stop();
284-
showStage();
286+
Main.showStage();
285287
Alert alert = new Alert(Alert.AlertType.ERROR,
286288
"Saving blobs failed. Check your internet connection.\n\nIf your internet is working and you can connect to apple.com in your browser, please create a new issue on Github or PM me on Reddit. The log has been copied to your clipboard.",
287289
githubIssue, redditPM, ButtonType.OK);
@@ -291,14 +293,14 @@ private static void saveBackgroundBlobs(int preset) {
291293
reportError(alert, tsscheckerLog);
292294
});
293295
Notification.Notifier.INSTANCE.notify(notification);
294-
} else if (tsscheckerLog.contains("iOS " + version + " for device " + identifier + " IS NOT being signed")) {
296+
} else if (containsIgnoreCase(tsscheckerLog, "iOS " + version + " for device " + identifier + " IS NOT being signed")) {
295297
continue;
296298
} else {
297299
Notification notification = new Notification("Saving blobs failed", "An unknown error occurred. Click here to report this error.", Notification.ERROR_ICON);
298300
Notification.Notifier.INSTANCE.setPopupLifetime(Duration.minutes(1));
299-
Notification.Notifier.INSTANCE.setOnNotificationPressed((event) -> {
301+
Notification.Notifier.INSTANCE.setOnNotificationPressed(event -> {
300302
Notification.Notifier.INSTANCE.stop();
301-
showStage();
303+
Main.showStage();
302304
Alert alert = new Alert(Alert.AlertType.ERROR, "Saving blobs failed." + "\n\nPlease create a new issue on Github or PM me on Reddit. The log has been copied to your clipboard.",
303305
githubIssue, redditPM, ButtonType.CANCEL);
304306
resizeAlertButtons(alert);
@@ -312,12 +314,6 @@ private static void saveBackgroundBlobs(int preset) {
312314
}
313315
}
314316

315-
private static void showStage() {
316-
primaryStage.show();
317-
primaryStage.toFront();
318-
primaryStage.requestFocus();
319-
}
320-
321317
static void stopBackground(boolean showAlert) {
322318
inBackground = false;
323319
executor.shutdownNow();

src/main/java/com/airsquared/blobsaver/Controller.java

Lines changed: 31 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import javafx.application.Platform;
2525
import javafx.collections.FXCollections;
2626
import javafx.event.ActionEvent;
27+
import javafx.event.EventHandler;
2728
import javafx.fxml.FXML;
2829
import javafx.scene.control.*;
2930
import javafx.scene.effect.DropShadow;
@@ -33,6 +34,7 @@
3334
import javafx.scene.paint.Color;
3435
import javafx.stage.DirectoryChooser;
3536
import javafx.stage.Stage;
37+
import javafx.stage.WindowEvent;
3638
import org.json.JSONArray;
3739

3840
import java.awt.Desktop;
@@ -111,9 +113,6 @@ static void afterStageShowing() {
111113
btn.setText("Load " + appPrefs.get("Name Preset" + i, ""));
112114
}
113115
}
114-
if (PlatformUtil.isMac()) {
115-
INSTANCE.useMacOSMenuBar();
116-
}
117116
checkForUpdates(false);
118117
}
119118

@@ -188,6 +187,25 @@ public void initialize() {
188187
path = path + System.getProperty("file.separator") + "Blobs";
189188
}
190189
pathField.setText(path);
190+
191+
192+
if (PlatformUtil.isMac()) {
193+
// resize stage to account for removed menu bar
194+
((VBox) menuBar.getParent()).setMinHeight(560.0);
195+
((VBox) menuBar.getParent()).setPrefHeight(560.0);
196+
presetVBox.setMinHeight(560.0);
197+
presetVBox.setPrefHeight(560.0);
198+
199+
((VBox) menuBar.getParent()).getChildren().remove(menuBar);
200+
201+
primaryStage.setOnShowing(new EventHandler<WindowEvent>() {
202+
@Override
203+
public void handle(WindowEvent event) {
204+
useMacOSMenuBar();
205+
primaryStage.removeEventHandler(event.getEventType(), this);
206+
}
207+
});
208+
}
191209
}
192210

193211
private static void addListenerToSetNullEffect(TextField... textFields) {
@@ -266,8 +284,8 @@ public void betaCheckBoxHandler() {
266284
ipswField.setEffect(borderGlow);
267285
buildIDField.setDisable(false);
268286
buildIDField.setEffect(borderGlow);
269-
if (versionCheckBox.isSelected()) {
270-
versionCheckBox.fire();
287+
if (versionCheckBox.isSelected()) { //cannot use latest versions + beta blobs in conjunction
288+
versionCheckBox.fire(); //turns latest version off
271289
}
272290
versionCheckBox.setDisable(true);
273291
} else {
@@ -588,14 +606,6 @@ public void aboutMenuHandler() {
588606
}
589607

590608
private void useMacOSMenuBar() {
591-
// resize stage to account for removed menu bar
592-
((VBox) menuBar.getParent()).setMinHeight(560.0);
593-
((VBox) menuBar.getParent()).setPrefHeight(560.0);
594-
presetVBox.setMinHeight(560.0);
595-
presetVBox.setPrefHeight(560.0);
596-
597-
((VBox) menuBar.getParent()).getChildren().remove(menuBar);
598-
599609
MenuBar macOSMenuBar = new MenuBar();
600610
MenuToolkit tk = MenuToolkit.toolkit();
601611

@@ -735,7 +745,7 @@ public void chooseTimeToRunHandler() {
735745
appPrefs.put("Time unit for background", choiceBox.getValue());
736746
} else {
737747
log("alert menu canceled");
738-
backgroundSettingsButton.fire();
748+
backgroundSettingsButton.fire(); //goes back to main menu
739749
return;
740750
}
741751
if (Background.inBackground) {
@@ -748,39 +758,23 @@ public void chooseTimeToRunHandler() {
748758
}
749759

750760
public void startBackgroundHandler() {
751-
if (Background.inBackground) {
752-
if (PlatformUtil.isMac()) {
753-
Alert alert = new Alert(Alert.AlertType.INFORMATION,
754-
"You will need to restart the application for changes to take effect.", ButtonType.OK);
755-
alert.showAndWait();
756-
appPrefs.putBoolean("Show background startup message", true);
757-
appPrefs.putBoolean("Start background immediately", false);
758-
Platform.exit();
759-
} else {
760-
Background.stopBackground(true);
761-
appPrefs.putBoolean("Show background startup message", true);
762-
appPrefs.putBoolean("Start background immediately", false);
763-
startBackgroundButton.setText("Start background");
764-
}
765-
} else if (appPrefs.getBoolean("Show background startup message", true) && PlatformUtil.isMac()) {
766-
Alert alert = new Alert(Alert.AlertType.INFORMATION,
767-
"You will need to restart the application for changes to take effect. By default, when you launch this application, it will start up in the background. "
768-
+ "If you would like to show the window, find the icon in your system tray/status bar and click on \"Open Window\"", ButtonType.OK);
769-
alert.showAndWait();
770-
appPrefs.putBoolean("Show background startup message", false);
771-
appPrefs.putBoolean("Start background immediately", true);
772-
Platform.exit();
761+
if (Background.inBackground) { //stops background if already in background
762+
Background.stopBackground(true);
763+
appPrefs.putBoolean("Show background startup message", true);
764+
appPrefs.putBoolean("Start background immediately", false);
765+
startBackgroundButton.setText("Start background");
773766
} else if (appPrefs.getBoolean("Show background startup message", true)) {
774767
Alert alert = new Alert(Alert.AlertType.INFORMATION,
775768
"The application will now enter the background. By default, when you launch this application, it will start up in the background. "
776769
+ "If you would like to show the window, find the icon in your system tray/status bar and click on \"Open Window\"", ButtonType.OK);
777770
alert.showAndWait();
778771
appPrefs.putBoolean("Show background startup message", false);
779772
appPrefs.putBoolean("Start background immediately", true);
773+
startBackgroundButton.setText("Stop background");
780774
Background.startBackground(false);
781775
} else {
782776
Background.startBackground(false);
783-
startBackgroundButton.setText("Cancel Background");
777+
startBackgroundButton.setText("Stop Background");
784778
}
785779
}
786780

src/main/java/com/airsquared/blobsaver/Libimobiledevice.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ public static void throwIfNeeded(int errorCode, boolean showAlert, ErrorCodeType
205205
static {
206206
try {
207207
//noinspection ConstantConditions
208-
System.setProperty("jna.library.path", Shared.getlibimobiledeviceFolder().getPath());
208+
System.setProperty("jna.library.path", Shared.getLibimobiledeviceFolder().getPath());
209209
} catch (IOException e) {
210210
newReportableError("Error: unable to get libimobiledevice folder", e.getMessage());
211211
}

0 commit comments

Comments
 (0)