Compare commits

..

1 Commits

4 changed files with 44 additions and 1 deletions

View File

@ -70,6 +70,9 @@ int main(int argc, char *argv[])
QCommandLineOption stopRunning("stop-running", "Stop any running instances");
parser.addOption(stopRunning);
QCommandLineOption terminateEnvironmentOnShutdown("terminate-environment-on-shutdown", "Terminate the desktop environment if the browser is shut down (i3 and sway supported)");
parser.addOption(terminateEnvironmentOnShutdown);
QCommandLineOption helpOption = parser.addHelpOption();
@ -137,6 +140,9 @@ int main(int argc, char *argv[])
options.setIgnoreSslErrors(true);
}
if (parser.isSet(terminateEnvironmentOnShutdown)) {
options.setTerminateEnvironmentOnShutdown(true);
}
if ( positional.length() > 0) {
options.setUrl( positional[0 ] );

View File

@ -202,6 +202,26 @@ void MainWindow::closeEvent(QCloseEvent *event) {
qInfo() << "Modo quiosco activado, ignorando intento de cerrar ventana";
event->ignore();
}
OGCommandLineOptions &options = OGCommandLineOptions::getInstance();
if (options.getTerminateEnvironmentOnShutdown()) {
qInfo() << "Shutdown requested, will try to terminate the desktop environment now.";
auto swaysock = qgetenv("SWAYSOCK");
auto i3sock = qgetenv("I3SOCK");
if (swaysock.length() > 0) {
qInfo() << "We seem to be running Sway, sending termination command";
event->ignore();
m_shutdown_process.start("swaymsg", QStringList() << "exit");
} else if (i3sock.length() > 0) {
qInfo() << "We seem to be running i3, sending termination command";
event->ignore();
m_shutdown_process.start("i3-msg", QStringList() << "exit");
} else {
qInfo() << "Unknown environment running, can't stop it.";
}
}
}
@ -288,6 +308,8 @@ void MainWindow::commandQueued(const QString &command, bool confirm, bool return
connect(m_command.process, &QProcess::readyReadStandardOutput,this,&MainWindow::slotProcessOutput);
connect(m_command.process, &QProcess::readyReadStandardError,this,&MainWindow::slotProcessErrorOutput);
connect(&m_shutdown_process, &QProcess::finished,this,&MainWindow::slotShutdownProcessFinished);
if(isAdmin()) {
m_output->setTextColor(QColor(Qt::darkGreen));
@ -471,6 +493,12 @@ void MainWindow::slotProcessError(QProcess::ProcessError error)
finishProgressBar();
}
void slotShutdownProcessFinished(int code, QProcess::ExitStatus status) {
qInfo() << "Shutdown process finished with code" << code << "; status" << status;
qInfo() << "Now quitting.";
QCoreApplication::exit(0);
}
void MainWindow::slotCreateTerminal()
{
QTermWidget* console = new QTermWidget(1,this);

View File

@ -68,6 +68,9 @@ class MainWindow : public QMainWindow
void slotProcessOutput();
void slotProcessErrorOutput();
void slotShutdownProcessFinished(int code, QProcess::ExitStatus status);
// Funcion para crear terminales
void slotCreateTerminal();
void slotDeleteTerminal();
@ -112,6 +115,7 @@ class MainWindow : public QMainWindow
QLineEdit *m_webBar;
//QProcess *m_process;
QProcess m_shutdown_process;
QMap<QString,QString> m_env;
QFile *m_logfile;

View File

@ -38,6 +38,10 @@ class OGCommandLineOptions {
bool getIgnoreSslErrors() const { return _ignoreSslErrors; }
void setIgnoreSslErrors(bool value) { _ignoreSslErrors = value; }
bool getTerminateEnvironmentOnShutdown() const { return _terminateEnvironmentOnShutdown; }
void setTerminateEnvironmentOnShutdown(bool value) { _terminateEnvironmentOnShutdown = value; }
private:
OGCommandLineOptions() {
@ -48,4 +52,5 @@ private:
NewTabBehavior _newTabBehavior{ReplacePage};
bool _ignoreSslErrors = false;
};
bool _terminateEnvironmentOnShutdown = false;
};