diff --git a/GlosSIConfig/UIModel.cpp b/GlosSIConfig/UIModel.cpp index 6704918..0f0ca26 100644 --- a/GlosSIConfig/UIModel.cpp +++ b/GlosSIConfig/UIModel.cpp @@ -275,6 +275,16 @@ void UIModel::enableSteamInputXboxSupport() } } +bool UIModel::restartSteam() +{ + const auto path = getSteamPath(); + if (QProcess::execute("taskkill.exe", {"/im", steam_executable_name_, "/f"}) != 0) { + return false; + } + QProcess::startDetached(QString::fromStdWString(path) + "/" + steam_executable_name_); + return true; +} + void UIModel::updateCheck() { auto manager = new QNetworkAccessManager(); diff --git a/GlosSIConfig/UIModel.h b/GlosSIConfig/UIModel.h index 0daadea..3ac7782 100644 --- a/GlosSIConfig/UIModel.h +++ b/GlosSIConfig/UIModel.h @@ -50,16 +50,15 @@ class UIModel : public QObject { Q_INVOKABLE QVariantMap manualProps(QVariant shortcut); Q_INVOKABLE void enableSteamInputXboxSupport(); + Q_INVOKABLE bool restartSteam(); + Q_INVOKABLE void updateCheck(); #ifdef _WIN32 Q_INVOKABLE QVariantList uwpApps(); #endif - [[nodiscard]] bool writeShortcutsVDF( - const std::wstring& mode, - const std::wstring& name, - const std::wstring& shortcutspath, - bool is_admin_try = false) const; + [[nodiscard]] bool writeShortcutsVDF(const std::wstring& mode, const std::wstring& name, + const std::wstring& shortcutspath, bool is_admin_try = false) const; bool getIsWindows() const; [[nodiscard]] bool hasAcrylicEffect() const; @@ -87,6 +86,7 @@ class UIModel : public QObject { QString shortcutsfile_ = "/config/shortcuts.vdf"; QString user_config_file_ = "/config/localconfig.vdf"; QString user_data_path_ = "/userdata/"; + QString steam_executable_name_ = "steam.exe"; QVariantList targets_; diff --git a/GlosSIConfig/qml/main.qml b/GlosSIConfig/qml/main.qml index dcf7be4..7c32f59 100644 --- a/GlosSIConfig/qml/main.qml +++ b/GlosSIConfig/qml/main.qml @@ -76,7 +76,34 @@ Window { InfoDialog { id: steamChangedDialog titleText: qsTr("Steam shortcuts changed!") - text: qsTr("Please restart Steam to reload your changes") + text: qsTr("You have to restart Steam before your changes become visible") + onConfirmed: function (callback) { + callback(); + } + } + + InfoDialog { + id: steamChangedOnCloseDialog + titleText: qsTr("Steam shortcuts changed!") + text: qsTr("Please restart Steam to reload your changes\nRestart Steam now?") + onConfirmed: function (closeWindow) { + if (uiModel.restartSteam()) { + closeWindow(); + } else { + // meh I really should write a dialogUtil or some shit... + failedRestartingSteamDialog.confirmedParam = closeWindow; + failedRestartingSteamDialog.open(); + } + } + buttonText: qsTr("Yes") + extraButton: true + extraButtonText: qsTr("No") + } + + InfoDialog { + id: failedRestartingSteamDialog + titleText: qsTr("Failed restarting Steam!") + text: qsTr("You have to restart Steam before your changes become visible") onConfirmed: function (callback) { callback(); } @@ -86,9 +113,11 @@ Window { id: newVersionDialog titleText: qsTr("New version available!") text: qsTr("Would you like to visit the download page now?") - onConfirmed: function () { + onConfirmed: function (callback) { + callback(); Qt.openUrlExternally(`https://glossi.flatspot.pictures/#downloads-${uiModel.newVersionName}`); } + buttonText: qsTr("Yes") extraButton: true extraButtonText: qsTr("Remind me later") visible: !!uiModel.newVersionName @@ -136,10 +165,10 @@ Window { text: "🗙" onClicked: steamShortcutsChanged ? (function(){ - steamChangedDialog.confirmedParam = () => { + steamChangedOnCloseDialog.confirmedParam = () => { window.close() } - steamChangedDialog.open() + steamChangedOnCloseDialog.open() })() : window.close() background: Rectangle {