Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add method to keep Wifi active #18

Merged
merged 1 commit into from
Apr 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions src/ndb/NDBDbus.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

/*!
Expand Down Expand Up @@ -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.
*
Expand Down
6 changes: 6 additions & 0 deletions src/ndb/NDBDbus.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand All @@ -129,6 +133,7 @@ class NDBDbus : public QObject, protected QDBusContext {
void handleStackedWidgetDestroyed();
void onDlgLineEditAccepted();
void onDlgLineEditRejected();
void onWWAboutToKillWifi(PermissionRequest* allow);
private:
void *libnickel;
QSet<QString> connectedSignals;
Expand All @@ -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();
Expand Down