Almost a release

This commit is contained in:
jens 2021-03-03 19:19:07 +01:00
parent e5f172c890
commit ee7639d923
4 changed files with 92 additions and 30 deletions

View File

@ -22,6 +22,7 @@ language=de-DE
sslDebug=false sslDebug=false
keystoreFilename= keystoreFilename=
keystorePassword=changeme keystorePassword=changeme
hideWindowWhenIdle=true
logFolderPath=/var/log/rhasspyVisualConversationTool logFolderPath=/var/log/rhasspyVisualConversationTool
logLevel=5 logLevel=5
@ -33,7 +34,7 @@ mqttClientUseAuthentication=false
mqttClientUsername= mqttClientUsername=
mqttClientPassword= mqttClientPassword=
siteId= siteId=satellite01
``` ```
If you have set _mqttClientUseSsl=true_ it's at least likely you have your own PKI. In that case create a java keystore and put your root certificate in it. Then save the keystore in the folder of the jar and config file and put its filename for _keystoreFilename_ . If you have set _mqttClientUseSsl=true_ it's at least likely you have your own PKI. In that case create a java keystore and put your root certificate in it. Then save the keystore in the folder of the jar and config file and put its filename for _keystoreFilename_ .

View File

@ -3,6 +3,7 @@ package com.jens.rhasspy.visualtool;
import java.awt.AWTException; import java.awt.AWTException;
import java.awt.Dimension; import java.awt.Dimension;
import java.awt.Font; import java.awt.Font;
import java.awt.Frame;
import java.awt.Robot; import java.awt.Robot;
import java.awt.event.MouseEvent; import java.awt.event.MouseEvent;
import java.awt.event.MouseListener; import java.awt.event.MouseListener;
@ -39,6 +40,10 @@ public class GUI
static GUI instance = null; static GUI instance = null;
Font defaultFont = new Font(Font.SANS_SERIF, Font.PLAIN, 20); Font defaultFont = new Font(Font.SANS_SERIF, Font.PLAIN, 20);
final String idleMessage = "Waiting for session...";
final int idleTime = 2000;
boolean initialConnectionEstablished = false;
static Dimension defaultContainerDim = new Dimension(700, 250); static Dimension defaultContainerDim = new Dimension(700, 250);
static Dimension zeroDim = new Dimension(0, 0); static Dimension zeroDim = new Dimension(0, 0);
@ -91,7 +96,7 @@ public class GUI
Border margin = new EmptyBorder(10,10,10,10); Border margin = new EmptyBorder(10,10,10,10);
connectionStatusTextField.setBorder(new CompoundBorder(border, margin)); connectionStatusTextField.setBorder(new CompoundBorder(border, margin));
mainTextField.setText("Waiting for session..."); mainTextField.setText(idleMessage);
mainTextField.setFont(defaultFont); mainTextField.setFont(defaultFont);
if(mainTextField.isEditable()) if(mainTextField.isEditable())
mainTextField.setEditable(false); mainTextField.setEditable(false);
@ -110,14 +115,28 @@ public class GUI
mainFrame.add(optionsFrame); mainFrame.add(optionsFrame);
mainFrame.setVisible(true); mainFrame.setVisible(true);
if(Settings.hideWindowWhenIdle && initialConnectionEstablished)
minimizeDelayed();
} }
public void updateConnectionStatus(boolean connected) public void updateConnectionStatus(boolean connected)
{ {
if(connected) if(connected)
{
if(!initialConnectionEstablished)
initialConnectionEstablished = true;
connectionStatusTextField.setText("Connected to: " + Settings.mqttClientServerHostname); connectionStatusTextField.setText("Connected to: " + Settings.mqttClientServerHostname);
if(Settings.hideWindowWhenIdle)
minimizeDelayed();
}
else else
{
connectionStatusTextField.setText("Not connected"); connectionStatusTextField.setText("Not connected");
getFocus();
}
} }
public void updateWindow() public void updateWindow()
@ -137,6 +156,14 @@ public class GUI
optionsFrame.setVisible(false); optionsFrame.setVisible(false);
mainFrame.repaint(); mainFrame.repaint();
if(textEntriesList.contains(idleMessage))
{
if(Settings.hideWindowWhenIdle)
minimizeDelayed();
}
else
getFocus();
} }
public void displayOptions(String[] options) public void displayOptions(String[] options)
@ -215,7 +242,7 @@ public class GUI
if(MqttTopic.isMatched(Settings.topicNameWakewordRecognized, topic)) if(MqttTopic.isMatched(Settings.topicNameWakewordRecognized, topic))
{ {
turnOnScreen(); wakeUpScreen();
textEntriesList.clear(); textEntriesList.clear();
textEntriesList.add(getMeString() + "Hello! What can I do for you?"); textEntriesList.add(getMeString() + "Hello! What can I do for you?");
@ -223,7 +250,7 @@ public class GUI
} }
else if(MqttTopic.isMatched(Settings.topicNameIntentsRecognized, topic)) else if(MqttTopic.isMatched(Settings.topicNameIntentsRecognized, topic))
{ {
turnOnScreen(); wakeUpScreen();
JSONObject jo = new JSONObject(payload); JSONObject jo = new JSONObject(payload);
textEntriesList.clear(); textEntriesList.clear();
@ -233,23 +260,13 @@ public class GUI
else if(MqttTopic.isMatched(Settings.topicNameDisplayText, topic)) else if(MqttTopic.isMatched(Settings.topicNameDisplayText, topic))
{ {
JSONObject jo = new JSONObject(payload); JSONObject jo = new JSONObject(payload);
/*
* This is deactivated only for test purposes.
* Afterwards for a conversation flow sayText needs to be used.
*/
// textEntriesList.clear();
textEntriesList.add(getMeString() + jo.getString("text")); textEntriesList.add(getMeString() + jo.getString("text"));
updateWindow(); updateWindow();
} }
else if(MqttTopic.isMatched(Settings.topicNameDisplayOptions, topic)) else if(MqttTopic.isMatched(Settings.topicNameDisplayOptions, topic))
{ {
JSONObject jo = new JSONObject(payload); JSONObject jo = new JSONObject(payload);
/*
* This is deactivated only for test purposes.
* Afterwards for a conversation flow sayText needs to be used.
*/
// textEntriesList.clear();
String[] options = jo.getString("text").split(";"); String[] options = jo.getString("text").split(";");
displayOptions(options); displayOptions(options);
@ -264,7 +281,7 @@ public class GUI
else if(MqttTopic.isMatched(Settings.topicNameSessionEnded, topic)) else if(MqttTopic.isMatched(Settings.topicNameSessionEnded, topic))
{ {
textEntriesList.clear(); textEntriesList.clear();
textEntriesList.add("Waiting for session..."); textEntriesList.add(idleMessage);
updateWindow(); updateWindow();
} }
} }
@ -279,9 +296,11 @@ public class GUI
return "Me: \t"; return "Me: \t";
} }
static void turnOnScreen() static void wakeUpScreen()
{ {
/* /*
* Original plans based on console commands.
*
* pi@raspberrypi11:~ $ DISPLAY=:0 xset q * pi@raspberrypi11:~ $ DISPLAY=:0 xset q
Keyboard Control: Keyboard Control:
auto repeat: on key click percent: 0 LED mask: 00000000 auto repeat: on key click percent: 0 LED mask: 00000000
@ -313,20 +332,59 @@ public class GUI
pi@raspberrypi11:~ $ pi@raspberrypi11:~ $
*/ */
Thread t = new Thread(new Runnable()
{
@Override
public void run()
{
try
{
/*
* Move the mouse cursor
*
* Using this amount of movements has proven relatively reliable.
* Using less has not always woken up the screen or only woke it
* up, but did not also unblank it, resulting in a well-lit, but
* still black screen.
*/
Robot robot = new Robot();
for(int xCoord = 500; xCoord < 550; xCoord++)
for(int yCoord = 500; yCoord < 550; yCoord++)
robot.mouseMove(xCoord, yCoord);
}
catch(Exception e)
{
}
}});
t.start();
}
void getFocus()
{
java.awt.EventQueue.invokeLater(new Runnable()
{
@Override
public void run()
{
mainFrame.setState(Frame.NORMAL);
mainFrame.toFront();
mainFrame.repaint();
}
});
}
void minimizeDelayed()
{
try try
{ {
// These coordinates are screen coordinates Thread.sleep(idleTime);
// int xCoord = 500;
// int yCoord = 500;
// Move the cursor
Robot robot = new Robot();
for(int xCoord = 500; xCoord < 505; xCoord++)
for(int yCoord = 500; yCoord < 505; yCoord++)
robot.mouseMove(xCoord, yCoord);
}
catch (AWTException e)
{
} }
catch(Exception e)
{}
mainFrame.setState(Frame.ICONIFIED);
} }
} }

