diff --git a/bin/main/de/tudbut/gimpshot/GIMPShot.class b/bin/main/de/tudbut/gimpshot/GIMPShot.class index 6511b81..1892cd7 100644 Binary files a/bin/main/de/tudbut/gimpshot/GIMPShot.class and b/bin/main/de/tudbut/gimpshot/GIMPShot.class differ diff --git a/build.gradle b/build.gradle index f76a648..d62bf0c 100644 --- a/build.gradle +++ b/build.gradle @@ -11,6 +11,10 @@ plugins { id 'application' } +configurations { + fat +} + repositories { // Use Maven Central for resolving dependencies. mavenCentral() @@ -21,16 +25,13 @@ repositories { dependencies { // This dependency is used by the application. - implementation 'com.google.guava:guava:30.1.1-jre' - implementation("de.tudbut:tuddylib:gitlab-1.0.2") + implementation(fat("de.tudbut:tuddylib:gitlab-1.0.2")) } -application { - // Define the main class for the application. - mainClass = 'de.tudbut.gimpshot.GIMPShot' +mainClassName = 'de.tudbut.gimpshot.GIMPShot' + +jar { + from { configurations.fat.collect { it.isDirectory() ? it : zipTree(it) } } + manifest.attributes(['Main-Class':mainClassName]) } -tasks.named('test') { - // Use JUnit Platform for unit tests. - useJUnitPlatform() -} diff --git a/src/main/java/de/tudbut/gimpshot/GIMPShot.java b/src/main/java/de/tudbut/gimpshot/GIMPShot.java index 4cb1ffe..fda78fb 100644 --- a/src/main/java/de/tudbut/gimpshot/GIMPShot.java +++ b/src/main/java/de/tudbut/gimpshot/GIMPShot.java @@ -11,13 +11,33 @@ import javax.imageio.ImageIO; import tudbut.tools.Tools2; public class GIMPShot { + public static void main(String[] args) throws IOException, AWTException, InterruptedException { + // Screenshot immediately, dont wait for config. BufferedImage image = Tools2.screenshot(); - File f = new File("gimpshot-screenshot.png"); + File f = new File(System.getenv().getOrDefault("TMPDIR", "/tmp") + "/gs_screenshot.png"); f.deleteOnExit(); FileOutputStream os = new FileOutputStream(f); ImageIO.write(image, "png", os); os.close(); - Runtime.getRuntime().exec("gimp -ndfs gimpshot-screenshot.png".split(" ")).waitFor(); + + // Read config now + Config config = new Config(getConfigPath()); + Runtime.getRuntime().exec(new String[] { + "sh", + "-c", + config.getCommand() + .replace("$f", f.getAbsolutePath()) + .replace("$r", image.getWidth() + "x" + image.getHeight()) + .replace("$R", image.getWidth() + "," + image.getHeight()) + .replace("$w", String.valueOf(image.getWidth())) + .replace("$h", String.valueOf(image.getHeight())) + }).waitFor(); + } + + public static String getConfigPath() { + String cfg = System.getenv().getOrDefault("XDG_CONFIG_HOME", System.getProperty("user.home") + "/.config"); + new File(cfg, "gimpshot").mkdir(); + return new File(cfg + "/gimpshot", "config.tcn").getAbsolutePath(); } }