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] Tauri auto-migration util fails #9400

Open
aleksey-hoffman opened this issue Apr 7, 2024 · 8 comments · May be fixed by #9545
Open

[bug] Tauri auto-migration util fails #9400

aleksey-hoffman opened this issue Apr 7, 2024 · 8 comments · May be fixed by #9545
Labels
status: needs triage This issue needs to triage, applied to new issues type: bug

Comments

@aleksey-hoffman
Copy link

aleksey-hoffman commented Apr 7, 2024

Describe the bug

Migration util is not working:

npm run tauri migrate

> sigma-file-manager-v2@2.0.0-alpha.1 tauri
> tauri migrate

    Info Replacing `@tauri-apps/api/tauri` with `@tauri-apps/api/core` on C:\Users\aleks\data\projects\sigma-file-manager\src\stores\storage\workspaces.ts
    Info Installing Cargo dependency "tauri-plugin-http"...
    Updating crates.io index
      Adding tauri-plugin-http v2.0.0-beta.4 to dependencies.
             Features:
             - blocking
             - brotli
             - cookies
             - default-tls
             - deflate
             - gzip
             - http3
             - json
             - multipart
             - native-tls
             - native-tls-alpn
             - native-tls-vendored
             - rustls-tls
             - rustls-tls-manual-roots
             - rustls-tls-native-roots
             - rustls-tls-webpki-roots
             - socks
             - stream
             - trust-dns
             - unsafe-headers
    Blocking waiting for file lock on package cache
    Updating crates.io index
error: invalid character `{` in package name: `tauri-plugin-{{name}}`, characters must be Unicode XID characters (numbers, `-`, `_`, or most letters)
 --> ..\..\..\..\.cargo\git\checkouts\plugins-workspace-fd0259fcb18f51ad\5817611\shared\template\Cargo.toml:2:8
  |
2 | name = "tauri-plugin-{{name}}"
  |        ^^^^^^^^^^^^^^^^^^^^^^^
  |
error: failed to select a version for `tauri`.
    ... required by package `sigma-file-manager-v2 v2.0.0-alpha.1 (C:\Users\aleks\data\projects\sigma-file-manager\src-tauri)`
versions that meet the requirements `^2.0.0-beta` are: 2.0.0-beta.14, 2.0.0-beta.13, 2.0.0-beta.12, 2.0.0-beta.11, 2.0.0-beta.10, 2.0.0-beta.9, 2.0.0-beta.8, 2.0.0-beta.7, 2.0.0-beta.6, 2.0.0-beta.5, 2.0.0-beta.4, 2.0.0-beta.3, 2.0.0-beta.2, 2.0.0-beta.1, 2.0.0-beta.0

the package `tauri` links to the native library `Tauri`, but it conflicts with a previous package which links to `Tauri` as well:
package `tauri v2.0.0-beta.14`
    ... which satisfies dependency `tauri = "^2.0.0-beta"` of package `sigma-file-manager-v2 v2.0.0-alpha.1 (C:\Users\aleks\data\projects\sigma-file-manager\src-tauri)`
Only one package in the dependency graph may specify the same links value. This helps ensure that only one copy of a native library is linked in the final binary. Try to adjust your dependencies so that only one package uses the `links = "Tauri"` value. For more information, see https://doc.rust-lang.org/cargo/reference/resolver.html#links.

the package `sigma-file-manager-v2` depends on `tauri`, with features: `window-set-content-protected` but `tauri` does not have these features.


failed to select a version for `tauri` which could resolve this conflict
    Error Failed to install Cargo dependency

Reproduction

Repo: https://github.com/aleksey-hoffman/sigma-file-manager/tree/v2

Following auto-migration guide:

npm install @tauri-apps/cli@next
npm run tauri migrate

Expected behavior

To auto migrate project from v1 to v2

Full tauri info output

[✔] Environment
    - OS: Windows 10.0.22631 X64
    ✔ WebView2: 123.0.2420.81
    ✔ MSVC: Visual Studio Community 2022
    ✔ rustc: 1.77.1 (7cf61ebde 2024-03-27)
    ✔ cargo: 1.77.1 (e52e36006 2024-03-26)
    ✔ rustup: 1.27.0 (bbb9276d2 2024-03-08)
    ✔ Rust toolchain: stable-x86_64-pc-windows-msvc (default)
    - node: 20.12.1
    - pnpm: 8.8.0
    - npm: 10.5.0

