mirror of
https://github.com/hyprwm/hyprland-qtutils.git
synced 2024-12-25 19:49:49 +01:00
utils: add update-screen
This commit is contained in:
parent
a5b4f1e8b3
commit
debf0498a1
6 changed files with 227 additions and 0 deletions
|
@ -17,4 +17,5 @@ pkg_check_modules(hyprutils REQUIRED IMPORTED_TARGET hyprutils)
|
|||
qt_standard_project_setup(REQUIRES 6.5)
|
||||
|
||||
add_subdirectory(utils/dialog)
|
||||
add_subdirectory(utils/update-screen)
|
||||
|
||||
|
|
36
utils/update-screen/CMakeLists.txt
Normal file
36
utils/update-screen/CMakeLists.txt
Normal file
|
@ -0,0 +1,36 @@
|
|||
cmake_minimum_required(VERSION 3.16)
|
||||
|
||||
project(hyprland-update-screen VERSION ${VER} LANGUAGES CXX)
|
||||
|
||||
set(CMAKE_CXX_STANDARD 23)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
|
||||
find_package(Qt6 6.5 REQUIRED COMPONENTS Widgets Quick QuickControls2 WaylandClient)
|
||||
find_package(PkgConfig REQUIRED)
|
||||
|
||||
pkg_check_modules(hyprutils REQUIRED IMPORTED_TARGET hyprutils)
|
||||
|
||||
qt_standard_project_setup(REQUIRES 6.5)
|
||||
|
||||
qt_add_executable(hyprland-update-screen
|
||||
main.cpp
|
||||
UpdateScreen.cpp
|
||||
)
|
||||
|
||||
qt_add_qml_module(hyprland-update-screen
|
||||
URI org.hyprland.update-screen
|
||||
VERSION 1.0
|
||||
QML_FILES main.qml
|
||||
)
|
||||
|
||||
target_link_libraries(hyprland-update-screen PRIVATE
|
||||
Qt6::Widgets Qt6::QuickControls2 Qt6::WaylandClientPrivate PkgConfig::hyprutils
|
||||
)
|
||||
|
||||
|
||||
include(GNUInstallDirs)
|
||||
install(TARGETS hyprland-update-screen
|
||||
BUNDLE DESTINATION .
|
||||
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
|
||||
)
|
17
utils/update-screen/UpdateScreen.cpp
Normal file
17
utils/update-screen/UpdateScreen.cpp
Normal file
|
@ -0,0 +1,17 @@
|
|||
#include "UpdateScreen.hpp"
|
||||
#include <print>
|
||||
#include <hyprutils/string/String.hpp>
|
||||
#include <hyprutils/os/Process.hpp>
|
||||
using namespace Hyprutils::String;
|
||||
|
||||
CUpdateScreen::CUpdateScreen(QObject* parent) : QObject(parent) {
|
||||
;
|
||||
}
|
||||
|
||||
void CUpdateScreen::onButtonPress(QString buttonName) {
|
||||
if (buttonName == "dontshow") {
|
||||
Hyprutils::OS::CProcess proc("hyprland-dialog", {"--title", "Information", "--text", "If you wish to disable this dialog, set ecosystem:no_update_news to true in your Hyprland config.", "--buttons", "ok"});
|
||||
proc.runAsync();
|
||||
} else if (buttonName == "quit")
|
||||
exit(0);
|
||||
}
|
23
utils/update-screen/UpdateScreen.hpp
Normal file
23
utils/update-screen/UpdateScreen.hpp
Normal file
|
@ -0,0 +1,23 @@
|
|||
#pragma once
|
||||
|
||||
#include <QObject>
|
||||
#include <QQmlApplicationEngine>
|
||||
#include <QPixmap>
|
||||
#include <QIcon>
|
||||
#include <qcontainerfwd.h>
|
||||
#include <qqmlintegration.h>
|
||||
#include <qtmetamacros.h>
|
||||
|
||||
class CUpdateScreen : public QObject {
|
||||
Q_OBJECT;
|
||||
QML_NAMED_ELEMENT(UpdateScreen);
|
||||
QML_SINGLETON;
|
||||
Q_PROPERTY(QString newVersion MEMBER newVersion CONSTANT);
|
||||
|
||||
public:
|
||||
explicit CUpdateScreen(QObject* parent = nullptr);
|
||||
|
||||
QString newVersion;
|
||||
|
||||
Q_INVOKABLE void onButtonPress(QString buttonName = "");
|
||||
};
|
54
utils/update-screen/main.cpp
Normal file
54
utils/update-screen/main.cpp
Normal file
|
@ -0,0 +1,54 @@
|
|||
#include "UpdateScreen.hpp"
|
||||
#include <hyprutils/string/VarList.hpp>
|
||||
#include <print>
|
||||
#include <qapplication.h>
|
||||
#include <qqmlapplicationengine.h>
|
||||
#include <qquickstyle.h>
|
||||
#include <qtenvironmentvariables.h>
|
||||
#include <QQmlContext>
|
||||
|
||||
using namespace Hyprutils::String;
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
// disable logs to not trash the stdout
|
||||
qputenv("QT_LOGGING_RULES", QByteArray("*.debug=false;qml=false"));
|
||||
|
||||
auto dialog = new CUpdateScreen();
|
||||
|
||||
for (int i = 1; i < argc; ++i) {
|
||||
std::string_view arg = argv[i];
|
||||
|
||||
if (arg == "--new-version") {
|
||||
if (i + 1 >= argc) {
|
||||
std::println(stderr, "--new-version requires a parameter");
|
||||
return 1;
|
||||
}
|
||||
|
||||
dialog->newVersion = argv[i + 1];
|
||||
|
||||
i++;
|
||||
continue;
|
||||
}
|
||||
|
||||
std::println(stderr, "invalid arg {}", argv[i]);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (dialog->newVersion.isEmpty()) {
|
||||
std::println(stderr, "missing --new-version");
|
||||
return 1;
|
||||
}
|
||||
|
||||
QApplication app(argc, argv);
|
||||
app.setApplicationName("Hyprland Updated!");
|
||||
app.setApplicationDisplayName("Hyprland Updated");
|
||||
|
||||
if (qEnvironmentVariableIsEmpty("QT_QUICK_CONTROLS_STYLE"))
|
||||
QQuickStyle::setStyle("org.kde.desktop");
|
||||
|
||||
QQmlApplicationEngine engine;
|
||||
engine.rootContext()->setContextProperty("updateScreen", dialog);
|
||||
engine.load("qrc:/qt/qml/org/hyprland/update-screen/main.qml");
|
||||
|
||||
return app.exec();
|
||||
}
|
96
utils/update-screen/main.qml
Normal file
96
utils/update-screen/main.qml
Normal file
|
@ -0,0 +1,96 @@
|
|||
pragma ComponentBehavior: Bound
|
||||
|
||||
import QtQuick
|
||||
import QtQuick.Controls
|
||||
import QtQuick.Layouts
|
||||
|
||||
ApplicationWindow {
|
||||
id: window
|
||||
|
||||
FontMetrics { id: fontMetrics }
|
||||
|
||||
property var windowPadding: 10
|
||||
|
||||
minimumWidth: Math.max(fontMetrics.height * 10, mainLayout.Layout.minimumWidth) + mainLayout.anchors.margins * 2 + windowPadding * 2
|
||||
minimumHeight: Math.max(fontMetrics.height * 10, mainLayout.Layout.minimumHeight) + mainLayout.anchors.margins * 2 + windowPadding * 2
|
||||
maximumWidth: minimumWidth
|
||||
maximumHeight: minimumHeight
|
||||
visible: true
|
||||
|
||||
component Separator: Rectangle {
|
||||
color: Qt.darker(system.windowText, 1.5)
|
||||
}
|
||||
|
||||
component VSeparator: Separator {
|
||||
implicitWidth: 1
|
||||
Layout.fillHeight: true
|
||||
Layout.topMargin: fontMetrics.height
|
||||
Layout.bottomMargin: fontMetrics.height
|
||||
}
|
||||
|
||||
component HSeparator: Separator {
|
||||
implicitHeight: 1
|
||||
Layout.fillWidth: true
|
||||
Layout.leftMargin: fontMetrics.height * 8
|
||||
Layout.rightMargin: fontMetrics.height * 8
|
||||
}
|
||||
|
||||
SystemPalette {
|
||||
id: system
|
||||
colorGroup: SystemPalette.Active
|
||||
}
|
||||
|
||||
ColumnLayout {
|
||||
id: mainLayout
|
||||
spacing: fontMetrics.height
|
||||
|
||||
anchors {
|
||||
fill: parent
|
||||
margins: 4
|
||||
}
|
||||
|
||||
Text {
|
||||
font.pointSize: fontMetrics.height
|
||||
color: system.windowText
|
||||
text: "Hyprland updated to " + updateScreen.newVersion + "!"
|
||||
Layout.alignment: Qt.AlignHCenter
|
||||
}
|
||||
|
||||
HSeparator {}
|
||||
|
||||
Text {
|
||||
color: system.windowText
|
||||
text: "Hyprland has been updated! <span style=\"font-family: 'Noto Color Emoji';\">😁</span><br/><br/>Please check the release notes on GitHub: <a href=\"https://github.com/hyprwm/Hyprland/releases\">https://github.com/hyprwm/Hyprland/releases</a><br/><br/>Every release may come with breaking changes, so if you get any config errors, try checking the latest release notes."
|
||||
Layout.alignment: Qt.AlignHCenter
|
||||
horizontalAlignment: Text.AlignHCenter
|
||||
textFormat: TextEdit.RichText
|
||||
onLinkActivated: Qt.openUrlExternally(link)
|
||||
}
|
||||
|
||||
Rectangle {
|
||||
color: "transparent"
|
||||
Layout.minimumHeight: 10
|
||||
Layout.fillHeight: true
|
||||
}
|
||||
|
||||
RowLayout {
|
||||
spacing: 6
|
||||
Layout.leftMargin: 20
|
||||
Layout.alignment: Qt.AlignRight
|
||||
|
||||
Button {
|
||||
text: "Don't show this when I update"
|
||||
onClicked: (e) => {
|
||||
updateScreen.onButtonPress("dontshow");
|
||||
}
|
||||
}
|
||||
|
||||
Button {
|
||||
text: "Thanks!"
|
||||
onClicked: (e) => {
|
||||
updateScreen.onButtonPress("quit");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue