Skip to content

Commit

Permalink
🚧 fix by moving UI work to main thread
Browse files Browse the repository at this point in the history
  • Loading branch information
vnepogodin committed Nov 8, 2023
1 parent 87c267a commit 07def11
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 17 deletions.
35 changes: 18 additions & 17 deletions src/km-window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,23 +162,8 @@ MainWindow::MainWindow(QWidget* parent)
m_kernels.clear();
m_kernels = Kernel::get_kernels(m_handle);

m_conf_progress_dialog->setLabelText(tr("Please wait...\nInitializing kernels.."));
m_conf_progress_dialog->show();

auto* tree_kernels = m_ui->treeKernels;
tree_kernels->blockSignals(true);
tree_kernels->clear();

// NOTE: I don't think this should be parallelized, because it's already not running on the main thread
init_kernels_tree_widget(tree_kernels, std::span{m_kernels});

tree_kernels->blockSignals(false);
m_conf_progress_dialog->hide();

m_ui->ok->setEnabled(false);
m_thread_running.store(false, std::memory_order_relaxed);

QMessageBox::critical(this, "CachyOS Kernel Manager", tr("Please restart Kernel Manager if you want to run 'Execute' again"));
// schedule init_kernels to be executed in the main thread
QMetaObject::invokeMethod(this, "init_kernels", Qt::QueuedConnection);
}

m_running.store(false, std::memory_order_relaxed);
Expand Down Expand Up @@ -360,6 +345,22 @@ void Work::doHeavyCalculations() {
m_func();
}

void MainWindow::init_kernels() noexcept {
// show progress dialog to indicate user something is happening
m_conf_progress_dialog->setLabelText(tr("Please wait...\nInitializing kernels.."));
m_conf_progress_dialog->show();

auto* tree_kernels = m_ui->treeKernels;
tree_kernels->blockSignals(true);
tree_kernels->clear();

// NOTE: I don't think this should be parallelized, because it's already not running on the main thread
init_kernels_tree_widget(tree_kernels, std::span{m_kernels});

tree_kernels->blockSignals(false);
m_conf_progress_dialog->hide();
}

void MainWindow::on_execute() noexcept {
if (m_running.load(std::memory_order_consume))
return;
Expand Down
2 changes: 2 additions & 0 deletions src/km-window.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ class MainWindow final : public QMainWindow {

void item_changed(QTreeWidgetItem* item, int column) noexcept;

void init_kernels() noexcept;

protected:
void closeEvent(QCloseEvent* event) override;

Expand Down

0 comments on commit 07def11

Please sign in to comment.