Repository: tauri-apps/tauri (language: rust)

Issue:
[bug] follow offical document create Window Customization occur error?
### Describe the bug

I follow the official documents exactly,But It not effect.
![5](https://github.com/user-attachments/assets/adeed7d8-af57-437b-8c25-bbf2ddcaf78f)
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:
```console 
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


<img width="833" alt="20241110232330" src="https://github.com/user-attachments/assets/da892406-f0b9-4277-9321-7de0fd22234d">

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

```text
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

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


### Additional context

_No response_


Discussion / hints:
What if you leave `app > security > capabilities` empty and only keep `src-tauri/capabilities/default.json5`?
> 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
Hmm, that's weird, does it work if you convert the capability file from json5 to json?
> 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 ?
Probably a bug then, I'll take a look into it

Fix patch:
diff --git a/.changes/json5-capability-files.md b/.changes/json5-capability-files.md
new file mode 100644
index 000000000000..b0fe7fb54699
--- /dev/null
+++ b/.changes/json5-capability-files.md
@@ -0,0 +1,6 @@
+---
+"tauri": patch:bug
+"tauri-utils": patch:bug
+---
+
+Fix `.json5` capability files not recognized even with `config-json5` feature enabled
diff --git a/crates/tauri-utils/src/acl/build.rs b/crates/tauri-utils/src/acl/build.rs
index d32eb0232846..12ce4e9e0a84 100644
--- a/crates/tauri-utils/src/acl/build.rs
+++ b/crates/tauri-utils/src/acl/build.rs
@@ -34,7 +34,12 @@ pub const PERMISSION_FILE_EXTENSIONS: &[&str] = &["json", "toml"];
 pub const PERMISSION_DOCS_FILE_NAME: &str = "reference.md";
 
 /// Allowed capability file extensions
-const CAPABILITY_FILE_EXTENSIONS: &[&str] = &["json", "toml"];
+const CAPABILITY_FILE_EXTENSIONS: &[&str] = &[
+  "json",
+  #[cfg(feature = "config-json5")]
+  "json5",
+  "toml",
+];
 
 /// Known folder name of the capability schemas
 const CAPABILITIES_SCHEMA_FOLDER_NAME: &str = "schemas";
diff --git a/crates/tauri-utils/src/acl/capability.rs b/crates/tauri-utils/src/acl/capability.rs
index 9ac56f3ed83c..d5aeb3a79eac 100644
--- a/crates/tauri-utils/src/acl/capability.rs
+++ b/crates/tauri-utils/src/acl/capability.rs
@@ -267,6 +267,8 @@ impl CapabilityFile {
     let file: Self = match ext.as_str() {
       "toml" => toml::from_str(&capability_file)?,
       "json" => serde_json::from_str(&capability_file)?,
+      #[cfg(feature = "config-json5")]
+      "json5" => json5::from_str(&capability_file)?,
       _ => return Err(super::Error::UnknownCapabilityFormat(ext)),
     };
     Ok(file)
diff --git a/crates/tauri-utils/src/acl/mod.rs b/crates/tauri-utils/src/acl/mod.rs
index 40e475fde51c..7821b7c068ba 100644
--- a/crates/tauri-utils/src/acl/mod.rs
+++ b/crates/tauri-utils/src/acl/mod.rs
@@ -103,6 +103,11 @@ pub enum Error {
   #[error("failed to parse JSON: {0}")]
   Json(#[from] serde_json::Error),
 
+  /// Invalid JSON5 encountered
+  #[cfg(feature = "config-json5")]
+  #[error("failed to parse JSON5: {0}")]
+  Json5(#[from] json5::Error),
+
   /// Invalid permissions file format
   #[error("unknown permission format {0}")]
   UnknownPermissionFormat(String),


Test patch: