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.52k stars 2.58k forks source link

[bug] follow offical document create Window Customization occur error? #11637

Closed 3517277 closed 1 week ago

3517277 commented 2 weeks ago

Describe the bug

I follow the official documents exactly,But It not effect. 5 but I refer to issue answer to delete src-tauri/capabilities/default.json5 conmment and add to tauri.config.json,then it is work order!look like this:

  "$schema": "https://schema.tauri.app/config/2.0.0",
  "productName": "tauri-app",
  "version": "0.1.0",
  "identifier": "com.kitsen.app",
  "build": {
    "beforeDevCommand": "deno task dev",
    "devUrl": "http://localhost:1420",
    "beforeBuildCommand": "deno task build",
    "frontendDist": "../dist"
  },
  "app": {
    "windows": [
      {
        "title": "tauri-app",
        "label" : "main",
        "width": 800,
        "height": 600,
        "decorations": false
      }
    ],
    "security": {
      "csp": null,
      "capabilities": [
        {
          "identifier": "title-bar",
          "windows": [
            "*"
          ],
          "permissions": [
            "core:window:allow-start-dragging",
            "core:window:allow-minimize",
            "core:window:allow-toggle-maximize",
            "core:window:allow-close",
            "core:window:allow-internal-toggle-maximize"
          ]
        }
      ]
    },
    "withGlobalTauri": true
  },
  "bundle": {
    "active": true,
    "targets": "all",
    "icon": [
      "icons/32x32.png",
      "icons/128x128.png",
      "icons/128x128@2x.png",
      "icons/icon.icns",
      "icons/icon.ico"
    ]
  }
}```

why? So I do like this :
1、add comment in [src-tauri/capabilities/default.json5]
```{
  "$schema": "../gen/schemas/desktop-schema.json",
  "identifier": "default",
  "description": "Capability for the main window",
  "windows": [
    "*"
  ],
  "permissions": [
    "core:default",
    "shell:allow-open",
    "http:default",
    "store:default",
    "core:window:default", // 除core:window:allow-start-dragging外的默认
    "core:window:allow-close", //"core:window:allow-close",  // 启用关闭命令
    "core:window:allow-minimize", //"core:window:allow-minimize", // 启用最小化命令
    "core:window:allow-start-dragging", // 启用拖曳命令
    "core:window:allow-toggle-maximize", // 启用最大化命令
    "core:window:allow-internal-toggle-maximize", // 启用internal_toggle_maximize 命令,无需任何预先配置的范围。
    {
      "identifier": "http:default",
      "allow": [
        {
          "url": "http:*"
        },
        {
          "url": "https:*"
        }
      ]
    }
  ]
}

2、edit [tauri.config.json]

  "$schema": "https://schema.tauri.app/config/2.0.0",
  "productName": "tauri-app",
  "version": "0.1.0",
  "identifier": "com.kitsen.app",
  "build": {
    "beforeDevCommand": "deno task dev",
    "devUrl": "http://localhost:1420",
    "beforeBuildCommand": "deno task build",
    "frontendDist": "../dist"
  },
  "app": {
    "windows": [
      {
        "title": "tauri-app",
        "label" : "main",
        "width": 800,
        "height": 600,
        "decorations": false
      }
    ],
    "security": {
      "csp": null,
      "capabilities": [
        "default"
      ]
    },
    "withGlobalTauri": true
  },
  "bundle": {
    "active": true,
    "targets": "all",
    "icon": [
      "icons/32x32.png",
      "icons/128x128.png",
      "icons/128x128@2x.png",
      "icons/icon.icns",
      "icons/icon.ico"
    ]
  }
}

compile ..... It panic:

error: proc macro panicked                                  
  --> src\lib.rs:14:14
   |
14 |         .run(tauri::generate_context!())
   |              ^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = help: message: capability with identifier default not found

error: could not compile `tauri-app` (lib) due to 1 previous error

I expnad tauri::generate_context!(),the code look like this

20241110232330

so,is this has bug?After Defulat::default an empty BtreeMap, Next,remove item in it ?Is It always error?

Reproduction

No response

Expected behavior

No response

Full tauri info output

WARNING: no lock files found, defaulting to npm

[✔] Environment
    - OS: Windows 10.0.22631 x86_64 (X64)
    ✔ WebView2: 130.0.2849.56
    ✔ MSVC: Visual Studio Community 2022
    ✔ 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-pc-windows-msvc (environment override by RUSTUP_TOOLCHAIN)
    - node: 20.11.0
    - pnpm: 8.15.1
    - yarn: 1.22.22
    - npm: 10.2.4
    - bun: 1.1.30

[-] Packages
    - tauri 🦀: 2.1.0
    - tauri-build 🦀: 2.0.3
    - wry 🦀: 0.47.0
    - tao 🦀: 0.30.6
    - tauri-cli 🦀: 2.0.2
    - @tauri-apps/api : 2.0.3
    - @tauri-apps/cli : 2.0.2

[-] Plugins
    - tauri-plugin-shell 🦀: 2.0.2
    - @tauri-apps/plugin-shell : 2.0.1
    - tauri-plugin-fs 🦀: 2.0.3
    - @tauri-apps/plugin-fs : not installed!
    - tauri-plugin-store 🦀: 2.1.0
    - @tauri-apps/plugin-store : 2.0.0
    - tauri-plugin-http 🦀: 2.0.3
    - @tauri-apps/plugin-http : 2.0.1

[-] App
    - build-type: bundle
    - CSP: unset
    - frontendDist: ../dist
    - devUrl: http://localhost:1420/
    - framework: Vue.js
    - bundler: Vite

Stack trace

window.close not allowed. Permissions associated with this command: window:allow-close

Additional context

No response

Legend-Master commented 2 weeks ago

What if you leave app > security > capabilities empty and only keep src-tauri/capabilities/default.json5?

3517277 commented 2 weeks ago

What if you leave app > security > capabilities empty and only keep src-tauri/capabilities/default.json5?

Then you run success,but it tips :“window.close not allowed. Permissions associated with this command: window:allow-close ” when you close or min or max

Legend-Master commented 2 weeks ago

Hmm, that's weird, does it work if you convert the capability file from json5 to json?

3517277 commented 1 week ago

Hmm, that's weird, does it work if you convert the capability file from json5 to json?

Yes,convert the capability file and tauri.config file from json5 to josn. it does working properly.But why?Is it a bug ?

Legend-Master commented 1 week ago

Probably a bug then, I'll take a look into it

3517277 commented 1 week ago

Probably a bug then, I'll take a look into it

Thank you, I will pay attention to the version update