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.73k stars 2.59k forks source link

[bug] #11526

Closed ribborges closed 1 month ago

ribborges commented 1 month ago

Describe the bug

I'm using react with tauri (V2) to create an app, but my customized window controls aren't working. Have i done something wrong?

The app renders correctly, but the buttons don't work.

Reproduction

Here is the WindowControl component code:

import { ReactNode, useEffect, useState } from "react";
import { getCurrentWindow, Window } from '@tauri-apps/api/window';

export default function WindowControl() {
    const [appWindow, setAppWindow] = useState<Window>()

    async function setupAppWindow() {
        setAppWindow(await getCurrentWindow());
    }

    useEffect(() => {
        setupAppWindow()
    }, [])

    function windowMinimize() {
        appWindow?.minimize()
    }
    function windowToggleMaximize() {
        appWindow?.toggleMaximize()
    }
    function windowClose() {
        appWindow?.close()
    }

    return (
        <div data-tauri-drag-region className="titlebar">
            <button
                onClick={windowClose}
            >X</button>
            <button
                onClick={windowToggleMaximize}
            >[]</button>
            <button
                onClick={windowMinimize}
            >_</button>
        </div>
    );
}

Expected behavior

No response

Full tauri info output

> tauri-native@1.0.0 tauri
> tauri info

[✔] Environment
    - OS: Pop!_OS 24.4.0 x86_64 (X64)
    ✔ webkit2gtk-4.1: 2.46.1
    ✔ rsvg2: 2.58.0
    ✔ rustc: 1.82.0 (f6e511eec 2024-10-15)
    ✔ cargo: 1.82.0 (8f40fc59f 2024-08-21)
    ✔ rustup: 1.27.1 (54dd3d00f 2024-04-24)
    ✔ Rust toolchain: stable-x86_64-unknown-linux-gnu (default)
    - node: 20.18.0
    - npm: 10.8.2

[-] Packages
    - tauri 🦀: 2.0.6
    - tauri-build 🦀: 2.0.2
    - wry 🦀: 0.46.3
    - tao 🦀: 0.30.3
    - @tauri-apps/api : 2.0.3
    - @tauri-apps/cli : 2.0.5

[-] Plugins
    - tauri-plugin-log 🦀: 2.0.1
    - @tauri-apps/plugin-log : not installed!

[-] App
    - build-type: bundle
    - CSP: unset
    - frontendDist: ../build
    - devUrl: http://localhost:8081/
    - framework: React

Stack trace

No response

Additional context

No response

amrbashir commented 1 month ago

what does your capability file look like? does it have the necessary permissions? check the devtools console for errors.

ribborges commented 1 month ago

My capabilities file:

{
  "$schema": "../gen/schemas/desktop-schema.json",
  "identifier": "default",
  "description": "enables the default permissions",
  "windows": [
    "main"
  ],
  "permissions": [
    "core:default",
    "core:window:default",
    "core:window:allow-start-dragging"
  ]
}

I added the "core:window:default" and "core:window:allow-start-dragging" as it shows in the documentation: https://v2.tauri.app/plugin/window-customization/

amrbashir commented 1 month ago

you also need the other permissions mentioned in that page.

ribborges commented 1 month ago

God, i feel so dumb right now 😅 Thank you