From 8ea8308812b03ca9263111a927d4c206d066ed8d Mon Sep 17 00:00:00 2001 From: shermp <14854761+shermp@users.noreply.github.com> Date: Sun, 21 Apr 2024 14:31:11 +1200 Subject: [PATCH] Add ndbWifiKeepalive --- src/ndb/NDBDbus.cc | 31 +++++++++++++++++++++++++++++++ src/ndb/NDBDbus.h | 6 ++++++ 2 files changed, 37 insertions(+) diff --git a/src/ndb/NDBDbus.cc b/src/ndb/NDBDbus.cc index 8913ada..72eb13b 100644 --- a/src/ndb/NDBDbus.cc +++ b/src/ndb/NDBDbus.cc @@ -117,6 +117,7 @@ NDBDbus::NDBDbus(QObject* parent) : QObject(parent), QDBusContext() { } // Image NDB_RESOLVE_SYMBOL("_ZN5Image11sizeForTypeERK6DeviceRK7QString", nh_symoutptr(nSym.Image__sizeForType)); + NDB_RESOLVE_SYMBOL("_ZN16WirelessWatchdog14sharedInstanceEv", nh_symoutptr(nSym.WirelessWatchdog__sharedInstance)); } /*! @@ -840,6 +841,36 @@ void NDBDbus::ndbWireless(const char *act) { nm_action_result_free(res); } +void NDBDbus::onWWAboutToKillWifi(PermissionRequest* allow) { + if (allow != nullptr) { + NDB_DEBUG("WirelessWatchdog wants to kill Wifi. Denying request."); + *allow = false; + } + return; +} + +/*! + * \brief Keep Wifi connection alive + * + * Prevents Nickel from killing the Wifi connection after a short amount of time. + * Set \a keepalive to \c true to enable the keepalive, and \c false to disable it. + * It is best to only keep Wifi enabled as long as necessary. + * + * \since 0.3.0 + */ +void NDBDbus::ndbWifiKeepalive(bool keepalive) { + NDB_DBUS_USB_ASSERT((void) 0); + NDB_DBUS_ASSERT((void) 0, QDBusError::InternalError, nSym.WirelessWatchdog__sharedInstance, "no WirelessWatchdog::sharedInstance() symbol"); + WirelessWatchdog *wd = nSym.WirelessWatchdog__sharedInstance(); + NDB_DBUS_ASSERT((void) 0, QDBusError::InternalError, wd, "could not get WirelessWatchdog::sharedInstance()"); + if (keepalive) { + QObject::connect(wd, SIGNAL(aboutToKillWifi(PermissionRequest*)), this, SLOT(onWWAboutToKillWifi(PermissionRequest*)), Qt::UniqueConnection); + } else { + QObject::disconnect(wd, SIGNAL(aboutToKillWifi(PermissionRequest*)), this, SLOT(onWWAboutToKillWifi(PermissionRequest*))); + } + return; +} + /*! * \brief Open the web browser. * diff --git a/src/ndb/NDBDbus.h b/src/ndb/NDBDbus.h index 0394795..71affef 100644 --- a/src/ndb/NDBDbus.h +++ b/src/ndb/NDBDbus.h @@ -21,6 +21,8 @@ typedef QWidget N3Dialog; typedef void Device; typedef QObject FSSyncManager; typedef FSSyncManager N3FSSyncManager; +typedef bool PermissionRequest; +typedef QObject WirelessWatchdog; #ifndef NDB_DBUS_IFACE_NAME #define NDB_DBUS_IFACE_NAME "com.github.shermp.nickeldbus" @@ -108,6 +110,8 @@ class NDBDbus : public QObject, protected QDBusContext { void wfmConnectWireless(); void wfmConnectWirelessSilently(); void wfmSetAirplaneMode(QString const& action); + // Wireless watchdog + void ndbWifiKeepalive(bool keepalive); // Web Browser (BrowserWorkflowManager) void bwmOpenBrowser(bool modal = false, QString const& url = QString(), QString const& css = QString()); // Nickel Settings @@ -129,6 +133,7 @@ class NDBDbus : public QObject, protected QDBusContext { void handleStackedWidgetDestroyed(); void onDlgLineEditAccepted(); void onDlgLineEditRejected(); + void onWWAboutToKillWifi(PermissionRequest* allow); private: void *libnickel; QSet connectedSignals; @@ -150,6 +155,7 @@ class NDBDbus : public QObject, protected QDBusContext { QSize (*Image__sizeForType)(Device*, QString const&); N3FSSyncManager* (*N3FSSyncManager__sharedInstance)(); void (*N3FSSyncManager__sync)(N3FSSyncManager* _this, QStringList* paths); + WirelessWatchdog* (*WirelessWatchdog__sharedInstance)(); } nSym; QTimer *viewTimer; bool ndbInUSBMS();