server

Clone or download

Better start at boot

Modified Files

package com.stream_pi.server.connection;
package com.stream_pi.server.connection;
import com.stream_pi.server.controller.ServerListener;
import com.stream_pi.server.controller.ServerListener;
import com.stream_pi.server.window.ExceptionAndAlertHandler;
import com.stream_pi.server.window.ExceptionAndAlertHandler;
import com.stream_pi.util.exception.MinorException;
import com.stream_pi.util.exception.MinorException;
import com.stream_pi.util.exception.SevereException;
import com.stream_pi.util.exception.SevereException;
import javafx.application.Platform;
import javafx.application.Platform;
import java.io.IOException;
import java.io.IOException;
import java.net.*;
import java.net.*;
import java.util.Enumeration;
import java.util.Enumeration;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.logging.Logger;
import java.util.logging.Logger;
public class MainServer extends Thread {
public class MainServer extends Thread
{
private ServerListener serverListener;
private ServerListener serverListener;
private Logger logger = Logger.getLogger(MainServer.class.getName());
private Logger logger = Logger.getLogger(MainServer.class.getName());
private int port;
private int port;
private ServerSocket serverSocket = null;
private ServerSocket serverSocket = null;
//private Server server;
private AtomicBoolean stop = new AtomicBoolean(false);
private AtomicBoolean stop = new AtomicBoolean(false);
private ExceptionAndAlertHandler exceptionAndAlertHandler;
private ExceptionAndAlertHandler exceptionAndAlertHandler;
public MainServer(ServerListener serverListener, ExceptionAndAlertHandler exceptionAndAlertHandler)
public MainServer(ServerListener serverListener, ExceptionAndAlertHandler exceptionAndAlertHandler)
{
{
this.exceptionAndAlertHandler = exceptionAndAlertHandler;
this.exceptionAndAlertHandler = exceptionAndAlertHandler;
this.serverListener = serverListener;
this.serverListener = serverListener;
}
}
public void setPort(int port) {
public void setPort(int port) {
this.port = port;
this.port = port;
}
}
@Override
@Override
public synchronized void start() {
public synchronized void start() {
stop.set(false);
stop.set(false);
super.start();
super.start();
}
}
public void stopListeningForConnections()
public void stopListeningForConnections()
{
{
/*if(server !=null)
{
if(!server.isShutdown())
server.shutdown();
}*/
try
try
{
{
logger.info("Stopping listening for connections ...");
logger.info("Stopping listening for connections ...");
if(serverSocket!=null)
if(serverSocket!=null)
{
if(!serverSocket.isClosed())
if(!serverSocket.isClosed())
{
{
stop.set(true);
stop.set(true);
serverSocket.close();
serverSocket.close();
}
}
} catch (IOException e) {
}
}
catch (IOException e)
{
e.printStackTrace();
e.printStackTrace();
}
}
finally {
finally {
logger.info("... Done!");
logger.info("... Done!");
}
}
}
}
@Override
@Override
public void run() {
public void run()
{
logger.warning("Starting main server on port "+port+" ...");
logger.warning("Starting main server on port "+port+" ...");
try {
try
{
logger.info("Starting server on port "+port+" ...");
logger.info("Starting server on port "+port+" ...");
serverSocket = new ServerSocket(port);
serverSocket = new ServerSocket(port);
setupStageTitle(true);
setupStageTitle();
while(!stop.get())
while(!stop.get())
{
{
Socket s = serverSocket.accept();
Socket s = serverSocket.accept();
ClientConnections.getInstance().addConnection(new ClientConnection(s, serverListener, exceptionAndAlertHandler));
ClientConnections.getInstance().addConnection(new ClientConnection(s, serverListener, exceptionAndAlertHandler));
logger.info("New client connected ("+s.getRemoteSocketAddress()+") !");
logger.info("New client connected ("+s.getRemoteSocketAddress()+") !");
}
}
}
}
catch (SocketException e)
catch (SocketException e)
{
{
if(!e.getMessage().contains("Socket closed") && !e.getMessage().contains("Interrupted function call: accept failed"))
if(!e.getMessage().contains("Socket closed") && !e.getMessage().contains("Interrupted function call: accept failed"))
{
{
logger.info("Main Server stopped accepting calls ...");
logger.info("Main Server stopped accepting calls ...");
setupStageTitle(false);
serverListener.onServerStartFailure();
exceptionAndAlertHandler.handleMinorException(new MinorException("Sorry!","Server could not be started at "+port+".\n" +
exceptionAndAlertHandler.handleMinorException(new MinorException("Sorry!","Server could not be started at "+port+".\n" +
"This could be due to another process or another instance of Stream-Pi Server using the same port. \n\n" +
"This could be due to another process or another instance of Stream-Pi Server using the same port. \n\n" +
"If another Server Instance probably running, close it. If not, try changing the port in settings and restart Stream-Pi Server." +
"If another Server Instance probably running, close it. If not, try changing the port in settings and restart Stream-Pi Server." +
"If the problem still persists, consider contacting us. \n\nFull Message : "+e.getMessage()));
"If the problem still persists, consider contacting us. \n\nFull Message : "+e.getMessage()));
e.printStackTrace();
e.printStackTrace();
}
}
}
}
catch (IOException e)
catch (IOException e)
{
{
exceptionAndAlertHandler.handleSevereException(new SevereException("MainServer io Exception occurred!"));
exceptionAndAlertHandler.handleSevereException(new SevereException("MainServer io Exception occurred!"));
e.printStackTrace();
e.printStackTrace();
}
}
}
}
private void setupStageTitle(boolean isSuccess)
private void setupStageTitle()
{
{
try
try
{
{
if(isSuccess)
StringBuilder ips = new StringBuilder();
{
StringBuilder ips = new StringBuilder();
Enumeration<NetworkInterface> e = NetworkInterface.getNetworkInterfaces();
Enumeration<NetworkInterface> e = NetworkInterface.getNetworkInterfaces();
while(e.hasMoreElements())
while(e.hasMoreElements())
{
NetworkInterface n = e.nextElement();
Enumeration<InetAddress> ee = n.getInetAddresses();
while (ee.hasMoreElements())
{
{
NetworkInterface n = e.nextElement();
InetAddress i = ee.nextElement();
Enumeration<InetAddress> ee = n.getInetAddresses();
String hostAddress = i.getHostAddress();
while (ee.hasMoreElements())
if(i instanceof Inet4Address)
{
{
InetAddress i = ee.nextElement();
ips.append(hostAddress);
String hostAddress = i.getHostAddress();
if(e.hasMoreElements())
if(i instanceof Inet4Address)
ips.append(" / ");
{
ips.append(hostAddress);
if(e.hasMoreElements())
ips.append(" / ");
}
}
}
}
}
Platform.runLater(()-> serverListener.getStage().setTitle("Stream-Pi Server - IP(s): "+ips+" | Port: "+ port));
}
else
{
Platform.runLater(()-> serverListener.getStage().setTitle("Stream-Pi Server - Offline"));
}
}
Platform.runLater(()-> serverListener.getStage().setTitle("Stream-Pi Server - IP(s): "+ips+" | Port: "+ port));
}
}
catch (Exception e)
catch (Exception e)
{
{
e.printStackTrace();
e.printStackTrace();
exceptionAndAlertHandler.handleMinorException(new MinorException("Error",e.getMessage()));
exceptionAndAlertHandler.handleMinorException(new MinorException("Error",e.getMessage()));
}
}
}
}
}
}
package com.stream_pi.server.controller;
package com.stream_pi.server.controller;
import com.stream_pi.action_api.action.Action;
import com.stream_pi.action_api.action.Action;
import com.stream_pi.action_api.action.ActionType;
import com.stream_pi.action_api.action.ActionType;
import com.stream_pi.action_api.action.PropertySaver;
import com.stream_pi.action_api.action.PropertySaver;
import com.stream_pi.action_api.action.ServerConnection;
import com.stream_pi.action_api.action.ServerConnection;
import com.stream_pi.action_api.externalplugin.NormalAction;
import com.stream_pi.action_api.externalplugin.NormalAction;
import com.stream_pi.action_api.externalplugin.ToggleAction;
import com.stream_pi.action_api.externalplugin.ToggleAction;
import com.stream_pi.action_api.externalplugin.ToggleExtras;
import com.stream_pi.action_api.externalplugin.ToggleExtras;
import com.stream_pi.server.Main;
import com.stream_pi.server.Main;
import com.stream_pi.server.action.ExternalPlugins;
import com.stream_pi.server.action.ExternalPlugins;
import com.stream_pi.server.client.Client;
import com.stream_pi.server.client.Client;
import com.stream_pi.server.client.ClientProfile;
import com.stream_pi.server.client.ClientProfile;
import com.stream_pi.server.connection.ClientConnection;
import com.stream_pi.server.connection.ClientConnection;
import com.stream_pi.server.connection.ClientConnections;
import com.stream_pi.server.connection.ClientConnections;
import com.stream_pi.server.connection.MainServer;
import com.stream_pi.server.connection.MainServer;
import com.stream_pi.server.info.ServerInfo;
import com.stream_pi.server.info.ServerInfo;
import com.stream_pi.server.info.StartupFlags;
import com.stream_pi.server.info.StartupFlags;
import com.stream_pi.server.io.Config;
import com.stream_pi.server.io.Config;
import com.stream_pi.server.window.Base;
import com.stream_pi.server.window.Base;
import com.stream_pi.server.window.dashboard.DashboardBase;
import com.stream_pi.server.window.dashboard.DashboardBase;
import com.stream_pi.server.window.dashboard.DonatePopupContent;
import com.stream_pi.server.window.dashboard.DonatePopupContent;
import com.stream_pi.server.window.dashboard.actiongridpane.ActionBox;
import com.stream_pi.server.window.dashboard.actiongridpane.ActionBox;
import com.stream_pi.server.window.firsttimeuse.FirstTimeUse;
import com.stream_pi.server.window.firsttimeuse.FirstTimeUse;
import com.stream_pi.server.window.settings.SettingsBase;
import com.stream_pi.server.window.settings.SettingsBase;
import com.stream_pi.util.alert.StreamPiAlert;
import com.stream_pi.util.alert.StreamPiAlert;
import com.stream_pi.util.alert.StreamPiAlertListener;
import com.stream_pi.util.alert.StreamPiAlertListener;
import com.stream_pi.util.alert.StreamPiAlertType;
import com.stream_pi.util.alert.StreamPiAlertType;
import com.stream_pi.util.exception.*;
import com.stream_pi.util.exception.*;
import com.stream_pi.util.iohelper.IOHelper;
import com.stream_pi.util.iohelper.IOHelper;
import javafx.animation.Animation;
import javafx.animation.Animation;
import javafx.animation.Interpolator;
import javafx.animation.Interpolator;
import javafx.animation.KeyFrame;
import javafx.animation.KeyFrame;
import javafx.animation.KeyValue;
import javafx.animation.KeyValue;
import javafx.animation.Timeline;
import javafx.animation.Timeline;
import javafx.application.Platform;
import javafx.application.Platform;
import javafx.concurrent.Task;
import javafx.concurrent.Task;
import javafx.scene.Node;
import javafx.scene.Node;
import javafx.scene.Scene;
import javafx.scene.Scene;
import javafx.scene.image.Image;
import javafx.scene.image.Image;
import javafx.scene.media.AudioClip;
import javafx.scene.media.AudioClip;
import javafx.stage.Modality;
import javafx.stage.Modality;
import javafx.stage.Stage;
import javafx.stage.Stage;
import javafx.stage.WindowEvent;
import javafx.stage.WindowEvent;
import javafx.util.Duration;
import javafx.util.Duration;
import java.awt.MenuItem;
import java.awt.MenuItem;
import java.awt.PopupMenu;
import java.awt.PopupMenu;
import java.awt.SystemTray;
import java.awt.SystemTray;
import java.awt.Toolkit;
import java.awt.Toolkit;
import java.awt.TrayIcon;
import java.awt.TrayIcon;
import java.io.File;
import java.io.File;
import java.net.SocketAddress;
import java.net.SocketAddress;
import java.util.Objects;
import java.util.Objects;
import java.util.Random;
import java.util.Random;
import java.util.Timer;
import java.util.Timer;
import java.util.TimerTask;
import java.util.TimerTask;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledExecutorService;
import java.util.logging.Level;
import java.util.logging.Level;
public class Controller extends Base implements PropertySaver, ServerConnection, ToggleExtras
public class Controller extends Base implements PropertySaver, ServerConnection, ToggleExtras
{
{
private final ExecutorService executor = Executors.newCachedThreadPool();
private final ExecutorService executor = Executors.newCachedThreadPool();
private MainServer mainServer;
private MainServer mainServer;
private Animation openSettingsAnimation;
private Animation openSettingsAnimation;
private Animation closeSettingsAnimation;
private Animation closeSettingsAnimation;
public Controller(){
public Controller(){
mainServer = null;
mainServer = null;
}
}
public void setupDashWindow() throws SevereException
public void setupDashWindow() throws SevereException
{
{
try
try
{
{
getStage().setOnCloseRequest(this::onCloseRequest);
getStage().setOnCloseRequest(this::onCloseRequest);
}
}
catch (Exception e)
catch (Exception e)
{
{
e.printStackTrace();
e.printStackTrace();
throw new SevereException(e.getMessage());
throw new SevereException(e.getMessage());
}
}
}
}
@Override
@Override
public void init()
public void init()
{
{
try
try
{
{
initBase();
initBase();
setupDashWindow();
setupDashWindow();
setupSettingsWindowsAnimations();
setupSettingsWindowsAnimations();
ExternalPlugins.getInstance().setPropertySaver(this);
ExternalPlugins.getInstance().setPropertySaver(this);
ExternalPlugins.getInstance().setToggleExtras(this);
ExternalPlugins.getInstance().setToggleExtras(this);
ExternalPlugins.getInstance().setServerConnection(this);
ExternalPlugins.getInstance().setServerConnection(this);
getDashboardBase().getPluginsPane().getSettingsButton().setOnAction(event -> {
getDashboardBase().getPluginsPane().getSettingsButton().setOnAction(event -> {
openSettingsAnimation.play();
openSettingsAnimation.play();
});
});
getSettingsBase().getCloseButton().setOnAction(event -> {
getSettingsBase().getCloseButton().setOnAction(event -> {
closeSettingsAnimation.play();
closeSettingsAnimation.play();
});
});
getSettingsBase().getThemesSettings().setController(this);
getSettingsBase().getThemesSettings().setController(this);
mainServer = new MainServer(this, this);
mainServer = new MainServer(this, this);
if(getConfig().isFirstTimeUse())
if(getConfig().isFirstTimeUse())
{
{
firstTimeUse = new FirstTimeUse(this, this);
firstTimeUse = new FirstTimeUse(this, this);
getChildren().add(firstTimeUse);
getChildren().add(firstTimeUse);
firstTimeUse.toFront();
firstTimeUse.toFront();
getStage().setTitle("Stream-Pi Server");
getStage().setTitle("Stream-Pi Server");
getStage().show();
getStage().show();
}
}
else
else
{
{
if(getConfig().isAllowDonatePopup())
if(getConfig().isAllowDonatePopup())
{
{
if(new Random().nextInt(50) == 3)
if(new Random().nextInt(50) == 3)
new DonatePopupContent(getHostServices(), this).show();
new DonatePopupContent(getHostServices(), this).show();
}
}
othInit();
othInit();
}
}
}
}
catch (SevereException e)
catch (SevereException e)
{
{
handleSevereException(e);
handleSevereException(e);
}
}
}
}
@Override
public void onServerStartFailure()
{
Platform.runLater(()-> getStage().setTitle("Stream-Pi Server - Offline"));
disableTrayIcon = true;
}
@Override
@Override
public void othInit()
public void othInit()
{
{
try
try
{
{
if(StartupFlags.START_MINIMISED && SystemTray.isSupported())
if(StartupFlags.START_MINIMISED && SystemTray.isSupported())
{
{
minimiseApp();
minimiseApp();
}
}
else
else
{
{
getStage().show();
getStage().show();
}
}
StreamPiAlert.setIsShowPopup(getConfig().isShowAlertsPopup());
StreamPiAlert.setIsShowPopup(getConfig().isShowAlertsPopup());
}
}
catch(MinorException e)
catch(MinorException e)
{
{
handleMinorException(e);
handleMinorException(e);
}
}
if(getConfig().getSoundOnActionClickedStatus())
if(getConfig().getSoundOnActionClickedStatus())
{
{
initSoundOnActionClicked();
initSoundOnActionClicked();
}
}
executor.execute(new Task<Void>() {
executor.execute(new Task<Void>() {
@Override
@Override
protected Void call()
protected Void call()
{
{
try
try
{
{
getSettingsBase().getGeneralSettings().loadDataFromConfig();
getSettingsBase().getGeneralSettings().loadDataFromConfig();
//themes
//themes
getSettingsBase().getThemesSettings().setThemes(getThemes());
getSettingsBase().getThemesSettings().setThemes(getThemes());
getSettingsBase().getThemesSettings().setCurrentThemeFullName(getCurrentTheme().getFullName());
getSettingsBase().getThemesSettings().setCurrentThemeFullName(getCurrentTheme().getFullName());
getSettingsBase().getThemesSettings().loadThemes();
getSettingsBase().getThemesSettings().loadThemes();
//clients
//clients
getSettingsBase().getClientsSettings().loadData();
getSettingsBase().getClientsSettings().loadData();
try
try
{
{
//Plugins
//Plugins
Platform.runLater(()->{
Platform.runLater(()->{
getDashboardBase().getPluginsPane().clearData();
getDashboardBase().getPluginsPane().clearData();
getDashboardBase().getPluginsPane().loadOtherActions();
getDashboardBase().getPluginsPane().loadOtherActions();
});
});
ExternalPlugins.setPluginsLocation(getConfig().getPluginsPath());
ExternalPlugins.setPluginsLocation(getConfig().getPluginsPath());
ExternalPlugins.getInstance().init();
ExternalPlugins.getInstance().init();
Platform.runLater(()->getDashboardBase().getPluginsPane().loadData());
Platform.runLater(()->getDashboardBase().getPluginsPane().loadData());
getSettingsBase().getPluginsSettings().loadPlugins();
getSettingsBase().getPluginsSettings().loadPlugins();
}
}
catch (MinorException e)
catch (MinorException e)
{
{
getSettingsBase().getPluginsSettings().showPluginInitError();
getSettingsBase().getPluginsSettings().showPluginInitError();
handleMinorException(e);
handleMinorException(e);
}
}
//Server
//Server
mainServer.setPort(getConfig().getPort());
mainServer.setPort(getConfig().getPort());
mainServer.start();
mainServer.start();
}
}
catch (SevereException e)
catch (SevereException e)
{
{
handleSevereException(e);
handleSevereException(e);
}
}
return null;
return null;
}
}
});
});
}
}
@Override
@Override
public void factoryReset()
public void factoryReset()
{
{
getLogger().info("Reset to factory ...");
getLogger().info("Reset to factory ...");
onQuitApp();
onQuitApp();
boolean result = IOHelper.deleteFile(getServerInfo().getPrePath());
boolean result = IOHelper.deleteFile(getServerInfo().getPrePath());
if(result)
if(result)
{
{
init();
init();
}
}
else
else
{
{
handleSevereException(new SevereException("Unable to delete all files successfully. Installation corrupt. Re-install."));
handleSevereException(new SevereException("Unable to delete all files successfully. Installation corrupt. Re-install."));
}
}
}
}
private void setupSettingsWindowsAnimations()
private void setupSettingsWindowsAnimations()
{
{
Node settingsNode = getSettingsBase();
Node settingsNode = getSettingsBase();
Node dashboardNode = getDashboardBase();
Node dashboardNode = getDashboardBase();
openSettingsAnimation = createOpenSettingsAnimation(settingsNode, dashboardNode);
openSettingsAnimation = createOpenSettingsAnimation(settingsNode, dashboardNode);
closeSettingsAnimation = createCloseSettingsAnimation(settingsNode, dashboardNode);
closeSettingsAnimation = createCloseSettingsAnimation(settingsNode, dashboardNode);
}
}
private boolean disableTrayIcon = false;
public void onCloseRequest(WindowEvent event)
public void onCloseRequest(WindowEvent event)
{
{
try
try
{
{
if(Config.getInstance().getMinimiseToSystemTrayOnClose() &&
if(Config.getInstance().getMinimiseToSystemTrayOnClose() &&
SystemTray.isSupported())
SystemTray.isSupported() && !disableTrayIcon)
{
{
minimiseApp();
minimiseApp();
event.consume();
event.consume();
return;
return;
}
}
onQuitApp();
onQuitApp();
exit();
exit();
}
}
catch (SevereException e)
catch (SevereException e)
{
{
handleSevereException(e);
handleSevereException(e);
}
}
catch (MinorException e)
catch (MinorException e)
{
{
handleMinorException(e);
handleMinorException(e);
}
}
}
}
public void onQuitApp()
public void onQuitApp()
{
{
getLogger().info("Shutting down ...");
getLogger().info("Shutting down ...");
try
try
{
{
if(getConfig() != null)
if(getConfig() != null)
{
{
getConfig().setStartupWindowSize(getWidth(), getHeight());
getConfig().setStartupWindowSize(getWidth(), getHeight());
getConfig().setRightDividerPositions(getDashboardBase().getDividerPositions());
getConfig().setRightDividerPositions(getDashboardBase().getDividerPositions());
getConfig().setLeftDividerPositions(getDashboardBase().getLeftSplitPane().getDividerPositions());
getConfig().setLeftDividerPositions(getDashboardBase().getLeftSplitPane().getDividerPositions());
getConfig().save();
getConfig().save();
}
}
}
}
catch (SevereException e)
catch (SevereException e)
{
{
handleSevereException(e);
handleSevereException(e);
}
}
stopServerAndAllConnections();
stopServerAndAllConnections();
ExternalPlugins.getInstance().shutDownActions();
ExternalPlugins.getInstance().shutDownActions();
closeLogger();
closeLogger();
Config.nullify();
Config.nullify();
}
}
public void exit()
public void exit()
{
{
executor.shutdown();
executor.shutdown();
Platform.exit();
Platform.exit();
}
}
private void stopServerAndAllConnections()
private void stopServerAndAllConnections()
{
{
if(mainServer!=null)
if(mainServer!=null)
mainServer.stopListeningForConnections();
mainServer.stopListeningForConnections();
ClientConnections.getInstance().disconnectAll();
ClientConnections.getInstance().disconnectAll();
}
}
@Override
@Override
public void restart()
public void restart()
{
{
getLogger().info("Restarting ...");
getLogger().info("Restarting ...");
onQuitApp();
onQuitApp();
Platform.runLater(this::init);
Platform.runLater(this::init);
}
}
public void minimiseApp() throws MinorException
public void minimiseApp() throws MinorException
{
{
try
try
{
{
SystemTray systemTray = SystemTray.getSystemTray();
SystemTray systemTray = SystemTray.getSystemTray();
if(getTrayIcon() == null)
if(getTrayIcon() == null)
initIconTray(systemTray);
initIconTray(systemTray);
systemTray.add(getTrayIcon());
systemTray.add(getTrayIcon());
getStage().hide();
getStage().hide();
getStage().setOnShown(windowEvent -> {
getStage().setOnShown(windowEvent -> {
systemTray.remove(getTrayIcon());
systemTray.remove(getTrayIcon());
});
});
}
}
catch(Exception e)
catch(Exception e)
{
{
throw new MinorException(e.getMessage());
throw new MinorException(e.getMessage());
}
}
}
}
public void initIconTray(SystemTray systemTray)
public void initIconTray(SystemTray systemTray)
{
{
Platform.setImplicitExit(false);
Platform.setImplicitExit(false);
PopupMenu popup = new PopupMenu();
PopupMenu popup = new PopupMenu();
MenuItem exitItem = new MenuItem("Exit");
MenuItem exitItem = new MenuItem("Exit");
exitItem.addActionListener(l->{
exitItem.addActionListener(l->{
systemTray.remove(getTrayIcon());
systemTray.remove(getTrayIcon());
onQuitApp();
onQuitApp();
exit();
exit();
});
});
popup.add(exitItem);
popup.add(exitItem);
TrayIcon trayIcon = new TrayIcon(
TrayIcon trayIcon = new TrayIcon(
Toolkit.getDefaultToolkit().getImage(Main.class.getResource("app_icon.png")),
Toolkit.getDefaultToolkit().getImage(Main.class.getResource("app_icon.png")),
"Stream-Pi Server",
"Stream-Pi Server",
popup
popup
);
);
trayIcon.addActionListener(l-> Platform.runLater(()-> {
trayIcon.addActionListener(l-> Platform.runLater(()-> {
getStage().show();
getStage().show();
getStage().setAlwaysOnTop(true);
getStage().setAlwaysOnTop(true);
getStage().setAlwaysOnTop(false);
getStage().setAlwaysOnTop(false);
}));
}));
trayIcon.setImageAutoSize(true);
trayIcon.setImageAutoSize(true);
this.trayIcon = trayIcon;
this.trayIcon = trayIcon;
}
}
private TrayIcon trayIcon = null;
private TrayIcon trayIcon = null;
public TrayIcon getTrayIcon()
public TrayIcon getTrayIcon()
{
{
return trayIcon;
return trayIcon;
}
}
@Override
@Override
public void handleMinorException(MinorException e)
public void handleMinorException(MinorException e)
{
{
getLogger().log(Level.SEVERE, e.getShortMessage(), e);
getLogger().log(Level.SEVERE, e.getShortMessage(), e);
e.printStackTrace();
e.printStackTrace();
new StreamPiAlert(e.getTitle(), e.getShortMessage(), StreamPiAlertType.WARNING).show();
new StreamPiAlert(e.getTitle(), e.getShortMessage(), StreamPiAlertType.WARNING).show();
}
}
@Override
@Override
public void handleSevereException(SevereException e)
public void handleSevereException(SevereException e)
{
{
getLogger().log(Level.SEVERE, e.getShortMessage(), e);
getLogger().log(Level.SEVERE, e.getShortMessage(), e);
e.printStackTrace();
e.printStackTrace();
StreamPiAlert alert = new StreamPiAlert(e.getTitle(), e.getShortMessage(), StreamPiAlertType.ERROR);
StreamPiAlert alert = new StreamPiAlert(e.getTitle(), e.getShortMessage(), StreamPiAlertType.ERROR);
alert.setOnClicked(new StreamPiAlertListener()
alert.setOnClicked(new StreamPiAlertListener()
{
{
@Override
@Override
public void onClick(String txt)
public void onClick(String txt)
{
{
onQuitApp();
onQuitApp();
exit();
exit();
}
}
});
});
alert.show();
alert.show();
}
}
private AudioClip audioClip = null;
private AudioClip audioClip = null;
private String audioFilePath = null;
private String audioFilePath = null;
private void playSound()
private void playSound()
{
{
if(audioClip.isPlaying())
if(audioClip.isPlaying())
{
{
Platform.runLater(audioClip::stop);
Platform.runLater(audioClip::stop);
return;
return;
}
}
Platform.runLater(audioClip::play);
Platform.runLater(audioClip::play);
}
}
@Override
@Override
public void initSoundOnActionClicked()
public void initSoundOnActionClicked()
{
{
audioFilePath = getConfig().getSoundOnActionClickedFilePath();
audioFilePath = getConfig().getSoundOnActionClickedFilePath();
File file = new File(audioFilePath);
File file = new File(audioFilePath);
if(!file.exists())
if(!file.exists())
{
{
audioFilePath = null;
audioFilePath = null;
audioClip = null;
audioClip = null;
getConfig().setSoundOnActionClickedStatus(false);
getConfig().setSoundOnActionClickedStatus(false);
getConfig().setSoundOnActionClickedFilePath("");
getConfig().setSoundOnActionClickedFilePath("");
handleMinorException(new MinorException("The sound file for on action click sound is missing."));
handleMinorException(new MinorException("The sound file for on action click sound is missing."));
return;
return;
}
}
audioClip = new AudioClip(file.toURI().toString());
audioClip = new AudioClip(file.toURI().toString());
}
}
@Override
@Override
public void onActionClicked(Client client, String profileID, String actionID, boolean toggle)
public void onActionClicked(Client client, String profileID, String actionID, boolean toggle)
{
{
try
try
{
{
Action action = client.getProfileByID(profileID).getActionByID(actionID);
Action action = client.getProfileByID(profileID).getActionByID(actionID);
if(getConfig().getSoundOnActionClickedStatus())
if(getConfig().getSoundOnActionClickedStatus())
{
{
playSound();
playSound();
}
}
if(action.isInvalid())
if(action.isInvalid())
{
{
throw new MinorException(
throw new MinorException(
"The action isn't installed on the server."
"The action isn't installed on the server."
);
);
}
}
executor.execute(new Task<Void>() {
executor.execute(new Task<Void>() {
@Override
@Override
protected Void call()
protected Void call()
{
{
try
try
{
{
Thread.sleep(action.getDelayBeforeExecuting());
Thread.sleep(action.getDelayBeforeExecuting());
getLogger().info("action "+action.getID()+" clicked!");
getLogger().info("action "+action.getID()+" clicked!");
if(action instanceof ToggleAction)
if(action instanceof ToggleAction)
{
{
onToggleActionClicked((ToggleAction) action, toggle, profileID,
onToggleActionClicked((ToggleAction) action, toggle, profileID,
client.getRemoteSocketAddress());
client.getRemoteSocketAddress());
}
}
else if (action instanceof NormalAction)
else if (action instanceof NormalAction)
{
{
onNormalActionClicked((NormalAction) action, profileID,
onNormalActionClicked((NormalAction) action, profileID,
client.getRemoteSocketAddress());
client.getRemoteSocketAddress());
}
}
}
}
catch (InterruptedException e)
catch (InterruptedException e)
{
{
e.printStackTrace();
e.printStackTrace();
getLogger().info("onActionClicked scheduled task was interrupted ...");
getLogger().info("onActionClicked scheduled task was interrupted ...");
}
}
return null;
return null;
}
}
});
});
}
}
catch (Exception e)
catch (Exception e)
{
{
e.printStackTrace();
e.printStackTrace();
handleMinorException(new MinorException(e.getMessage()));
handleMinorException(new MinorException(e.getMessage()));
}
}
}
}
public synchronized void onNormalActionClicked(NormalAction action, String profileID, SocketAddress socketAddress)
public synchronized void onNormalActionClicked(NormalAction action, String profileID, SocketAddress socketAddress)
{
{
try
try
{
{
action.onActionClicked();
action.onActionClicked();
}
}
catch (MinorException e)
catch (MinorException e)
{
{
sendActionFailed(e, socketAddress, profileID, action.getID());
sendActionFailed(e, socketAddress, profileID, action.getID());
}
}
}
}
public synchronized void onToggleActionClicked(ToggleAction action, boolean toggle, String profileID, SocketAddress socketAddress)
public synchronized void onToggleActionClicked(ToggleAction action, boolean toggle, String profileID, SocketAddress socketAddress)
{
{
try
try
{
{
if(toggle)
if(toggle)
{
{
action.onToggleOn();
action.onToggleOn();
}
}
else
else
{
{
action.onToggleOff();
action.onToggleOff();
}
}
}
}
catch (MinorException e)
catch (MinorException e)
{
{
sendActionFailed(e, socketAddress, profileID, action.getID());
sendActionFailed(e, socketAddress, profileID, action.getID());
}
}
}
}
@Override
@Override
public void clearTemp() {
public void clearTemp() {
Platform.runLater(() -> {
Platform.runLater(() -> {
getDashboardBase().getClientAndProfileSelectorPane().refresh();
getDashboardBase().getClientAndProfileSelectorPane().refresh();
getDashboardBase().getActionGridPane().clear();
getDashboardBase().getActionGridPane().clear();
getDashboardBase().getActionGridPane().setFreshRender(true);
getDashboardBase().getActionGridPane().setFreshRender(true);
getDashboardBase().getActionDetailsPane().clear();
getDashboardBase().getActionDetailsPane().clear();
getSettingsBase().getClientsSettings().loadData();
getSettingsBase().getClientsSettings().loadData();
});
});
}
}
@Override
@Override
public void saveServerProperties()
public void saveServerProperties()
{
{
try
try
{
{
ExternalPlugins.getInstance().saveServerSettings();
ExternalPlugins.getInstance().saveServerSettings();
getSettingsBase().getPluginsSettings().loadPlugins();
getSettingsBase().getPluginsSettings().loadPlugins();
} catch (MinorException e) {
} catch (MinorException e) {
e.printStackTrace();
e.printStackTrace();
handleMinorException(e);
handleMinorException(e);
}
}
}
}
private void saveClientActionMain(String profileID, String actionID, SocketAddress socketAddress, boolean sendIcons)
private void saveClientActionMain(String profileID, String actionID, SocketAddress socketAddress, boolean sendIcons)
{
{
try {
try {
ClientConnection clientConnection = ClientConnections.getInstance().getClientConnectionBySocketAddress(socketAddress);
ClientConnection clientConnection = ClientConnections.getInstance().getClientConnectionBySocketAddress(socketAddress);
ClientProfile clientProfile = clientConnection.getClient().getProfileByID(profileID);
ClientProfile clientProfile = clientConnection.getClient().getProfileByID(profileID);
Action action = clientProfile.getActionByID(actionID);
Action action = clientProfile.getActionByID(actionID);
clientConnection.saveActionDetails(profileID, action);
clientConnection.saveActionDetails(profileID, action);
if(sendIcons && action.isHasIcon())
if(sendIcons && action.isHasIcon())
{
{
saveAllIcons(profileID, actionID, socketAddress, false);
saveAllIcons(profileID, actionID, socketAddress, false);
}
}
Platform.runLater(()->{
Platform.runLater(()->{
try {
try {
ActionBox actionBox = getDashboardBase().getActionGridPane().getActionBoxByIDAndProfileID(
ActionBox actionBox = getDashboardBase().getActionGridPane().getActionBoxByIDAndProfileID(
action.getID(),
action.getID(),
profileID
profileID
);
);
if(actionBox != null)
if(actionBox != null)
{
{
Platform.runLater(actionBox::init);
Platform.runLater(actionBox::init);
}
}
if(getDashboardBase().getActionDetailsPane().getAction() != null)
if(getDashboardBase().getActionDetailsPane().getAction() != null)
{
{
// This block is executed when no Action is selected.
// This block is executed when no Action is selected.
if(getDashboardBase().getActionDetailsPane().getAction().getID().equals(actionID))
if(getDashboardBase().getActionDetailsPane().getAction().getID().equals(actionID))
{
{
getDashboardBase().getActionDetailsPane().setAction(action);
getDashboardBase().getActionDetailsPane().setAction(action);
getDashboardBase().getActionDetailsPane().refresh();
getDashboardBase().getActionDetailsPane().refresh();
}
}
}
}
}
}
catch (Exception e)
catch (Exception e)
{
{
e.printStackTrace();
e.printStackTrace();
}
}
});
});
}
}
catch (SevereException e)
catch (SevereException e)
{
{
handleSevereException(e);
handleSevereException(e);
}
}
}
}
@Override
@Override
public void saveClientAction(String profileID, String actionID, SocketAddress socketAddress, boolean sendIcons, boolean runAsync)
public void saveClientAction(String profileID, String actionID, SocketAddress socketAddress, boolean sendIcons, boolean runAsync)
{
{
if(runAsync)
if(runAsync)
{
{
executor.execute(new Task<Void>() {
executor.execute(new Task<Void>() {
@Override
@Override
protected Void call()
protected Void call()
{
{
saveClientActionMain(profileID, actionID, socketAddress, sendIcons);
saveClientActionMain(profileID, actionID, socketAddress, sendIcons);
return null;
return null;
}
}
});
});
}
}
else
else
{
{
saveClientActionMain(profileID, actionID, socketAddress, sendIcons);
saveClientActionMain(profileID, actionID, socketAddress, sendIcons);
}
}
}
}
@Override
@Override
public void saveAllIcons(String profileID, String actionID, SocketAddress socketAddress)
public void saveAllIcons(String profileID, String actionID, SocketAddress socketAddress)
{
{
saveAllIcons(profileID, actionID, socketAddress, true);
saveAllIcons(profileID, actionID, socketAddress, true);
}
}
public void saveAllIcons(String profileID, String actionID, SocketAddress socketAddress, boolean async)
public void saveAllIcons(String profileID, String actionID, SocketAddress socketAddress, boolean async)
{
{
if(async)
if(async)
{
{
executor.execute(new Task<Void>() {
executor.execute(new Task<Void>() {
@Override
@Override
protected Void call()
protected Void call()
{
{
saveAllIconsMain(profileID, actionID, socketAddress);
saveAllIconsMain(profileID, actionID, socketAddress);
return null;
return null;
}
}
});
});
}
}
else
else
{
{
saveAllIconsMain(profileID, actionID, socketAddress);
saveAllIconsMain(profileID, actionID, socketAddress);
}
}
}
}
private void saveAllIconsMain(String profileID, String actionID, SocketAddress socketAddress)
private void saveAllIconsMain(String profileID, String actionID, SocketAddress socketAddress)
{
{
try {
try {
ClientConnection clientConnection = ClientConnections.getInstance().getClientConnectionBySocketAddress(socketAddress);
ClientConnection clientConnection = ClientConnections.getInstance().getClientConnectionBySocketAddress(socketAddress);
ClientProfile clientProfile = clientConnection.getClient().getProfileByID(profileID);
ClientProfile clientProfile = clientConnection.getClient().getProfileByID(profileID);
Action action = clientProfile.getActionByID(actionID);
Action action = clientProfile.getActionByID(actionID);
for(String eachState : action.getIcons().keySet())
for(String eachState : action.getIcons().keySet())
{
{
clientConnection.sendIcon(profileID, actionID, eachState,
clientConnection.sendIcon(profileID, actionID, eachState,
action.getIcon(eachState));
action.getIcon(eachState));
}
}
}
}
catch (SevereException e)
catch (SevereException e)
{
{
handleSevereException(e);
handleSevereException(e);
}
}
}
}
@Override
@Override
public void saveIcon(String state, String profileID, String actionID, SocketAddress socketAddress) {
public void saveIcon(String state, String profileID, String actionID, SocketAddress socketAddress) {
executor.execute(new Task<Void>() {
executor.execute(new Task<Void>() {
@Override
@Override
protected Void call()
protected Void call()
{
{
try {
try {
ClientConnection clientConnection = ClientConnections.getInstance().getClientConnectionBySocketAddress(socketAddress);
ClientConnection clientConnection = ClientConnections.getInstance().getClientConnectionBySocketAddress(socketAddress);
ClientProfile clientProfile = clientConnection.getClient().getProfileByID(profileID);
ClientProfile clientProfile = clientConnection.getClient().getProfileByID(profileID);
Action action = clientProfile.getActionByID(actionID);
Action action = clientProfile.getActionByID(actionID);
clientConnection.sendIcon(profileID, actionID, state, action.getIcon(state));
clientConnection.sendIcon(profileID, actionID, state, action.getIcon(state));
}
}
catch (SevereException e)
catch (SevereException e)
{
{
handleSevereException(e);
handleSevereException(e);
}
}
return null;
return null;
}
}
});
});
}
}
@Override
@Override
public com.stream_pi.util.platform.Platform getPlatform() {
public com.stream_pi.util.platform.Platform getPlatform() {
return ServerInfo.getInstance().getPlatform();
return ServerInfo.getInstance().getPlatform();
}
}
@Override
@Override
public void sendActionFailed(MinorException exception, SocketAddress socketAddress, String profileID, String actionID)
public void sendActionFailed(MinorException exception, SocketAddress socketAddress, String profileID, String actionID)
{
{
if(exception.getTitle() != null)
if(exception.getTitle() != null)
{
{
exception.setShortMessage(exception.getTitle()+"\n"+exception.getShortMessage());
exception.setShortMessage(exception.getTitle()+"\n"+exception.getShortMessage());
}
}
exception.setTitle("Error while running action");
exception.setTitle("Error while running action");
handleMinorException(exception);
handleMinorException(exception);
executor.execute(new Task<Void>() {
executor.execute(new Task<Void>() {
@Override
@Override
protected Void call()
protected Void call()
{
{
try {
try {
ClientConnections.getInstance().getClientConnectionBySocketAddress(socketAddress)
ClientConnections.getInstance().getClientConnectionBySocketAddress(socketAddress)
.sendActionFailed(profileID, actionID);
.sendActionFailed(profileID, actionID);
}
}
catch (SevereException e)
catch (SevereException e)
{
{
handleSevereException(e);
handleSevereException(e);
}
}
return null;
return null;
}
}
});
});
}
}
private Animation createOpenSettingsAnimation(Node settingsNode, Node dashboardNode) {
private Animation createOpenSettingsAnimation(Node settingsNode, Node dashboardNode) {
Timeline openSettingsTimeline = new Timeline();
Timeline openSettingsTimeline = new Timeline();
openSettingsTimeline.setCycleCount(1);
openSettingsTimeline.setCycleCount(1);
openSettingsTimeline.getKeyFrames().addAll(
openSettingsTimeline.getKeyFrames().addAll(
new KeyFrame(Duration.millis(0.0D),
new KeyFrame(Duration.millis(0.0D),
new KeyValue(settingsNode.opacityProperty(),
new KeyValue(settingsNode.opacityProperty(),
0.0D, Interpolator.EASE_IN),
0.0D, Interpolator.EASE_IN),
new KeyValue(settingsNode.scaleXProperty(),
new KeyValue(settingsNode.scaleXProperty(),
1.1D, Interpolator.EASE_IN),
1.1D, Interpolator.EASE_IN),
new KeyValue(settingsNode.scaleYProperty(),
new KeyValue(settingsNode.scaleYProperty(),
1.1D, Interpolator.EASE_IN),
1.1D, Interpolator.EASE_IN),
new KeyValue(settingsNode.scaleZProperty(),
new KeyValue(settingsNode.scaleZProperty(),
1.1D, Interpolator.EASE_IN)),
1.1D, Interpolator.EASE_IN)),
new KeyFrame(Duration.millis(90.0D),
new KeyFrame(Duration.millis(90.0D),
new KeyValue(settingsNode.opacityProperty(),
new KeyValue(settingsNode.opacityProperty(),
1.0D, Interpolator.LINEAR),
1.0D, Interpolator.LINEAR),
new KeyValue(settingsNode.scaleXProperty(),
new KeyValue(settingsNode.scaleXProperty(),
1.0D, Interpolator.LINEAR),
1.0D, Interpolator.LINEAR),
new KeyValue(settingsNode.scaleYProperty(),
new KeyValue(settingsNode.scaleYProperty(),
1.0D, Interpolator.LINEAR),
1.0D, Interpolator.LINEAR),
new KeyValue(settingsNode.scaleZProperty(),
new KeyValue(settingsNode.scaleZProperty(),
1.0D, Interpolator.LINEAR)),
1.0D, Interpolator.LINEAR)),
new KeyFrame(Duration.millis(0.0D),
new KeyFrame(Duration.millis(0.0D),
new KeyValue(dashboardNode.opacityProperty(),
new KeyValue(dashboardNode.opacityProperty(),
1.0D, Interpolator.LINEAR),
1.0D, Interpolator.LINEAR),
new KeyValue(dashboardNode.scaleXProperty(),
new KeyValue(dashboardNode.scaleXProperty(),
1.0D, Interpolator.LINEAR),
1.0D, Interpolator.LINEAR),
new KeyValue(dashboardNode.scaleYProperty(),
new KeyValue(dashboardNode.scaleYProperty(),
1.0D, Interpolator.LINEAR),
1.0D, Interpolator.LINEAR),
new KeyValue(dashboardNode.scaleZProperty(),
new KeyValue(dashboardNode.scaleZProperty(),
1.0D, Interpolator.LINEAR)),
1.0D, Interpolator.LINEAR)),
new KeyFrame(Duration.millis(90.0D),
new KeyFrame(Duration.millis(90.0D),
new KeyValue(dashboardNode.opacityProperty(),
new KeyValue(dashboardNode.opacityProperty(),
0.0D, Interpolator.LINEAR),
0.0D, Interpolator.LINEAR),
new KeyValue(dashboardNode.scaleXProperty(),
new KeyValue(dashboardNode.scaleXProperty(),
0.9D, Interpolator.LINEAR),
0.9D, Interpolator.LINEAR),
new KeyValue(dashboardNode.scaleYProperty(),
new KeyValue(dashboardNode.scaleYProperty(),
0.9D, Interpolator.LINEAR),
0.9D, Interpolator.LINEAR),
new KeyValue(dashboardNode.scaleZProperty(),
new KeyValue(dashboardNode.scaleZProperty(),
0.9D, Interpolator.LINEAR))
0.9D, Interpolator.LINEAR))
);
);
openSettingsTimeline.setOnFinished(e -> settingsNode.toFront());
openSettingsTimeline.setOnFinished(e -> settingsNode.toFront());
return openSettingsTimeline;
return openSettingsTimeline;
}
}
private Animation createCloseSettingsAnimation(Node settingsNode, Node dashboardNode) {
private Animation createCloseSettingsAnimation(Node settingsNode, Node dashboardNode) {
Timeline closeSettingsTimeline = new Timeline();
Timeline closeSettingsTimeline = new Timeline();
closeSettingsTimeline.setCycleCount(1);
closeSettingsTimeline.setCycleCount(1);
closeSettingsTimeline.getKeyFrames().addAll(
closeSettingsTimeline.getKeyFrames().addAll(
new KeyFrame(Duration.millis(0.0D),
new KeyFrame(Duration.millis(0.0D),
new KeyValue(settingsNode.opacityProperty(),
new KeyValue(settingsNode.opacityProperty(),
1.0D, Interpolator.LINEAR),
1.0D, Interpolator.LINEAR),
new KeyValue(settingsNode.scaleXProperty(),
new KeyValue(settingsNode.scaleXProperty(),
1.0D, Interpolator.LINEAR),
1.0D, Interpolator.LINEAR),
new KeyValue(settingsNode.scaleYProperty(),
new KeyValue(settingsNode.scaleYProperty(),
1.0D, Interpolator.LINEAR),
1.0D, Interpolator.LINEAR),
new KeyValue(settingsNode.scaleZProperty(),
new KeyValue(settingsNode.scaleZProperty(),
1.0D, Interpolator.LINEAR)),
1.0D, Interpolator.LINEAR)),
new KeyFrame(Duration.millis(90.0D),
new KeyFrame(Duration.millis(90.0D),
new KeyValue(settingsNode.opacityProperty(),
new KeyValue(settingsNode.opacityProperty(),
0.0D, Interpolator.LINEAR),
0.0D, Interpolator.LINEAR),
new KeyValue(settingsNode.scaleXProperty(),
new KeyValue(settingsNode.scaleXProperty(),
1.1D, Interpolator.LINEAR),
1.1D, Interpolator.LINEAR),
new KeyValue(settingsNode.scaleYProperty(),
new KeyValue(settingsNode.scaleYProperty(),
1.1D, Interpolator.LINEAR),
1.1D, Interpolator.LINEAR),
new KeyValue(settingsNode.scaleZProperty(),
new KeyValue(settingsNode.scaleZProperty(),
1.1D, Interpolator.LINEAR)),
1.1D, Interpolator.LINEAR)),
new KeyFrame(Duration.millis(0.0D),
new KeyFrame(Duration.millis(0.0D),
new KeyValue(dashboardNode.opacityProperty(),
new KeyValue(dashboardNode.opacityProperty(),
0.0D, Interpolator.LINEAR),
0.0D, Interpolator.LINEAR),
new KeyValue(dashboardNode.scaleXProperty(),
new KeyValue(dashboardNode.scaleXProperty(),
0.9D, Interpolator.LINEAR),
0.9D, Interpolator.LINEAR),
new KeyValue(dashboardNode.scaleYProperty(),
new KeyValue(dashboardNode.scaleYProperty(),
0.9D, Interpolator.LINEAR),
0.9D, Interpolator.LINEAR),
new KeyValue(dashboardNode.scaleZProperty(),
new KeyValue(dashboardNode.scaleZProperty(),
0.9D, Interpolator.LINEAR)),
0.9D, Interpolator.LINEAR)),
new KeyFrame(Duration.millis(90.0D),
new KeyFrame(Duration.millis(90.0D),
new KeyValue(dashboardNode.opacityProperty(),
new KeyValue(dashboardNode.opacityProperty(),
1.0D, Interpolator.LINEAR),
1.0D, Interpolator.LINEAR),
new KeyValue(dashboardNode.scaleXProperty(),
new KeyValue(dashboardNode.scaleXProperty(),
1.0D, Interpolator.LINEAR),
1.0D, Interpolator.LINEAR),
new KeyValue(dashboardNode.scaleYProperty(),
new KeyValue(dashboardNode.scaleYProperty(),
1.0D, Interpolator.LINEAR),
1.0D, Interpolator.LINEAR),
new KeyValue(dashboardNode.scaleZProperty(),
new KeyValue(dashboardNode.scaleZProperty(),
1.0D, Interpolator.LINEAR))
1.0D, Interpolator.LINEAR))
);
);
closeSettingsTimeline.setOnFinished(event1 -> {
closeSettingsTimeline.setOnFinished(event1 -> {
dashboardNode.toFront();
dashboardNode.toFront();
executor.execute(new Task<Void>() {
executor.execute(new Task<Void>() {
@Override
@Override
protected Void call() {
protected Void call() {
try {
try {
getSettingsBase().getClientsSettings().loadData();
getSettingsBase().getClientsSettings().loadData();
getSettingsBase().getGeneralSettings().loadDataFromConfig();
getSettingsBase().getGeneralSettings().loadDataFromConfig();
getSettingsBase().getPluginsSettings().loadPlugins();
getSettingsBase().getPluginsSettings().loadPlugins();
getSettingsBase().getThemesSettings().setThemes(getThemes());
getSettingsBase().getThemesSettings().setThemes(getThemes());
getSettingsBase().getThemesSettings().setCurrentThemeFullName(getCurrentTheme().getFullName());
getSettingsBase().getThemesSettings().setCurrentThemeFullName(getCurrentTheme().getFullName());
getSettingsBase().getThemesSettings().loadThemes();
getSettingsBase().getThemesSettings().loadThemes();
getSettingsBase().setDefaultTabToGeneral();
getSettingsBase().setDefaultTabToGeneral();
}
}
catch (SevereException e)
catch (SevereException e)
{
{
handleSevereException(e);
handleSevereException(e);
}
}
catch (MinorException e)
catch (MinorException e)
{
{
handleMinorException(e);
handleMinorException(e);
}
}
return null;
return null;
}
}
});
});
});
});
return closeSettingsTimeline;
return closeSettingsTimeline;
}
}
@Override
@Override
public void setToggleStatus(boolean currentStatus, String profileID, String actionID, SocketAddress clientSocketAddress)
public void setToggleStatus(boolean currentStatus, String profileID, String actionID, SocketAddress clientSocketAddress)
throws MinorException
throws MinorException
{
{
ClientConnection clientConnection = ClientConnections.getInstance().getClientConnectionBySocketAddress(
ClientConnection clientConnection = ClientConnections.getInstance().getClientConnectionBySocketAddress(
clientSocketAddress
clientSocketAddress
);
);
if(clientConnection == null)
if(clientConnection == null)
throw new ClientNotFoundException("setToggleStatus failed because no client found with given socket address");
throw new ClientNotFoundException("setToggleStatus failed because no client found with given socket address");
new Thread(new Task<Void>() {
new Thread(new Task<Void>() {
@Override
@Override
protected Void call()
protected Void call()
{
{
try
try
{
{
clientConnection.setToggleStatus(currentStatus, profileID, actionID);
clientConnection.setToggleStatus(currentStatus, profileID, actionID);
}
}
catch (SevereException e)
catch (SevereException e)
{
{
handleSevereException(e);
handleSevereException(e);
}
}
return null;
return null;
}
}
}).start();
}).start();
}
}
}
}
package com.stream_pi.server.controller;
package com.stream_pi.server.controller;
import com.stream_pi.action_api.externalplugin.NormalAction;
import com.stream_pi.action_api.externalplugin.NormalAction;
import com.stream_pi.action_api.externalplugin.ToggleAction;
import com.stream_pi.action_api.externalplugin.ToggleAction;
import com.stream_pi.server.client.Client;
import com.stream_pi.server.client.Client;
import com.stream_pi.server.window.dashboard.ClientAndProfileSelectorPane;
import com.stream_pi.server.window.dashboard.ClientAndProfileSelectorPane;
import com.stream_pi.server.window.dashboard.DashboardBase;
import com.stream_pi.server.window.dashboard.DashboardBase;
import com.stream_pi.server.window.settings.SettingsBase;
import com.stream_pi.server.window.settings.SettingsBase;
import com.stream_pi.util.exception.SevereException;
import com.stream_pi.util.exception.SevereException;
import javafx.stage.Stage;
import javafx.stage.Stage;
import java.net.SocketAddress;
import java.net.SocketAddress;
public interface ServerListener
public interface ServerListener
{
{
void onActionClicked(Client client, String profileID, String actionID, boolean toggle);
void onActionClicked(Client client, String profileID, String actionID, boolean toggle);
void clearTemp();
void clearTemp();
void init();
void init();
void restart();
void restart();
void othInit();
void othInit();
Stage getStage();
Stage getStage();
DashboardBase getDashboardBase();
DashboardBase getDashboardBase();
SettingsBase getSettingsBase();
SettingsBase getSettingsBase();
void initLogger() throws SevereException;
void initLogger() throws SevereException;
void factoryReset();
void factoryReset();
void initSoundOnActionClicked();
void initSoundOnActionClicked();
void onServerStartFailure();
}
}
package com.stream_pi.server.window.settings;
package com.stream_pi.server.window.settings;
import com.stream_pi.action_api.actionproperty.property.FileExtensionFilter;
import com.stream_pi.action_api.actionproperty.property.FileExtensionFilter;
import com.stream_pi.server.controller.ServerListener;
import com.stream_pi.server.controller.ServerListener;
import com.stream_pi.server.info.StartupFlags;
import com.stream_pi.server.info.StartupFlags;
import com.stream_pi.server.io.Config;
import com.stream_pi.server.io.Config;
import com.stream_pi.server.window.ExceptionAndAlertHandler;
import com.stream_pi.server.window.ExceptionAndAlertHandler;
import com.stream_pi.server.info.ServerInfo;
import com.stream_pi.server.info.ServerInfo;
import com.stream_pi.util.alert.StreamPiAlert;
import com.stream_pi.util.alert.StreamPiAlert;
import com.stream_pi.util.alert.StreamPiAlertListener;
import com.stream_pi.util.alert.StreamPiAlertListener;
import com.stream_pi.util.alert.StreamPiAlertType;
import com.stream_pi.util.alert.StreamPiAlertType;
import com.stream_pi.util.checkforupdates.CheckForUpdates;
import com.stream_pi.util.checkforupdates.CheckForUpdates;
import com.stream_pi.util.checkforupdates.UpdateHyperlinkOnClick;
import com.stream_pi.util.checkforupdates.UpdateHyperlinkOnClick;
import com.stream_pi.util.exception.MinorException;
import com.stream_pi.util.exception.MinorException;
import com.stream_pi.util.exception.SevereException;
import com.stream_pi.util.exception.SevereException;
import com.stream_pi.util.platform.PlatformType;
import com.stream_pi.util.platform.PlatformType;
import com.stream_pi.util.startatboot.StartAtBoot;
import com.stream_pi.util.startatboot.StartAtBoot;
import com.stream_pi.util.uihelper.HBoxInputBox;
import com.stream_pi.util.uihelper.HBoxInputBox;
import com.stream_pi.util.uihelper.HBoxInputBoxWithDirectoryChooser;
import com.stream_pi.util.uihelper.HBoxInputBoxWithDirectoryChooser;
import com.stream_pi.util.uihelper.HBoxInputBoxWithFileChooser;
import com.stream_pi.util.uihelper.HBoxInputBoxWithFileChooser;
import com.stream_pi.util.uihelper.HBoxWithSpaceBetween;
import com.stream_pi.util.uihelper.HBoxWithSpaceBetween;
import javafx.application.HostServices;
import javafx.application.HostServices;
import javafx.application.Platform;
import javafx.application.Platform;
import javafx.concurrent.Task;
import javafx.concurrent.Task;
import javafx.event.ActionEvent;
import javafx.event.ActionEvent;
import javafx.geometry.Insets;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.geometry.Pos;
import javafx.scene.control.Button;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.control.TextField;
import javafx.scene.layout.*;
import javafx.scene.layout.*;
import javafx.stage.DirectoryChooser;
import javafx.stage.DirectoryChooser;
import javafx.stage.FileChooser;
import javafx.stage.FileChooser;
import org.controlsfx.control.ToggleSwitch;
import org.controlsfx.control.ToggleSwitch;
import org.kordamp.ikonli.javafx.FontIcon;
import org.kordamp.ikonli.javafx.FontIcon;
import org.w3c.dom.Text;
import org.w3c.dom.Text;
import java.awt.SystemTray;
import java.awt.SystemTray;
import java.io.File;
import java.io.File;
import java.util.logging.Logger;
import java.util.logging.Logger;
public class GeneralSettings extends VBox {
public class GeneralSettings extends VBox {
private final TextField serverNameTextField;
private final TextField serverNameTextField;
private final TextField portTextField;
private final TextField portTextField;
private final TextField pluginsPathTextField;
private final TextField pluginsPathTextField;
private final TextField themesPathTextField;
private final TextField themesPathTextField;
private final TextField actionGridPaneActionBoxSize;
private final TextField actionGridPaneActionBoxSize;
private final TextField actionGridPaneActionBoxGap;
private final TextField actionGridPaneActionBoxGap;
private final ToggleSwitch startOnBootToggleSwitch;
private final ToggleSwitch startOnBootToggleSwitch;
private final HBoxWithSpaceBetween startOnBootHBox;
private final HBoxWithSpaceBetween startOnBootHBox;
private final TextField soundOnActionClickedFilePathTextField;
private final TextField soundOnActionClickedFilePathTextField;
private final ToggleSwitch soundOnActionClickedToggleSwitch;
private final ToggleSwitch soundOnActionClickedToggleSwitch;
private final HBoxWithSpaceBetween soundOnActionClickedToggleSwitchHBox;
private final HBoxWithSpaceBetween soundOnActionClickedToggleSwitchHBox;
private final ToggleSwitch minimizeToSystemTrayOnCloseToggleSwitch;
private final ToggleSwitch minimizeToSystemTrayOnCloseToggleSwitch;
private final HBoxWithSpaceBetween minimizeToSystemTrayOnCloseHBox;
private final HBoxWithSpaceBetween minimizeToSystemTrayOnCloseHBox;
private final ToggleSwitch showAlertsPopupToggleSwitch;
private final ToggleSwitch showAlertsPopupToggleSwitch;
private final HBoxWithSpaceBetween showAlertsPopupHBox;
private final HBoxWithSpaceBetween showAlertsPopupHBox;
private final Button saveButton;
private final Button saveButton;
private final Button checkForUpdatesButton;
private final Button checkForUpdatesButton;
private final Button factoryResetButton;
private final Button factoryResetButton;
private Logger logger;
private Logger logger;
private ExceptionAndAlertHandler exceptionAndAlertHandler;
private ExceptionAndAlertHandler exceptionAndAlertHandler;
private ServerListener serverListener;
private ServerListener serverListener;
private HostServices hostServices;
private HostServices hostServices;
public GeneralSettings(ExceptionAndAlertHandler exceptionAndAlertHandler, ServerListener serverListener, HostServices hostServices)
public GeneralSettings(ExceptionAndAlertHandler exceptionAndAlertHandler, ServerListener serverListener, HostServices hostServices)
{
{
this.hostServices = hostServices;
this.hostServices = hostServices;
this.exceptionAndAlertHandler = exceptionAndAlertHandler;
this.exceptionAndAlertHandler = exceptionAndAlertHandler;
this.serverListener = serverListener;
this.serverListener = serverListener;
logger = Logger.getLogger(GeneralSettings.class.getName());
logger = Logger.getLogger(GeneralSettings.class.getName());
serverNameTextField = new TextField();
serverNameTextField = new TextField();
portTextField = new TextField();
portTextField = new TextField();
pluginsPathTextField = new TextField();
pluginsPathTextField = new TextField();
themesPathTextField = new TextField();
themesPathTextField = new TextField();
actionGridPaneActionBoxSize = new TextField();
actionGridPaneActionBoxSize = new TextField();
actionGridPaneActionBoxGap = new TextField();
actionGridPaneActionBoxGap = new TextField();
startOnBootToggleSwitch = new ToggleSwitch();
startOnBootToggleSwitch = new ToggleSwitch();
startOnBootHBox = new HBoxWithSpaceBetween("Start on Boot", startOnBootToggleSwitch);
startOnBootHBox = new HBoxWithSpaceBetween("Start on Boot", startOnBootToggleSwitch);
startOnBootHBox.managedProperty().bind(startOnBootHBox.visibleProperty());
startOnBootHBox.managedProperty().bind(startOnBootHBox.visibleProperty());
soundOnActionClickedToggleSwitch = new ToggleSwitch();
soundOnActionClickedToggleSwitch = new ToggleSwitch();
soundOnActionClickedToggleSwitchHBox = new HBoxWithSpaceBetween("Sound on Action Clicked", soundOnActionClickedToggleSwitch);
soundOnActionClickedToggleSwitchHBox = new HBoxWithSpaceBetween("Sound on Action Clicked", soundOnActionClickedToggleSwitch);
soundOnActionClickedFilePathTextField = new TextField();
soundOnActionClickedFilePathTextField = new TextField();
HBoxInputBoxWithFileChooser soundHBoxInputBoxWithFileChooser = new HBoxInputBoxWithFileChooser("Sound File Path", soundOnActionClickedFilePathTextField,
HBoxInputBoxWithFileChooser soundHBoxInputBoxWithFileChooser = new HBoxInputBoxWithFileChooser("Sound File Path", soundOnActionClickedFilePathTextField,
new FileChooser.ExtensionFilter("Sounds","*.mp3","*.mp4", "*.m4a", "*.m4v","*.wav","*.aif", "*.aiff","*.fxm","*.flv","*.m3u8"));
new FileChooser.ExtensionFilter("Sounds","*.mp3","*.mp4", "*.m4a", "*.m4v","*.wav","*.aif", "*.aiff","*.fxm","*.flv","*.m3u8"));
soundHBoxInputBoxWithFileChooser.setUseLast(false);
soundHBoxInputBoxWithFileChooser.setUseLast(false);
soundHBoxInputBoxWithFileChooser.setRememberThis(false);
soundHBoxInputBoxWithFileChooser.setRememberThis(false);
soundHBoxInputBoxWithFileChooser.getFileChooseButton().disableProperty().bind(soundOnActionClickedToggleSwitch.selectedProperty().not());
soundHBoxInputBoxWithFileChooser.getFileChooseButton().disableProperty().bind(soundOnActionClickedToggleSwitch.selectedProperty().not());
minimizeToSystemTrayOnCloseToggleSwitch = new ToggleSwitch();
minimizeToSystemTrayOnCloseToggleSwitch = new ToggleSwitch();
minimizeToSystemTrayOnCloseHBox = new HBoxWithSpaceBetween("Minimise To Tray On Close", minimizeToSystemTrayOnCloseToggleSwitch);
minimizeToSystemTrayOnCloseHBox = new HBoxWithSpaceBetween("Minimise To Tray On Close", minimizeToSystemTrayOnCloseToggleSwitch);
showAlertsPopupToggleSwitch = new ToggleSwitch();
showAlertsPopupToggleSwitch = new ToggleSwitch();
showAlertsPopupHBox = new HBoxWithSpaceBetween("Show Popup On Alert", showAlertsPopupToggleSwitch);
showAlertsPopupHBox = new HBoxWithSpaceBetween("Show Popup On Alert", showAlertsPopupToggleSwitch);
checkForUpdatesButton = new Button("Check for updates");
checkForUpdatesButton = new Button("Check for updates");
checkForUpdatesButton.setOnAction(event->checkForUpdates());
checkForUpdatesButton.setOnAction(event->checkForUpdates());
factoryResetButton = new Button("Factory Reset");
factoryResetButton = new Button("Factory Reset");
factoryResetButton.setOnAction(actionEvent -> onFactoryResetButtonClicked());
factoryResetButton.setOnAction(actionEvent -> onFactoryResetButtonClicked());
getStyleClass().add("general_settings");
getStyleClass().add("general_settings");
prefWidthProperty().bind(widthProperty());
prefWidthProperty().bind(widthProperty());
setAlignment(Pos.CENTER);
setAlignment(Pos.CENTER);
setSpacing(5);
setSpacing(5);
getChildren().addAll(
getChildren().addAll(
new HBoxInputBox("Server Name", serverNameTextField),
new HBoxInputBox("Server Name", serverNameTextField),
new HBoxInputBox("Port", portTextField),
new HBoxInputBox("Port", portTextField),
new HBoxInputBox("Grid Pane - Box Size", actionGridPaneActionBoxSize),
new HBoxInputBox("Grid Pane - Box Size", actionGridPaneActionBoxSize),
new HBoxInputBox("Grid Pane - Box Gap", actionGridPaneActionBoxGap),
new HBoxInputBox("Grid Pane - Box Gap", actionGridPaneActionBoxGap),
new HBoxInputBoxWithDirectoryChooser("Plugins Path", pluginsPathTextField),
new HBoxInputBoxWithDirectoryChooser("Plugins Path", pluginsPathTextField),
new HBoxInputBoxWithDirectoryChooser("Themes Path", themesPathTextField),
new HBoxInputBoxWithDirectoryChooser("Themes Path", themesPathTextField),
soundHBoxInputBoxWithFileChooser,
soundHBoxInputBoxWithFileChooser,
soundOnActionClickedToggleSwitchHBox,
soundOnActionClickedToggleSwitchHBox,
minimizeToSystemTrayOnCloseHBox,
minimizeToSystemTrayOnCloseHBox,
startOnBootHBox,
startOnBootHBox,
showAlertsPopupHBox
showAlertsPopupHBox
);
);
serverNameTextField.setPrefWidth(200);
serverNameTextField.setPrefWidth(200);
saveButton = new Button("Save");
saveButton = new Button("Save");
saveButton.setOnAction(event->save());
saveButton.setOnAction(event->save());
getChildren().addAll(factoryResetButton, checkForUpdatesButton, saveButton);
getChildren().addAll(factoryResetButton, checkForUpdatesButton, saveButton);
setPadding(new Insets(10));
setPadding(new Insets(10));
}
}
private void checkForUpdates()
private void checkForUpdates()
{
{
new CheckForUpdates(checkForUpdatesButton,
new CheckForUpdates(checkForUpdatesButton,
PlatformType.SERVER, ServerInfo.getInstance().getVersion(), new UpdateHyperlinkOnClick() {
PlatformType.SERVER, ServerInfo.getInstance().getVersion(), new UpdateHyperlinkOnClick() {
@Override
@Override
public void handle(ActionEvent actionEvent) {
public void handle(ActionEvent actionEvent) {
hostServices.showDocument(getURL());
hostServices.showDocument(getURL());
}
}
});
});
}
}
public void loadDataFromConfig() throws SevereException {
public void loadDataFromConfig() throws SevereException {
Config config = Config.getInstance();
Config config = Config.getInstance();
Platform.runLater(()->
Platform.runLater(()->
{
{
serverNameTextField.setText(config.getServerName());
serverNameTextField.setText(config.getServerName());
portTextField.setText(config.getPort()+"");
portTextField.setText(config.getPort()+"");
pluginsPathTextField.setText(config.getPluginsPath());
pluginsPathTextField.setText(config.getPluginsPath());
themesPathTextField.setText(config.getThemesPath());
themesPathTextField.setText(config.getThemesPath());
actionGridPaneActionBoxSize.setText(config.getActionGridActionSize()+"");
actionGridPaneActionBoxSize.setText(config.getActionGridActionSize()+"");
actionGridPaneActionBoxGap.setText(config.getActionGridActionGap()+"");
actionGridPaneActionBoxGap.setText(config.getActionGridActionGap()+"");
minimizeToSystemTrayOnCloseToggleSwitch.setSelected(config.getMinimiseToSystemTrayOnClose());
minimizeToSystemTrayOnCloseToggleSwitch.setSelected(config.getMinimiseToSystemTrayOnClose());
showAlertsPopupToggleSwitch.setSelected(config.isShowAlertsPopup());
showAlertsPopupToggleSwitch.setSelected(config.isShowAlertsPopup());
startOnBootToggleSwitch.setSelected(config.getStartOnBoot());
startOnBootToggleSwitch.setSelected(config.getStartOnBoot());
soundOnActionClickedToggleSwitch.setSelected(config.getSoundOnActionClickedStatus());
soundOnActionClickedToggleSwitch.setSelected(config.getSoundOnActionClickedStatus());
soundOnActionClickedFilePathTextField.setText(config.getSoundOnActionClickedFilePath());
soundOnActionClickedFilePathTextField.setText(config.getSoundOnActionClickedFilePath());
});
});
}
}
public void save()
public void save()
{
{
new Thread(new Task<Void>() {
new Thread(new Task<Void>() {
@Override
@Override
protected Void call()
protected Void call()
{
{
try {
try {
boolean toBeReloaded = false;
boolean toBeReloaded = false;
boolean dashToBeReRendered = false;
boolean dashToBeReRendered = false;
Platform.runLater(()->{
Platform.runLater(()->{
saveButton.setDisable(true);
saveButton.setDisable(true);
});
});
String serverNameStr = serverNameTextField.getText();
String serverNameStr = serverNameTextField.getText();
String serverPortStr = portTextField.getText();
String serverPortStr = portTextField.getText();
String pluginsPathStr = pluginsPathTextField.getText();
String pluginsPathStr = pluginsPathTextField.getText();
String themesPathStr = themesPathTextField.getText();
String themesPathStr = themesPathTextField.getText();
String actionGridActionBoxSize = actionGridPaneActionBoxSize.getText();
String actionGridActionBoxSize = actionGridPaneActionBoxSize.getText();
String actionGridActionBoxGap = actionGridPaneActionBoxGap.getText();
String actionGridActionBoxGap = actionGridPaneActionBoxGap.getText();
boolean minimizeToSystemTrayOnClose = minimizeToSystemTrayOnCloseToggleSwitch.isSelected();
boolean minimizeToSystemTrayOnClose = minimizeToSystemTrayOnCloseToggleSwitch.isSelected();
boolean showAlertsPopup = showAlertsPopupToggleSwitch.isSelected();
boolean showAlertsPopup = showAlertsPopupToggleSwitch.isSelected();
boolean startOnBoot = startOnBootToggleSwitch.isSelected();
boolean startOnBoot = startOnBootToggleSwitch.isSelected();
boolean soundOnActionClicked = soundOnActionClickedToggleSwitch.isSelected();
boolean soundOnActionClicked = soundOnActionClickedToggleSwitch.isSelected();
String soundOnActionClickedFilePath = soundOnActionClickedFilePathTextField.getText();
String soundOnActionClickedFilePath = soundOnActionClickedFilePathTextField.getText();
Config config = Config.getInstance();
Config config = Config.getInstance();
StringBuilder errors = new StringBuilder();
StringBuilder errors = new StringBuilder();
if(serverNameStr.isBlank())
if(serverNameStr.isBlank())
{
{
errors.append("* Server Name cannot be blank.\n");
errors.append("* Server Name cannot be blank.\n");
}
}
else
else
{
{
if(!config.getServerName().equals(serverNameStr))
if(!config.getServerName().equals(serverNameStr))
{
{
toBeReloaded = true;
toBeReloaded = true;
}
}
}
}
int serverPort=-1;
int serverPort=-1;
try {
try {
serverPort = Integer.parseInt(serverPortStr);
serverPort = Integer.parseInt(serverPortStr);
if (serverPort < 1024)
if (serverPort < 1024)
errors.append("* Server Port must be more than 1024\n");
errors.append("* Server Port must be more than 1024\n");
else if(serverPort > 65535)
else if(serverPort > 65535)
errors.append("* Server Port must be lesser than 65535\n");
errors.append("* Server Port must be lesser than 65535\n");
if(config.getPort()!=serverPort)
if(config.getPort()!=serverPort)
{
{
toBeReloaded = true;
toBeReloaded = true;
}
}
}
}
catch (NumberFormatException e)
catch (NumberFormatException e)
{
{
errors.append("* Server Port must be integer.\n");
errors.append("* Server Port must be integer.\n");
}
}
int actionSize=-1;
int actionSize=-1;
try {
try {
actionSize = Integer.parseInt(actionGridActionBoxSize);
actionSize = Integer.parseInt(actionGridActionBoxSize);
if(config.getActionGridActionSize() != actionSize)
if(config.getActionGridActionSize() != actionSize)
{
{
dashToBeReRendered = true;
dashToBeReRendered = true;
}
}
}
}
catch (NumberFormatException e)
catch (NumberFormatException e)
{
{
errors.append("* action Size must be integer.\n");
errors.append("* action Size must be integer.\n");
}
}
int actionGap=-1;
int actionGap=-1;
try {
try {
actionGap = Integer.parseInt(actionGridActionBoxGap);
actionGap = Integer.parseInt(actionGridActionBoxGap);
if(config.getActionGridActionGap() != actionGap)
if(config.getActionGridActionGap() != actionGap)
{
{
dashToBeReRendered = true;
dashToBeReRendered = true;
}
}
}
}
catch (NumberFormatException e)
catch (NumberFormatException e)
{
{
errors.append("* action Gap must be integer.\n");
errors.append("* action Gap must be integer.\n");
}
}
if(pluginsPathStr.isBlank())
if(pluginsPathStr.isBlank())
{
{
errors.append("* Plugins Path must not be blank.\n");
errors.append("* Plugins Path must not be blank.\n");
}
}
else
else
{
{
if(!config.getPluginsPath().equals(pluginsPathStr))
if(!config.getPluginsPath().equals(pluginsPathStr))
{
{
toBeReloaded = true;
toBeReloaded = true;
}
}
}
}
if(themesPathStr.isBlank())
if(themesPathStr.isBlank())
{
{
errors.append("* Themes Path must not be blank.\n");
errors.append("* Themes Path must not be blank.\n");
}
}
else
else
{
{
if(!config.getThemesPath().equals(themesPathStr))
if(!config.getThemesPath().equals(themesPathStr))
{
{
toBeReloaded = true;
toBeReloaded = true;
}
}
}
}
if(!errors.toString().isEmpty())
if(!errors.toString().isEmpty())
{
{
throw new MinorException("Uh Oh!", "Please rectify the following errors and try again :\n"+errors.toString());
throw new MinorException("Uh Oh!", "Please rectify the following errors and try again :\n"+errors.toString());
}
}
if(config.getStartOnBoot() != startOnBoot)
if(config.getStartOnBoot() != startOnBoot)
{
{
if(StartupFlags.RUNNER_FILE_NAME == null)
StartAtBoot startAtBoot = new StartAtBoot(PlatformType.SERVER, ServerInfo.getInstance().getPlatform());
if(startOnBoot)
{
{
new StreamPiAlert("Uh Oh", "No Runner File Name Specified as startup arguments. Cant set run at boot.", StreamPiAlertType.ERROR).show();
try
startOnBoot = false;
}
else
{
StartAtBoot startAtBoot = new StartAtBoot(PlatformType.SERVER, ServerInfo.getInstance().getPlatform());
if(startOnBoot)
{
{
startAtBoot.create(new File(StartupFlags.RUNNER_FILE_NAME));
startAtBoot.create(StartupFlags.RUNNER_FILE_NAME);
}
}
else
catch (MinorException e)
{
{
boolean result = startAtBoot.delete();
exceptionAndAlertHandler.handleMinorException(e);
if(!result)
startOnBoot = false;
new StreamPiAlert("Uh Oh!", "Unable to delete starter file", StreamPiAlertType.ERROR).show();
}
}
}
}
else
{
boolean result = startAtBoot.delete();
if(!result)
new StreamPiAlert("Uh Oh!", "Unable to delete starter file", StreamPiAlertType.ERROR).show();
}
}
}
if(minimizeToSystemTrayOnClose)
if(minimizeToSystemTrayOnClose)
{
{
if(!SystemTray.isSupported())
if(!SystemTray.isSupported())
{
{
StreamPiAlert alert = new StreamPiAlert("Not Supported", "Tray System not supported on this platform ", StreamPiAlertType.ERROR);
StreamPiAlert alert = new StreamPiAlert("Not Supported", "Tray System not supported on this platform ", StreamPiAlertType.ERROR);
alert.show();
alert.show();
minimizeToSystemTrayOnClose = false;
minimizeToSystemTrayOnClose = false;
}
}
}
}
if(soundOnActionClicked)
if(soundOnActionClicked)
{
{
if(soundOnActionClickedFilePath.isBlank())
if(soundOnActionClickedFilePath.isBlank())
{
{
StreamPiAlert alert = new StreamPiAlert("No sound file specified",
StreamPiAlert alert = new StreamPiAlert("No sound file specified",
"Sound File cannot be empty", StreamPiAlertType.ERROR);
"Sound File cannot be empty", StreamPiAlertType.ERROR);
alert.show();
alert.show();
soundOnActionClicked = false;
soundOnActionClicked = false;
}
}
else
else
{
{
File soundFile = new File(soundOnActionClickedFilePath);
File soundFile = new File(soundOnActionClickedFilePath);
if(!soundFile.exists() || !soundFile.isFile())
if(!soundFile.exists() || !soundFile.isFile())
{
{
StreamPiAlert alert = new StreamPiAlert("File not found",
StreamPiAlert alert = new StreamPiAlert("File not found",
"No sound file at \n"+soundOnActionClickedFilePath+"\n" +
"No sound file at \n"+soundOnActionClickedFilePath+"\n" +
"Unable to set sound on action clicked.", StreamPiAlertType.ERROR);
"Unable to set sound on action clicked.", StreamPiAlertType.ERROR);
alert.show();
alert.show();
soundOnActionClicked = false;
soundOnActionClicked = false;
}
}
}
}
}
}
config.setServerName(serverNameStr);
config.setServerName(serverNameStr);
config.setServerPort(serverPort);
config.setServerPort(serverPort);
config.setActionGridGap(actionGap);
config.setActionGridGap(actionGap);
config.setActionGridSize(actionSize);
config.setActionGridSize(actionSize);
config.setPluginsPath(pluginsPathStr);
config.setPluginsPath(pluginsPathStr);
config.setThemesPath(themesPathStr);
config.setThemesPath(themesPathStr);
config.setMinimiseToSystemTrayOnClose(minimizeToSystemTrayOnClose);
config.setMinimiseToSystemTrayOnClose(minimizeToSystemTrayOnClose);
StreamPiAlert.setIsShowPopup(showAlertsPopup);
StreamPiAlert.setIsShowPopup(showAlertsPopup);
config.setShowAlertsPopup(showAlertsPopup);
config.setShowAlertsPopup(showAlertsPopup);
config.setStartupOnBoot(startOnBoot);
config.setStartupOnBoot(startOnBoot);
if(soundOnActionClicked)
if(soundOnActionClicked)
{
{
serverListener.initSoundOnActionClicked();
serverListener.initSoundOnActionClicked();
}
}
config.setSoundOnActionClickedStatus(soundOnActionClicked);
config.setSoundOnActionClickedStatus(soundOnActionClicked);
config.setSoundOnActionClickedFilePath(soundOnActionClickedFilePath);
config.setSoundOnActionClickedFilePath(soundOnActionClickedFilePath);
config.save();
config.save();
loadDataFromConfig();
loadDataFromConfig();
if(toBeReloaded)
if(toBeReloaded)
{
{
StreamPiAlert restartPrompt = new StreamPiAlert(
StreamPiAlert restartPrompt = new StreamPiAlert(
"Warning",
"Warning",
"Stream-Pi Server needs to be restarted for these changes to take effect. Restart?\n" +
"Stream-Pi Server needs to be restarted for these changes to take effect. Restart?\n" +
"All your current connections will be disconnected.",
"All your current connections will be disconnected.",
StreamPiAlertType.WARNING
StreamPiAlertType.WARNING
);
);
String yesOption = "Yes";
String yesOption = "Yes";
String noOption = "No";
String noOption = "No";
restartPrompt.setButtons(yesOption, noOption);
restartPrompt.setButtons(yesOption, noOption);
restartPrompt.setOnClicked(new StreamPiAlertListener() {
restartPrompt.setOnClicked(new StreamPiAlertListener() {
@Override
@Override
public void onClick(String s) {
public void onClick(String s) {
if(s.equals(yesOption))
if(s.equals(yesOption))
{
{
serverListener.restart();
serverListener.restart();
}
}
}
}
});
});
restartPrompt.show();
restartPrompt.show();
}
}
if(dashToBeReRendered)
if(dashToBeReRendered)
{
{
serverListener.clearTemp();
serverListener.clearTemp();
}
}
}
}
catch (MinorException e)
catch (MinorException e)
{
{
exceptionAndAlertHandler.handleMinorException(e);
exceptionAndAlertHandler.handleMinorException(e);
}
}
catch (SevereException e)
catch (SevereException e)
{
{
exceptionAndAlertHandler.handleSevereException(e);
exceptionAndAlertHandler.handleSevereException(e);
}
}
finally {
finally {
Platform.runLater(()->{
Platform.runLater(()->{
saveButton.setDisable(false);
saveButton.setDisable(false);
});
});
}
}
return null;
return null;
}
}
}).start();
}).start();
}
}
private void onFactoryResetButtonClicked()
private void onFactoryResetButtonClicked()
{
{
StreamPiAlert confirmation = new StreamPiAlert("Warning","Are you sure?\n" +
StreamPiAlert confirmation = new StreamPiAlert("Warning","Are you sure?\n" +
"This will erase everything.",StreamPiAlertType.WARNING);
"This will erase everything.",StreamPiAlertType.WARNING);
String yesButton = "Yes";
String yesButton = "Yes";
String noButton = "No";
String noButton = "No";
confirmation.setButtons(yesButton, noButton);
confirmation.setButtons(yesButton, noButton);
confirmation.setOnClicked(new StreamPiAlertListener() {
confirmation.setOnClicked(new StreamPiAlertListener() {
@Override
@Override
public void onClick(String s) {
public void onClick(String s) {
if(s.equals(yesButton))
if(s.equals(yesButton))
{
{
serverListener.factoryReset();
serverListener.factoryReset();
}
}
}
}
});
});
confirmation.show();
confirmation.show();
}
}
}
}