View File

@ -45,6 +45,7 @@ public class Settings
public static final String default_dateFormat = "dd.MM.yyyy HH:mm:ss:SSSS"; public static final String default_dateFormat = "dd.MM.yyyy HH:mm:ss:SSSS";
public static final boolean default_logFileEnabled = false; public static final boolean default_logFileEnabled = false;
public static final String default_logFolderPath = "/var/log/homecontrol"; public static final String default_logFolderPath = "/var/log/homecontrol";
public static final boolean default_hideWindowWhenIdle = true;
public static final int default_logLevel = 3; public static final int default_logLevel = 3;
public static final int default_logMaxSize = 5; public static final int default_logMaxSize = 5;
public static final String default_encryptionKey="choose_a_password"; public static final String default_encryptionKey="choose_a_password";
@ -75,6 +76,7 @@ public class Settings
public static boolean sslDebug; public static boolean sslDebug;
public static String keystoreFilename; public static String keystoreFilename;
public static String keystorePassword; public static String keystorePassword;
public static boolean hideWindowWhenIdle;
public static String dateFormat = default_dateFormat; public static String dateFormat = default_dateFormat;
@ -124,6 +126,7 @@ public class Settings
sslDebug = Boolean.parseBoolean(prop.getProperty("sslDebug", String.valueOf(default_sslDebug))); sslDebug = Boolean.parseBoolean(prop.getProperty("sslDebug", String.valueOf(default_sslDebug)));
keystoreFilename = prop.getProperty("keystoreFilename", default_keystoreFilename); keystoreFilename = prop.getProperty("keystoreFilename", default_keystoreFilename);
keystorePassword = prop.getProperty("keystorePassword", default_keystorePassword); keystorePassword = prop.getProperty("keystorePassword", default_keystorePassword);
hideWindowWhenIdle = Boolean.parseBoolean(prop.getProperty("hideWindowWhenIdle", String.valueOf(default_hideWindowWhenIdle)));
logFileEnabled = Boolean.parseBoolean(prop.getProperty("logFileEnabled", String.valueOf(default_logFileEnabled))); logFileEnabled = Boolean.parseBoolean(prop.getProperty("logFileEnabled", String.valueOf(default_logFileEnabled)));
logFolderPath = prop.getProperty("logFolderPath", String.valueOf(default_logFolderPath)); logFolderPath = prop.getProperty("logFolderPath", String.valueOf(default_logFolderPath));

Binary file not shown.