Skip to content

Commit f7a2b4c

Browse files
committed
Fix primaryStage not opening while in background
1 parent a4e42c2 commit f7a2b4c

File tree

2 files changed

+6
-15
lines changed

2 files changed

+6
-15
lines changed

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

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
import javafx.application.Platform;
2525
import javafx.collections.FXCollections;
2626
import javafx.event.ActionEvent;
27-
import javafx.event.EventHandler;
2827
import javafx.fxml.FXML;
2928
import javafx.scene.control.*;
3029
import javafx.scene.effect.DropShadow;
@@ -34,7 +33,6 @@
3433
import javafx.scene.paint.Color;
3534
import javafx.stage.DirectoryChooser;
3635
import javafx.stage.Stage;
37-
import javafx.stage.WindowEvent;
3836
import org.json.JSONArray;
3937

4038
import java.awt.Desktop;
@@ -113,6 +111,9 @@ static void afterStageShowing() {
113111
btn.setText("Load " + appPrefs.get("Name Preset" + i, ""));
114112
}
115113
}
114+
if (PlatformUtil.isMac()) {
115+
INSTANCE.useMacOSMenuBar();
116+
}
116117
checkForUpdates(false);
117118
}
118119

@@ -187,18 +188,6 @@ public void initialize() {
187188
path = path + System.getProperty("file.separator") + "Blobs";
188189
}
189190
pathField.setText(path);
190-
191-
// use macos menu bar or not
192-
if (PlatformUtil.isMac()) {
193-
primaryStage.setOnShowing(new EventHandler<WindowEvent>() {
194-
@Override
195-
public void handle(WindowEvent event) {
196-
useMacOSMenuBar();
197-
log("using macOS menu bar");
198-
primaryStage.removeEventHandler(event.getEventType(), this);
199-
}
200-
});
201-
}
202191
}
203192

204193
private static void addListenerToSetNullEffect(TextField... textFields) {
@@ -663,6 +652,7 @@ private void useMacOSMenuBar() {
663652

664653
// needs to be run with Platform.runLater(), otherwise the application menu doesn't show up
665654
Platform.runLater(() -> tk.setGlobalMenuBar(macOSMenuBar));
655+
log("using macOS menu bar");
666656
}
667657

668658
public void backgroundSettingsHandler() {

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ public void start(Stage primaryStage) throws IOException {
9999
if (Background.inBackground) {
100100
primaryStage.hide();
101101
} else {
102-
stop();
102+
Platform.exit();
103103
}
104104
});
105105
appPrefs.put("App version", appVersion);
@@ -110,6 +110,7 @@ public void stop() {
110110
if (Background.inBackground) {
111111
Background.stopBackground(false);
112112
}
113+
System.exit(0);
113114
}
114115
}
115116
}

0 commit comments

Comments
 (0)