From d346270da2ce78997056e29de46078f032f9ee50 Mon Sep 17 00:00:00 2001 From: 0xboobface <0xboobface@gmail.com> Date: Thu, 24 Jan 2019 17:36:23 +0100 Subject: [PATCH] Show the number of active recordings in the window title Use the event system to show the number of active recordings in the window title. Requested in #155. --- .../java/ctbrec/ui/CamrecApplication.java | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/client/src/main/java/ctbrec/ui/CamrecApplication.java b/client/src/main/java/ctbrec/ui/CamrecApplication.java index 0e8cf692..057915aa 100644 --- a/client/src/main/java/ctbrec/ui/CamrecApplication.java +++ b/client/src/main/java/ctbrec/ui/CamrecApplication.java @@ -17,13 +17,16 @@ import java.util.concurrent.TimeUnit; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import com.google.common.eventbus.Subscribe; import com.squareup.moshi.JsonAdapter; import com.squareup.moshi.Moshi; import com.squareup.moshi.Types; import ctbrec.Config; +import ctbrec.Model; import ctbrec.StringUtil; import ctbrec.Version; +import ctbrec.event.Event; import ctbrec.event.EventBusHolder; import ctbrec.event.EventHandler; import ctbrec.event.EventHandlerConfiguration; @@ -69,9 +72,11 @@ public class CamrecApplication extends Application { private List sites = new ArrayList<>(); public static HttpClient httpClient; public static String title; + private Stage primaryStage; @Override public void start(Stage primaryStage) throws Exception { + this.primaryStage = primaryStage; logEnvironment(); sites.add(new BongaCams()); sites.add(new Cam4()); @@ -82,6 +87,7 @@ public class CamrecApplication extends Application { sites.add(new Streamate()); loadConfig(); registerAlertSystem(); + registerActiveRecordingsCounter(); createHttpClient(); hostServices = getHostServices(); createRecorder(); @@ -238,6 +244,24 @@ public class CamrecApplication extends Application { }).start(); } + private void registerActiveRecordingsCounter() { + EventBusHolder.BUS.register(new Object() { + @Subscribe + public void handleEvent(Event evt) { + if(evt.getType() == Event.Type.MODEL_STATUS_CHANGED || evt.getType() == Event.Type.RECORDING_STATUS_CHANGED) { + try { + List models = recorder.getOnlineModels(); + long count = models.stream().filter(m -> !recorder.isSuspended(m)).count(); + String _title = count > 0 ? "(" + count + ") " + title : title; + Platform.runLater(() -> primaryStage.setTitle(_title)); + } catch (Exception e) { + LOG.warn("Couldn't update window title", e); + } + } + } + }); + } + private void writeColorSchemeStyleSheet(Stage primaryStage) { File colorCss = new File(Config.getInstance().getConfigDir(), "color.css"); try(FileOutputStream fos = new FileOutputStream(colorCss)) {