From 7e286b90b6a935a57e3f58e2594c4436b3be88ad Mon Sep 17 00:00:00 2001 From: David Lane <42013603+ReenigneArcher@users.noreply.github.com> Date: Sun, 25 Jan 2026 12:06:51 -0500 Subject: [PATCH] feat(windows): add ViGEmBus driver management API and UI integration (#4625) Introduces backend API endpoints for ViGEmBus status and installation, updates Windows build scripts to handle ViGEmBus versioning and installer download, and integrates ViGEmBus status and installation controls into the web UI. Removes legacy PowerShell scripts for gamepad driver management and related NSIS installer commands. --- cmake/compile_definitions/windows.cmake | 5 + cmake/packaging/windows.cmake | 11 +- cmake/packaging/windows_nsis.cmake | 10 -- cmake/targets/windows.cmake | 3 +- docs/api.md | 6 + docs/getting_started.md | 21 +-- docs/troubleshooting.md | 7 +- src/confighttp.cpp | 135 ++++++++++++++++++ src/platform/windows/misc.cpp | 27 ++++ src/platform/windows/misc.h | 10 ++ src_assets/common/assets/web/index.html | 29 ++++ .../assets/web/public/assets/locale/en.json | 17 ++- .../common/assets/web/troubleshooting.html | 123 ++++++++++++++-- .../windows/misc/gamepad/install-gamepad.ps1 | 20 --- .../misc/gamepad/uninstall-gamepad.ps1 | 8 -- 15 files changed, 360 insertions(+), 72 deletions(-) delete mode 100644 src_assets/windows/misc/gamepad/install-gamepad.ps1 delete mode 100644 src_assets/windows/misc/gamepad/uninstall-gamepad.ps1 diff --git a/cmake/compile_definitions/windows.cmake b/cmake/compile_definitions/windows.cmake index 2dd9615c..c1a2c95f 100644 --- a/cmake/compile_definitions/windows.cmake +++ b/cmake/compile_definitions/windows.cmake @@ -48,6 +48,11 @@ set_target_properties(sunshine_rc_object PROPERTIES INCLUDE_DIRECTORIES "" ) +# ViGEmBus version +set(VIGEMBUS_PACKAGED_V "1.21.442") +set(VIGEMBUS_PACKAGED_V_2 "${VIGEMBUS_PACKAGED_V}.0") +list(APPEND SUNSHINE_DEFINITIONS VIGEMBUS_PACKAGED_VERSION="${VIGEMBUS_PACKAGED_V_2}") + set(PLATFORM_TARGET_FILES "${CMAKE_SOURCE_DIR}/src/platform/windows/publish.cpp" "${CMAKE_SOURCE_DIR}/src/platform/windows/misc.h" diff --git a/cmake/packaging/windows.cmake b/cmake/packaging/windows.cmake index 4b00584f..069fd851 100644 --- a/cmake/packaging/windows.cmake +++ b/cmake/packaging/windows.cmake @@ -5,9 +5,11 @@ install(TARGETS sunshine RUNTIME DESTINATION "." COMPONENT application) install(FILES "${ZLIB}" DESTINATION "." COMPONENT application) # ViGEmBus installer -set(VIGEMBUS_INSTALLER "${CMAKE_BINARY_DIR}/vigembus_installer.exe") +set(VIGEMBUS_INSTALLER "${CMAKE_BINARY_DIR}/scripts/vigembus_installer.exe") +set(VIGEMBUS_DOWNLOAD_URL_1 "https://github.com/nefarius/ViGEmBus/releases/download") +set(VIGEMBUS_DOWNLOAD_URL_2 "v${VIGEMBUS_PACKAGED_V_2}/ViGEmBus_${VIGEMBUS_PACKAGED_V}_x64_x86_arm64.exe") file(DOWNLOAD - "https://github.com/nefarius/ViGEmBus/releases/download/v1.21.442.0/ViGEmBus_1.21.442_x64_x86_arm64.exe" + "${VIGEMBUS_DOWNLOAD_URL_1}/${VIGEMBUS_DOWNLOAD_URL_2}" ${VIGEMBUS_INSTALLER} SHOW_PROGRESS EXPECTED_HASH SHA256=155c50f1eec07bdc28d2f61a3e3c2c6c132fee7328412de224695f89143316bc @@ -45,9 +47,6 @@ install(DIRECTORY "${SUNSHINE_SOURCE_ASSETS_DIR}/windows/misc/autostart/" install(DIRECTORY "${SUNSHINE_SOURCE_ASSETS_DIR}/windows/misc/firewall/" DESTINATION "scripts" COMPONENT firewall) -install(DIRECTORY "${SUNSHINE_SOURCE_ASSETS_DIR}/windows/misc/gamepad/" - DESTINATION "scripts" - COMPONENT gamepad) # Sunshine assets install(DIRECTORY "${SUNSHINE_SOURCE_ASSETS_DIR}/windows/assets/" @@ -107,7 +106,7 @@ set(CPACK_COMPONENT_FIREWALL_GROUP "Scripts") # gamepad scripts set(CPACK_COMPONENT_GAMEPAD_DISPLAY_NAME "Virtual Gamepad") -set(CPACK_COMPONENT_GAMEPAD_DESCRIPTION "Scripts to install and uninstall Virtual Gamepad.") +set(CPACK_COMPONENT_GAMEPAD_DESCRIPTION "ViGEmBus installer for virtual gamepad support.") set(CPACK_COMPONENT_GAMEPAD_GROUP "Scripts") # include specific packaging diff --git a/cmake/packaging/windows_nsis.cmake b/cmake/packaging/windows_nsis.cmake index 8ac1ce95..6644a17d 100644 --- a/cmake/packaging/windows_nsis.cmake +++ b/cmake/packaging/windows_nsis.cmake @@ -15,8 +15,6 @@ SET(CPACK_NSIS_EXTRA_INSTALL_COMMANDS nsExec::ExecToLog '\\\"$INSTDIR\\\\scripts\\\\update-path.bat\\\" add' nsExec::ExecToLog '\\\"$INSTDIR\\\\scripts\\\\migrate-config.bat\\\"' nsExec::ExecToLog '\\\"$INSTDIR\\\\scripts\\\\add-firewall-rule.bat\\\"' - nsExec::ExecToLog \ - 'powershell.exe -NoProfile -ExecutionPolicy Bypass -File \\\"$INSTDIR\\\\scripts\\\\install-gamepad.ps1\\\"' nsExec::ExecToLog '\\\"$INSTDIR\\\\scripts\\\\install-service.bat\\\"' nsExec::ExecToLog '\\\"$INSTDIR\\\\scripts\\\\autostart-service.bat\\\"' NoController: @@ -29,14 +27,6 @@ set(CPACK_NSIS_EXTRA_UNINSTALL_COMMANDS nsExec::ExecToLog '\\\"$INSTDIR\\\\scripts\\\\delete-firewall-rule.bat\\\"' nsExec::ExecToLog '\\\"$INSTDIR\\\\scripts\\\\uninstall-service.bat\\\"' nsExec::ExecToLog '\\\"$INSTDIR\\\\${CMAKE_PROJECT_NAME}.exe\\\" --restore-nvprefs-undo' - MessageBox MB_YESNO|MB_ICONQUESTION \ - 'Do you want to remove Virtual Gamepad?' \ - /SD IDNO IDNO NoGamepad - nsExec::ExecToLog \ - 'powershell.exe -NoProfile -ExecutionPolicy Bypass -File \ - \\\"$INSTDIR\\\\scripts\\\\uninstall-gamepad.ps1\\\"'; \ - skipped if no - NoGamepad: MessageBox MB_YESNO|MB_ICONQUESTION \ 'Do you want to remove $INSTDIR (this includes the configuration, cover images, and settings)?' \ /SD IDNO IDNO NoDelete diff --git a/cmake/targets/windows.cmake b/cmake/targets/windows.cmake index 33a67cfd..d5807aa6 100644 --- a/cmake/targets/windows.cmake +++ b/cmake/targets/windows.cmake @@ -5,4 +5,5 @@ find_library(ZLIB ZLIB1) list(APPEND SUNSHINE_EXTERNAL_LIBRARIES $ Windowsapp.lib - Wtsapi32.lib) + Wtsapi32.lib + version.lib) diff --git a/docs/api.md b/docs/api.md index 5313d598..0834b6e2 100644 --- a/docs/api.md +++ b/docs/api.md @@ -57,6 +57,12 @@ basic authentication with the admin username and password. ## POST /api/restart @copydoc confighttp::restart() +## GET /api/vigembus/status +@copydoc confighttp::getViGEmBusStatus() + +## POST /api/vigembus/install +@copydoc confighttp::installViGEmBus() +
| Previous | Next | diff --git a/docs/getting_started.md b/docs/getting_started.md index c0d40752..58532341 100644 --- a/docs/getting_started.md +++ b/docs/getting_started.md @@ -369,21 +369,7 @@ overflow menu. Different versions of Windows may provide slightly different step scripts/delete-firewall-rule.bat ``` -4. Virtual Gamepad Support - - Install: - ```bash - cd /d {path to extracted directory} - scripts/install-gamepad.bat - ``` - - Uninstall: - ```bash - cd /d {path to extracted directory} - scripts/uninstall-gamepad.bat - ``` - -5. Windows service +4. Windows service Install: ```bash @@ -465,6 +451,11 @@ Sunshine can only access microphones on macOS due to system limitations. To stre > [!CAUTION] > Gamepads are not currently supported. +### Windows +In order for virtual gamepads to work, you must install ViGEmBus. You can do this from the troubleshooting tab +in the web UI, as long as you are running Sunshine as a service or as an administrator. After installation, it is +recommended to restart your computer. + ## Usage ### Basic usage diff --git a/docs/troubleshooting.md b/docs/troubleshooting.md index b5b211bf..844693e7 100644 --- a/docs/troubleshooting.md +++ b/docs/troubleshooting.md @@ -223,7 +223,12 @@ launchctl load -w /Library/LaunchAgents/org.freedesktop.dbus-session.plist ## Windows ### No gamepad detected -Verify that you've installed [Nefarius Virtual Gamepad](https://github.com/nefarius/ViGEmBus/releases/latest). +You must install ViGEmBus to use virtual gamepads. You can install this from the troubleshooting tab of the web UI. + +Alternatively, you can manually install it from +[ViGEmBus releases](https://github.com/nefarius/ViGEmBus/releases/latest). You must use version 1.17 or newer. + +After installation, it is recommended to restart your computer. ### Permission denied Since Sunshine runs as a service on Windows, it may not have the same level of access that your regular user account diff --git a/src/confighttp.cpp b/src/confighttp.cpp index 197fcf51..00312ccc 100644 --- a/src/confighttp.cpp +++ b/src/confighttp.cpp @@ -20,6 +20,13 @@ #include #include +#ifdef _WIN32 + #include "platform/windows/misc.h" + + #include + #include +#endif + // local includes #include "config.h" #include "confighttp.h" @@ -1171,6 +1178,132 @@ namespace confighttp { platf::restart(); } + /** + * @brief Get ViGEmBus driver version and installation status. + * @param response The HTTP response object. + * @param request The HTTP request object. + * + * @api_examples{/api/vigembus/status| GET| null} + */ + void getViGEmBusStatus(resp_https_t response, req_https_t request) { + if (!authenticate(response, request)) { + return; + } + + print_req(request); + + nlohmann::json output_tree; + +#ifdef _WIN32 + std::string version_str; + bool installed = false; + bool version_compatible = false; + + // Check if ViGEmBus driver exists + std::filesystem::path driver_path = std::filesystem::path(std::getenv("SystemRoot") ? std::getenv("SystemRoot") : "C:\\Windows") / "System32" / "drivers" / "ViGEmBus.sys"; + + if (std::filesystem::exists(driver_path)) { + installed = platf::getFileVersionInfo(driver_path, version_str); + if (installed) { + // Parse version string to check compatibility (>= 1.17.0.0) + std::vector version_parts; + std::stringstream ss(version_str); + std::string part; + while (std::getline(ss, part, '.')) { + version_parts.push_back(part); + } + + if (version_parts.size() >= 2) { + int major = std::stoi(version_parts[0]); + int minor = std::stoi(version_parts[1]); + version_compatible = (major > 1) || (major == 1 && minor >= 17); + } + } + } + + output_tree["installed"] = installed; + output_tree["version"] = version_str; + output_tree["version_compatible"] = version_compatible; + output_tree["packaged_version"] = VIGEMBUS_PACKAGED_VERSION; +#else + output_tree["error"] = "ViGEmBus is only available on Windows"; + output_tree["installed"] = false; + output_tree["version"] = ""; + output_tree["version_compatible"] = false; + output_tree["packaged_version"] = ""; +#endif + + send_response(response, output_tree); + } + + /** + * @brief Install ViGEmBus driver with elevated permissions. + * @param response The HTTP response object. + * @param request The HTTP request object. + * + * @api_examples{/api/vigembus/install| POST| null} + */ + void installViGEmBus(resp_https_t response, req_https_t request) { + if (!check_content_type(response, request, "application/json")) { + return; + } + if (!authenticate(response, request)) { + return; + } + + print_req(request); + + nlohmann::json output_tree; + +#ifdef _WIN32 + // Get the path to the vigembus installer + const std::filesystem::path installer_path = platf::appdata().parent_path() / "scripts" / "vigembus_installer.exe"; + + if (!std::filesystem::exists(installer_path)) { + output_tree["status"] = false; + output_tree["error"] = "ViGEmBus installer not found"; + send_response(response, output_tree); + return; + } + + // Run the installer with elevated permissions + std::error_code ec; + boost::filesystem::path working_dir = boost::filesystem::path(installer_path.string()).parent_path(); + boost::process::v1::environment env = boost::this_process::environment(); + + // Run with elevated permissions, non-interactive + const std::string install_cmd = std::format("{} /quiet", installer_path.string()); + auto child = platf::run_command(true, false, install_cmd, working_dir, env, nullptr, ec, nullptr); + + if (ec) { + output_tree["status"] = false; + output_tree["error"] = "Failed to start installer: " + ec.message(); + send_response(response, output_tree); + return; + } + + // Wait for the installer to complete + child.wait(ec); + + if (ec) { + output_tree["status"] = false; + output_tree["error"] = "Installer failed: " + ec.message(); + } else { + int exit_code = child.exit_code(); + output_tree["status"] = (exit_code == 0); + output_tree["exit_code"] = exit_code; + if (exit_code != 0) { + output_tree["error"] = std::format("Installer exited with code {}", exit_code); + } + } +#else + output_tree["status"] = false; + output_tree["error"] = "ViGEmBus installation is only available on Windows"; +#endif + + send_response(response, output_tree); + } + void start() { platf::set_thread_name("confighttp"); auto shutdown_event = mail::man->event(mail::shutdown); @@ -1209,6 +1342,8 @@ namespace confighttp { server.resource["^/api/configLocale$"]["GET"] = getLocale; server.resource["^/api/restart$"]["POST"] = restart; server.resource["^/api/reset-display-device-persistence$"]["POST"] = resetDisplayDevicePersistence; + server.resource["^/api/vigembus/status$"]["GET"] = getViGEmBusStatus; + server.resource["^/api/vigembus/install$"]["POST"] = installViGEmBus; server.resource["^/api/password$"]["POST"] = savePassword; server.resource["^/api/apps/([0-9]+)$"]["DELETE"] = deleteApp; server.resource["^/api/clients/unpair-all$"]["POST"] = unpairAll; diff --git a/src/platform/windows/misc.cpp b/src/platform/windows/misc.cpp index 63cf8ac1..5a4ea26e 100644 --- a/src/platform/windows/misc.cpp +++ b/src/platform/windows/misc.cpp @@ -1761,4 +1761,31 @@ namespace platf { std::unique_ptr create_high_precision_timer() { return std::make_unique(); } + + bool getFileVersionInfo(const std::filesystem::path &file_path, std::string &version_str) { + DWORD handle = 0; + DWORD size = GetFileVersionInfoSizeW(file_path.wstring().c_str(), &handle); + if (size == 0) { + return false; + } + + std::vector buffer(size); + if (!GetFileVersionInfoW(file_path.wstring().c_str(), handle, size, buffer.data())) { + return false; + } + + VS_FIXEDFILEINFO *file_info = nullptr; + if (UINT file_info_size = 0; !VerQueryValueW(buffer.data(), L"\\", (LPVOID *) &file_info, &file_info_size)) { + return false; + } + + DWORD major = HIWORD(file_info->dwFileVersionMS); + DWORD minor = LOWORD(file_info->dwFileVersionMS); + DWORD build = HIWORD(file_info->dwFileVersionLS); + DWORD revision = LOWORD(file_info->dwFileVersionLS); + + version_str = std::format("{}.{}.{}.{}", major, minor, build, revision); + + return true; + } } // namespace platf diff --git a/src/platform/windows/misc.h b/src/platform/windows/misc.h index 11e7af4a..198c1b2b 100644 --- a/src/platform/windows/misc.h +++ b/src/platform/windows/misc.h @@ -6,6 +6,8 @@ // standard includes #include +#include +#include #include // platform includes @@ -19,4 +21,12 @@ namespace platf { int64_t qpc_counter(); std::chrono::nanoseconds qpc_time_difference(int64_t performance_counter1, int64_t performance_counter2); + + /** + * @brief Get file version information from a Windows executable or driver file. + * @param file_path Path to the file to query. + * @param version_str Output parameter for version string in format "major.minor.build.revision". + * @return true if version info was successfully extracted, false otherwise. + */ + bool getFileVersionInfo(const std::filesystem::path &file_path, std::string &version_str); } // namespace platf diff --git a/src_assets/common/assets/web/index.html b/src_assets/common/assets/web/index.html index 4a8660af..576d9797 100644 --- a/src_assets/common/assets/web/index.html +++ b/src_assets/common/assets/web/index.html @@ -21,6 +21,21 @@ View Logs
+ +
+
+ +
+

{{ $t('index.vigembus_not_installed_title') }}

+

{{ $t('index.vigembus_not_installed_desc') }}

+
+
+

{{ $t('index.vigembus_outdated_title') }}

+

{{ $t('index.vigembus_outdated_desc', { version: vigembus.version }) }}

+
+ {{ $t('index.fix_now') }} +
+
@@ -94,18 +109,32 @@ preReleaseVersion: null, loading: true, logs: null, + platform: "", + controllerEnabled: false, + vigembus: null, } }, async created() { try { let config = await fetch("./api/config").then((r) => r.json()); this.notifyPreReleases = config.notify_pre_releases; + this.platform = config.platform; + this.controllerEnabled = config.controller !== "disabled"; this.version = new SunshineVersion(null, config.version); console.log("Version: ", this.version.version) this.githubVersion = new SunshineVersion(await fetch("https://api.github.com/repos/LizardByte/Sunshine/releases/latest").then((r) => r.json()), null); console.log("GitHub Version: ", this.githubVersion.version) this.preReleaseVersion = new SunshineVersion((await fetch("https://api.github.com/repos/LizardByte/Sunshine/releases").then((r) => r.json())).find(release => release.prerelease), null); console.log("Pre-Release Version: ", this.preReleaseVersion.version) + + // Fetch ViGEmBus status only on Windows when controller is enabled + if (this.platform === 'windows' && this.controllerEnabled) { + try { + this.vigembus = await fetch("./api/vigembus/status").then((r) => r.json()); + } catch (e) { + console.error("Failed to fetch ViGEmBus status:", e); + } + } } catch (e) { console.error(e); } diff --git a/src_assets/common/assets/web/public/assets/locale/en.json b/src_assets/common/assets/web/public/assets/locale/en.json index 331dc631..18b72a49 100644 --- a/src_assets/common/assets/web/public/assets/locale/en.json +++ b/src_assets/common/assets/web/public/assets/locale/en.json @@ -381,6 +381,7 @@ "index": { "description": "Sunshine is a self-hosted game stream host for Moonlight.", "download": "Download", + "fix_now": "Fix Now", "installed_version_not_stable": "You are running a pre-release version of Sunshine. You may experience bugs or other issues. Please report any issues you encounter. Thank you for helping to make Sunshine a better software!", "loading_latest": "Loading latest release...", "new_pre_release": "A new Pre-Release Version is Available!", @@ -388,6 +389,10 @@ "startup_errors": "Attention! Sunshine detected these errors during startup. We STRONGLY RECOMMEND fixing them before streaming.", "version_dirty": "Thank you for helping to make Sunshine a better software!", "version_latest": "You are running the latest version of Sunshine", + "vigembus_not_installed_desc": "Virtual gamepad support will not work without the ViGEmBus driver. Click the button below to install it.", + "vigembus_not_installed_title": "ViGEmBus Driver Not Installed", + "vigembus_outdated_desc": "You are running an outdated version of ViGEmBus (v{version}). Version 1.17 or higher is required for proper gamepad support. Click the button below to update.", + "vigembus_outdated_title": "ViGEmBus Driver Outdated", "welcome": "Hello, Sunshine!" }, "navbar": { @@ -451,7 +456,17 @@ "unpair_single_no_devices": "There are no paired devices.", "unpair_single_success": "However, the device(s) may still be in an active session. Use the 'Force Close' button above to end any open sessions.", "unpair_single_unknown": "Unknown Client", - "unpair_title": "Unpair Devices" + "unpair_title": "Unpair Devices", + "vigembus_compatible": "ViGEmBus is installed and compatible.", + "vigembus_current_version": "Current Version", + "vigembus_desc": "ViGEmBus is required for virtual gamepad support. Install or update the driver if it's missing or outdated (version 1.17 or higher required).", + "vigembus_incompatible": "ViGEmBus version is too old. Please install version 1.17 or higher.", + "vigembus_install": "ViGEmBus Driver", + "vigembus_install_button": "Install ViGEmBus v{version}", + "vigembus_install_error": "Failed to install ViGEmBus driver.", + "vigembus_install_success": "ViGEmBus driver installed successfully! You may need to restart your computer.", + "vigembus_force_reinstall_button": "Force Reinstall ViGEmBus v{version}", + "vigembus_not_installed": "ViGEmBus is not installed." }, "welcome": { "confirm_password": "Confirm password", diff --git a/src_assets/common/assets/web/troubleshooting.html b/src_assets/common/assets/web/troubleshooting.html index d742867f..0b23a455 100644 --- a/src_assets/common/assets/web/troubleshooting.html +++ b/src_assets/common/assets/web/troubleshooting.html @@ -40,6 +40,45 @@

{{ $t('troubleshooting.troubleshooting') }}

+ +
+
+

{{ $t('troubleshooting.vigembus_install') }}

+
+

{{ $t('troubleshooting.vigembus_desc') }}

+
+

{{ $t('troubleshooting.vigembus_current_version') }}: {{ vigembus.version }}

+
+ {{ $t('troubleshooting.vigembus_compatible') }} +
+
+ {{ $t('troubleshooting.vigembus_incompatible') }} +
+
+
+ {{ $t('troubleshooting.vigembus_not_installed') }} +
+
+ {{ $t('troubleshooting.vigembus_install_success') }} +
+
+ {{ vigemBusInstallError || $t('troubleshooting.vigembus_install_error') }} +
+
+ +
+
+
@@ -169,8 +208,18 @@ restartPressed: false, showApplyMessage: false, platform: "", + controllerEnabled: false, unpairAllPressed: false, unpairAllStatus: null, + vigembus: { + installed: false, + version: '', + version_compatible: false, + packaged_version: '', + }, + vigemBusInstallPressed: false, + vigemBusInstallStatus: null, + vigemBusInstallError: null, }; }, computed: { @@ -186,6 +235,11 @@ .then((r) => r.json()) .then((r) => { this.platform = r.platform; + this.controllerEnabled = r.controller !== "disabled"; + // Fetch ViGEmBus status only on Windows when gamepad is enabled + if (this.platform === 'windows' && this.controllerEnabled) { + this.refreshViGEmBusStatus(); + } }); this.logInterval = setInterval(() => { @@ -207,7 +261,7 @@ }, closeApp() { this.closeAppPressed = true; - fetch("./api/apps/close", { + fetch("./api/apps/close", { method: "POST", headers: { "Content-Type": "application/json" @@ -223,7 +277,7 @@ }, unpairAll() { this.unpairAllPressed = true; - fetch("./api/clients/unpair-all", { + fetch("./api/clients/unpair-all", { method: "POST", headers: { "Content-Type": "application/json" @@ -240,12 +294,12 @@ }); }, unpairSingle(uuid) { - fetch("./api/clients/unpair", { - method: "POST", + fetch("./api/clients/unpair", { + method: "POST", headers: { 'Content-Type': 'application/json' - }, - body: JSON.stringify({ uuid }) + }, + body: JSON.stringify({ uuid }) }).then(() => { this.showApplyMessage = true; this.refreshClients(); @@ -285,11 +339,11 @@ }, ddResetPersistence() { this.ddResetPressed = true; - fetch("/api/reset-display-device-persistence", { + fetch("/api/reset-display-device-persistence", { method: "POST", - headers: { - "Content-Type": "application/json" - } + headers: { + "Content-Type": "application/json" + } }) .then((r) => r.json()) .then((r) => { @@ -300,6 +354,55 @@ }, 5000); }); }, + refreshViGEmBusStatus() { + fetch("/api/vigembus/status") + .then((r) => r.json()) + .then((r) => { + this.vigembus = { + installed: r.installed || false, + version: r.version || '', + version_compatible: r.version_compatible || false, + packaged_version: r.packaged_version, + }; + }) + .catch((err) => { + console.error("Failed to fetch ViGEmBus status:", err); + }); + }, + installViGEmBus() { + this.vigemBusInstallPressed = true; + this.vigemBusInstallStatus = null; + this.vigemBusInstallError = null; + fetch("/api/vigembus/install", { + method: "POST", + headers: { + "Content-Type": "application/json" + } + }) + .then((r) => r.json()) + .then((r) => { + this.vigemBusInstallPressed = false; + this.vigemBusInstallStatus = r.status; + if (!r.status && r.error) { + this.vigemBusInstallError = r.error; + } + setTimeout(() => { + this.vigemBusInstallStatus = null; + this.vigemBusInstallError = null; + }, 10000); + // Refresh status after installation attempt + this.refreshViGEmBusStatus(); + }) + .catch((err) => { + this.vigemBusInstallPressed = false; + this.vigemBusInstallStatus = false; + this.vigemBusInstallError = err.message; + setTimeout(() => { + this.vigemBusInstallStatus = null; + this.vigemBusInstallError = null; + }, 10000); + }); + }, }, }); diff --git a/src_assets/windows/misc/gamepad/install-gamepad.ps1 b/src_assets/windows/misc/gamepad/install-gamepad.ps1 deleted file mode 100644 index b5715ffa..00000000 --- a/src_assets/windows/misc/gamepad/install-gamepad.ps1 +++ /dev/null @@ -1,20 +0,0 @@ -# Check if a compatible version of ViGEmBus is already installed (1.17 or later) -try { - $vigemBusPath = "$env:SystemRoot\System32\drivers\ViGEmBus.sys" - $fileVersion = (Get-Item $vigemBusPath).VersionInfo.FileVersion - - if ($fileVersion -ge [System.Version]"1.17") { - Write-Information "The installed version is 1.17 or later, no update needed. Exiting." - exit 0 - } -} -catch { - Write-Information "ViGEmBus driver not found or inaccessible, proceeding with installation." -} - -# Install Virtual Gamepad -$scriptPath = Split-Path -Parent $MyInvocation.MyCommand.Path -$installerPath = Join-Path $scriptPath "vigembus_installer.exe" -Start-Process ` - -FilePath $installerPath ` - -ArgumentList "/passive", "/promptrestart" diff --git a/src_assets/windows/misc/gamepad/uninstall-gamepad.ps1 b/src_assets/windows/misc/gamepad/uninstall-gamepad.ps1 deleted file mode 100644 index daf1a278..00000000 --- a/src_assets/windows/misc/gamepad/uninstall-gamepad.ps1 +++ /dev/null @@ -1,8 +0,0 @@ -# Use Get-CimInstance to find and uninstall Virtual Gamepad -$product = Get-CimInstance -ClassName Win32_Product -Filter "Name='ViGEm Bus Driver'" -if ($product) { - Invoke-CimMethod -InputObject $product -MethodName Uninstall - Write-Information "ViGEm Bus Driver uninstalled successfully" -} else { - Write-Warning "ViGEm Bus Driver not found" -}