Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[bug] Differences in behavior between appWindow.listen() and listen() #4493

Closed
icambron opened this issue Jun 27, 2022 · 4 comments
Closed

Comments

@icambron
Copy link
Contributor

Describe the bug

appWindow.listen() isn't triggered by window.emit_to or window.emit_all calls, whereas listen() is. My conversation on Discord with @FabianLars suggested this wasn't supposed to the case.

Reproduction

Given some JS code like:

import { listen } from "@tauri-apps/api/event";
import { appWindow } from "@tauri-apps/api/window";

listen("foo", e => console.log("foo", e);
appWindow.listen("bar", e => console.log("bar", e));

and Rust like:

window.emit("foo", "payload"); // works
window.emit_to("main", "foo", "payload") // works
window.emit_all("foo", "payload") // works

window.emit("bar", "payload"); //works
window.emit_to("main", "bar", "payload") // does NOT work
window.emit_all("bar", "payload") // does NOT work

Expected behavior

No response

Platform and versions

❯ yarn tauri info                                                                                                                                                                
yarn run v1.22.17                                                                                                                                                                
$ /Users/isaac/code/lqbk/blot3/node_modules/.bin/tauri info                                                                                                                      
                                                                                                                                                                                 
Environment                                                                                                                                                                      
  › OS: Mac OS 12.4.0 X64                                                                                                                                                        
  › Node.js: 18.4.0                                                                                                                                                              
  › npm: 8.12.1                                                                                                                                                                  
  › pnpm: Not installed!                                                                                                                                                         
  › yarn: 1.22.17                                                                                                                                                                
  › rustup: 1.24.3                                                                                                                                                               
  › rustc: 1.61.0                                                                                                                                                                
  › cargo: 1.61.0                                                                                                                                                                
  › Rust toolchain: stable-aarch64-apple-darwin                                                                                                                                  
                                                                                                                                                                                 
Packages                                                                                                                                                                         
  › @tauri-apps/cli [NPM]: 1.0.0                                                                                                                                                 
  › @tauri-apps/api [NPM]: 1.0.1                                                                                                                                                 
  › tauri [RUST]: 1.0.0,                                                                                                                                                         
  › tauri-build [RUST]: 1.0.0,                                                                                                                                                   
  › tao [RUST]: 0.11.2,                                                                                                                                                          
  › wry [RUST]: 0.18.3,                                                                                                                                                          
                                                                                                                                                                                 
App                                                                                                                                                                              
  › build-type: bundle                                                                                                                                                           
  › CSP: default-src blob: data: filesystem: ws: wss: http: https: tauri: asset: customprotocol: 'unsafe-eval' 'unsafe-inline' 'self' img-src: 'self'                            
  › distDir: ../dist                                                                                                                                                             
  › devPath: http://localhost:3000/                                                                                                                                              
  › framework: React                                                                                                                                                             
                                                                                                                                                                                 
App directory structure                                                                                                                                                          
  ├─ types                                                                                                                                                                       
  ├─ test                                                                                                                                                                        
  ├─ dist                                                                                                                                                                        
  ├─ node_modules                                                                                                                                                                
  ├─ browser                                                                                                                                                                     
  ├─ public                                                                                                                                                                      
  ├─ src-tauri                                                                                                                                                                   
  └─ src                                                                                                                                                                         
✨  Done in 7.08s.  


### Stack trace

_No response_

### Additional context

_No response_
@lucasfernog
Copy link
Member

The problem here is that the emit_to and emit_all functions are implemented in the Manager trait, so the logic is shared between Window, App and AppHandle. So we're firing a global event in this case, like we should for the app implementation; but for Window we should mark it as a window-specific event.

@FabianLars
Copy link
Member

@lucasfernog I think this is still not fixed. I completely forgot about the PR and thought we just didn't fix it yet, but i talked about this on discord a few times, and there's this: tauri-apps/plugins-workspace#282 which seems to be fixed if we use the event module instead of appWindow (tauri-apps/plugins-workspace#283)

@lucasfernog lucasfernog reopened this Mar 15, 2023
@lucasfernog
Copy link
Member

https://tauri.app/v1/api/js/window#listen
Listen to an event emitted by the backend that is tied to the webview window.
it's expected (and confusing) behavior.. the global listener can receive window-specific events, but not the other way around

@lucasfernog
Copy link
Member

Though revisiting the entire event system this totally feel like a bug. emit_all not reaching all windows is just nonsense. Easy fix though.

lucasfernog added a commit that referenced this issue Jun 8, 2023
This was documented behavior in some functions, but unexpected in other cases. This PR clarifies the event system and also adds examples to all APIs.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants