-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Code refactor to handle both Windows and Mac
- Loading branch information
Showing
14 changed files
with
179 additions
and
107 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,3 +35,6 @@ out/ | |
|
||
### VS Code ### | ||
.vscode/ | ||
|
||
### Debug stuff ### | ||
.debug |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,77 @@ | ||
package io.skyshard.configuration; | ||
|
||
import java.awt.*; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.apache.commons.lang3.SystemUtils; | ||
import org.bytedeco.javacv.FFmpegFrameGrabber; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
import java.awt.*; | ||
|
||
@Slf4j | ||
@Configuration | ||
public class GrabConfig { | ||
|
||
@Bean | ||
public FFmpegFrameGrabber grabber() { | ||
/** | ||
* Create a FFmpegFrameGrabber to capture that screen region. We use this instead of a more | ||
* 'common' robot.createScreenCapture() approach as its faster, and works correctly on Mac OS. | ||
*/ | ||
@Bean | ||
public FFmpegFrameGrabber grabber() { | ||
|
||
final Dimension dimension = getDimension(); | ||
|
||
final FFmpegFrameGrabber grabber = getSystemSpecificGrabber(); | ||
|
||
grabber.setFrameRate(30); | ||
grabber.setImageWidth(dimension.width); | ||
grabber.setImageHeight(dimension.height); | ||
grabber.setOption("preset", "ultrafast"); | ||
|
||
return grabber; | ||
} | ||
|
||
/** | ||
* Return a grabber for either windows or mac; If you're trying to run this on anything else it will most likely | ||
* fail. | ||
*/ | ||
private FFmpegFrameGrabber getSystemSpecificGrabber() { | ||
|
||
if (SystemUtils.IS_OS_WINDOWS) { | ||
return buildGrabber("desktop", "gdigrab"); | ||
} | ||
|
||
if (SystemUtils.IS_OS_MAC) { | ||
|
||
// 2:0 represents the screen you want to grab, if primary display set as 1:0, if external monitor 2:0. | ||
return buildGrabber("2:0", "avfoundation"); | ||
} | ||
|
||
throw new RuntimeException("Unsupported System. Exiting..."); | ||
} | ||
|
||
/** | ||
* Function to create a new grabber with predefined settings. | ||
*/ | ||
private FFmpegFrameGrabber buildGrabber(final String filename, final String format) { | ||
|
||
FFmpegFrameGrabber grabber = new FFmpegFrameGrabber(filename); | ||
grabber.setFormat(format); | ||
|
||
return grabber; | ||
} | ||
|
||
/** | ||
* Identify the resolution of the current monitor. | ||
*/ | ||
private Dimension getDimension() { | ||
|
||
final Dimension dimension = Toolkit.getDefaultToolkit().getScreenSize(); | ||
final var dimension = Toolkit.getDefaultToolkit().getScreenSize(); | ||
|
||
log.info( | ||
"Using screen dimensions {}x{} as reference points", dimension.width, dimension.height); | ||
log.info( | ||
"Using screen dimensions {}x{} as reference points", dimension.width, dimension.height); | ||
|
||
final FFmpegFrameGrabber grabber = new FFmpegFrameGrabber("desktop"); | ||
grabber.setFormat("gdigrab"); | ||
grabber.setFrameRate(1); | ||
grabber.setImageWidth(dimension.width); | ||
grabber.setImageHeight(dimension.height); | ||
grabber.setOption("preset", "ultrafast"); | ||
return dimension; | ||
} | ||
|
||
return grabber; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,8 @@ | ||
package io.skyshard.services; | ||
|
||
import io.skyshard.domain.Target; | ||
import java.util.List; | ||
|
||
public interface AttackService { | ||
|
||
void attack(Target target); | ||
|
||
void attack(List<Target> targets); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.