tauri-apps / tauri

Build smaller, faster, and more secure desktop applications with a web frontend.
https://tauri.app
Apache License 2.0
79.91k stars 2.37k forks source link

[bug] [v2] Some of the corrections made by the migration tool are incorrect. #10192

Closed mikoto2000 closed 5 days ago

mikoto2000 commented 1 week ago

Describe the bug

When using the migration tool, the following parts were incorrectly corrected, causing an error.

  1. import { convertFileSrc } from '@tauri-apps/api/tauri' -> import { convertFileSrc } from 'core'
  2. import { appWindow } from '@tauri-apps/api/window' -> import { appWindow } from 'webviewWindow'
  3. (Related to 2.) appWindow -> not change(appWindow not defined)
  4. import { dialog } from '@tauri-apps/api' -> not change

These have been corrected as follows.

  1. Change to import { convertFileSrc } from '@tauri-apps/api/core'
  2. Change to import { appWindow } from '@tauri-apps/api/webviewWindow'
  3. Changed appWindow to getCurrent and other appWindow same changes.
  4. Change to import { open } from '@tauri-apps/plugin-dialog'

For 1. and 2., we will probably need to update this process.

https://github.com/tauri-apps/tauri/blob/11aa7743e7a277ed9ec3e92040dc484afe77d261/tooling/cli/src/migrate/frontend.rs#L57-L59

I don't think the migration tool can handle 3. and 4., but I wanted to report it just in case.

Reproduction

git clone http://github.com/mikoto2000/scab-player
cd scab-player
npm i @tauri-apps/cli@next @tauri-apps/api@next
npm run tauri migrate
npm run tauri dev

Expected behavior

This error should not occur.

Full tauri info output

node@ea91fd36a6f2:/workspaces/scab-player3$ npm run tauri info

> scab-player@0.1.0 tauri
> tauri info

[✔] Environment
    - OS: Debian 12.0.0 X64
    ✔ webkit2gtk-4.1: 2.44.2
    ✔ rsvg2: 2.54.7
    ✔ rustc: 1.78.0 (9b00956e5 2024-04-29)
    ✔ cargo: 1.78.0 (54d8815d0 2024-03-26)
    ✔ rustup: 1.27.1 (54dd3d00f 2024-04-24)
    ✔ Rust toolchain: stable-x86_64-unknown-linux-gnu (default)
    - node: 22.2.0
    - yarn: 1.22.19
    - npm: 10.7.0

[-] Packages
    - tauri [RUST]: 2.0.0-beta.22
    - tauri-build [RUST]: 2.0.0-beta.17
    - wry [RUST]: 0.40.1
    - tao [RUST]: 0.28.1
    - @tauri-apps/api [NPM]: 2.0.0-beta.13
    - @tauri-apps/cli [NPM]: 2.0.0-beta.20

[-] App
    - build-type: bundle
    - CSP: default-src 'self'; connect-src ipc: http://ipc.localhost; media-src stream: http://stream.localhost asset: http://asset.localhost
    - frontendDist: ../build
    - devUrl: http://localhost:3000/
    - framework: React

Stack trace

no stac trace.

Additional context

No response

amrbashir commented 1 week ago

I opened a PR for this:

mikoto2000 commented 1 week ago

@amrbashir Thank you for fix and comment!

And sorry, there were some omissions in reporting some steps regarding the dialogues. There may have been a problem with these steps.

1. Remove "rlib" in "Cargo.toml"

Added the following to Cargo.toml according to Upgrade from Tauri 1.0 | Tauri

[lib]
name = "app_lib"
crate-type = ["staticlib", "cdylib", "rlib"]

I got this error:

Compiled successfully!

You can now view scab-player in the browser.

  Local:            http://localhost:3000
  On Your Network:  http://172.17.0.3:3000

Note that the development build is not optimized.
To create a production build, use npm run build.

webpack compiled successfully
Files successfully emitted, waiting for typecheck results...
Issues checking in progress...
No issues found.
    Info Watching /home/node/scab-player2/src-tauri for changes...
warning: output filename collision.
The lib target `app_lib` in package `scab-player v0.1.0 (/home/node/scab-player2/src-tauri)` has the same output filename as the lib target `app_lib` in package `scab-player v0.1.0 (/home/node/scab-player2/src-tauri)`.
Colliding filename is: /home/node/scab-player2/src-tauri/target/debug/deps/libapp_lib.rlib
The targets should have unique names.
Consider changing their names to be unique or compiling them separately.
This may become a hard error in the future; see <https://github.com/rust-lang/cargo/issues/6313>.
thread 'main' panicked at src/cargo/core/compiler/fingerprint/mod.rs:1103:13:
assertion failed: mtimes.insert(output.clone(), mtime).is_none()
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

The template created by npm create tauri-app@latest -- --beta did not include rlib, so I removed rlib.

2. Migrate tool is not change @tauri-apps/api to 2.x.x-beta.xx.

I change to 2.0.0-beta.14 manually. (Is there any intention for the migration tool not to change this?)

I create minimum code(repository: mikoto2000/TauriMigrationExample).

App.tsx:

import { dialog } from '@tauri-apps/api'

import './App.css';

function App() {

  async function selectChannelBaseDirectory() {
    const _ = await dialog.open({
      title: "Select channel base directory",
      directory: true
    });
  }

  return (
    <div className="App">
      <button onClick={selectChannelBaseDirectory} >チャンネル選択</button>
    </div>
  );
}

export default App;

From Migrate to Dialog Plugin - Upgrade from Tauri 1.0 | Tauri, dialog is need migrate to plugin-dialog.

So, expected result is this(But I didn't change the migration tool):

import { open } from '@tauri-apps/plugin-dialog';

import './App.css';

function App() {

  async function selectChannelBaseDirectory() {
    await open({
      title: "Select channel base directory",
      directory: true
    });
  }

  return (
    <div className="App">
      <button onClick={selectChannelBaseDirectory} >チャンネル選択</button>
    </div>
  );
}

export default App;
amrbashir commented 1 week ago

in the dialog example you provided,

import { dialog } from '@tauri-apps/api';

will change to

import dialog from '@tauri-apps/plugin-dialog';

so the rest of the code should work

mikoto2000 commented 1 week ago

@amrbashir Got it, understood. Thank you for the corrections!