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
keystoreFilename=
keystorePassword=changeme
hideWindowWhenIdle=true
logFolderPath=/var/log/rhasspyVisualConversationTool
logLevel=5
@ -33,7 +34,7 @@ mqttClientUseAuthentication=false
mqttClientUsername=
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_ .

View File

@ -3,6 +3,7 @@ package com.jens.rhasspy.visualtool;
import java.awt.AWTException;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Frame;
import java.awt.Robot;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
@ -39,6 +40,10 @@ public class GUI
static GUI instance = null;
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 zeroDim = new Dimension(0, 0);
@ -91,7 +96,7 @@ public class GUI
Border margin = new EmptyBorder(10,10,10,10);
connectionStatusTextField.setBorder(new CompoundBorder(border, margin));
mainTextField.setText("Waiting for session...");
mainTextField.setText(idleMessage);
mainTextField.setFont(defaultFont);
if(mainTextField.isEditable())
mainTextField.setEditable(false);
@ -110,14 +115,28 @@ public class GUI
mainFrame.add(optionsFrame);
mainFrame.setVisible(true);
if(Settings.hideWindowWhenIdle && initialConnectionEstablished)
minimizeDelayed();
}
public void updateConnectionStatus(boolean connected)
{
if(connected)
{
if(!initialConnectionEstablished)
initialConnectionEstablished = true;
connectionStatusTextField.setText("Connected to: " + Settings.mqttClientServerHostname);
if(Settings.hideWindowWhenIdle)
minimizeDelayed();
}
else
{
connectionStatusTextField.setText("Not connected");
getFocus();
}
}
public void updateWindow()
@ -137,6 +156,14 @@ public class GUI
optionsFrame.setVisible(false);
mainFrame.repaint();
if(textEntriesList.contains(idleMessage))
{
if(Settings.hideWindowWhenIdle)
minimizeDelayed();
}
else
getFocus();
}
public void displayOptions(String[] options)
@ -215,7 +242,7 @@ public class GUI
if(MqttTopic.isMatched(Settings.topicNameWakewordRecognized, topic))
{
turnOnScreen();
wakeUpScreen();
textEntriesList.clear();
textEntriesList.add(getMeString() + "Hello! What can I do for you?");
@ -223,7 +250,7 @@ public class GUI
}
else if(MqttTopic.isMatched(Settings.topicNameIntentsRecognized, topic))
{
turnOnScreen();
wakeUpScreen();
JSONObject jo = new JSONObject(payload);
textEntriesList.clear();
@ -233,23 +260,13 @@ public class GUI
else if(MqttTopic.isMatched(Settings.topicNameDisplayText, topic))
{
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"));
updateWindow();
}
else if(MqttTopic.isMatched(Settings.topicNameDisplayOptions, topic))
{
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(";");
displayOptions(options);
@ -264,7 +281,7 @@ public class GUI
else if(MqttTopic.isMatched(Settings.topicNameSessionEnded, topic))
{
textEntriesList.clear();
textEntriesList.add("Waiting for session...");
textEntriesList.add(idleMessage);
updateWindow();
}
}
@ -279,9 +296,11 @@ public class GUI
return "Me: \t";
}
static void turnOnScreen()
static void wakeUpScreen()
{
/*
* Original plans based on console commands.
*
* pi@raspberrypi11:~ $ DISPLAY=:0 xset q
Keyboard Control:
auto repeat: on key click percent: 0 LED mask: 00000000
@ -313,20 +332,59 @@ public class GUI
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
{
// These coordinates are screen coordinates
// 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)
{
Thread.sleep(idleTime);
}
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 boolean default_logFileEnabled = false;
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_logMaxSize = 5;
public static final String default_encryptionKey="choose_a_password";
@ -75,6 +76,7 @@ public class Settings
public static boolean sslDebug;
public static String keystoreFilename;
public static String keystorePassword;
public static boolean hideWindowWhenIdle;
public static String dateFormat = default_dateFormat;
@ -124,6 +126,7 @@ public class Settings
sslDebug = Boolean.parseBoolean(prop.getProperty("sslDebug", String.valueOf(default_sslDebug)));
keystoreFilename = prop.getProperty("keystoreFilename", default_keystoreFilename);
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)));
logFolderPath = prop.getProperty("logFolderPath", String.valueOf(default_logFolderPath));

Binary file not shown.