[-] Packages
    - tauri [RUST]: 1.6.0
    - tauri-build [RUST]: 1.5.1
    - wry [RUST]: 0.24.7
    - tao [RUST]: 0.16.7
    - tauri-cli [RUST]: 2.0.0-alpha.6
    - @tauri-apps/api [NPM]: 1.5.3
    - @tauri-apps/cli [NPM]: 2.0.0-beta.12

[-] App
    - build-type: bundle
    - CSP: unset
    - frontendDist: ../dist
    - devUrl: http://localhost:5180/
    - framework: Vue.js
    - bundler: Vite
@aleksey-hoffman aleksey-hoffman added status: needs triage This issue needs to triage, applied to new issues type: bug labels Apr 7, 2024
@FabianLars
Copy link
Sponsor Member

The issue should be the store plugin. Try running cargo update before migrate.
If that doesn't work, try changing it's branch to v2 and run cargo update again.
If that also doesn't work, downgrade rust to 1.76 until after the migration (Only 1.77+ is affected by this error message. We fixed the root cause but it needs cargo update to pull the latest commits)

@FabianLars
Copy link
Sponsor Member

Oh, the app didn't load the full error message, apologies. I think the second error can also be fixed by upgrading the store first (or commenting it out while migrating). I think the migrate command currently can't handle v1 plugins.

@aleksey-hoffman
Copy link
Author

I added all the latest cargo dependencies and ran cargo update:

tauri-plugin-store = "2.0.0-beta"
tauri-plugin-dialog = "2.0.0-beta"
tauri-plugin-fs = "2.0.0-beta"
tauri-plugin-shell = "2.0.0-beta"
tauri-plugin-http = "2.0.0-beta"
tauri-plugin-notification = "2.0.0-beta"
tauri-plugin-global-shortcut = "2.0.0-beta"
tauri-plugin-os = "2.0.0-beta"
tauri-plugin-process = "2.0.0-beta"
tauri-plugin-clipboard-manager = "2.0.0-beta"
tauri-plugin-window = "2.0.0-alpha"

but I now get internal Tauri errors:

error[E0432]: unresolved import `tauri::Icon`
 --> C:\Users\aleks\.cargo\registry\src\index.crates.io-6f17d22bba15001f\tauri-plugin-window-2.0.0-alpha.2\src\desktop_commands.rs:8:28
  |
8 |     AppHandle, CursorIcon, Icon, Manager, Monitor, PhysicalPosition, PhysicalSize, Position,
  |                            ^^^^ no `Icon` in the root
  |
  = help: consider importing this variant instead:
          tauri::menu::MenuItemKind::Icon

error[E0603]: struct `WindowBuilder` is private
   --> C:\Users\aleks\.cargo\registry\src\index.crates.io-6f17d22bba15001f\tauri-plugin-window-2.0.0-alpha.2\src\desktop_commands.rs:67:20
    |
67  |     tauri::window::WindowBuilder::from_config(&app, options).build()?;
    |                    ^^^^^^^^^^^^^ private struct
    |
note: the struct `WindowBuilder` is defined here
   --> C:\Users\aleks\.cargo\registry\src\index.crates.io-6f17d22bba15001f\tauri-2.0.0-beta.14\src\window\mod.rs:112:1
    |
112 | / unstable_struct!(
113 | |   #[doc = "A builder for a window managed by Tauri."]
114 | |   struct WindowBuilder<'a, R: Runtime, M: Manager<R>> {
115 | |     manager: &'a M,
...   |
124 | |   }
125 | | );
    | |_^
    = note: this error originates in the macro `unstable_struct` (in Nightly builds, run with -Z macro-backtrace for more info)

Some errors have detailed explanations: E0432, E0603.
For more information about an error, try `rustc --explain E0432`.
error: could not compile `tauri-plugin-window` (lib) due to 2 previous errors

