Skip to content

Commit

Permalink
Fix bug - sometimes channels aren't saved
Browse files Browse the repository at this point in the history
  • Loading branch information
dewcked authored Feb 20, 2022
1 parent 9d2554c commit b730eff
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 16 deletions.
27 changes: 12 additions & 15 deletions src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ void MainWindow::setupCustomContextMenu()
_contextMenuActions << new QAction("Settings", this) << new QAction("Load Stream", this) << new QAction("Quit", this) << new QAction("Experimental", this);
connect(_contextMenuActions[0], SIGNAL(triggered()), _Submodules, SLOT(showDialog()));
connect(_contextMenuActions[1], SIGNAL(triggered()), this, SLOT(loadStream()));
connect(_contextMenuActions[2], SIGNAL(triggered()), this, SLOT(quit()));
connect(_contextMenuActions[2], SIGNAL(triggered()), this, SLOT(close()));
_contextMenu.addActions(_contextMenuActions);
}

Expand All @@ -114,26 +114,22 @@ void MainWindow::quitChatterino()
_lChatterinoLock = true;
_wChatterinowindow->hide();
_wChatterinowindow->setParent(nullptr);
QString command = QString("taskkill /pid " + QString::number(_pChatterinoProcess->processId(), 10));
QByteArray ba = command.toLocal8Bit();
const char *c_str = ba.data();
system(c_str);
_lChatterinoLock = false;
_pChatterinoProcess->terminate();
}

void MainWindow::closeEvent(QCloseEvent *event)
{
MainWindow::quit();
event->ignore();
}

void MainWindow::quit()
{
// Add graceful quit
MainWindow::quitChatterino();
_pStreamlinkProcess.at(0)->kill(); // terminate doesn't work properly on Windows
_pStreamlinkProcess.at(1)->kill(); // terminate doesn't work properly on Windows
QApplication::quit();
QTimer *exit = new QTimer();
connect(exit, &QTimer::timeout, this,
[=]()
{
if (_pChatterinoProcess->state() == QProcess::NotRunning && _pStreamlinkProcess.at(0)->state() == QProcess::NotRunning && _pStreamlinkProcess.at(0)->state() == QProcess::NotRunning)
event->accept();
});
exit->start(10);
}

// Show context menu
Expand Down Expand Up @@ -288,7 +284,7 @@ void MainWindow::setupStreamlink()
if (_pStreamlinkProcess.at(!_bStreamlinkProcessSelector)->state() != QProcess::NotRunning)
{
QTimer::singleShot(600, this, [=]()
{ _pStreamlinkProcess.at(!_bStreamlinkProcessSelector)->kill(); }); // terminate doesn't work on Windows
{ _pStreamlinkProcess.at(!_bStreamlinkProcessSelector)->terminate(); });
}
resizeEmbeds();
}
Expand Down Expand Up @@ -439,6 +435,7 @@ void MainWindow::loadStream()
connect(loadStream, &QTimer::timeout, this,
[=]()
{
qDebug() << _pChatterinoProcess->state();
if (_pChatterinoProcess->state() == QProcess::NotRunning)
{
QString channel = loadCurrentChannel();
Expand Down
1 change: 0 additions & 1 deletion src/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ private slots:
void initialize();
void refreshStream();
void loadStream();
void quit();

protected:
void resizeEvent(QResizeEvent *event) override;
Expand Down

0 comments on commit b730eff

Please sign in to comment.