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] getAll() doesn't include windows created in JavaScript. #3297

Closed
XuluWarrior opened this issue Jan 28, 2022 · 9 comments
Closed

[bug] getAll() doesn't include windows created in JavaScript. #3297

XuluWarrior opened this issue Jan 28, 2022 · 9 comments

Comments

@XuluWarrior
Copy link

Describe the bug

If I create a new window in the main WebView, the array returned bygetAll() doesn't include the new window.

Reproduction

  1. Include the following code in the WebView
  import { window as tauriWindow } from '@tauri-apps/api';
  
  const w = new tauriWindow.WebviewWindow('child', {
    title: 'Child',
    resizable: true,
    width: 700,
    height: 600,
    url: "child.html"
  });
  setTimeout(() => console.log('all', tauriWindow.getAll()), 2000); // Wait a bit in case it takes time for windows to be created/updated
  console.log(tauriWindow.getAll());
  1. The output to console only includes the main window.

Expected behavior

I would expect the array returned by getAll() to contain both the main and child windows.

Platform and versions

Operating System - Mac OS, version 11.6.2 X64

Node.js environment
  Node.js - 14.18.2
  @tauri-apps/cli - 1.0.0-beta.10
  @tauri-apps/api - 1.0.0-beta.8

Global packages
  npm - 6.14.15
  yarn - 1.22.17

Rust environment
  rustc - 1.57.0
  cargo - 1.57.0

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

App
  tauri.rs - 1.0.0-beta.8 (I am actually running { git = "https://github.com/tauri-apps/tauri", branch = "next" } )
  build-type - bundle
  CSP - default-src blob: data: filesystem: ws: wss: http: https: tauri: 'unsafe-eval' 'unsafe-inline' 'self' img-src: 'self'
  distDir - ../build
  devPath - http://localhost:3000
  framework - React

Stack trace

No response

Additional context

No response

@lucasfernog
Copy link
Member

I couldn't reproduce it on the API example. Did you try increasing the timeout value?

@XuluWarrior
Copy link
Author

I have tried it manually in the console and never see child in the returned values.

What do you mean by the API example? I can try that too?

@lucasfernog
Copy link
Member

The API example is located here https://github.com/tauri-apps/tauri/tree/next/examples/api but you need to setup the repo in order to use it.

@XuluWarrior
Copy link
Author

This is the branch I'm using that reproduces the issue. Based off a project generated using create-tauri-app

https://github.com/tallarium/tauri-experiments/tree/next/get-all

@lucasfernog
Copy link
Member

I see that. Let me see what is the problem.

@lucasfernog
Copy link
Member

You're creating the window before the Tauri event system is ready and the tauri://window-created event (which is used to update the windows array) is lost. If I change setup() to setTimeout(setup, 2000) it works. I'll see what I can do to fix this, we had a queue for this purpose but IIRC it wasn't needed anymore.

@XuluWarrior
Copy link
Author

Adding the timeout does work 👍🏾

If an event queue isn't an option would it be sensible to have an app.isReady promise/callback?
Somewhere to put calls that require the necessary plumbing is in place before running.

@XuluWarrior
Copy link
Author

Alternatively, maybe windows creation should be blocked/queued until the event system is ready.

@iSplasher
Copy link

Adding the timeout does work 👍🏾

If an event queue isn't an option would it be sensible to have an app.isReady promise/callback? Somewhere to put calls that require the necessary plumbing is in place before running.

Something like app.isReady would be great.

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