forked from j62/ctbrec
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:
parent
2c67b0b75c
commit
d346270da2
|
@ -17,13 +17,16 @@ import java.util.concurrent.TimeUnit;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import com.google.common.eventbus.Subscribe;
|
||||||
import com.squareup.moshi.JsonAdapter;
|
import com.squareup.moshi.JsonAdapter;
|
||||||
import com.squareup.moshi.Moshi;
|
import com.squareup.moshi.Moshi;
|
||||||
import com.squareup.moshi.Types;
|
import com.squareup.moshi.Types;
|
||||||
|
|
||||||
import ctbrec.Config;
|
import ctbrec.Config;
|
||||||
|
import ctbrec.Model;
|
||||||
import ctbrec.StringUtil;
|
import ctbrec.StringUtil;
|
||||||
import ctbrec.Version;
|
import ctbrec.Version;
|
||||||
|
import ctbrec.event.Event;
|
||||||
import ctbrec.event.EventBusHolder;
|
import ctbrec.event.EventBusHolder;
|
||||||
import ctbrec.event.EventHandler;
|
import ctbrec.event.EventHandler;
|
||||||
import ctbrec.event.EventHandlerConfiguration;
|
import ctbrec.event.EventHandlerConfiguration;
|
||||||
|
@ -69,9 +72,11 @@ public class CamrecApplication extends Application {
|
||||||
private List<Site> sites = new ArrayList<>();
|
private List<Site> sites = new ArrayList<>();
|
||||||
public static HttpClient httpClient;
|
public static HttpClient httpClient;
|
||||||
public static String title;
|
public static String title;
|
||||||
|
private Stage primaryStage;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void start(Stage primaryStage) throws Exception {
|
public void start(Stage primaryStage) throws Exception {
|
||||||
|
this.primaryStage = primaryStage;
|
||||||
logEnvironment();
|
logEnvironment();
|
||||||
sites.add(new BongaCams());
|
sites.add(new BongaCams());
|
||||||
sites.add(new Cam4());
|
sites.add(new Cam4());
|
||||||
|
@ -82,6 +87,7 @@ public class CamrecApplication extends Application {
|
||||||
sites.add(new Streamate());
|
sites.add(new Streamate());
|
||||||
loadConfig();
|
loadConfig();
|
||||||
registerAlertSystem();
|
registerAlertSystem();
|
||||||
|
registerActiveRecordingsCounter();
|
||||||
createHttpClient();
|
createHttpClient();
|
||||||
hostServices = getHostServices();
|
hostServices = getHostServices();
|
||||||
createRecorder();
|
createRecorder();
|
||||||
|
@ -238,6 +244,24 @@ public class CamrecApplication extends Application {
|
||||||
}).start();
|
}).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) {
|
private void writeColorSchemeStyleSheet(Stage primaryStage) {
|
||||||
File colorCss = new File(Config.getInstance().getConfigDir(), "color.css");
|
File colorCss = new File(Config.getInstance().getConfigDir(), "color.css");
|
||||||
try(FileOutputStream fos = new FileOutputStream(colorCss)) {
|
try(FileOutputStream fos = new FileOutputStream(colorCss)) {
|
||||||
|
|
Loading…
Reference in New Issue