mirror of
https://github.com/arcan1s/awesome-widgets.git
synced 2025-07-14 06:15:49 +00:00
add socket activation for extensions (#118)
Option `X-AW-Socket` is used. Any message received by this socket will trigger extension update. If the option is set, `X-AW-Interval` will be ignored
This commit is contained in:
@ -44,6 +44,8 @@ ExtUpgrade::ExtUpgrade(QWidget *parent, const QString filePath)
|
||||
m_process = new QProcess(nullptr);
|
||||
connect(m_process, SIGNAL(finished(int)), this, SLOT(updateValue()));
|
||||
m_process->waitForFinished(0);
|
||||
|
||||
connect(this, SIGNAL(socketActivated()), this, SLOT(startProcess()));
|
||||
}
|
||||
|
||||
|
||||
@ -53,6 +55,7 @@ ExtUpgrade::~ExtUpgrade()
|
||||
|
||||
m_process->kill();
|
||||
m_process->deleteLater();
|
||||
disconnect(this, SIGNAL(socketActivated()), this, SLOT(startProcess()));
|
||||
delete ui;
|
||||
}
|
||||
|
||||
@ -145,11 +148,8 @@ QVariantHash ExtUpgrade::run()
|
||||
if (!isActive())
|
||||
return m_values;
|
||||
|
||||
if ((m_times == 1) && (m_process->state() == QProcess::NotRunning)) {
|
||||
QString cmd = QString("sh -c \"%1\"").arg(executable());
|
||||
qCInfo(LOG_LIB) << "Run cmd" << cmd;
|
||||
m_process->start(cmd);
|
||||
}
|
||||
if (m_times == 1)
|
||||
startProcess();
|
||||
|
||||
// update value
|
||||
if (m_times >= interval())
|
||||
@ -209,6 +209,14 @@ void ExtUpgrade::writeConfiguration() const
|
||||
}
|
||||
|
||||
|
||||
void ExtUpgrade::startProcess()
|
||||
{
|
||||
QString cmd = QString("sh -c \"%1\"").arg(executable());
|
||||
qCInfo(LOG_LIB) << "Run cmd" << cmd;
|
||||
m_process->start(cmd);
|
||||
}
|
||||
|
||||
|
||||
void ExtUpgrade::updateValue()
|
||||
{
|
||||
qCInfo(LOG_LIB) << "Cmd returns" << m_process->exitCode();
|
||||
@ -230,6 +238,13 @@ void ExtUpgrade::updateValue()
|
||||
}
|
||||
|
||||
|
||||
bool ExtUpgrade::canRun()
|
||||
{
|
||||
return ((isActive()) && (m_process->state() == QProcess::NotRunning)
|
||||
&& (socket().isEmpty()));
|
||||
}
|
||||
|
||||
|
||||
void ExtUpgrade::translate()
|
||||
{
|
||||
ui->label_name->setText(i18n("Name"));
|
||||
|
Reference in New Issue
Block a user