tauri-apps / tauri

Build smaller, faster, and more secure desktop and mobile applications with a web frontend.
https://tauri.app
Apache License 2.0
85.03k stars 2.57k forks source link

[bug] Trying to make Steam Overlay work with Tauri #6196

Closed Elanis closed 1 year ago

Elanis commented 1 year ago

Hi !

This issue is a follow up to a conversation on Discord.

I'm trying to make Steam overlay work on a Tauri app, but it doesn't show up. It doesn't show up when user is interacting AND when user is passive (e.g. unlocking an achievement).

This mean the bug is probably because it cannot hook to the program.

Note: every idea tried was:

Here's what Steamworks Documentation says about Steam Overlay:

Your game does not need to do anything special for the overlay to work, it automatically hooks into any game launched from Steam! While in development and running your game in a debugger, the overlay is loaded when you call SteamAPI_Init. As such you'll need to make sure to call SteamAPI_Init prior to initializing the OpenGL/D3D device, otherwise it won't be able to hook the device creation.

The overlay supports games that use DirectX 7 - 12, OpenGL, Metal, and Vulkan. The overlay will not be active in software-rasterized games.

And from my own experience, I know that browser based game works with Steam overlay (tried with Electron and nw.js).

I tried using steamworks-rs two ways:

fn main() {
    let (client, _single) = match Client::init() {
        Ok((client, _single)) => (client, _single),
        Err(error) => panic!("Error while connecting to Steam: {:?}", error),
    };

    tauri::Builder::default()
        .manage(client)
        .setup(|app| {
            app.asset_protocol_scope().allow_directory(std::env::current_dir()?, true)?;

            Ok(())
        })
        .invoke_handler(tauri::generate_handler![get_steam_id, get_steam_auth_ticket, get_steam_language])
        .run(tauri::generate_context!())
        .expect("error while running tauri application");
}

or

    tauri::Builder::default()
        .setup(|app| {
            app.asset_protocol_scope().allow_directory(std::env::current_dir()?, true)?;

            let (client, _single) = match Client::init() {
                Ok((client, _single)) => (client, _single),
                Err(error) => panic!("Error while connecting to Steam: {:?}", error),
            };

            app.manage(client);

            println!("Setup");

            Ok(())
        })
        .invoke_handler(tauri::generate_handler![get_steam_id, get_steam_auth_ticket, get_steam_language])
        .run(tauri::generate_context!())
        .expect("error while running tauri application");

But it doesn't work. Note that Client::init() calls SteamAPI_init under the hood, see this function in steamworks-rs repo.

I don't know a lot about Tauri internals or lifecycle, so maybe I missed something. That's why I'm here. Does someone in the team understand what could be my bug ?

I understand that Tauri isn't made for games, but maybe it's a bug from my usage and someone can help me 😄

Thanks !

Platform and versions

Environment › OS: Windows 10.0.22621 X64 › Webview2: 109.0.1518.70 › MSVC:

Packages › @tauri-apps/cli [NPM]: 1.2.3 › @tauri-apps/api [NPM]: 1.2.0 › tauri [RUST]: 1.2.4, › tauri-build [RUST]: 1.2.1, › tao [RUST]: 0.15.8, › wry [RUST]: 0.23.4,

App › build-type: build › CSP: default-src 'self'; img-src 'self' asset: https://asset.localhost; connect-src http://localhost:9876 ws://localhost:9876 › distDir: ../dist › devPath: http://localhost:1420/ › framework: React › bundler: Vite

App directory structure ├─ .git ├─ .github ├─ dist ├─ i18n ├─ node_modules ├─ public ├─ src ├─ src-tauri └─ steam-dll

amrbashir commented 1 year ago

Maybe related to https://github.com/tauri-apps/wry/issues/451 but you could try opening the overlay manually using https://partner.steamgames.com/doc/api/ISteamFriends#ActivateGameOverlay just to see if the overlay is attached correctly.

Elanis commented 1 year ago

Hi, I tried indeed and it doesn't work. I tried:

None of these ideas shows anything over the game (Overlay or notifications) :/ So, that's why I'm guessing it's really not hooking.

amrbashir commented 1 year ago

Ah I think I understand now, if I understand the following correctly,

As such you'll need to make sure to call SteamAPI_Init prior to initializing the OpenGL/D3D device, otherwise it won't be able to hook the device creation.

then steam injects its overlay into the OpenGL/D3D APIs, however, tauri doesn't use any of these directly and I am not sure how the WebView2 renders tbh since its code is closed-source.

I will close this as I don't see it as a bug but if you want, open an issue upstream in WebView2 repo, maybe it is worth discussing steam integration with webview2.

Elanis commented 1 year ago

Thanks for your feedback, I will try to get informations on WebView2 repo, it's worth trying :)

skymen commented 1 year ago

For anyone wondering, here's an interesting article made by the lead developer of Construct about that issue of rendering the Steam Overlay over WebView2 https://www.construct.net/en/blogs/ashleys-blog-2/trying-show-steam-overlay-1861

I don't think there's anything that Tauri can do to fix this. It either needs to be fixed by WebView2 or by Steam

CosmoLau commented 4 weeks ago

What's new on this issue?

Elanis commented 4 weeks ago

Not working yet and I didn't have time to contact Valve or try more things. For the moment, I accepted I wouldn't have a Steam overlay.