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] the Monitor class not correctly initialize #4672

Closed
parrotdance opened this issue Jul 14, 2022 · 5 comments
Closed

[bug] the Monitor class not correctly initialize #4672

parrotdance opened this issue Jul 14, 2022 · 5 comments
Labels
status: needs triage This issue needs to triage, applied to new issues type: bug

Comments

@parrotdance
Copy link

Describe the bug

const monitor = await currentMonitor()
if (monitor) {
  const { size, scaleFactor } = monitor
  size.toLogical(scaleFactor); // <--- [Error] toLogical does not exist on size
}

I have searched and read #2599 and #2621, and I think if we return a Monitor instance here:

/**
 * Returns the monitor on which the window currently resides.
 * Returns `null` if current monitor can't be detected.
 */
async function currentMonitor(): Promise<Monitor | null> {
  return invokeTauriCommand({
    __tauriModule: 'Window',
    message: {
      cmd: 'manage',
      data: {
        cmd: {
          type: 'currentMonitor'
        }
      }
    }
  })
} // .then(res => new Monitor( ... ))

this problem might be solved.

Reproduction

No response

Expected behavior

No response

Platform and versions

$ yarn tauri info
  › Node.js: 16.14.2
  › npm: 8.5.0
  › pnpm: Not installed!
  › yarn: 1.22.17
  › rustup: 1.24.3
  › rustc: 1.62.0
  › cargo: 1.62.0
  › Rust toolchain: stable-x86_64-pc-windows-msvc

Packages
  › @tauri-apps/cli [NPM]: 1.0.3
  › @tauri-apps/api [NPM]: 1.0.2
  › tauri [RUST]: 1.0.3,
  › tauri-build [RUST]: 1.0.3,
  › tao [RUST]: 0.12.1,
  › wry [RUST]: 0.19.0,

App
  › build-type: bundle
  › CSP: unset
  › distDir: ../dist
  › devPath: http://localhost:3000/

App directory structure
  ├─ node_modules
  ├─ src
  └─ src-tauri
Done in 14.76s.

Stack trace

No response

Additional context

No response

@parrotdance parrotdance added status: needs triage This issue needs to triage, applied to new issues type: bug labels Jul 14, 2022
@parrotdance
Copy link
Author

parrotdance commented Jul 14, 2022

In fact I think we should not solve problems like this one-by-one.

There should be another layer like factory function to receive all return value of invokeTauriCommand and output a correctly initialized JS value.

Or find a way to convert tagged rust trait method into JS class method. Which looks not easy, and needs to consider about much of edge cases and constraints.

@lucasfernog
Copy link
Member

I think it'll be easier to manage this in the function itself, converting the JSON object to the correct class.

@parrotdance
Copy link
Author

parrotdance commented Jul 14, 2022

@lucasfernog but how to map a JSON object to the correct class? create a wrapper json object with the origin object and a class name identifier?

@lucasfernog
Copy link
Member

The class interface should be adapted for each case. Same as #2621 we need to map the size and position fields of the Monitor to its classes.

@parrotdance
Copy link
Author

parrotdance commented Jul 15, 2022

@lucasfernog I am not sure if I totally understand your opinion, but if you mean to use the same solution as #2621 to solve this problem, I will happy to try to handle this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: needs triage This issue needs to triage, applied to new issues type: bug
Projects
None yet
Development

No branches or pull requests

2 participants