Fix to remove alert if timeout expires during system sleep. master
authorNot Zed <notzed@gmail.com>
Wed, 4 May 2022 21:11:20 +0000 (06:41 +0930)
committerNot Zed <notzed@gmail.com>
Wed, 4 May 2022 21:11:20 +0000 (06:41 +0930)
Makefile
java/notzed.busyalert/au/notzed/busyalert/BusyAlert.java
src/busyalert.in

index ffbcd10..a7d27ee 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1,7 +1,8 @@
 
 
-VERSION=-0
+VERSION=-1
 
 
-JAVAFX_HOME=/usr/lib64/javafx-sdk-13
+JAVAFX_HOME=/usr/local/javafx-sdk-15
+JAVA_HOME=/usr/local/jdk-15
 
 CFLAGS=-Wall -Wno-parentheses
 CPPFLAGS=
 
 CFLAGS=-Wall -Wno-parentheses
 CPPFLAGS=
@@ -33,8 +34,9 @@ clean:
        rm -rf bin
 
 install: bin/notzed.busyalert.jar bin/busymon
        rm -rf bin
 
 install: bin/notzed.busyalert.jar bin/busymon
-       sed -e 's,@JAVAFX_HOME@,$(JAVAFX_HOME),g' \
-           -e 's,@MODULE_DIR@,$(DESTDIR)$(prefix)/share/notzed.busyalert,g' \
+       sed -e 's,@JAVA_HOME@,$(JAVA_HOME),g' \
+           -e 's,@JAVAFX_HOME@,$(JAVAFX_HOME),g' \
+           -e 's,@MODULE_DIR@,$(prefix)/share/notzed.busyalert,g' \
           < src/busyalert.in > bin/busyalert
        chmod 755 bin/busyalert
        install -D bin/busyalert $(DESTDIR)$(prefix)/share/notzed.busyalert/busyalert
           < src/busyalert.in > bin/busyalert
        chmod 755 bin/busyalert
        install -D bin/busyalert $(DESTDIR)$(prefix)/share/notzed.busyalert/busyalert
@@ -48,4 +50,3 @@ dist:
        src/busyalert.in src/busymon.c \
        $(notzed.busyalert_JAVA) \
        contrib
        src/busyalert.in src/busymon.c \
        $(notzed.busyalert_JAVA) \
        contrib
-
index 2e51f39..00e0427 100644 (file)
@@ -22,6 +22,7 @@ import java.time.temporal.ChronoUnit;
 import java.util.concurrent.Executors;
 import java.util.concurrent.ScheduledExecutorService;
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.Executors;
 import java.util.concurrent.ScheduledExecutorService;
 import java.util.concurrent.TimeUnit;
+import java.util.function.BooleanSupplier;
 import javafx.application.Application;
 import javafx.application.Platform;
 import javafx.geometry.Insets;
 import javafx.application.Application;
 import javafx.application.Platform;
 import javafx.geometry.Insets;
@@ -39,6 +40,8 @@ import javafx.stage.Stage;
 public class BusyAlert extends Application {
 
        long timeout = 60 * 5;
 public class BusyAlert extends Application {
 
        long timeout = 60 * 5;
+       Label time = new Label();
+       Instant start = Instant.now();
 
        ScheduledExecutorService queue = Executors.newSingleThreadScheduledExecutor((r) -> {
                Thread t = new Thread(r);
 
        ScheduledExecutorService queue = Executors.newSingleThreadScheduledExecutor((r) -> {
                Thread t = new Thread(r);
@@ -47,10 +50,7 @@ public class BusyAlert extends Application {
        });
 
        @Override
        });
 
        @Override
-       public void start(Stage primaryStage) throws Exception {
-               Stage stage = new Stage();
-
-               Label time = new Label();
+       public void start(Stage stage) throws Exception {
                Label text = new Label("BREAK NOW!");
                VBox box = new VBox(text, time);
 
                Label text = new Label("BREAK NOW!");
                VBox box = new VBox(text, time);
 
@@ -65,8 +65,6 @@ public class BusyAlert extends Application {
 
                text.setFont(Font.font("monspaced", 96));
 
 
                text.setFont(Font.font("monspaced", 96));
 
-               Instant start = Instant.now();
-
                Scene scene = new Scene(box);
 
                stage.setFullScreen(true);
                Scene scene = new Scene(box);
 
                stage.setFullScreen(true);
@@ -75,28 +73,20 @@ public class BusyAlert extends Application {
 
                stage.show();
 
 
                stage.show();
 
-               queueForever(() -> {
-                       Duration delta = Duration.between(start, Instant.now());
-                       long waited = delta.get(ChronoUnit.SECONDS);
-                       long left = timeout - waited;
-
-                       time.setText(String.format("%3d:%02d", left / 60, left % 60));
-               });
-
-               queue.schedule(() -> Platform.runLater(stage::close),
-                       timeout, TimeUnit.SECONDS);
-       }
-
-       void queueForever(Runnable r) {
-               queue.schedule(() -> {
-                       Platform.runLater(r);
-                       queueForever(r);
-               },
-                       1, TimeUnit.SECONDS
-               );
+               update();
        }
 
        void update() {
        }
 
        void update() {
+               Duration delta = Duration.between(start, Instant.now());
+               long waited = delta.get(ChronoUnit.SECONDS);
+               long left = timeout - waited;
+
+               if (left >= 0) {
+                       Platform.runLater(() -> time.setText(String.format("%3d:%02d", left / 60, left % 60)));
+                       queue.schedule(this::update, 1, TimeUnit.SECONDS);
+               } else {
+                       Platform.exit();
+               }
        }
 
        public static void main(String[] args) {
        }
 
        public static void main(String[] args) {
index 2b6623f..0649c40 100644 (file)
@@ -1,3 +1,3 @@
 #!/bin/bash
 
 #!/bin/bash
 
-exec java --module-path=@MODULE_DIR@:${JAVAFX_HOME:-@JAVAFX_HOME@}/lib -m notzed.busyalert/au.notzed.busyalert.BusyAlert
+exec @JAVA_HOME@/bin/java --module-path=@MODULE_DIR@:@JAVAFX_HOME@/lib -m notzed.busyalert/au.notzed.busyalert.BusyAlert