Skip to content

Commit

Permalink
New action: Restart Tailscale daemon
Browse files Browse the repository at this point in the history
  • Loading branch information
SneWs committed Jul 30, 2024
1 parent 4a01ec6 commit 69a58c3
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 5 deletions.
14 changes: 10 additions & 4 deletions SysCommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,15 @@

#include <QDebug>

void SysCommand::refreshDns()
{
void SysCommand::restartTailscaleDaemon() {
QStringList args;
args << "restart";
args << "tailscaled";

runCommand("systemctl", args, false, true);
}

void SysCommand::refreshDns() {
QStringList args;
args << "restart";
args << "systemd-resolved";
Expand Down Expand Up @@ -75,8 +82,7 @@ bool SysCommand::copyFile(const QString& fromFile, const QString& toFile, bool u
return pProcess->exitCode() == 0;
}

void SysCommand::runCommand(const QString& cmd, QStringList args, bool jsonResult, bool usePkExec)
{
void SysCommand::runCommand(const QString& cmd, QStringList args, bool jsonResult, bool usePkExec) {
pProcess = std::make_unique<QProcess>(this);
connect(pProcess.get(), &QProcess::finished, this, [this](int exitCode, QProcess::ExitStatus status) {
qDebug() << "Process exit code " << exitCode << " - " << status;
Expand Down
1 change: 1 addition & 0 deletions SysCommand.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class SysCommand : public QObject
{
Q_OBJECT
public:
void restartTailscaleDaemon();
void refreshDns();
void makeDir(const QString& path, bool usePkExec = false);
void mountFs(const QString& remote, const QString& path, const QString& fsType, const QString& options = "", bool usePkExec = false);
Expand Down
7 changes: 7 additions & 0 deletions TrayMenuManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ TrayMenuManager::TrayMenuManager(TailSettings& s, TailRunner* runner, QObject* p
pExitNodeNone->setChecked(true);
pExitNodeNone->setEnabled(false);
pRefreshLocalDns = std::make_unique<QAction>("Refresh Local DNS");
pRestartTailscale = std::make_unique<QAction>("Restart Tailscale");

setupWellKnownActions();

Expand Down Expand Up @@ -114,6 +115,7 @@ void TrayMenuManager::buildNotConnectedMenu(TailStatus const* pTailStatus) const
pThisDevice->setText(pTailStatus->user->loginName);
pTrayMenu->addAction(pThisDevice.get());
auto* actions = pTrayMenu->addMenu("Custom Actions");
actions->addAction(pRestartTailscale.get());
actions->addAction(pRefreshLocalDns.get());
pTrayMenu->addSeparator();
pTrayMenu->addAction(pPreferences.get());
Expand Down Expand Up @@ -265,6 +267,7 @@ void TrayMenuManager::buildConnectedMenu(TailStatus const* pTailStatus) const {
pTrayMenu->addSeparator();

auto* actions = pTrayMenu->addMenu("Custom Actions");
actions->addAction(pRestartTailscale.get());
actions->addAction(pRefreshLocalDns.get());

pTrayMenu->addSeparator();
Expand Down Expand Up @@ -398,6 +401,10 @@ void TrayMenuManager::setupWellKnownActions() const {
}
);

connect(pRestartTailscale.get(), &QAction::triggered, this, [this](bool) {
pSysCommand->restartTailscaleDaemon();
});

connect(pRefreshLocalDns.get(), &QAction::triggered, this, [this](bool) {
pSysCommand->refreshDns();
});
Expand Down
3 changes: 2 additions & 1 deletion TrayMenuManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ class TrayMenuManager : public QObject
std::unique_ptr<QAction> pAbout;
std::unique_ptr<QAction> pThisDevice;
std::unique_ptr<QAction> pExitNodeNone;
std::unique_ptr<QAction> pRefreshLocalDns;
std::unique_ptr<QAction> pRefreshLocalDns;
std::unique_ptr<QAction> pRestartTailscale;
std::unique_ptr<SysCommand> pSysCommand;

private:
Expand Down

0 comments on commit 69a58c3

Please sign in to comment.