forked from j62/ctbrec
Merge branch 'dev' into fc2
This commit is contained in:
commit
e7feaad11c
|
@ -250,7 +250,7 @@ public class CamrecApplication extends Application {
|
|||
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) {
|
||||
if(evt.getType() == Event.Type.MODEL_ONLINE || 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();
|
||||
|
|
|
@ -1,6 +1,12 @@
|
|||
package ctbrec.ui;
|
||||
|
||||
import java.awt.AWTException;
|
||||
import java.awt.Desktop;
|
||||
import java.awt.Image;
|
||||
import java.awt.SystemTray;
|
||||
import java.awt.Toolkit;
|
||||
import java.awt.TrayIcon;
|
||||
import java.awt.TrayIcon.MessageType;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
|
@ -8,6 +14,8 @@ import java.net.URI;
|
|||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import ctbrec.OS;
|
||||
import ctbrec.io.StreamRedirectThread;
|
||||
import javafx.geometry.Insets;
|
||||
import javafx.scene.control.Alert;
|
||||
import javafx.scene.control.Label;
|
||||
|
@ -18,6 +26,9 @@ public class DesktopIntegration {
|
|||
|
||||
private static final transient Logger LOG = LoggerFactory.getLogger(DesktopIntegration.class);
|
||||
|
||||
private static SystemTray tray;
|
||||
private static TrayIcon trayIcon;
|
||||
|
||||
public static void open(String uri) {
|
||||
try {
|
||||
CamrecApplication.hostServices.showDocument(uri);
|
||||
|
@ -95,4 +106,65 @@ public class DesktopIntegration {
|
|||
info.getDialogPane().setExpanded(true);
|
||||
info.show();
|
||||
}
|
||||
|
||||
public static void notification(String title, String header, String msg) {
|
||||
if(OS.getOsType() == OS.TYPE.LINUX) {
|
||||
notifyLinux(title, header, msg);
|
||||
} else if(OS.getOsType() == OS.TYPE.WINDOWS) {
|
||||
notifyWindows(title, header, msg);
|
||||
} else if(OS.getOsType() == OS.TYPE.MAC) {
|
||||
notifyMac(title, header, msg);
|
||||
} else {
|
||||
// unknown system, try systemtray notification anyways
|
||||
notifySystemTray(title, header, msg);
|
||||
}
|
||||
}
|
||||
|
||||
private static void notifyLinux(String title, String header, String msg) {
|
||||
try {
|
||||
Process p = Runtime.getRuntime().exec(new String[] {
|
||||
"notify-send",
|
||||
"-u", "normal",
|
||||
"-t", "5000",
|
||||
"-a", title,
|
||||
header,
|
||||
msg.replaceAll("-", "\\\\-").replaceAll("\\s", "\\\\ "),
|
||||
"--icon=dialog-information"
|
||||
});
|
||||
new Thread(new StreamRedirectThread(p.getInputStream(), System.out)).start();
|
||||
new Thread(new StreamRedirectThread(p.getErrorStream(), System.err)).start();
|
||||
} catch (IOException e1) {
|
||||
LOG.error("Notification failed", e1);
|
||||
}
|
||||
}
|
||||
|
||||
private static void notifyWindows(String title, String header, String msg) {
|
||||
notifySystemTray(title, header, msg);
|
||||
}
|
||||
|
||||
private static void notifyMac(String title, String header, String msg) {
|
||||
notifySystemTray(title, header, msg);
|
||||
}
|
||||
|
||||
private synchronized static void notifySystemTray(String title, String header, String msg) {
|
||||
if(SystemTray.isSupported()) {
|
||||
if(tray == null) {
|
||||
LOG.debug("Creating tray icon");
|
||||
tray = SystemTray.getSystemTray();
|
||||
Image image = Toolkit.getDefaultToolkit().createImage(DesktopIntegration.class.getResource("/icon64.png"));
|
||||
trayIcon = new TrayIcon(image, title);
|
||||
trayIcon.setImageAutoSize(true);
|
||||
trayIcon.setToolTip(title);
|
||||
try {
|
||||
tray.add(trayIcon);
|
||||
} catch (AWTException e) {
|
||||
LOG.error("Coulnd't add tray icon", e);
|
||||
}
|
||||
}
|
||||
LOG.debug("Display tray message");
|
||||
trayIcon.displayMessage(header, msg, MessageType.INFO);
|
||||
} else {
|
||||
LOG.error("SystemTray notifications not supported by this OS");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
package ctbrec.ui.event;
|
||||
|
||||
import ctbrec.Model;
|
||||
import ctbrec.OS;
|
||||
import ctbrec.event.Action;
|
||||
import ctbrec.event.Event;
|
||||
import ctbrec.event.EventHandlerConfiguration.ActionConfiguration;
|
||||
import ctbrec.event.ModelStateChangedEvent;
|
||||
import ctbrec.event.RecordingStateChangedEvent;
|
||||
import ctbrec.ui.CamrecApplication;
|
||||
import ctbrec.ui.DesktopIntegration;
|
||||
|
||||
public class ShowNotification extends Action {
|
||||
|
||||
|
@ -33,7 +33,7 @@ public class ShowNotification extends Action {
|
|||
default:
|
||||
msg = evt.getDescription();
|
||||
}
|
||||
OS.notification(CamrecApplication.title, header, msg);
|
||||
DesktopIntegration.notification(CamrecApplication.title, header, msg);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -14,7 +14,6 @@ import org.slf4j.LoggerFactory;
|
|||
|
||||
import ctbrec.Config;
|
||||
import ctbrec.Model;
|
||||
import ctbrec.OS;
|
||||
import ctbrec.Recording;
|
||||
import ctbrec.StringUtil;
|
||||
import ctbrec.event.Event;
|
||||
|
@ -29,6 +28,7 @@ import ctbrec.event.ModelStatePredicate;
|
|||
import ctbrec.event.RecordingStatePredicate;
|
||||
import ctbrec.recorder.Recorder;
|
||||
import ctbrec.ui.CamrecApplication;
|
||||
import ctbrec.ui.DesktopIntegration;
|
||||
import ctbrec.ui.controls.FileSelectionBox;
|
||||
import ctbrec.ui.controls.ProgramSelectionBox;
|
||||
import ctbrec.ui.controls.Wizard;
|
||||
|
@ -266,7 +266,7 @@ public class ActionSettingsPanel extends TitledPane {
|
|||
testNotification.setOnAction(evt -> {
|
||||
DateTimeFormatter format = DateTimeFormatter.ofLocalizedTime(FormatStyle.MEDIUM);
|
||||
ZonedDateTime time = ZonedDateTime.now();
|
||||
OS.notification(CamrecApplication.title, "Test Notification", "Oi, what's up! " + format.format(time));
|
||||
DesktopIntegration.notification(CamrecApplication.title, "Test Notification", "Oi, what's up! " + format.format(time));
|
||||
});
|
||||
testNotification.disableProperty().bind(showNotification.selectedProperty().not());
|
||||
|
||||
|
|
|
@ -1,13 +1,6 @@
|
|||
package ctbrec;
|
||||
|
||||
import java.awt.AWTException;
|
||||
import java.awt.Image;
|
||||
import java.awt.SystemTray;
|
||||
import java.awt.Toolkit;
|
||||
import java.awt.TrayIcon;
|
||||
import java.awt.TrayIcon.MessageType;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.nio.file.Path;
|
||||
|
@ -18,8 +11,6 @@ import java.util.Map.Entry;
|
|||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import ctbrec.io.StreamRedirectThread;
|
||||
|
||||
public class OS {
|
||||
|
||||
private static final transient Logger LOG = LoggerFactory.getLogger(OS.class);
|
||||
|
@ -129,61 +120,4 @@ public class OS {
|
|||
}
|
||||
return env;
|
||||
}
|
||||
|
||||
public static void notification(String title, String header, String msg) {
|
||||
if(OS.getOsType() == OS.TYPE.LINUX) {
|
||||
notifyLinux(title, header, msg);
|
||||
} else if(OS.getOsType() == OS.TYPE.WINDOWS) {
|
||||
notifyWindows(title, header, msg);
|
||||
} else if(OS.getOsType() == OS.TYPE.MAC) {
|
||||
notifyMac(title, header, msg);
|
||||
} else {
|
||||
// unknown system, try systemtray notification anyways
|
||||
notifySystemTray(title, header, msg);
|
||||
}
|
||||
}
|
||||
|
||||
private static void notifyLinux(String title, String header, String msg) {
|
||||
try {
|
||||
Process p = Runtime.getRuntime().exec(new String[] {
|
||||
"notify-send",
|
||||
"-u", "normal",
|
||||
"-t", "5000",
|
||||
"-a", title,
|
||||
header,
|
||||
msg.replaceAll("-", "\\\\-").replaceAll("\\s", "\\\\ "),
|
||||
"--icon=dialog-information"
|
||||
});
|
||||
new Thread(new StreamRedirectThread(p.getInputStream(), System.out)).start();
|
||||
new Thread(new StreamRedirectThread(p.getErrorStream(), System.err)).start();
|
||||
} catch (IOException e1) {
|
||||
LOG.error("Notification failed", e1);
|
||||
}
|
||||
}
|
||||
|
||||
private static void notifyWindows(String title, String header, String msg) {
|
||||
notifySystemTray(title, header, msg);
|
||||
}
|
||||
|
||||
private static void notifyMac(String title, String header, String msg) {
|
||||
notifySystemTray(title, header, msg);
|
||||
}
|
||||
|
||||
private static void notifySystemTray(String title, String header, String msg) {
|
||||
if(SystemTray.isSupported()) {
|
||||
SystemTray tray = SystemTray.getSystemTray();
|
||||
Image image = Toolkit.getDefaultToolkit().createImage(OS.class.getResource("/icon64.png"));
|
||||
TrayIcon trayIcon = new TrayIcon(image, title);
|
||||
trayIcon.setImageAutoSize(true);
|
||||
trayIcon.setToolTip(title);
|
||||
try {
|
||||
tray.add(trayIcon);
|
||||
} catch (AWTException e) {
|
||||
LOG.error("Coulnd't add tray icon", e);
|
||||
}
|
||||
trayIcon.displayMessage(header, msg, MessageType.INFO);
|
||||
} else {
|
||||
LOG.error("SystemTray notifications not supported by this OS");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -178,4 +178,20 @@ public class LiveJasmin extends AbstractSite {
|
|||
private LiveJasminHttpClient getLiveJasminHttpClient() {
|
||||
return (LiveJasminHttpClient) httpClient;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Model createModelFromUrl(String url) {
|
||||
Matcher m = Pattern.compile("http.*?livejasmin\\.com.*?#!chat/(.*)").matcher(url);
|
||||
if(m.find()) {
|
||||
String name = m.group(1);
|
||||
return createModel(name);
|
||||
}
|
||||
m = Pattern.compile("http.*?livejasmin\\.com.*?/chat-html5/(.*)").matcher(url);
|
||||
if(m.find()) {
|
||||
String name = m.group(1);
|
||||
return createModel(name);
|
||||
}
|
||||
|
||||
return super.createModelFromUrl(url);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue