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

[bug] The IconMenuItem icon cannot be used in a webview #10563

Open solid-component opened 3 months ago

solid-component commented 3 months ago

Describe the bug

const toImage = async () => {
  return new Promise((resolve) => {
    const img = new Image();
    img.src = logo;
    img.onload = () => {
      requestAnimationFrame(() => {
        // 创建canvas元素
        let canvas = document.createElement("canvas");
        document.body.append(canvas);
        canvas.width = img.width;
        canvas.height = img.height;
        let ctx = canvas.getContext("2d")!;

        const imageData = ctx.createImageData(100, 100);

        // 遍历每个像素点
        for (let i = 0; i < imageData.data.length; i += 4) {
          // 修改像素数据
          imageData.data[i + 0] = 190; // R 值
          imageData.data[i + 1] = 0; // G 值
          imageData.data[i + 2] = 210; // B 值
          imageData.data[i + 3] = 0; // A 值
        }

        //   const imageData = ctx.getImageData(0,0, canvas.width, canvas.height)
        resolve(new Uint8Array(imageData.data.buffer));
      });
    };
  });
};

const submenu = async (menuText: string, text: string) => {
  const icon = await toImage();
  let res = await Submenu.new({
    text: menuText,
    enabled: true,
    items: [
      await IconMenuItem.new({
        icon,
        enabled: true,
        //   icon: new Uint8Array([0, 0, 0, 1]),
        text: "icon menu",
      }),
      await MenuItem.new({
        text,
        enabled: true,
        action() {
          console.log(`点击了${menuText}-${text}`);
        },
      }),
    ],
  });
  return res;
};

error: Unhandled Promise Rejection: invalid args options for command new: data did not match any variant of untagged enum Icon

Reproduction

No response

Expected behavior

No response

Full tauri info output

[✔] Environment
    - OS: Mac OS 14.1.0 X64
    ✔ Xcode Command Line Tools: installed
    ✔ rustc: 1.75.0 (82e1608df 2023-12-21)
    ✔ cargo: 1.75.0 (1d8b05cdd 2023-11-20)
    ✔ rustup: 1.26.0 (2023-04-05)
    ✔ Rust toolchain: stable-aarch64-apple-darwin (default)
    - node: 22.2.0
    - pnpm: 8.13.1
    - npm: 10.7.0
    - bun: 1.0.30

[-] Packages
    - tauri [RUST]: 2.0.0-rc.0
    - tauri-build [RUST]: 2.0.0-rc.0
    - wry [RUST]: 0.41.0
    - tao [RUST]: 0.28.1
    - @tauri-apps/api [NPM]: 2.0.0-rc.0
    - @tauri-apps/cli [NPM]: 2.0.0-rc.1

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

Stack trace

No response

Additional context

No response

lucasfernog commented 1 month ago

I can't really reproduce this, can you share the logo you're using?