@FabianLars
Copy link
Sponsor Member

remove the window plugin, it's part of the core library again. It's also the plugin mentioned in the error so hopefully that's the (only) issue there.

@aleksey-hoffman
Copy link
Author

aleksey-hoffman commented Apr 12, 2024

@FabianLars I think that worked, thanks!
Could you also let me know how do you get a window in v2 now? The following no longer works:

fn main() {
    tauri::Builder::default()
        .setup(setup_handler)
        .plugin(tauri_plugin_store::Builder::default().build())
        .invoke_handler(tauri::generate_handler![
           ...
        ])
        .run(tauri::generate_context!())
        .expect("error while running tauri application");
}

fn setup_handler(app: &mut tauri::App) -> Result<(), Box<dyn std::error::Error + 'static>> {
    let mut main_window = app.get_window("main").unwrap();
    Ok(())
}

Error:

no method named `get_window` found for mutable reference `&mut tauri::App` in the current scope
method not found in `&mut App`

@FabianLars
Copy link
Sponsor Member

in preparation of multiwebview support, get_window was renamed to get_webview_window

@QiuChenly
Copy link

QiuChenly commented Apr 13, 2024

in preparation of multiwebview support, get_window was renamed to get_webview_window

Thank you reply! it's solved my question about use window-vibrancy 0.5.0 in Tauri v2 beta, now everything are working! thx!!!
image

if anyone have more question, there is my code:

// Prevents additional console window on Windows in release, DO NOT REMOVE!!
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]

// Learn more about Tauri commands at https://tauri.app/v1/guides/features/command
#[tauri::command]
fn greet(name: &str) -> String {
    format!("Hello, {}! You've been greeted from Rust!", name)
}

use tauri::Manager;
use tauri_plugin_autostart::MacosLauncher;
use tauri_plugin_autostart::ManagerExt;
use window_vibrancy::{apply_blur, apply_vibrancy, NSVisualEffectMaterial};

fn main() {
    // `tauri::AppHandle` now has the following additional method
    tauri::Builder::default()
        .plugin(tauri_plugin_fs::init())
        .plugin(tauri_plugin_clipboard_manager::init())
        .plugin(tauri_plugin_autostart::init(
            MacosLauncher::LaunchAgent,
            Some(vec!["--flag1", "--flag2"]),
        ))
        .plugin(tauri_plugin_dialog::init())
        .plugin(tauri_plugin_http::init())
        .plugin(tauri_plugin_os::init())
        .plugin(tauri_plugin_shell::init())
        .plugin(tauri_plugin_window_state::Builder::default().build())
        .setup(|app| {
            let handle = app.app_handle();
            let main_window = handle.get_webview_window("main").unwrap();

            #[cfg(target_os = "macos")]
            apply_vibrancy(
                &main_window,
                NSVisualEffectMaterial::HudWindow,
                None,
                Some(8_f64),
            )
            .expect("Unsupported platform! 'apply_vibrancy' is only supported on macOS");

            #[cfg(target_os = "windows")]
            apply_blur(&main_window, Some((18, 18, 18, 125)))
                .expect("Unsupported platform! 'apply_blur' is only supported on Windows");

            // Get the autostart manager
            let autostart_manager = app.autolaunch();
            // Enable autostart
            let _ = autostart_manager.enable();
            // Check enable state
            println!(
                "registered for autostart? {}",
                autostart_manager.is_enabled().unwrap()
            );
            // Disable autostart
            let _ = autostart_manager.disable();
            Ok(())
        })
        .invoke_handler(tauri::generate_handler![greet])
        .run(tauri::generate_context!())
        .expect("error while running tauri application");
}

@aleksey-hoffman
Copy link
Author

@FabianLars @lucasfernog guys, please consider prioritizing writing some docs for the Rust side.
It's super difficult to migrate the app to v2. For example, Tray no longer works, API changed drastically, and there's no examples in the docs at all:
https://docs.rs/tauri/2.0.0-beta.15/tauri/tray/index.html

@amrbashir amrbashir linked a pull request Apr 22, 2024 that will close this issue
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

Successfully merging a pull request may close this issue.

3 participants