Skip to content

Calling unlisten from JavaScript removes all listeners #2264

@Florob

Description

@Florob

Describe the bug

Calling any unlisten() function returned by a listen() call remove all callbacks registered through listen().

To Reproduce

Steps to reproduce the behavior:

  1. Create a new tauri project (or use an existing one)
  2. Add the following code:
import { listen } from "@tauri-apps/api/event";
async function setup() {
  let unlisten = await listen("tauri://blur", () => console.log("blur"));
  await listen("tauri://focus", () => console.log("focus"));;
  await listen("tauri://resize", () => console.log("resize"));;

  unlisten();
}
setup();
  1. Open a console
  2. Resize/focus/blur the window
  3. Observe none of the callbacks are triggered

Expected behavior

Only the callback associated with the unlisten() function should be unregistered.

Platform and Versions (required):

Operating System - Arch Linux, version Rolling Release X64

Node.js environment
  Node.js - 16.5.0
  @tauri-apps/cli - 1.0.0-beta.6
  @tauri-apps/api - 1.0.0-beta.5

Global packages
  npm - 7.17.0
  yarn - 1.22.10

Rust environment
  rustc - 1.53.0
  cargo - 1.53.0

App directory structure
/node_modules
/src
/src-tauri
/.git

App
  tauri.rs - 1.0.0-beta.5
  build-type - bundle
  CSP - default-src blob: data: filesystem: ws: wss: http: https: tauri: 'unsafe-eval' 'unsafe-inline' 'self' img-src: 'self'
  distDir - ../dist
  devPath - http://localhost:3000

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions