diff --git a/packages/instwin/include/instwin/core/installer.hpp b/packages/instwin/include/instwin/core/installer.hpp index ba958fb..4a5c374 100644 --- a/packages/instwin/include/instwin/core/installer.hpp +++ b/packages/instwin/include/instwin/core/installer.hpp @@ -16,11 +16,11 @@ enum InstallResult { Warning = 3, }; -class InstallerWorker : public QObject { +class InstallerWorker : public QThread { Q_OBJECT -public slots: - void run(); +public: + InstallerWorker(QObject *parent); signals: void onLog(std::string s); @@ -28,6 +28,8 @@ public slots: void onResult(InstallResult result); private: + void run() override; + std::string timeString(); }; @@ -35,7 +37,7 @@ class Installer : public QObject { Q_OBJECT public: - Installer(); + Installer(QObject *parent); public slots: void start(); @@ -46,7 +48,6 @@ public slots: void onResult(InstallResult result); private: - QThread thread; InstallerWorker worker; }; diff --git a/packages/instwin/include/instwin/windows/mainwindow.hpp b/packages/instwin/include/instwin/windows/mainwindow.hpp index 30b0284..e336a6b 100644 --- a/packages/instwin/include/instwin/windows/mainwindow.hpp +++ b/packages/instwin/include/instwin/windows/mainwindow.hpp @@ -23,8 +23,8 @@ class MainWindow : public QMainWindow { ~MainWindow(); public slots: - void navigateToProgressPage(); - void navigateToFinishPage(); + [[maybe_unused]] void navigateToProgressPage(); + [[maybe_unused]] void navigateToFinishPage(); void appendProgressLog(std::string s); private: diff --git a/packages/instwin/src/core/installer.cpp b/packages/instwin/src/core/installer.cpp index 0b33135..9021ed9 100644 --- a/packages/instwin/src/core/installer.cpp +++ b/packages/instwin/src/core/installer.cpp @@ -2,6 +2,9 @@ namespace InstWin { +InstallerWorker::InstallerWorker(QObject *parent) : QThread(parent) { +} + void InstallerWorker::run() { emit onProgress(0); emit onLog(std::format("Installation started at {}.", timeString())); @@ -14,16 +17,14 @@ std::string InstallerWorker::timeString() { return std::format("{:%Y-%m-%d %H:%M:%OS}", std::chrono::system_clock::now()); } -Installer::Installer() { - worker.moveToThread(&thread); - connect(this, &Installer::start, &worker, &InstallerWorker::run); +Installer::Installer(QObject *parent) : QObject(parent), worker(this) { connect(&worker, &InstallerWorker::onLog, this, &Installer::onLog); connect(&worker, &InstallerWorker::onProgress, this, &Installer::onProgress); connect(&worker, &InstallerWorker::onResult, this, &Installer::onResult); } void Installer::start() { - thread.start(); + worker.start(); } } // namespace InstWin diff --git a/packages/instwin/src/windows/mainwindow.cpp b/packages/instwin/src/windows/mainwindow.cpp index 7b1f1e4..5873c73 100644 --- a/packages/instwin/src/windows/mainwindow.cpp +++ b/packages/instwin/src/windows/mainwindow.cpp @@ -1,7 +1,8 @@ #include "instwin/windows/mainwindow.hpp" #include "ui_mainwindow.h" -MainWindow::MainWindow() : QMainWindow(nullptr), ui(new Ui::MainWindow) { +MainWindow::MainWindow() + : QMainWindow(nullptr), ui(new Ui::MainWindow), installer(this) { // Setup UI ui->setupUi(this); @@ -10,6 +11,11 @@ MainWindow::MainWindow() : QMainWindow(nullptr), ui(new Ui::MainWindow) { &InstWin::Installer::onLog, this, &MainWindow::appendProgressLog); + connect( + ui->installButton, + &QPushButton::clicked, + &installer, + &InstWin::Installer::start); initializeWindowStyle(); } @@ -47,11 +53,11 @@ void MainWindow::initializeWindowStyle() { int dwmUseDarkMode = 1; DwmSetWindowAttribute( hWnd, - supports >= 2 ? 20 - : // DWMWINDOWATTRIBUTE::DWMWA_USE_IMMERSIVE_DARK_MODE - // = 20 (starting from 18985) - 19, // DWMWINDOWATTRIBUTE::DWMWA_USE_IMMERSIVE_DARK_MODE - // = 19 (before 18985) + supports >= 2 ? 20 // DWMWINDOWATTRIBUTE::DWMWA_USE_IMMERSIVE_DARK_MODE + : // = 20 (starting from 18985) + // DWMWINDOWATTRIBUTE::DWMWA_USE_IMMERSIVE_DARK_MODE + 19, // = 19 (before 18985) + &dwmUseDarkMode, sizeof(dwmUseDarkMode)); unsigned int dwmCornerPreference = @@ -79,7 +85,6 @@ void MainWindow::initializeWindowStyle() { void MainWindow::navigateToProgressPage() { ui->centralWidget->setCurrentIndex(1); - installer.start(); } void MainWindow::navigateToFinishPage() { @@ -89,6 +94,8 @@ void MainWindow::navigateToFinishPage() { void MainWindow::appendProgressLog(std::string s) { ui->progressPageLog->moveCursor(QTextCursor::End); ui->progressPageLog->insertPlainText(s.c_str()); + ui->progressPageLog->moveCursor(QTextCursor::End); + ui->progressPageLog->insertPlainText("\n"); QScrollBar *verticalScrollBar = ui->progressPageLog->verticalScrollBar(); verticalScrollBar->setValue(verticalScrollBar->maximum()); }