fix gradle script, add working jar task, add custom command support

This commit is contained in:
Daniella 2022-07-13 22:20:28 +02:00
parent 960d75a936
commit 93f725fcae
3 changed files with 32 additions and 11 deletions

View file

@ -11,6 +11,10 @@ plugins {
id 'application' id 'application'
} }
configurations {
fat
}
repositories { repositories {
// Use Maven Central for resolving dependencies. // Use Maven Central for resolving dependencies.
mavenCentral() mavenCentral()
@ -21,16 +25,13 @@ repositories {
dependencies { dependencies {
// This dependency is used by the application. // This dependency is used by the application.
implementation 'com.google.guava:guava:30.1.1-jre' implementation(fat("de.tudbut:tuddylib:gitlab-1.0.2"))
implementation("de.tudbut:tuddylib:gitlab-1.0.2")
} }
application { mainClassName = 'de.tudbut.gimpshot.GIMPShot'
// Define the main class for the application.
mainClass = '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()
}

View file

@ -11,13 +11,33 @@ import javax.imageio.ImageIO;
import tudbut.tools.Tools2; import tudbut.tools.Tools2;
public class GIMPShot { public class GIMPShot {
public static void main(String[] args) throws IOException, AWTException, InterruptedException { public static void main(String[] args) throws IOException, AWTException, InterruptedException {
// Screenshot immediately, dont wait for config.
BufferedImage image = Tools2.screenshot(); 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(); f.deleteOnExit();
FileOutputStream os = new FileOutputStream(f); FileOutputStream os = new FileOutputStream(f);
ImageIO.write(image, "png", os); ImageIO.write(image, "png", os);
os.close(); 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();
} }
} }