Add desktop notifications, enable enrolling when the wizard is displayed
This commit is contained in:
committed by
Patrick Nicolas
parent
59192bac6c
commit
2aa12de520
@@ -173,6 +173,8 @@ if (WIVRN_BUILD_SERVER)
|
||||
find_package(CLI11 REQUIRED)
|
||||
|
||||
pkg_check_modules(glib2 REQUIRED IMPORTED_TARGET glib-2.0 gio-2.0 gio-unix-2.0)
|
||||
|
||||
pkg_check_modules(libnotify REQUIRED IMPORTED_TARGET libnotify)
|
||||
endif()
|
||||
|
||||
if (WIVRN_BUILD_DASHBOARD)
|
||||
|
||||
@@ -640,22 +640,12 @@ void main_window::on_server_start_timeout()
|
||||
|
||||
void main_window::on_action_settings()
|
||||
{
|
||||
assert(not settings_window);
|
||||
|
||||
settings_window = new settings(server_interface);
|
||||
connect(settings_window, &QDialog::finished, this, [&]() {
|
||||
settings_window->deleteLater();
|
||||
settings_window = nullptr;
|
||||
});
|
||||
settings_window->exec();
|
||||
settings{server_interface}.exec();
|
||||
}
|
||||
|
||||
void main_window::on_action_wizard()
|
||||
{
|
||||
assert(not wizard_window);
|
||||
|
||||
wizard_window = new wizard;
|
||||
wizard_window->exec();
|
||||
wizard{}.exec();
|
||||
}
|
||||
|
||||
void main_window::on_action_usb(const std::string & serial)
|
||||
|
||||
@@ -49,9 +49,6 @@ class main_window : public QMainWindow
|
||||
Ui::MainWindow * ui = nullptr;
|
||||
wivrn_server * server_interface = nullptr;
|
||||
|
||||
settings * settings_window = nullptr;
|
||||
wizard * wizard_window = nullptr;
|
||||
|
||||
QIcon icon{":/images/wivrn.png"};
|
||||
QSystemTrayIcon systray{icon};
|
||||
|
||||
|
||||
@@ -107,6 +107,38 @@ void wivrn_server::on_server_properties_changed(const QString & interface_name,
|
||||
pinChanged(m_pin = changed_properties["Pin"].toString());
|
||||
}
|
||||
|
||||
if (changed_properties.contains("KnownKeys"))
|
||||
{
|
||||
m_knownKeys.clear();
|
||||
|
||||
const auto keys = qvariant_cast<QDBusArgument>(changed_properties["KnownKeys"]);
|
||||
keys.beginArray();
|
||||
|
||||
while (not keys.atEnd())
|
||||
{
|
||||
keys.beginStructure();
|
||||
QString public_key;
|
||||
QString name;
|
||||
keys >> name >> public_key;
|
||||
keys.endStructure();
|
||||
|
||||
m_knownKeys.push_back(HeadsetKey{public_key, name});
|
||||
}
|
||||
keys.endArray();
|
||||
|
||||
knownKeysChanged(m_knownKeys);
|
||||
}
|
||||
|
||||
if (changed_properties.contains("EnrollEnabled"))
|
||||
{
|
||||
enrollEnabledChanged(m_isEnrollEnabled = changed_properties["EnrollEnabled"].toBool());
|
||||
}
|
||||
|
||||
if (changed_properties.contains("EncryptionEnabled"))
|
||||
{
|
||||
encryptionEnabledChanged(m_isEncryptionEnabled = changed_properties["EncryptionEnabled"].toBool());
|
||||
}
|
||||
|
||||
if (changed_properties.contains("RecommendedEyeSize"))
|
||||
{
|
||||
const auto arg = qvariant_cast<QDBusArgument>(changed_properties["RecommendedEyeSize"]);
|
||||
@@ -210,6 +242,26 @@ void wivrn_server::setJsonConfiguration(QString new_configuration)
|
||||
server_interface->setJsonConfiguration(m_jsonConfiguration = new_configuration);
|
||||
}
|
||||
|
||||
void wivrn_server::revoke_key(QString public_key)
|
||||
{
|
||||
server_interface->RevokeKey(public_key);
|
||||
}
|
||||
|
||||
void wivrn_server::rename_key(QString public_key, QString name)
|
||||
{
|
||||
server_interface->RenameKey(public_key, name);
|
||||
}
|
||||
|
||||
QString wivrn_server::enroll_headset(int timeout_secs)
|
||||
{
|
||||
return server_interface->EnrollHeadset(timeout_secs).value();
|
||||
}
|
||||
|
||||
void wivrn_server::disable_enroll_headset()
|
||||
{
|
||||
server_interface->DisableEnrollHeadset();
|
||||
}
|
||||
|
||||
QString wivrn_server::hostname()
|
||||
{
|
||||
static auto _hostname = []() -> QString {
|
||||
|
||||
@@ -38,6 +38,13 @@ class wivrn_server : public QObject
|
||||
QDBusPendingCallWatcher * get_all_properties_call_watcher = nullptr;
|
||||
|
||||
public:
|
||||
struct HeadsetKey
|
||||
{
|
||||
QString public_key;
|
||||
QString name;
|
||||
};
|
||||
using HeadsetKeys = std::vector<HeadsetKey>;
|
||||
|
||||
wivrn_server(QObject * parent = nullptr);
|
||||
wivrn_server(const wivrn_server &) = delete;
|
||||
wivrn_server & operator=(const wivrn_server &) = delete;
|
||||
@@ -47,7 +54,16 @@ public:
|
||||
Q_PROPERTY(bool serverRunning READ isServerRunning NOTIFY serverRunningChanged)
|
||||
Q_PROPERTY(bool headsetConnected READ isHeadsetConnected NOTIFY headsetConnectedChanged)
|
||||
Q_PROPERTY(QString jsonConfiguration READ jsonConfiguration WRITE setJsonConfiguration)
|
||||
|
||||
// Authentication
|
||||
Q_PROPERTY(QString pin READ pin NOTIFY pinChanged)
|
||||
Q_PROPERTY(HeadsetKeys knownKeys READ knownKeys NOTIFY knownKeysChanged)
|
||||
Q_PROPERTY(bool enrollEnabled READ isEnrollEnabled NOTIFY enrollEnabledChanged)
|
||||
Q_PROPERTY(bool encryptionEnabled READ isEncryptionEnabled NOTIFY encryptionEnabledChanged)
|
||||
void revoke_key(QString public_key);
|
||||
void rename_key(QString public_key, QString name);
|
||||
QString enroll_headset(int timeout_secs = 120);
|
||||
void disable_enroll_headset();
|
||||
|
||||
// Headset information, valid only if HeadsetConnected is true
|
||||
Q_PROPERTY(QSize recommendedEyeSize READ recommendedEyeSize NOTIFY recommendedEyeSizeChanged)
|
||||
@@ -89,6 +105,21 @@ public:
|
||||
return m_pin;
|
||||
}
|
||||
|
||||
HeadsetKeys knownKeys() const
|
||||
{
|
||||
return m_knownKeys;
|
||||
}
|
||||
|
||||
bool isEnrollEnabled() const
|
||||
{
|
||||
return m_isEnrollEnabled;
|
||||
}
|
||||
|
||||
bool isEncryptionEnabled() const
|
||||
{
|
||||
return m_isEncryptionEnabled;
|
||||
}
|
||||
|
||||
QSize recommendedEyeSize() const
|
||||
{
|
||||
return m_recommendedEyeSize;
|
||||
@@ -169,7 +200,11 @@ private:
|
||||
bool m_serverRunning{};
|
||||
bool m_headsetConnected{};
|
||||
QString m_jsonConfiguration{};
|
||||
|
||||
QString m_pin{};
|
||||
HeadsetKeys m_knownKeys;
|
||||
bool m_isEnrollEnabled{};
|
||||
bool m_isEncryptionEnabled{};
|
||||
|
||||
QSize m_recommendedEyeSize{};
|
||||
std::vector<float> m_availableRefreshRates{};
|
||||
@@ -189,6 +224,9 @@ Q_SIGNALS:
|
||||
void serverRunningChanged(bool);
|
||||
void headsetConnectedChanged(bool);
|
||||
void pinChanged(QString);
|
||||
void knownKeysChanged(HeadsetKeys);
|
||||
void enrollEnabledChanged(bool);
|
||||
void encryptionEnabledChanged(bool);
|
||||
|
||||
void recommendedEyeSizeChanged(QSize);
|
||||
void availableRefreshRatesChanged(const std::vector<float> &);
|
||||
|
||||
+24
-4
@@ -125,10 +125,8 @@ wizard::wizard() :
|
||||
});
|
||||
ui->label_steam_command->setText(server->steamCommand());
|
||||
|
||||
connect(server, &wivrn_server::pinChanged, this, [this](QString value) {
|
||||
ui->label_pin->setText(value);
|
||||
});
|
||||
ui->label_pin->setText(server->pin());
|
||||
connect(server, &wivrn_server::pinChanged, this, &wizard::on_pin_changed);
|
||||
on_pin_changed(server->pin());
|
||||
|
||||
setPixmap(WatermarkPixmap, QPixmap(":/images/wivrn.svg"));
|
||||
for (const headset & i: headsets_info)
|
||||
@@ -404,6 +402,10 @@ void wizard::on_page_changed(int id)
|
||||
button(WizardButton::CustomButton1)->setText(tr("Skip"));
|
||||
setButtonLayout({QWizard::Stretch, QWizard::BackButton, QWizard::NextButton, QWizard::CustomButton1, QWizard::CancelButton});
|
||||
on_headset_connected_changed(server->isHeadsetConnected());
|
||||
|
||||
if (not server->isEnrollEnabled())
|
||||
server->enroll_headset(-1);
|
||||
|
||||
return;
|
||||
|
||||
case wizard_page::start_game:
|
||||
@@ -456,6 +458,8 @@ void wizard::retranslate()
|
||||
|
||||
wizard::~wizard()
|
||||
{
|
||||
server->disable_enroll_headset();
|
||||
|
||||
delete ui;
|
||||
ui = nullptr;
|
||||
}
|
||||
@@ -693,4 +697,20 @@ void wizard::on_headset_connected_changed(bool connected)
|
||||
}
|
||||
}
|
||||
|
||||
void wizard::on_pin_changed(QString pin)
|
||||
{
|
||||
if (pin == "")
|
||||
{
|
||||
ui->label_pin_1->setVisible(false);
|
||||
ui->label_pin_2->setVisible(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
ui->label_pin_1->setVisible(true);
|
||||
ui->label_pin_2->setVisible(true);
|
||||
}
|
||||
|
||||
ui->label_pin_2->setText(pin);
|
||||
}
|
||||
|
||||
#include "moc_wizard.cpp"
|
||||
|
||||
@@ -100,4 +100,6 @@ public:
|
||||
void update_welcome_page();
|
||||
void on_headset_connected_changed(bool);
|
||||
void on_custom_button_clicked(int which);
|
||||
|
||||
void on_pin_changed(QString pin);
|
||||
};
|
||||
|
||||
+2
-2
@@ -441,14 +441,14 @@
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="label_3">
|
||||
<widget class="QLabel" name="label_pin_1">
|
||||
<property name="text">
|
||||
<string>Use the following PIN to connect your headset:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="label_pin">
|
||||
<widget class="QLabel" name="label_pin_2">
|
||||
<property name="font">
|
||||
<font>
|
||||
<pointsize>14</pointsize>
|
||||
|
||||
@@ -36,8 +36,10 @@
|
||||
<arg type="s" name="Name"/>
|
||||
</method>
|
||||
<method name="EnrollHeadset">
|
||||
<arg type="i" name="TimeoutSecs"/>
|
||||
<arg type="s" name="Pin" direction="out"/>
|
||||
</method>
|
||||
<method name="DisableEnrollHeadset"/>
|
||||
|
||||
<property name="HeadsetConnected" type="b" access="read"/>
|
||||
<property name="SteamCommand" type="s" access="read"/>
|
||||
|
||||
@@ -174,6 +174,7 @@ target_include_directories(wivrn-server-dbus PUBLIC ${CMAKE_CURRENT_BINARY_DIR})
|
||||
add_dependencies(wivrn-server-dbus wivrn-server-dbus-codegen)
|
||||
target_link_libraries(wivrn-server-dbus PUBLIC PkgConfig::glib2)
|
||||
target_link_libraries(wivrn-server PUBLIC wivrn-server-dbus)
|
||||
target_link_libraries(wivrn-server PUBLIC PkgConfig::libnotify)
|
||||
|
||||
include(CompileGLSL)
|
||||
|
||||
|
||||
+49
-6
@@ -29,10 +29,11 @@
|
||||
|
||||
#include <CLI/CLI.hpp>
|
||||
#include <avahi-glib/glib-watch.h>
|
||||
#include <chrono>
|
||||
#include <chrono> // IWYU pragma: keep
|
||||
#include <filesystem>
|
||||
#include <iostream>
|
||||
#include <iterator>
|
||||
#include <libnotify/notification.h>
|
||||
#include <memory>
|
||||
#include <poll.h>
|
||||
#include <random>
|
||||
@@ -45,6 +46,7 @@
|
||||
#include <gio/gio.h>
|
||||
#include <glib-unix.h>
|
||||
#include <glib.h>
|
||||
#include <libnotify/notify.h>
|
||||
|
||||
#include <shared/ipc_protocol.h>
|
||||
#include <util/u_file.h>
|
||||
@@ -209,6 +211,7 @@ guint listener_watch;
|
||||
wivrn_connection::encryption_state enc_state = wivrn_connection::encryption_state::enabled;
|
||||
guint enroll_timeout;
|
||||
std::string pin;
|
||||
NotifyNotification * pin_notification;
|
||||
|
||||
WivrnServer * dbus_server;
|
||||
|
||||
@@ -530,6 +533,14 @@ gboolean control_received(gint fd, GIOCondition condition, gpointer user_data)
|
||||
|
||||
void set_encryption_state(wivrn_connection::encryption_state new_enc_state)
|
||||
{
|
||||
// TODO translate the notifications
|
||||
if (pin_notification)
|
||||
{
|
||||
notify_notification_close(pin_notification, nullptr);
|
||||
g_object_unref(G_OBJECT(pin_notification));
|
||||
pin_notification = nullptr;
|
||||
}
|
||||
|
||||
switch (new_enc_state)
|
||||
{
|
||||
case wivrn_connection::encryption_state::disabled:
|
||||
@@ -537,6 +548,9 @@ void set_encryption_state(wivrn_connection::encryption_state new_enc_state)
|
||||
std::cerr << "Encryption is disabled" << std::endl;
|
||||
wivrn_server_set_enroll_enabled(dbus_server, false);
|
||||
wivrn_server_set_encryption_enabled(dbus_server, false);
|
||||
|
||||
notify_notification_set_timeout(pin_notification, NOTIFY_EXPIRES_NEVER);
|
||||
notify_notification_show(pin_notification, nullptr);
|
||||
break;
|
||||
|
||||
case wivrn_connection::encryption_state::enabled:
|
||||
@@ -558,7 +572,11 @@ void set_encryption_state(wivrn_connection::encryption_state new_enc_state)
|
||||
wivrn_server_set_enroll_enabled(dbus_server, true);
|
||||
wivrn_server_set_encryption_enabled(dbus_server, true);
|
||||
|
||||
// TODO desktop notification
|
||||
// Desktop notification
|
||||
pin_notification = notify_notification_new("PIN", pin.c_str(), "dialog-password");
|
||||
notify_notification_set_timeout(pin_notification, NOTIFY_EXPIRES_NEVER);
|
||||
// TODO: notify_notification_set_image_from_pixbuf
|
||||
notify_notification_show(pin_notification, nullptr);
|
||||
|
||||
break;
|
||||
}
|
||||
@@ -628,15 +646,29 @@ gboolean on_handle_enroll_headset(WivrnServer * skeleton, GDBusMethodInvocation
|
||||
if (enroll_timeout)
|
||||
g_source_remove(enroll_timeout);
|
||||
|
||||
enroll_timeout = g_timeout_add(120'000, [](void *) {
|
||||
enroll_timeout = 0;
|
||||
set_encryption_state(wivrn_connection::encryption_state::enabled);
|
||||
return G_SOURCE_REMOVE; }, nullptr);
|
||||
int timeout_secs;
|
||||
GVariant * args = g_dbus_method_invocation_get_parameters(invocation);
|
||||
g_variant_get_child(args, 0, "i", &timeout_secs);
|
||||
|
||||
if (timeout_secs > 0)
|
||||
{
|
||||
enroll_timeout = g_timeout_add(timeout_secs * 1000, [](void *) {
|
||||
enroll_timeout = 0;
|
||||
set_encryption_state(wivrn_connection::encryption_state::enabled);
|
||||
return G_SOURCE_REMOVE; }, nullptr);
|
||||
}
|
||||
|
||||
g_dbus_method_invocation_return_value(invocation, g_variant_new("(s)", pin.c_str()));
|
||||
return G_SOURCE_CONTINUE;
|
||||
}
|
||||
|
||||
gboolean on_handle_disable_enroll_headset(WivrnServer * skeleton, GDBusMethodInvocation * invocation, gpointer user_data)
|
||||
{
|
||||
set_encryption_state(wivrn_connection::encryption_state::enabled);
|
||||
g_dbus_method_invocation_return_value(invocation, nullptr);
|
||||
return G_SOURCE_CONTINUE;
|
||||
}
|
||||
|
||||
void on_json_configuration(WivrnServer * server, const GParamSpec * pspec, gpointer data)
|
||||
{
|
||||
const char * json = wivrn_server_get_json_configuration(server);
|
||||
@@ -746,11 +778,18 @@ void on_name_acquired(GDBusConnection * connection, const gchar * name, gpointer
|
||||
NULL);
|
||||
|
||||
if (enc_state != wivrn_connection::encryption_state::disabled)
|
||||
{
|
||||
g_signal_connect(dbus_server,
|
||||
"handle-enroll-headset",
|
||||
G_CALLBACK(on_handle_enroll_headset),
|
||||
NULL);
|
||||
|
||||
g_signal_connect(dbus_server,
|
||||
"handle-disable-enroll-headset",
|
||||
G_CALLBACK(on_handle_disable_enroll_headset),
|
||||
NULL);
|
||||
}
|
||||
|
||||
wivrn_server_set_steam_command(dbus_server, steam_command().c_str());
|
||||
|
||||
on_headset_info_packet({});
|
||||
@@ -844,10 +883,14 @@ int inner_main(int argc, char * argv[], bool show_instructions)
|
||||
nullptr,
|
||||
nullptr);
|
||||
|
||||
// Initialize libnotify
|
||||
notify_init("WiVRn");
|
||||
|
||||
// Main loop
|
||||
g_main_loop_run(main_loop);
|
||||
|
||||
// Cleanup
|
||||
notify_uninit();
|
||||
runtime_setter.reset();
|
||||
stop_publishing();
|
||||
stop_listening();
|
||||
|
||||
Reference in New Issue
Block a user