Skip to content

Commit 751f935

Browse files
committed
Fix macOS menu bar not working when starting application in background
1 parent 83e5e0e commit 751f935

File tree

3 files changed

+15
-5
lines changed

3 files changed

+15
-5
lines changed

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

+3-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,9 @@ static void startBackground(boolean runOnlyOnce) {
7979
return;
8080
}
8181
if (!runOnlyOnce && Platform.isFxApplicationThread()) {
82-
Main.hideStage();
82+
if (Main.primaryStage.isShowing()) {
83+
Main.hideStage();
84+
}
8385
Notification.Notifier.INSTANCE.setPopupLifetime(Duration.seconds(30));
8486
Notification.Notifier.INSTANCE.notifyInfo("Background process has started", "Check your system tray/status bar for\nthe icon."
8587
+ presetsToSaveNames.toString().substring(1, presetsToSaveNames.toString().length() - 1));

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

+3-1
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,9 @@ public void savePresetHandler() {
464464
public void checkBlobs() { openURL("https://tsssaver.1conan.com/check.php"); }
465465

466466
public void helpLabelHandler(MouseEvent evt) {
467-
if (Main.SHOW_BREAKPOINT) return; // remember to put a breakpoint here
467+
if (Main.SHOW_BREAKPOINT) {
468+
return; // remember to put a breakpoint here
469+
}
468470

469471
String labelID;
470472
// if user clicks on question mark instead of padding, evt.getTarget() returns LabeledText instead of Label

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

+9-3
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,16 @@ public void start(Stage primaryStage) throws IOException {
112112
primaryStage.setResizable(false);
113113
Controller.afterStageShowing();
114114
Platform.setImplicitExit(false);
115+
showStage();
115116
if (appPrefs.getBoolean("Start background immediately", false)) {
116-
Background.startBackground(false);
117-
} else {
118-
showStage();
117+
/* I have to show the stage then hide it again in Platform.runLater() otherwise
118+
* the needed initialization code won't run at the right time when starting the background
119+
* (for example, the macOS menu bar won't work properly if I don't do this)
120+
*/
121+
Platform.runLater(() -> {
122+
hideStage();
123+
Background.startBackground(false);
124+
});
119125
}
120126

121127
//if in background, hide; else quit

0 commit comments

Comments
 (0)