| 36 | } |
| 37 | |
| 38 | @Override |
| 39 | public void run() { |
| 40 | doRun = true; |
| 41 | delay = 0; |
| 42 | if (!(body.trim().equals("null"))) { |
| 43 | try { |
| 44 | delay = Integer.valueOf(body.trim()); |
| 45 | } catch (NumberFormatException e) { |
| 46 | Platform.runLater(() -> { exitcode.Console.printText(termArea, String.format("Unknown argument(s): \"%s\"", body)); }); |
| 47 | doRun = false; |
| 48 | } |
| 49 | } |
| 50 | if (doRun) { |
| 51 | thread = new Thread(() -> { |
| 52 | if (delay >= 1) { |
| 53 | Platform.runLater(() -> { exitcode.Console.printText(termArea, String.format("Taking screenshot in %s seconds..", Snap.delay)); }); |
| 54 | IntStream.range(0, delay).forEachOrdered(n -> { |
| 55 | Platform.runLater(() -> { exitcode.Console.printText(termArea, String.format("%s..", (Snap.delay - n))); }); |
| 56 | try { Thread.sleep(1000); }catch(InterruptedException ignored){} |
| 57 | }); |
| 58 | } else { |
| 59 | Platform.runLater(() -> { exitcode.Console.printText(termArea, "Taking screenshot.."); }); |
| 60 | } |
| 61 | Platform.runLater(() -> { exitcode.Console.printText(termArea, "Cheese!"); }); |
| 62 | Platform.runLater(() -> { takeSnap(); }); |
| 63 | Platform.runLater(() -> { |
| 64 | if (!(Snap.snapshot == null)) { |
| 65 | exitcode.Console.printText(termArea, String.format("Screenshot saved to: %s", Snap.snapshot)); |
| 66 | } else { |
| 67 | exitcode.Console.printText(termArea, "Couldn't take Screenshot :("); |
| 68 | } |
| 69 | }); |
| 70 | return; |
| 71 | }); |
| 72 | thread.setDaemon(true); |
| 73 | thread.start(); |
| 74 | } |
| 75 | } |
| 76 | |
| 77 | public void takeSnap() { |
| 78 | Path currentPath = Paths.get(System.getProperty("user.dir")); |