Add timestamp screenshot for MacOS on debugging UI
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Bea 2024-08-05 23:52:13 +02:00
parent bef4913447
commit 8ef9ea9288
4 changed files with 51 additions and 10 deletions

View File

@ -1,8 +1,6 @@
# autosqueal
[![Build Status](https://drone.beatrice.wtf/api/badges/Tools/autosqeal/status.svg?ref=refs/heads/main)](https://drone.beatrice.wtf/Tools/autosqeal)
[![Quality Gate Status](https://sonar.beatrice.wtf/api/project_badges/measure?project=autosqueal&metric=alert_status&token=sqb_49dde556c032d0130640ea1e48875905b158d368)](https://sonar.beatrice.wtf/dashboard?id=autosqueal)
**Statistics**
[![Reliability Rating](https://sonar.beatrice.wtf/api/project_badges/measure?project=autosqueal&metric=reliability_rating&token=sqb_49dde556c032d0130640ea1e48875905b158d368)](https://sonar.beatrice.wtf/dashboard?id=autosqueal)
[![Security Rating](https://sonar.beatrice.wtf/api/project_badges/measure?project=autosqueal&metric=security_rating&token=sqb_49dde556c032d0130640ea1e48875905b158d368)](https://sonar.beatrice.wtf/dashboard?id=autosqueal)
[![Maintainability Rating](https://sonar.beatrice.wtf/api/project_badges/measure?project=autosqueal&metric=sqale_rating&token=sqb_49dde556c032d0130640ea1e48875905b158d368)](https://sonar.beatrice.wtf/dashboard?id=autosqueal)

View File

@ -16,7 +16,6 @@ public class Main {
LOGGER.info("Hello world!");
registerJNativeHook();
mainWindow.init();
}

View File

@ -6,6 +6,7 @@ import org.apache.logging.log4j.Logger;
import wtf.beatrice.autosqueal.controls.CursorMover;
import wtf.beatrice.autosqueal.listener.CursorMoveListener;
import wtf.beatrice.autosqueal.util.RunnerUtil;
import wtf.beatrice.autosqueal.util.SystemUtil;
import javax.swing.*;
import java.awt.*;
@ -16,7 +17,7 @@ public class MainWindow
{
private static final Logger LOGGER = LogManager.getLogger(MainWindow.class);
private static final int WINDOW_HEIGHT = 600;
private static final int WINDOW_HEIGHT = 700;
private static final int WINDOW_WIDTH = 800;
private Timer timerRunner = new Timer();
@ -40,25 +41,43 @@ public class MainWindow
int rescaleRateo = ((WINDOW_WIDTH - (2 * bordersPx)) * 100) / RunnerUtil.SCREEN_WIDTH;
int rescaleWidth = RunnerUtil.SCREEN_WIDTH * rescaleRateo / 100;
int rescaleHeight = RunnerUtil.SCREEN_HEIGHT * rescaleRateo / 100;
JLabel imageLabel = new JLabel(getScreenCapture(rescaleWidth, rescaleHeight));
JLabel imageLabel = new JLabel(new ImageIcon(getScreenCapture(rescaleWidth, rescaleHeight)));
imageLabel.setBounds(new Rectangle(bordersPx, bordersPx, rescaleWidth, rescaleHeight));
frame.add(imageLabel);
JLabel timestampLabel = new JLabel(new ImageIcon(getPreciseScreenshot()));
timestampLabel.setBounds(new Rectangle(bordersPx, bordersPx + rescaleHeight + bordersPx, 100, 30));
frame.add(timestampLabel);
frame.setLayout(null);
frame.setVisible(true);
}
private ImageIcon getScreenCapture(int rescaleWidth, int rescaleHeight) {
private Image getScreenCapture(int rescaleWidth, int rescaleHeight) {
Image fullImage = getScreenCapture();
return fullImage.getScaledInstance(rescaleWidth, rescaleHeight, Image.SCALE_FAST);
}
public Image getPreciseScreenshot() {
if(SystemUtil.getHostSystem().equals(SystemUtil.OperatingSystem.MAC_OS)) {
BufferedImage screenshot = getScreenCapture();
return screenshot.getSubimage(RunnerUtil.SCREEN_WIDTH - 100,0, 100, 30);
}
try {
Robot robot = new Robot();
BufferedImage fullImage = robot.createScreenCapture(new Rectangle(RunnerUtil.SCREEN_WIDTH, RunnerUtil.SCREEN_HEIGHT));
Image image = fullImage.getScaledInstance(rescaleWidth, rescaleHeight, Image.SCALE_FAST);
return new ImageIcon(image);
} catch (AWTException e) {
LOGGER.error("Robot initialization error", e);
return null;
}
public BufferedImage getScreenCapture() {
try {
Robot robot = new Robot();
return robot.createScreenCapture(new Rectangle(RunnerUtil.SCREEN_WIDTH, RunnerUtil.SCREEN_HEIGHT));
} catch (AWTException e) {
LOGGER.error("Robot initialization error", e);
}
return null;
}
public void toggleRunning() {
@ -95,4 +114,5 @@ public class MainWindow
toggleButton.setLabel(label);
}
}

View File

@ -0,0 +1,24 @@
package wtf.beatrice.autosqueal.util;
import java.util.Locale;
public class SystemUtil
{
public static OperatingSystem getHostSystem() {
String osName = System.getProperty("os.name").toLowerCase(Locale.ENGLISH);
if (osName.contains("win")) {
return OperatingSystem.WINDOWS;
} else if (osName.contains("nix") || osName.contains("nux")) {
return OperatingSystem.LINUX;
} else if (osName.contains("mac")) {
return OperatingSystem.MAC_OS;
} else {
return OperatingSystem.UNKNOWN;
}
}
public enum OperatingSystem {
WINDOWS, LINUX, MAC_OS, UNKNOWN;
}
}