Skip to content

Javascript API monitor functions don't work #2294

@woubuc

Description

@woubuc

Describe the bug

In the window API, the currentMonitor(), primaryMonitor() and availableMonitors() functions don't work. They call an incorrect command from the JS side which causes an error.

To Reproduce

Steps to reproduce the behavior:

  1. In a project with the JS API enabled, use any of the above functions.
  2. See an error in the Javascript console:

unknown variant primaryMonitor, expected createWebview or manage

Additional context

These three functions are standalone functions and call a top-level Tauri command, which is expected to be a variant of the Cmd enum. But these commands are actually in the WindowManagerCmd enum and should be invoked with a window label.

So I think a fix would be to move all three of these functions into the WebviewWindow class and call them with the current window label as a window command. Unless the availableMonitors() and primaryMonitor() functions should be standalone commands, in which case the Rust side will need to be updated to accept these as a top-level command.

Platform and Versions (required):

Operating System - Windows, version 10.0.19042 X64
Webview2 - 92.0.902.55

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

Global packages
  npm - 6.14.11
  yarn - 1.22.4

Rust environment
  rustc - 1.53.0
  cargo - 1.53.0

App directory structure
/.idea
/.nuxt
/assets
/components
/i18n
/layouts
/mixins
/node_modules
/pages
/plugins
/src-tauri
/static
/types
/utils

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
  framework - Vue.js (Nuxt)
  bundler - Webpack

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions