Skip to content

fix: Fix stage hidden action In Mac Arm #2133

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ public void show() {
private void initVisibilityProperty(Keys... excludeKeys) {
if (OSUtil.getOS().equals(OSUtil.OS.MAC)) {
supUseEasterEgg.setValue(false);
supScreenshotHideWindow.setValue(false);
supScreenColorPickerHideWindow.setValue(false);
}

for (Keys key : excludeKeys) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ private void initView() {
public void disableKeys(Keys... excludeKeys) {
if (OSUtil.getOS().equals(OSUtil.OS.MAC)) {
disableNode(useEasterEggCheckBox);
disableNode(screenshotHideWindowCheckBox);
disableNode(screenColorPickerHideWindowCheckBox);
}
for (Keys key : excludeKeys) {
switch (key) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import com.tlcsdm.core.javafx.util.Keys;
import com.tlcsdm.core.javafx.util.OSUtil;
import com.tlcsdm.core.util.I18nUtils;
import javafx.application.Platform;
import javafx.embed.swing.SwingFXUtils;
import javafx.geometry.Point2D;
import javafx.geometry.Pos;
Expand Down Expand Up @@ -81,6 +82,7 @@ public class ScreenshotStage extends Stage {
private final Robot robot;
private Label sizeLabel;
private final Label tipsLabel;
private volatile boolean isClosing = false;

/**
* 如果设置TRANSPARENT样式时 {@code stage.initStyle(StageStyle.TRANSPARENT);}
Expand Down Expand Up @@ -168,7 +170,6 @@ public ScreenshotStage() {
getClass().getResource("/com/tlcsdm/core/static/javafx/stage/screenshot-stage.css")).toExternalForm());
this.setScene(scene);
scene.setFill(Color.TRANSPARENT);
//scene.setCursor(new ImageCursor(new javafx.scene.image.Image(getClass().getResource("/images/color-cursor.png").toExternalForm())));
this.initStyle(StageStyle.TRANSPARENT);
rootPane.setVisible(false);

Expand Down Expand Up @@ -210,15 +211,17 @@ private HBox createControlsBox() {
Button copyImageBtn = new Button("", new Region());
copyImageBtn.getStyleClass().addAll("region-btn", "copy-btn");
copyImageBtn.setOnAction(event -> {
if (snapshotView.hasSelection() && snapshotView.getSelection().getWidth() > 1 && snapshotView.getSelection().getHeight() > 1) {
if (snapshotView.hasSelection() && snapshotView.getSelection().getWidth() > 1 && snapshotView.getSelection()
.getHeight() > 1) {
copyScreenshot();
}
});
//保存按钮
Button saveBtn = new Button("", new Region());
saveBtn.getStyleClass().addAll("region-btn", "save-btn");
saveBtn.setOnAction(event -> {
if (snapshotView.hasSelection() && snapshotView.getSelection().getWidth() > 1 && snapshotView.getSelection().getHeight() > 1) {
if (snapshotView.hasSelection() && snapshotView.getSelection().getWidth() > 1 && snapshotView.getSelection()
.getHeight() > 1) {
saveScreenshot();
}
});
Expand All @@ -245,15 +248,17 @@ private void saveScreenshot() {
FileChooser fileChooser = new FileChooser();
DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyyMMddHHmmss");
fileChooser.setInitialFileName("screenshot_" + dtf.format(LocalDateTime.now()));
fileChooser.getExtensionFilters().addAll(new FileChooser.ExtensionFilter("Image File", "*.jpg", "*.png", "*.bmp", "gif", "*.webp"));
fileChooser.getExtensionFilters().addAll(
new FileChooser.ExtensionFilter("Image File", "*.jpg", "*.png", "*.bmp", "gif", "*.webp"));
File outFile = fileChooser.showSaveDialog(this);
if (outFile == null) {
isSaving = false;
controlsBox.setVisible(true);
return;
}

BufferedImage bufferedImage = getScreenBufImg().getSubimage((int) (selection.getMinX() * screenScaleX), (int) (selection.getMinY() * screenScaleY),
BufferedImage bufferedImage = getScreenBufImg().getSubimage((int) (selection.getMinX() * screenScaleX),
(int) (selection.getMinY() * screenScaleY),
(int) (selection.getWidth() * screenScaleX), (int) (selection.getHeight() * screenScaleY));
boolean flag = false;
String[] supportedFormats = {".png", ".jpg", ".bmp", "gif", ".webp"};
Expand All @@ -269,7 +274,8 @@ private void saveScreenshot() {
File realExportDir;
int x = 0;
do {
realExportDir = new File(outFile.getParent() + File.separator + outFile.getName() + (x == 0 ? "" : "(" + x + ")") + "." + "jpg");
realExportDir = new File(
outFile.getParent() + File.separator + outFile.getName() + (x == 0 ? "" : "(" + x + ")") + "." + "jpg");
x++;
} while (realExportDir.exists());
outFile = realExportDir;
Expand Down Expand Up @@ -326,11 +332,19 @@ private BufferedImage getScreenBufImg() {
* 结束截屏
*/
private void endScreenshot() {
if (isClosing) {
return;
}
isClosing = true;
rootPane.setVisible(false);
if (hideMainStage) {
FxApp.primaryStage.setOpacity(1);
Platform.runLater(() -> {
FxApp.primaryStage.setOpacity(1);
FxApp.primaryStage.toFront();
});
}
this.hide();
isClosing = false;
}

public void showStage() {
Expand Down
Loading