forked from j62/ctbrec
1
0
Fork 0

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.
This commit is contained in:
0xboobface 2019-01-24 17:36:23 +01:00
parent 2c67b0b75c
commit d346270da2
1 changed files with 24 additions and 0 deletions

View File

@ -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<Site> 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<Model> 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)) {