ui: add native reload popup

This commit is contained in:
outfoxxed 2025-05-17 17:03:03 -07:00
parent 5c1d600e84
commit 8124a63ee4
Signed by untrusted user: outfoxxed
GPG key ID: 4C88A185FB89301E
13 changed files with 475 additions and 4 deletions

View file

@ -45,6 +45,8 @@ EngineGeneration::EngineGeneration(const QDir& rootPath, QmlScanner scanner)
QsEnginePlugin::runConstructGeneration(*this);
}
EngineGeneration::EngineGeneration(): EngineGeneration(QDir(), QmlScanner()) {}
EngineGeneration::~EngineGeneration() {
if (this->engine != nullptr) {
qFatal() << this << "destroyed without calling destroy()";

View file

@ -28,6 +28,7 @@ class EngineGeneration: public QObject {
Q_OBJECT;
public:
explicit EngineGeneration();
explicit EngineGeneration(const QDir& rootPath, QmlScanner scanner);
~EngineGeneration() override;
Q_DISABLE_COPY_MOVE(EngineGeneration);

View file

@ -173,6 +173,14 @@ public:
Q_INVOKABLE [[nodiscard]] QString statePath(const QString& path) const;
/// Equivalent to `${Quickshell.cacheDir}/${path}`
Q_INVOKABLE [[nodiscard]] QString cachePath(const QString& path) const;
/// When called from @@reloadCompleted() or @@reloadFailed(), prevents the
/// default reload popup from displaying.
///
/// The popup can also be blocked by setting `QS_NO_RELOAD_POPUP=1`.
Q_INVOKABLE void inhibitReloadPopup() { this->mInhibitReloadPopup = true; }
void clearReloadPopupInhibit() { this->mInhibitReloadPopup = false; }
[[nodiscard]] bool isReloadPopupInhibited() const { return this->mInhibitReloadPopup; }
[[nodiscard]] QString shellRoot() const;
@ -212,6 +220,8 @@ private slots:
private:
QuickshellGlobal(QObject* parent = nullptr);
bool mInhibitReloadPopup = false;
static qsizetype screensCount(QQmlListProperty<QuickshellScreenInfo>* prop);
static QuickshellScreenInfo* screenAt(QQmlListProperty<QuickshellScreenInfo>* prop, qsizetype i);
};

View file

@ -12,8 +12,10 @@
#include <qtmetamacros.h>
#include <qurl.h>
#include "../ui/reload_popup.hpp"
#include "../window/floatingwindow.hpp"
#include "generation.hpp"
#include "instanceinfo.hpp"
#include "qmlglobal.hpp"
#include "scan.hpp"
@ -68,6 +70,18 @@ void RootWrapper::reloadGraph(bool hard) {
qWarning().noquote() << error;
generation->destroy();
if (this->generation != nullptr) {
auto showPopup = true;
if (this->generation->qsgInstance != nullptr) {
this->generation->qsgInstance->clearReloadPopupInhibit();
emit this->generation->qsgInstance->reloadFailed(error);
showPopup = !this->generation->qsgInstance->isReloadPopupInhibited();
}
if (showPopup) qs::ui::ReloadPopup::spawnPopup(InstanceInfo::CURRENT.instanceId, true, error);
}
if (this->generation != nullptr && this->generation->qsgInstance != nullptr) {
emit this->generation->qsgInstance->reloadFailed(error);
}
@ -113,8 +127,16 @@ void RootWrapper::reloadGraph(bool hard) {
this->onWatchFilesChanged();
if (isReload && this->generation->qsgInstance != nullptr) {
emit this->generation->qsgInstance->reloadCompleted();
if (isReload) {
auto showPopup = true;
if (this->generation->qsgInstance != nullptr) {
this->generation->qsgInstance->clearReloadPopupInhibit();
emit this->generation->qsgInstance->reloadCompleted();
showPopup = !this->generation->qsgInstance->isReloadPopupInhibited();
}
if (showPopup) qs::ui::ReloadPopup::spawnPopup(InstanceInfo::CURRENT.instanceId, false, "");
}
}

View file

@ -11,6 +11,7 @@ Q_DECLARE_LOGGING_CATEGORY(logQmlScanner);
// expects canonical paths
class QmlScanner {
public:
QmlScanner() = default;
QmlScanner(const QDir& rootPath): rootPath(rootPath) {}
void scanDir(const QString& path);

View file

@ -1,6 +1,6 @@
function (qs_test name)
add_executable(${name} ${ARGN})
target_link_libraries(${name} PRIVATE Qt::Quick Qt::Test quickshell-core quickshell-window)
target_link_libraries(${name} PRIVATE Qt::Quick Qt::Test quickshell-core quickshell-window quickshell-ui)
add_test(NAME ${name} WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}" COMMAND $<TARGET_FILE:${name}>)
endfunction()