Skip to content

Commit

Permalink
vkconfig: Add Vulkan SDK release detection
Browse files Browse the repository at this point in the history
  • Loading branch information
christophe-lunarg committed Feb 17, 2025
1 parent 0ed717a commit ac2ab9f
Show file tree
Hide file tree
Showing 7 changed files with 251 additions and 39 deletions.
41 changes: 41 additions & 0 deletions vkconfig_gui/file_downloader.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Copyright (c) 2020-2025 Valve Corporation
* Copyright (c) 2020-2025 LunarG, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* Authors:
* - Christophe Riccio <[email protected]>
*/

#include "file_downloader.h"

#include <QNetworkRequest>

FileDownloader::FileDownloader(QUrl url, QObject* parent) : QObject(parent) {
connect(&m_WebCtrl, SIGNAL(finished(QNetworkReply*)), this, SLOT(fileDownloaded(QNetworkReply*)));

QNetworkRequest request(url);
m_WebCtrl.get(request);
}

FileDownloader::~FileDownloader() {}

void FileDownloader::fileDownloaded(QNetworkReply* pReply) {
m_DownloadedData = pReply->readAll();
// emit a signal
pReply->deleteLater();
emit downloaded();
}

QByteArray FileDownloader::downloadedData() const { return m_DownloadedData; }
45 changes: 45 additions & 0 deletions vkconfig_gui/file_downloader.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* Copyright (c) 2020-2025 Valve Corporation
* Copyright (c) 2020-2025 LunarG, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* Authors:
* - Christophe Riccio <[email protected]>
*/

#pragma once

#include <QObject>
#include <QByteArray>
#include <QNetworkAccessManager>
#include <QNetworkReply>

class FileDownloader : public QObject {
Q_OBJECT

public:
explicit FileDownloader(QUrl url, QObject* parent = 0);
virtual ~FileDownloader();
QByteArray downloadedData() const;

signals:
void downloaded();

private slots:
void fileDownloaded(QNetworkReply* pReply);

private:
QNetworkAccessManager m_WebCtrl;
QByteArray m_DownloadedData;
};
25 changes: 22 additions & 3 deletions vkconfig_gui/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,29 @@ MainWindow::MainWindow(QWidget *parent)

this->InitTray();
this->UpdateUI(UPDATE_REBUILD_UI);

this->_last_release = new FileDownloader(QUrl("https://vulkan.lunarg.com/sdk/latest.json"), this);
this->connect(this->_last_release, SIGNAL(downloaded()), this, SLOT(on_last_release_downloaded()));
}

MainWindow::~MainWindow() {}

void MainWindow::on_last_release_downloaded() {
QJsonParseError parse_error;
QJsonDocument json_doc = QJsonDocument::fromJson(_last_release->downloadedData(), &parse_error);
const QJsonObject &json_root_object = json_doc.object();
std::string new_version = json_root_object.value("windows").toString().toStdString();

QMessageBox alert(this);
alert.setWindowTitle("A new version of the Vulkan SDK is available");
alert.setText(new_version.c_str());
alert.setIcon(QMessageBox::Question);
alert.setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel);
alert.setDefaultButton(QMessageBox::Ok);
alert.setCheckBox(new QCheckBox("Do not show again."));
alert.exec();
}

void MainWindow::commitDataRequest(QSessionManager &manager) {
(void)manager;

Expand Down Expand Up @@ -288,9 +307,9 @@ void MainWindow::closeEvent(QCloseEvent *event) {
alert.setDefaultButton(QMessageBox::Ok);
alert.setCheckBox(new QCheckBox("Do not show again."));

QPalette palette, palette_saved = this->ui->settings_keep_running->palette();
QPalette palette, palette_saved = this->ui->preferences_keep_running->palette();
palette.setColor(QPalette::WindowText, QColor(Qt::red));
this->ui->settings_keep_running->setPalette(palette);
this->ui->preferences_keep_running->setPalette(palette);

this->ui->tab_widget->setCurrentIndex(TAB_PREFERENCES);

Expand All @@ -299,7 +318,7 @@ void MainWindow::closeEvent(QCloseEvent *event) {
configurator.Set(HIDE_MESSAGE_USE_SYSTEM_TRAY);
}

this->ui->settings_keep_running->setPalette(palette_saved);
this->ui->preferences_keep_running->setPalette(palette_saved);

if (ret_val == QMessageBox::Cancel) {
event->ignore(); // Not closing the window
Expand Down
12 changes: 8 additions & 4 deletions vkconfig_gui/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

#include "../vkconfig_core/type_executable_mode.h"

#include "file_downloader.h"
#include "tab_configurations.h"
#include "tab_layers.h"
#include "tab_applications.h"
Expand Down Expand Up @@ -59,18 +60,21 @@ class MainWindow : public QMainWindow {
std::unique_ptr<QDialog> vk_info_dialog;
std::unique_ptr<QDialog> vk_installation_dialog;

QSystemTrayIcon *_tray_icon;
QMenu *_tray_icon_menu;
QAction *_tray_restore_action;
QSystemTrayIcon *_tray_icon = nullptr;
QMenu *_tray_icon_menu = nullptr;
QAction *_tray_restore_action = nullptr;
std::array<QAction *, EXECUTABLE_SCOPE_COUNT> _tray_layers;
QAction *_tray_quit_action;
QAction *_tray_quit_action = nullptr;
FileDownloader *_last_release = nullptr;

private slots:
void trayActionRestore();
void on_tray_none(bool checked);
void on_tray_any(bool checked);
void on_tray_all(bool checked);
void on_tray_per(bool checked);
void on_last_release_downloaded();

void iconActivated(QSystemTrayIcon::ActivationReason reason);

public Q_SLOTS:
Expand Down
Loading

0 comments on commit ac2ab9f

Please sign in to comment.