From 24582f38213e7717af9c20f8c8fbb96de0430ce9 Mon Sep 17 00:00:00 2001 From: Lucas Nogueira Date: Mon, 31 Jul 2023 20:52:33 -0300 Subject: [PATCH 1/7] feat: add upgrade guide --- .../docs/2/guide/upgrade-migrate/index.mdx | 754 ++++++++++++++++++ 1 file changed, 754 insertions(+) create mode 100644 src/content/docs/2/guide/upgrade-migrate/index.mdx diff --git a/src/content/docs/2/guide/upgrade-migrate/index.mdx b/src/content/docs/2/guide/upgrade-migrate/index.mdx new file mode 100644 index 0000000000..c36a8efc96 --- /dev/null +++ b/src/content/docs/2/guide/upgrade-migrate/index.mdx @@ -0,0 +1,754 @@ +--- +title: Upgrade Guide +--- + +import { Tabs, TabItem } from '@astrojs/starlight/components'; + +## Migrate to v2 from v1 + +This guide walks you through migrating your Tauri v1 application to Tauri v2. Note that the v2 CLI includes a `migrate` command that automates most of the process and helps you finish the migration, so commit your pending changes and check it out. + + + + + ```sh + npm install @tauri-apps/cli@latest + npm run tauri migrate + ``` + + + + + ```sh + yarn upgrade @tauri-apps/cli --latest + yarn tauri migrate + ``` + + + + + ```sh + pnpm update @tauri-apps/cli --latest + pnpm tauri migrate + ``` + + + + + ```sh + cargo install tauri-cli + cargo tauri migrate + ``` + + + + +### Configuration + +Here's the list of tauri.conf.json breaking changes: + +#### Allowlist + +- The `tauri > allowlist` object has been removed. + +#### CLI + +- The `cli` configuration object has been moved from `tauri > cli` to `plugins > cli`. + +#### Protocol + +- The `tauri > allowlist > protocol > assetScope` configuration has been moved to `tauri > security > assetProtocol > scope`. + +#### Updater + +- The `updater` configuration object has been moved from `tauri > updater` to `tauri > bundle > updater`. +- The `dialog` option has been removed. +- The `endpoints` option has been moved to `plugins > updater`. + +### Cargo features + +#### Removed Cargo features + +- reqwest-client: reqwest is now the only supported client. +- reqwest-native-tls-vendored: use `native-tls-vendored` instead. +- process-command-api: use the `shell` plugin instead, see instructions in the following section. +- shell-open-api: use the `shell` plugin instead, see instructions in the following section. +- windows7-compat: moved to the `notification` plugin. +- updater: the updater is now a plugin. +- linux-protocol-headers: Now enabled by default since we upgraded our minimum webkit2gtk version. + +#### New Cargo features + +- linux-protocol-body: Enables custom protocol request body parsing, allowing the IPC to use it. Requires webkit2gtk 2.40. + +### Rust API + +- The plugin setup hook now receives a second argument, `tauri::plugin::PluginApi`. This type also exposes the plugin configuration object, so `Plugin::setup_with_config` has been removed. + +- The `tauri::api` module has been removed. Each API module can be found in a Tauri plugin. + +#### File System + +- The `tauri::api::file` module has been removed. Prefer the [`std::fs`](https://doc.rust-lang.org/std/fs/) functions. + +- The `tauri::Manager::fs_scope` has been removed. The file system scope can be accessed via `tauri_plugin_fs::FsExt`. + +#### Process and Shell + +- `tauri::api::process::current_binary` and `tauri::api::process::restart` has been moved to `tauri::process`. + +- The `tauri::api::process::Command`, `tauri::api::shell` and `tauri::Manager::shell_scope` APIs have been removed. Use the `shell` plugin instead: + +```toml +[dependencies] +tauri-plugin-shell = "2" +``` + +```rust +use tauri_plugin_shell::{ShellExt, process::CommandEvent}; +fn main() { + tauri::Builder::default() + .plugin(tauri_plugin_shell::init()) + .setup(|app| { + // open + app.shell().open("https://github.com/tauri-apps/tauri", None)?; + + // status() + let status = tauri::async_runtime::block_on(async move { app.shell().command("which").args(["ls"]).status().await.unwrap() }); + println!("`which` finished with status: {:?}", status.code()); + + // output() + let output = tauri::async_runtime::block_on(async move { app.shell().command("echo").args(["TAURI"]).output().await.unwrap() }); + assert!(output.status.success()); + assert_eq!(String::from_utf8(output.stdout).unwrap(), "TAURI"); + + // async + let handle = app.handle(); + tauri::async_runtime::spawn(async move { + let (mut rx, mut child) = handle.shell().command("cargo") + .args(["tauri", "dev"]) + .spawn() + .expect("Failed to spawn cargo"); + + let mut i = 0; + while let Some(event) = rx.recv().await { + if let CommandEvent::Stdout(line) = event { + println!("got: {}", String::from_utf8(line).unwrap()); + i += 1; + if i == 4 { + child.write("message from Rust\n".as_bytes()).unwrap(); + i = 0; + } + } + } + }); + Ok(()) + }) +} +``` + +#### Updater + +- The `tauri::updater` module has been removed. You must add the `tauri-plugin-updater` dependency: + +```toml +[dependencies] +tauri-plugin-updater = "2" +``` + +```rust +fn main() { + tauri::Builder::default() + .plugin(tauri_plugin_updater::Builder::new().build()) +} +``` + +- The `tauri::Builder` `updater_target` function has been removed. To set a custom updater target: + +```rust +fn main() { + let mut updater = tauri_plugin_updater::Builder::new(); + #[cfg(target_os = "macos")] + { + updater = updater.target("darwin-universal"); + } + tauri::Builder::default() + .plugin(updater.build()) +} +``` + +- The `App` and `AppHandle` `updater` function has been removed. To check for updates, use `updater` method from `tauri_plugin_updater::UpdaterExt`: + +```rust +use tauri_plugin_updater::UpdaterExt; + +fn main() { + tauri::Builder::default() + .plugin(tauri_plugin_updater::Builder::new().build()) + .setup(|app| { + let handle = app.handle(); + tauri::async_runtime::spawn(async move { + let response = handle.updater().check().await; + }); + Ok(()) + }) +} +``` + +- `tauri::RunEvent::Updater` has been removed. The updater state can now be handled in the `app.updater().check().await` return value itself. + +#### Dialog + +The `tauri::api::dialog` APIs were moved to the `dialog` plugin: + +```toml +[dependencies] +tauri-plugin-dialog = "2" +``` + +```rust +use tauri_plugin_dialog::DialogExt; +tauri::Builder::default() + .plugin(tauri_plugin_dialog::init()) + .setup(|app| { + app.dialog().file().pick_file(|file_path| { + // do something with the optional file path here + // the file path is `None` if the user closed the dialog + }); + + app.dialog().message("Tauri is Awesome!").show(); + Ok(()) + }) +``` + +#### HTTP + +The `tauri::api::http` module has been removed. Use the `http` plugin instead: + +```toml +[dependencies] +tauri-plugin-http = "2" +``` + +```rust +use tauri_plugin_dialog::{DialogExt, client}; +// `client` is a re-export of `reqwest`. APIs will be available in the future as DialogExt::http +tauri::Builder::default() + .plugin(tauri_plugin_http::init()) +``` + +#### IPC + +The `tauri::api::ipc` module has been rewritten and it is now exported as `tauri::ipc`. Check out the new APIs, specially `tauri::ipc::Channel`. + +#### Path + +The `tauri::api::path` module functions and `tauri::PathResolver` have been moved to `tauri::Manager::path`: + +```rust +use tauri::{path::BaseDirectory, Manager}; + +tauri::Builder::default() + .setup(|app| { + let home_dir_path = app.path().home_dir().expect("failed to get home dir"); + + let path = app.path().resolve("path/to/something", BaseDirectory::Config)?; + + Ok(()) + }) +``` + +#### Version + +The `tauri::api::version` module has been removed. Check out the [semver crate](https://docs.rs/semver/latest/semver/) instead. + +#### Global Shortcut + +`App::global_shortcut_manager` and `AppHandle::global_shortcut_manager` APIs have been moved to the global shortcut plugin: + +```toml +[dependencies] +tauri-plugin-global-shortcut = "2" +``` + +```rust +use tauri_plugin_global_shortcut::GlobalShortcutExt; +tauri::Builder::default() + .plugin(tauri_plugin_shortcut::init()) + .setup(|app| { + app.global_shortcut().register("CmdOrCtrl+Y")?; + Ok(()) + }) +``` + +#### Clipboard + +`App::clipboard_manager` and `AppHandle::clipboard_manager` APIs have been moved to the clipboard plugin: + +```toml +[dependencies] +tauri-plugin-clipboard = "2" +``` + +```rust +use tauri_plugin_clipboard::{ClipboardExt, ClipKind}; +tauri::Builder::default() + .plugin(tauri_plugin_clipboard::init()) + .setup(|app| { + app.clipboard().write(ClipKind::PlainText { + label: None, + text: "Tauri is awesome!".into(), + })?; + Ok(()) + }) +``` + +#### CLI + +The `App::get_cli_matches` function has been removed. Use the `cli` plugin instead: + +```toml +[dependencies] +tauri-plugin-cli = "2" +``` + +```rust +use tauri_plugin_cli::CliExt; +tauri::Builder::default() + .plugin(tauri_plugin_cli::init()) + .setup(|app| { + let cli_matches = app.cli().matches()?; + Ok(()) + }) +``` + +#### Scope + +`tauri::scope::ipc::RemoteDomainAccessScope::enable_tauri_api` and `tauri::scope::ipc::RemoteDomainAccessScope::enables_tauri_api` have been removed. Enable each core plugin individually via `tauri::scope::ipc::RemoteDomainAccessScope::add_plugin` instead. + +### JavaScript API + +The `@tauri-apps/api` package no longer provides non-core modules. Only the `tauri`, `path` and `event` modules are exported. + +#### File System + +The `@tauri-apps/api/fs` module has been removed. Use the `@tauri-apps/plugin-fs` plugin instead: + +```toml +# Cargo.toml +[dependencies] +tauri-plugin-fs = "2" +``` + +```rust +fn main() { + tauri::Builder::default() + .plugin(tauri_plugin_fs::init()) +} +``` + +```json +// package.json +{ + "dependencies": { + "@tauri-apps/plugin-fs": "^2.0.0" + } +} +``` + +```js +import { createDir, BaseDirectory } from '@tauri-apps/plugin-fs' +await createDir('db', { dir: BaseDirectory.AppLocalData }) +``` + +#### Process + +The `@tauri-apps/api/process` module has been removed. Use the `@tauri-apps/plugin-process` plugin instead: + +```toml +# Cargo.toml +[dependencies] +tauri-plugin-process = "2" +``` + +```rust +fn main() { + tauri::Builder::default() + .plugin(tauri_plugin_process::init()) +} +``` + +```json +// package.json +{ + "dependencies": { + "@tauri-apps/plugin-process": "^2.0.0" + } +} +``` + +```js +import { exit, relaunch } from '@tauri-apps/plugin-process' +await exit(0); +await relaunch(); +``` + +#### Shell + +The `@tauri-apps/api/shell` module has been removed. Use the `@tauri-apps/plugin-shell` plugin instead: + +```toml +# Cargo.toml +[dependencies] +tauri-plugin-shell = "2" +``` + +```rust +fn main() { + tauri::Builder::default() + .plugin(tauri_plugin_shell::init()) +} +``` + +```json +// package.json +{ + "dependencies": { + "@tauri-apps/plugin-shell": "^2.0.0" + } +} +``` + +```js +import { Command, open } from '@tauri-apps/plugin-shell' +const output = await Command.create('echo', 'message').execute() + +await open('https://github.com/tauri-apps/tauri') +``` + +#### Updater + +The `@tauri-apps/api/updater` module has been removed. Use the `@tauri-apps/plugin-updater` plugin instead: + +```toml +# Cargo.toml +[dependencies] +tauri-plugin-updater = "2" +``` + +```rust +fn main() { + tauri::Builder::default() + .plugin(tauri_plugin_updater::init()) +} +``` + +```json +// package.json +{ + "dependencies": { + "@tauri-apps/plugin-updater": "^2.0.0" + } +} +``` + +```js +import { check } from '@tauri-apps/plugin-updater' +import { relaunch } from '@tauri-apps/plugin-process' + +const update = await check() +if (update.response.available) { + console.log(`Update to ${update.response.latestVersion} available! Date: ${update.response.date}`) + console.log(`Release notes: ${update.response.body}`) + await update.downloadAndInstall() + // requires the `process` plugin + await relaunch() +} +``` + +#### Dialog + +The `@tauri-apps/api/dialog` module has been removed. Use the `@tauri-apps/plugin-dialog` plugin instead: + +```toml +# Cargo.toml +[dependencies] +tauri-plugin-dialog = "2" +``` + +```rust +fn main() { + tauri::Builder::default() + .plugin(tauri_plugin_dialog::init()) +} +``` + +```json +// package.json +{ + "dependencies": { + "@tauri-apps/plugin-dialog": "^2.0.0" + } +} +``` + +```js +import { save } from '@tauri-apps/plugin-dialog'; +const filePath = await save({ + filters: [{ + name: 'Image', + extensions: ['png', 'jpeg'] + }] +}); +``` +#### HTTP + +The `@tauri-apps/api/http` module has been removed. Use the `@tauri-apps/plugin-http` plugin instead: + +```toml +# Cargo.toml +[dependencies] +tauri-plugin-http = "2" +``` + +```rust +fn main() { + tauri::Builder::default() + .plugin(tauri_plugin_http::init()) +} +``` + +```json +// package.json +{ + "dependencies": { + "@tauri-apps/plugin-http": "^2.0.0" + } +} +``` + +```js +import { fetch } from '@tauri-apps/plugin-http' +const response = await fetch('https://raw.githubusercontent.com/tauri-apps/tauri/dev/package.json') +``` + +#### App + +The `@tauri-apps/api/app` module has been removed. Use the `@tauri-apps/plugin-app` plugin instead: + +```toml +# Cargo.toml +[dependencies] +tauri-plugin-app = "2" +``` + +```rust +fn main() { + tauri::Builder::default() + .plugin(tauri_plugin_app::init()) +} +``` + +```json +// package.json +{ + "dependencies": { + "@tauri-apps/plugin-app": "^2.0.0" + } +} +``` + +```js +import { show, hide } from '@tauri-apps/plugin-app' +await hide() +await show() +``` + +#### OS + +The `@tauri-apps/api/os` module has been removed. Use the `@tauri-apps/plugin-os` plugin instead: + +```toml +# Cargo.toml +[dependencies] +tauri-plugin-os = "2" +``` + +```rust +fn main() { + tauri::Builder::default() + .plugin(tauri_plugin_os::init()) +} +``` + +```json +// package.json +{ + "dependencies": { + "@tauri-apps/plugin-os": "^2.0.0" + } +} +``` + +```js +import { arch } from '@tauri-apps/plugin-os' +const architecture = await arch() +``` + +#### CLI + +The `@tauri-apps/api/cli` module has been removed. Use the `@tauri-apps/plugin-cli` plugin instead: + +```toml +# Cargo.toml +[dependencies] +tauri-plugin-cli = "2" +``` + +```rust +fn main() { + tauri::Builder::default() + .plugin(tauri_plugin_cli::init()) +} +``` + +```json +// package.json +{ + "dependencies": { + "@tauri-apps/plugin-cli": "^2.0.0" + } +} +``` + +```js +import { getMatches } from '@tauri-apps/plugin-cli' +const matches = await getMatches() +``` + +#### Global Shortcut + +The `@tauri-apps/api/global-shortcut` module has been removed. Use the `@tauri-apps/plugin-global-shortcut` plugin instead: + +```toml +# Cargo.toml +[dependencies] +tauri-plugin-global-shortcut = "2" +``` + +```rust +fn main() { + tauri::Builder::default() + .plugin(tauri_plugin_global_shortcut::init()) +} +``` + +```json +// package.json +{ + "dependencies": { + "@tauri-apps/plugin-global-shortcut": "^2.0.0" + } +} +``` + +```js +import { register } from '@tauri-apps/plugin-global-shortcut' +await register('CommandOrControl+Shift+C', () => { + console.log('Shortcut triggered'); +}); +``` + +#### Clipboard + +The `@tauri-apps/api/clipboard` module has been removed. Use the `@tauri-apps/plugin-clipboard-manager` plugin instead: + +```toml +# Cargo.toml +[dependencies] +tauri-plugin-clipboard = "2" +``` + +```rust +fn main() { + tauri::Builder::default() + .plugin(tauri_plugin_clipboard::init()) +} +``` + +```json +// package.json +{ + "dependencies": { + "@tauri-apps/plugin-clipboard-manager": "^2.0.0" + } +} +``` + +```js +import { writeText, readText } from '@tauri-apps/plugin-clipboard-manager'; +await writeText('Tauri is awesome!'); +assert(await readText(), 'Tauri is awesome!'); +``` + +#### Notification + +The `@tauri-apps/api/notification` module has been removed. Use the `@tauri-apps/plugin-notification` plugin instead: + +```toml +# Cargo.toml +[dependencies] +tauri-plugin-notification = "2" +``` + +```rust +fn main() { + tauri::Builder::default() + .plugin(tauri_plugin_notification::init()) +} +``` + +```json +// package.json +{ + "dependencies": { + "@tauri-apps/plugin-notification": "^2.0.0" + } +} +``` + +```js +import { sendNotification } from '@tauri-apps/plugin-notification' +sendNotification('Tauri is awesome!'); +``` + +#### Window + +The `@tauri-apps/api/window` module has been removed. Use the `@tauri-apps/plugin-window` plugin instead: + +```toml +# Cargo.toml +[dependencies] +tauri-plugin-window = "2" +``` + +```rust +fn main() { + tauri::Builder::default() + .plugin(tauri_plugin_window::init()) +} +``` + +```json +// package.json +{ + "dependencies": { + "@tauri-apps/plugin-window": "^2.0.0" + } +} +``` + +```js +import { appWindow } from '@tauri-apps/plugin-window'; +await appWindow.setTitle('Tauri'); +``` From 04bc299c316de3b770e10f6acc31207c2e1c6481 Mon Sep 17 00:00:00 2001 From: Lorenzo Lewis Date: Sat, 5 Aug 2023 17:01:49 +0100 Subject: [PATCH 2/7] update paragraph Signed-off-by: Lorenzo Lewis --- src/content/docs/2/guide/upgrade-migrate/index.mdx | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/content/docs/2/guide/upgrade-migrate/index.mdx b/src/content/docs/2/guide/upgrade-migrate/index.mdx index fe9b975bb9..ac023cb8fb 100644 --- a/src/content/docs/2/guide/upgrade-migrate/index.mdx +++ b/src/content/docs/2/guide/upgrade-migrate/index.mdx @@ -4,9 +4,7 @@ title: Upgrade Guide import { Tabs, TabItem } from '@astrojs/starlight/components'; -## Migrate to v2 from v1 - -This guide walks you through migrating your Tauri v1 application to Tauri v2. Note that the v2 CLI includes a `migrate` command that automates most of the process and helps you finish the migration, so commit your pending changes and check it out. +This guide walks you through migrating your Tauri 1.0 application to Tauri 2.0. The Tauri v2 CLI includes a `migrate` command that automates most of the process and helps you finish the migration: From 362036125c9e1c5bb3971d29ce672a15bae6dad9 Mon Sep 17 00:00:00 2001 From: Lorenzo Lewis Date: Sat, 5 Aug 2023 18:39:23 +0100 Subject: [PATCH 3/7] lots of updates Signed-off-by: Lorenzo Lewis --- .../2/guide/upgrade-migrate/from-tauri-1.mdx | 769 ++++++++++++++++++ .../docs/2/guide/upgrade-migrate/index.mdx | 763 +---------------- 2 files changed, 772 insertions(+), 760 deletions(-) create mode 100644 src/content/docs/2/guide/upgrade-migrate/from-tauri-1.mdx diff --git a/src/content/docs/2/guide/upgrade-migrate/from-tauri-1.mdx b/src/content/docs/2/guide/upgrade-migrate/from-tauri-1.mdx new file mode 100644 index 0000000000..78827c0b96 --- /dev/null +++ b/src/content/docs/2/guide/upgrade-migrate/from-tauri-1.mdx @@ -0,0 +1,769 @@ +--- +title: Migrate from Tauri 1.0 +--- + +import { Tabs, TabItem } from '@astrojs/starlight/components'; + +This guide walks you through migrating your Tauri 1.0 application to Tauri 2.0. + +## Automated Migration + +The Tauri v2 CLI includes a `migrate` command that automates most of the process and helps you finish the migration: + + + + + ```sh + npm install @tauri-apps/cli@latest + npm run tauri migrate + ``` + + + + + ```sh + yarn upgrade @tauri-apps/cli --latest + yarn tauri migrate + ``` + + + + + ```sh + pnpm update @tauri-apps/cli --latest + pnpm tauri migrate + ``` + + + + + ```sh + cargo install tauri-cli + cargo tauri migrate + ``` + + + + +## Summary of Changes + +Below is a summary of the changes from Tauri 1.0 to Tauri 2.0: + +### Tauri Configuration + +- `tauri > allowlist` removed. +- `tauri > allowlist > protocol > assetScope` moved to `tauri > security > assetProtocol > scope`. +- `tauri > cli` moved to `plugins > cli`. +- `tauri > updater` moved to `tauri > bundle > updater`. +- `tauri > updater > dialog` removed. +- `tauri > updater > endpoints` moved to `plugins > updater`. + +### New Cargo Features + +- linux-protocol-body: Enables custom protocol request body parsing, allowing the IPC to use it. Requires webkit2gtk 2.40. + +### Removed Cargo Features + +- reqwest-client: reqwest is now the only supported client. +- reqwest-native-tls-vendored: use `native-tls-vendored` instead. +- process-command-api: use the `shell` plugin instead (see instructions in the following section). +- shell-open-api: use the `shell` plugin instead (see instructions in the following section). +- windows7-compat: moved to the `notification` plugin. +- updater: Updater is now a plugin. +- linux-protocol-headers: Now enabled by default since we upgraded our minimum webkit2gtk version. + +### Rust Crate Changes + +- `api` module removed. Each API module can be found in a Tauri plugin. +- `api::dialog` module removed. Use `tauri-plugin-dialog` instead. [Migration](#migrate-to-dialog-plugin) +- `api::file` module removed. Use Rust's [`std::fs`](https://doc.rust-lang.org/std/fs/) instead. +- `api::http` module removed. Use `tauri-plugin-http` instead. [Migration](#migrate-to-http-plugin) +- `api::ip` module rewritten and moved to `tauri::ipc`. Check out the new APIs, specially `tauri::ipc::Channel`. +- `api::path` module functions and `tauri::PathResolved` moved to `tauri::Manager::path`. [Migration](#migrate-path-to-tauri-manager) +- `api::process::Command`, `tauri::api::shell` and `tauri::Manager::shell_scope` APIs removed. Use `tauri-plugin-shell` instead. [Migration](#migrate-to-shell-plugin) +- `api::process::current_binary` and `tauri::api::process::restart` moved to `tauri::process`. +- `api::version` module has been removed. Use the [semver crate](https://docs.rs/semver/latest/semver/) instead. +- `App::clipboard_manager` and `AppHandle::clipboard_manager` removed. Use `tauri-plugin-clipboard` instead. [Migration](#migrate-to-clipboard-plugin) +- `App::get_cli_matches` removed. Use `tauri-plugin-cli` instead. [Migration](#migrate-to-cli-plugin) +- `App::global_shortcut_manager` and `AppHandle::global_shortcut_manager` removed. Use `tauri-plugin-global-shortcut` instead. [Migration](#migrate-to-global-shortcut-plugin) +- `Manager::fs_scope` removed. The file system scope can be accessed via `tauri_plugin_fs::FsExt`. +- `Plugin::PluginApi` now receives a plugin configuration as a second argument. +- `Plugin::setup_with_config` removed. Use the updated `tauri::Plugin::PluginApi` instead. +- `scope::ipc::RemoteDomainAccessScope::enable_tauri_api` and `scope::ipc::RemoteDomainAccessScope::enables_tauri_api` removed. Enable each core plugin individually via `scope::ipc::RemoteDomainAccessScope::add_plugin` instead. +- `updater` module removed. Use `tauri-plugin-updater` instead. [Migration](#migrate-to-updater-plugin) + +### JavaScript API Changes + +The `@tauri-apps/api` package no longer provides non-core modules. Only the `tauri`, `path` and `event` modules are exported. All others have been moved to plugins. + +- `@tauri-apps/api/app` module removed. Use `@tauri-apps/plugin-app` instead. [Migration](#migrate-to-app-plugin) +- `@tauri-apps/api/cli` module removed. Use `@tauri-apps/plugin-cli` instead. [Migration](#migrate-to-cli-plugin) +- `@tauri-apps/api/clipboard` module removed. Use `@tauri-apps/plugin-clipboard` instead. [Migration](#migrate-to-clipboard-plugin) +- `@tauri-apps/api/dialog` module removed. Use `@tauri-apps/plugin-dialog` instead. [Migration](#migrate-to-dialog-plugin) +- `@tauri-apps/api/fs` module removed. Use `@tauri-apps/plugin-fs` instead. [Migration](#migrate-to-filesystem-plugin) +- `@tauri-apps/api/global-shortcut` module removed. Use `@tauri-apps/plugin-global-shortcut` instead. [Migration](#migrate-to-global-shortcut-plugin) +- `@tauri-apps/api/http` module removed. Use `@tauri-apps/plugin-http` instead. [Migration](#migrate-to-http-plugin) +- `@tauri-apps/api/os` module removed. Use `@tauri-apps/plugin-os` instead. [Migration](#migrate-to-os-plugin) +- `@tauri-apps/api/notification` module removed. Use `@tauri-apps/plugin-notification` instead. [Migration](#migrate-to-notification-plugin) +- `@tauri-apps/api/process` module removed. Use `@tauri-apps/plugin-process` instead. [Migration](#migrate-to-process-plugin) +- `@tauri-apps/api/shell` module removed. Use `@tauri-apps/plugin-shell` instead. [Migration](#migrate-to-shell-plugin) +- `@tauri-apps/api/updater` module removed. Use `@tauri-apps/plugin-updater` instead [Migration](#migrate-to-updater-plugin) +- `@tauri-apps/api/window` module removed. Use `@tauri-apps/plugin-window` instead [Migration](#migrate-to-window-plugin) + +## Detailed Migration Steps + +### Migrate to CLI Plugin + +The Rust `App::get_cli_matches` function and JavaScript `@tauri-apps/api/cli` module have been removed. Use the `cli` plugin instead: + +1. Add to cargo dependencies: + +```toml +# Cargo.toml +[dependencies] +tauri-plugin-cli = "2" +``` + +2. Use in JavaScript or Rust project: + + + + +```rust +fn main() { + tauri::Builder::default() + .plugin(tauri_plugin_cli::init()) +} +``` + +```json +// package.json +{ + "dependencies": { + "@tauri-apps/plugin-cli": "^2.0.0" + } +} +``` + +```js +import { getMatches } from '@tauri-apps/plugin-cli'; +const matches = await getMatches(); +``` + + + + +```rust +fn main() { + use tauri_plugin_cli::CliExt; + tauri::Builder::default() + .plugin(tauri_plugin_cli::init()) + .setup(|app| { + let cli_matches = app.cli().matches()?; + Ok(()) + }) +} +``` + + + + +### Migrate to Clipboard Plugin + +`App::clipboard_manager` and `AppHandle::clipboard_manager` APIs have been moved to the clipboard plugin: + +```toml +[dependencies] +tauri-plugin-clipboard = "2" +``` + +```rust +use tauri_plugin_clipboard::{ClipboardExt, ClipKind}; +tauri::Builder::default() + .plugin(tauri_plugin_clipboard::init()) + .setup(|app| { + app.clipboard().write(ClipKind::PlainText { + label: None, + text: "Tauri is awesome!".into(), + })?; + Ok(()) + }) +``` + +### Migrate to Clipboard Plugin + +The `@tauri-apps/api/clipboard` module has been removed. Use the `@tauri-apps/plugin-clipboard-manager` plugin instead: + +```toml +# Cargo.toml +[dependencies] +tauri-plugin-clipboard = "2" +``` + +```rust +fn main() { + tauri::Builder::default() + .plugin(tauri_plugin_clipboard::init()) +} +``` + +```json +// package.json +{ + "dependencies": { + "@tauri-apps/plugin-clipboard-manager": "^2.0.0" + } +} +``` + +```js +import { writeText, readText } from '@tauri-apps/plugin-clipboard-manager'; +await writeText('Tauri is awesome!'); +assert(await readText(), 'Tauri is awesome!'); +``` + +### Migrate to Dialog Plugin + +The `@tauri-apps/api/dialog` module has been removed. Use the `@tauri-apps/plugin-dialog` plugin instead: + +```toml +# Cargo.toml +[dependencies] +tauri-plugin-dialog = "2" +``` + +```rust +fn main() { + tauri::Builder::default() + .plugin(tauri_plugin_dialog::init()) +} +``` + +```json +// package.json +{ + "dependencies": { + "@tauri-apps/plugin-dialog": "^2.0.0" + } +} +``` + +```js +import { save } from '@tauri-apps/plugin-dialog'; +const filePath = await save({ + filters: [ + { + name: 'Image', + extensions: ['png', 'jpeg'], + }, + ], +}); +``` + +### Migrate to Dialog Plugin + +```toml +[dependencies] +tauri-plugin-dialog = "2" +``` + +```rust +use tauri_plugin_dialog::DialogExt; +tauri::Builder::default() + .plugin(tauri_plugin_dialog::init()) + .setup(|app| { + app.dialog().file().pick_file(|file_path| { + // do something with the optional file path here + // the file path is `None` if the user closed the dialog + }); + + app.dialog().message("Tauri is Awesome!").show(); + Ok(()) + }) +``` + +### Migrate to File System Plugin + +The `@tauri-apps/api/fs` module has been removed. Use the `@tauri-apps/plugin-fs` plugin instead: + +```toml +# Cargo.toml +[dependencies] +tauri-plugin-fs = "2" +``` + +```rust +fn main() { + tauri::Builder::default() + .plugin(tauri_plugin_fs::init()) +} +``` + +```json +// package.json +{ + "dependencies": { + "@tauri-apps/plugin-fs": "^2.0.0" + } +} +``` + +```js +import { createDir, BaseDirectory } from '@tauri-apps/plugin-fs'; +await createDir('db', { dir: BaseDirectory.AppLocalData }); +``` + +### Migrate to Global Shortcut Plugin + +`App::global_shortcut_manager` and `AppHandle::global_shortcut_manager` APIs have been moved to the global shortcut plugin: + +```toml +[dependencies] +tauri-plugin-global-shortcut = "2" +``` + +```rust +use tauri_plugin_global_shortcut::GlobalShortcutExt; +tauri::Builder::default() + .plugin(tauri_plugin_shortcut::init()) + .setup(|app| { + app.global_shortcut().register("CmdOrCtrl+Y")?; + Ok(()) + }) +``` + +### Migrate to Global Shortcut Plugin + +The `@tauri-apps/api/global-shortcut` module has been removed. Use the `@tauri-apps/plugin-global-shortcut` plugin instead: + +```toml +# Cargo.toml +[dependencies] +tauri-plugin-global-shortcut = "2" +``` + +```rust +fn main() { + tauri::Builder::default() + .plugin(tauri_plugin_global_shortcut::init()) +} +``` + +```json +// package.json +{ + "dependencies": { + "@tauri-apps/plugin-global-shortcut": "^2.0.0" + } +} +``` + +```js +import { register } from '@tauri-apps/plugin-global-shortcut'; +await register('CommandOrControl+Shift+C', () => { + console.log('Shortcut triggered'); +}); +``` + +### Migrate to HTTP Plugin + +The `tauri::api::http` module has been removed. Use the `http` plugin instead: + +```toml +[dependencies] +tauri-plugin-http = "2" +``` + +```rust +use tauri_plugin_dialog::{DialogExt, client}; +// `client` is a re-export of `reqwest`. APIs will be available in the future as DialogExt::http +tauri::Builder::default() + .plugin(tauri_plugin_http::init()) +``` + +### Migrate to HTTP Plugin + +The `@tauri-apps/api/http` module has been removed. Use the `@tauri-apps/plugin-http` plugin instead: + +```toml +# Cargo.toml +[dependencies] +tauri-plugin-http = "2" +``` + +```rust +fn main() { + tauri::Builder::default() + .plugin(tauri_plugin_http::init()) +} +``` + +```json +// package.json +{ + "dependencies": { + "@tauri-apps/plugin-http": "^2.0.0" + } +} +``` + +```js +import { fetch } from '@tauri-apps/plugin-http'; +const response = await fetch( + 'https://raw.githubusercontent.com/tauri-apps/tauri/dev/package.json' +); +``` + +### Migrate to Notification Plugin + +The `@tauri-apps/api/notification` module has been removed. Use the `@tauri-apps/plugin-notification` plugin instead: + +```toml +# Cargo.toml +[dependencies] +tauri-plugin-notification = "2" +``` + +```rust +fn main() { + tauri::Builder::default() + .plugin(tauri_plugin_notification::init()) +} +``` + +```json +// package.json +{ + "dependencies": { + "@tauri-apps/plugin-notification": "^2.0.0" + } +} +``` + +```js +import { sendNotification } from '@tauri-apps/plugin-notification'; +sendNotification('Tauri is awesome!'); +``` + +### Migrate to OS Plugin + +The `@tauri-apps/api/os` module has been removed. Use the `@tauri-apps/plugin-os` plugin instead: + +```toml +# Cargo.toml +[dependencies] +tauri-plugin-os = "2" +``` + +```rust +fn main() { + tauri::Builder::default() + .plugin(tauri_plugin_os::init()) +} +``` + +```json +// package.json +{ + "dependencies": { + "@tauri-apps/plugin-os": "^2.0.0" + } +} +``` + +```js +import { arch } from '@tauri-apps/plugin-os'; +const architecture = await arch(); +``` + +### Migrate to Process Plugin + +The `@tauri-apps/api/process` module has been removed. Use the `@tauri-apps/plugin-process` plugin instead: + +```toml +# Cargo.toml +[dependencies] +tauri-plugin-process = "2" +``` + +```rust +fn main() { + tauri::Builder::default() + .plugin(tauri_plugin_process::init()) +} +``` + +```json +// package.json +{ + "dependencies": { + "@tauri-apps/plugin-process": "^2.0.0" + } +} +``` + +```js +import { exit, relaunch } from '@tauri-apps/plugin-process'; +await exit(0); +await relaunch(); +``` + +### Migrate to Shell Plugin + +The `@tauri-apps/api/shell` module has been removed. Use the `@tauri-apps/plugin-shell` plugin instead: + +```toml +# Cargo.toml +[dependencies] +tauri-plugin-shell = "2" +``` + +```rust +fn main() { + tauri::Builder::default() + .plugin(tauri_plugin_shell::init()) +} +``` + +```json +// package.json +{ + "dependencies": { + "@tauri-apps/plugin-shell": "^2.0.0" + } +} +``` + +```js +import { Command, open } from '@tauri-apps/plugin-shell'; +const output = await Command.create('echo', 'message').execute(); + +await open('https://github.com/tauri-apps/tauri'); +``` + +### Migrate to Shell Plugin + +```toml +[dependencies] +tauri-plugin-shell = "2" +``` + +```rust +use tauri_plugin_shell::{ShellExt, process::CommandEvent}; +fn main() { + tauri::Builder::default() + .plugin(tauri_plugin_shell::init()) + .setup(|app| { + // open + app.shell().open("https://github.com/tauri-apps/tauri", None)?; + + // status() + let status = tauri::async_runtime::block_on(async move { app.shell().command("which").args(["ls"]).status().await.unwrap() }); + println!("`which` finished with status: {:?}", status.code()); + + // output() + let output = tauri::async_runtime::block_on(async move { app.shell().command("echo").args(["TAURI"]).output().await.unwrap() }); + assert!(output.status.success()); + assert_eq!(String::from_utf8(output.stdout).unwrap(), "TAURI"); + + // async + let handle = app.handle(); + tauri::async_runtime::spawn(async move { + let (mut rx, mut child) = handle.shell().command("cargo") + .args(["tauri", "dev"]) + .spawn() + .expect("Failed to spawn cargo"); + + let mut i = 0; + while let Some(event) = rx.recv().await { + if let CommandEvent::Stdout(line) = event { + println!("got: {}", String::from_utf8(line).unwrap()); + i += 1; + if i == 4 { + child.write("message from Rust\n".as_bytes()).unwrap(); + i = 0; + } + } + } + }); + Ok(()) + }) +} +``` + +### Migrate to Updater Plugin + +```toml +[dependencies] +tauri-plugin-updater = "2" +``` + +```rust +fn main() { + tauri::Builder::default() + .plugin(tauri_plugin_updater::Builder::new().build()) +} +``` + +### Migrate to Updater Plugin + +The `@tauri-apps/api/updater` module has been removed. Use the `@tauri-apps/plugin-updater` plugin instead: + +```toml +# Cargo.toml +[dependencies] +tauri-plugin-updater = "2" +``` + +```rust +fn main() { + tauri::Builder::default() + .plugin(tauri_plugin_updater::init()) +} +``` + +```json +// package.json +{ + "dependencies": { + "@tauri-apps/plugin-updater": "^2.0.0" + } +} +``` + +```js +import { check } from '@tauri-apps/plugin-updater'; +import { relaunch } from '@tauri-apps/plugin-process'; + +const update = await check(); +if (update.response.available) { + console.log( + `Update to ${update.response.latestVersion} available! Date: ${update.response.date}` + ); + console.log(`Release notes: ${update.response.body}`); + await update.downloadAndInstall(); + // requires the `process` plugin + await relaunch(); +} +``` + +#### Custom Updater Target + +The `tauri::Builder` `updater_target` function has been removed. To set a custom updater target: + +```rust +fn main() { + let mut updater = tauri_plugin_updater::Builder::new(); + #[cfg(target_os = "macos")] + { + updater = updater.target("darwin-universal"); + } + tauri::Builder::default() + .plugin(updater.build()) +} +``` + +#### Check for Updates + +- `tauri::updater` module removed. Use `tauri-plugin-updater` instead. +- `tauri::Builder` `updater_target` function removed. [Migration](#custom-updater-target) +- `App` and `AppHandle` `updater` function removed. [Migration](#check-for-updates) +- `tauri::RunEvent::Updater` removed. The updater state can now be handled in the `app.updater().check().await` return value itself. + +To check for updates use the `updater` method from `tauri_plugin_updater::UpdaterExt`: + +```rust +use tauri_plugin_updater::UpdaterExt; + +fn main() { + tauri::Builder::default() + .plugin(tauri_plugin_updater::Builder::new().build()) + .setup(|app| { + let handle = app.handle(); + tauri::async_runtime::spawn(async move { + let response = handle.updater().check().await; + }); + Ok(()) + }) +} +``` + +### Migrate to Window Plugin + +The `@tauri-apps/api/window` module has been removed. Use the `@tauri-apps/plugin-window` plugin instead: + +```toml +# Cargo.toml +[dependencies] +tauri-plugin-window = "2" +``` + +```rust +fn main() { + tauri::Builder::default() + .plugin(tauri_plugin_window::init()) +} +``` + +```json +// package.json +{ + "dependencies": { + "@tauri-apps/plugin-window": "^2.0.0" + } +} +``` + +```js +import { appWindow } from '@tauri-apps/plugin-window'; +await appWindow.setTitle('Tauri'); +``` + +### Migrate Path to Tauri Manager + +The `tauri::api::path` module functions and `tauri::PathResolver` have been moved to `tauri::Manager::path`: + +```rust +use tauri::{path::BaseDirectory, Manager}; + +tauri::Builder::default() + .setup(|app| { + let home_dir_path = app.path().home_dir().expect("failed to get home dir"); + + let path = app.path().resolve("path/to/something", BaseDirectory::Config)?; + + Ok(()) + }) +``` + +#### Migrate to App Plugin + +The `@tauri-apps/api/app` module has been removed. Use the `@tauri-apps/plugin-app` plugin instead: + +```toml +# Cargo.toml +[dependencies] +tauri-plugin-app = "2" +``` + +```rust +fn main() { + tauri::Builder::default() + .plugin(tauri_plugin_app::init()) +} +``` + +```json +// package.json +{ + "dependencies": { + "@tauri-apps/plugin-app": "^2.0.0" + } +} +``` + +```js +import { show, hide } from '@tauri-apps/plugin-app'; +await hide(); +await show(); +``` diff --git a/src/content/docs/2/guide/upgrade-migrate/index.mdx b/src/content/docs/2/guide/upgrade-migrate/index.mdx index ac023cb8fb..29341acabc 100644 --- a/src/content/docs/2/guide/upgrade-migrate/index.mdx +++ b/src/content/docs/2/guide/upgrade-migrate/index.mdx @@ -1,771 +1,14 @@ --- -title: Upgrade Guide +title: Upgrade & Migrate --- -import { Tabs, TabItem } from '@astrojs/starlight/components'; - -This guide walks you through migrating your Tauri 1.0 application to Tauri 2.0. The Tauri v2 CLI includes a `migrate` command that automates most of the process and helps you finish the migration: - - - - - ```sh - npm install @tauri-apps/cli@latest - npm run tauri migrate - ``` - - - - - ```sh - yarn upgrade @tauri-apps/cli --latest - yarn tauri migrate - ``` - - - - - ```sh - pnpm update @tauri-apps/cli --latest - pnpm tauri migrate - ``` - - - - - ```sh - cargo install tauri-cli - cargo tauri migrate - ``` - - - - -### Configuration - -Here's the list of tauri.conf.json breaking changes: - -#### Allowlist - -- The `tauri > allowlist` object has been removed. - -#### CLI - -- The `cli` configuration object has been moved from `tauri > cli` to `plugins > cli`. - -#### Protocol - -- The `tauri > allowlist > protocol > assetScope` configuration has been moved to `tauri > security > assetProtocol > scope`. - -#### Updater - -- The `updater` configuration object has been moved from `tauri > updater` to `tauri > bundle > updater`. -- The `dialog` option has been removed. -- The `endpoints` option has been moved to `plugins > updater`. - -### Cargo features - -#### Removed Cargo features - -- reqwest-client: reqwest is now the only supported client. -- reqwest-native-tls-vendored: use `native-tls-vendored` instead. -- process-command-api: use the `shell` plugin instead, see instructions in the following section. -- shell-open-api: use the `shell` plugin instead, see instructions in the following section. -- windows7-compat: moved to the `notification` plugin. -- updater: the updater is now a plugin. -- linux-protocol-headers: Now enabled by default since we upgraded our minimum webkit2gtk version. - -#### New Cargo features - -- linux-protocol-body: Enables custom protocol request body parsing, allowing the IPC to use it. Requires webkit2gtk 2.40. - -### Rust API - -- The plugin setup hook now receives a second argument, `tauri::plugin::PluginApi`. This type also exposes the plugin configuration object, so `Plugin::setup_with_config` has been removed. - -- The `tauri::api` module has been removed. Each API module can be found in a Tauri plugin. - -#### File System - -- The `tauri::api::file` module has been removed. Prefer the [`std::fs`](https://doc.rust-lang.org/std/fs/) functions. - -- The `tauri::Manager::fs_scope` has been removed. The file system scope can be accessed via `tauri_plugin_fs::FsExt`. - -#### Process and Shell - -- `tauri::api::process::current_binary` and `tauri::api::process::restart` has been moved to `tauri::process`. - -- The `tauri::api::process::Command`, `tauri::api::shell` and `tauri::Manager::shell_scope` APIs have been removed. Use the `shell` plugin instead: - -```toml -[dependencies] -tauri-plugin-shell = "2" -``` - -```rust -use tauri_plugin_shell::{ShellExt, process::CommandEvent}; -fn main() { - tauri::Builder::default() - .plugin(tauri_plugin_shell::init()) - .setup(|app| { - // open - app.shell().open("https://github.com/tauri-apps/tauri", None)?; - - // status() - let status = tauri::async_runtime::block_on(async move { app.shell().command("which").args(["ls"]).status().await.unwrap() }); - println!("`which` finished with status: {:?}", status.code()); - - // output() - let output = tauri::async_runtime::block_on(async move { app.shell().command("echo").args(["TAURI"]).output().await.unwrap() }); - assert!(output.status.success()); - assert_eq!(String::from_utf8(output.stdout).unwrap(), "TAURI"); - - // async - let handle = app.handle(); - tauri::async_runtime::spawn(async move { - let (mut rx, mut child) = handle.shell().command("cargo") - .args(["tauri", "dev"]) - .spawn() - .expect("Failed to spawn cargo"); - - let mut i = 0; - while let Some(event) = rx.recv().await { - if let CommandEvent::Stdout(line) = event { - println!("got: {}", String::from_utf8(line).unwrap()); - i += 1; - if i == 4 { - child.write("message from Rust\n".as_bytes()).unwrap(); - i = 0; - } - } - } - }); - Ok(()) - }) -} -``` - -#### Updater - -- The `tauri::updater` module has been removed. You must add the `tauri-plugin-updater` dependency: - -```toml -[dependencies] -tauri-plugin-updater = "2" -``` - -```rust -fn main() { - tauri::Builder::default() - .plugin(tauri_plugin_updater::Builder::new().build()) -} -``` - -- The `tauri::Builder` `updater_target` function has been removed. To set a custom updater target: - -```rust -fn main() { - let mut updater = tauri_plugin_updater::Builder::new(); - #[cfg(target_os = "macos")] - { - updater = updater.target("darwin-universal"); - } - tauri::Builder::default() - .plugin(updater.build()) -} -``` - -- The `App` and `AppHandle` `updater` function has been removed. To check for updates, use `updater` method from `tauri_plugin_updater::UpdaterExt`: - -```rust -use tauri_plugin_updater::UpdaterExt; - -fn main() { - tauri::Builder::default() - .plugin(tauri_plugin_updater::Builder::new().build()) - .setup(|app| { - let handle = app.handle(); - tauri::async_runtime::spawn(async move { - let response = handle.updater().check().await; - }); - Ok(()) - }) -} -``` - -- `tauri::RunEvent::Updater` has been removed. The updater state can now be handled in the `app.updater().check().await` return value itself. - -#### Dialog - -The `tauri::api::dialog` APIs were moved to the `dialog` plugin: - -```toml -[dependencies] -tauri-plugin-dialog = "2" -``` - -```rust -use tauri_plugin_dialog::DialogExt; -tauri::Builder::default() - .plugin(tauri_plugin_dialog::init()) - .setup(|app| { - app.dialog().file().pick_file(|file_path| { - // do something with the optional file path here - // the file path is `None` if the user closed the dialog - }); - - app.dialog().message("Tauri is Awesome!").show(); - Ok(()) - }) -``` - -#### HTTP - -The `tauri::api::http` module has been removed. Use the `http` plugin instead: - -```toml -[dependencies] -tauri-plugin-http = "2" -``` - -```rust -use tauri_plugin_dialog::{DialogExt, client}; -// `client` is a re-export of `reqwest`. APIs will be available in the future as DialogExt::http -tauri::Builder::default() - .plugin(tauri_plugin_http::init()) -``` - -#### IPC - -The `tauri::api::ipc` module has been rewritten and it is now exported as `tauri::ipc`. Check out the new APIs, specially `tauri::ipc::Channel`. - -#### Path - -The `tauri::api::path` module functions and `tauri::PathResolver` have been moved to `tauri::Manager::path`: - -```rust -use tauri::{path::BaseDirectory, Manager}; - -tauri::Builder::default() - .setup(|app| { - let home_dir_path = app.path().home_dir().expect("failed to get home dir"); - - let path = app.path().resolve("path/to/something", BaseDirectory::Config)?; - - Ok(()) - }) -``` - -#### Version - -The `tauri::api::version` module has been removed. Check out the [semver crate](https://docs.rs/semver/latest/semver/) instead. - -#### Global Shortcut - -`App::global_shortcut_manager` and `AppHandle::global_shortcut_manager` APIs have been moved to the global shortcut plugin: - -```toml -[dependencies] -tauri-plugin-global-shortcut = "2" -``` - -```rust -use tauri_plugin_global_shortcut::GlobalShortcutExt; -tauri::Builder::default() - .plugin(tauri_plugin_shortcut::init()) - .setup(|app| { - app.global_shortcut().register("CmdOrCtrl+Y")?; - Ok(()) - }) -``` - -#### Clipboard - -`App::clipboard_manager` and `AppHandle::clipboard_manager` APIs have been moved to the clipboard plugin: - -```toml -[dependencies] -tauri-plugin-clipboard = "2" -``` - -```rust -use tauri_plugin_clipboard::{ClipboardExt, ClipKind}; -tauri::Builder::default() - .plugin(tauri_plugin_clipboard::init()) - .setup(|app| { - app.clipboard().write(ClipKind::PlainText { - label: None, - text: "Tauri is awesome!".into(), - })?; - Ok(()) - }) -``` - -#### CLI - -The `App::get_cli_matches` function has been removed. Use the `cli` plugin instead: - -```toml -[dependencies] -tauri-plugin-cli = "2" -``` - -```rust -use tauri_plugin_cli::CliExt; -tauri::Builder::default() - .plugin(tauri_plugin_cli::init()) - .setup(|app| { - let cli_matches = app.cli().matches()?; - Ok(()) - }) -``` - -#### Scope - -`tauri::scope::ipc::RemoteDomainAccessScope::enable_tauri_api` and `tauri::scope::ipc::RemoteDomainAccessScope::enables_tauri_api` have been removed. Enable each core plugin individually via `tauri::scope::ipc::RemoteDomainAccessScope::add_plugin` instead. - -### JavaScript API - -The `@tauri-apps/api` package no longer provides non-core modules. Only the `tauri`, `path` and `event` modules are exported. - -#### File System - -The `@tauri-apps/api/fs` module has been removed. Use the `@tauri-apps/plugin-fs` plugin instead: - -```toml -# Cargo.toml -[dependencies] -tauri-plugin-fs = "2" -``` - -```rust -fn main() { - tauri::Builder::default() - .plugin(tauri_plugin_fs::init()) -} -``` - -```json -// package.json -{ - "dependencies": { - "@tauri-apps/plugin-fs": "^2.0.0" - } -} -``` - -```js -import { createDir, BaseDirectory } from '@tauri-apps/plugin-fs'; -await createDir('db', { dir: BaseDirectory.AppLocalData }); -``` - -#### Process - -The `@tauri-apps/api/process` module has been removed. Use the `@tauri-apps/plugin-process` plugin instead: - -```toml -# Cargo.toml -[dependencies] -tauri-plugin-process = "2" -``` - -```rust -fn main() { - tauri::Builder::default() - .plugin(tauri_plugin_process::init()) -} -``` - -```json -// package.json -{ - "dependencies": { - "@tauri-apps/plugin-process": "^2.0.0" - } -} -``` - -```js -import { exit, relaunch } from '@tauri-apps/plugin-process'; -await exit(0); -await relaunch(); -``` - -#### Shell - -The `@tauri-apps/api/shell` module has been removed. Use the `@tauri-apps/plugin-shell` plugin instead: - -```toml -# Cargo.toml -[dependencies] -tauri-plugin-shell = "2" -``` - -```rust -fn main() { - tauri::Builder::default() - .plugin(tauri_plugin_shell::init()) -} -``` - -```json -// package.json -{ - "dependencies": { - "@tauri-apps/plugin-shell": "^2.0.0" - } -} -``` - -```js -import { Command, open } from '@tauri-apps/plugin-shell'; -const output = await Command.create('echo', 'message').execute(); - -await open('https://github.com/tauri-apps/tauri'); -``` - -#### Updater - -The `@tauri-apps/api/updater` module has been removed. Use the `@tauri-apps/plugin-updater` plugin instead: - -```toml -# Cargo.toml -[dependencies] -tauri-plugin-updater = "2" -``` - -```rust -fn main() { - tauri::Builder::default() - .plugin(tauri_plugin_updater::init()) -} -``` - -```json -// package.json -{ - "dependencies": { - "@tauri-apps/plugin-updater": "^2.0.0" - } -} -``` - -```js -import { check } from '@tauri-apps/plugin-updater'; -import { relaunch } from '@tauri-apps/plugin-process'; - -const update = await check(); -if (update.response.available) { - console.log( - `Update to ${update.response.latestVersion} available! Date: ${update.response.date}` - ); - console.log(`Release notes: ${update.response.body}`); - await update.downloadAndInstall(); - // requires the `process` plugin - await relaunch(); -} -``` - -#### Dialog - -The `@tauri-apps/api/dialog` module has been removed. Use the `@tauri-apps/plugin-dialog` plugin instead: - -```toml -# Cargo.toml -[dependencies] -tauri-plugin-dialog = "2" -``` - -```rust -fn main() { - tauri::Builder::default() - .plugin(tauri_plugin_dialog::init()) -} -``` - -```json -// package.json -{ - "dependencies": { - "@tauri-apps/plugin-dialog": "^2.0.0" - } -} -``` - -```js -import { save } from '@tauri-apps/plugin-dialog'; -const filePath = await save({ - filters: [ - { - name: 'Image', - extensions: ['png', 'jpeg'], - }, - ], -}); -``` - -#### HTTP - -The `@tauri-apps/api/http` module has been removed. Use the `@tauri-apps/plugin-http` plugin instead: - -```toml -# Cargo.toml -[dependencies] -tauri-plugin-http = "2" -``` - -```rust -fn main() { - tauri::Builder::default() - .plugin(tauri_plugin_http::init()) -} -``` - -```json -// package.json -{ - "dependencies": { - "@tauri-apps/plugin-http": "^2.0.0" - } -} -``` - -```js -import { fetch } from '@tauri-apps/plugin-http'; -const response = await fetch( - 'https://raw.githubusercontent.com/tauri-apps/tauri/dev/package.json' -); -``` - -#### App - -The `@tauri-apps/api/app` module has been removed. Use the `@tauri-apps/plugin-app` plugin instead: - -```toml -# Cargo.toml -[dependencies] -tauri-plugin-app = "2" -``` - -```rust -fn main() { - tauri::Builder::default() - .plugin(tauri_plugin_app::init()) -} -``` - -```json -// package.json -{ - "dependencies": { - "@tauri-apps/plugin-app": "^2.0.0" - } -} -``` - -```js -import { show, hide } from '@tauri-apps/plugin-app'; -await hide(); -await show(); -``` - -#### OS - -The `@tauri-apps/api/os` module has been removed. Use the `@tauri-apps/plugin-os` plugin instead: - -```toml -# Cargo.toml -[dependencies] -tauri-plugin-os = "2" -``` - -```rust -fn main() { - tauri::Builder::default() - .plugin(tauri_plugin_os::init()) -} -``` - -```json -// package.json -{ - "dependencies": { - "@tauri-apps/plugin-os": "^2.0.0" - } -} -``` - -```js -import { arch } from '@tauri-apps/plugin-os'; -const architecture = await arch(); -``` - -#### CLI - -The `@tauri-apps/api/cli` module has been removed. Use the `@tauri-apps/plugin-cli` plugin instead: - -```toml -# Cargo.toml -[dependencies] -tauri-plugin-cli = "2" -``` - -```rust -fn main() { - tauri::Builder::default() - .plugin(tauri_plugin_cli::init()) -} -``` - -```json -// package.json -{ - "dependencies": { - "@tauri-apps/plugin-cli": "^2.0.0" - } -} -``` - -```js -import { getMatches } from '@tauri-apps/plugin-cli'; -const matches = await getMatches(); -``` - -#### Global Shortcut - -The `@tauri-apps/api/global-shortcut` module has been removed. Use the `@tauri-apps/plugin-global-shortcut` plugin instead: - -```toml -# Cargo.toml -[dependencies] -tauri-plugin-global-shortcut = "2" -``` - -```rust -fn main() { - tauri::Builder::default() - .plugin(tauri_plugin_global_shortcut::init()) -} -``` - -```json -// package.json -{ - "dependencies": { - "@tauri-apps/plugin-global-shortcut": "^2.0.0" - } -} -``` - -```js -import { register } from '@tauri-apps/plugin-global-shortcut'; -await register('CommandOrControl+Shift+C', () => { - console.log('Shortcut triggered'); -}); -``` - -#### Clipboard - -The `@tauri-apps/api/clipboard` module has been removed. Use the `@tauri-apps/plugin-clipboard-manager` plugin instead: - -```toml -# Cargo.toml -[dependencies] -tauri-plugin-clipboard = "2" -``` - -```rust -fn main() { - tauri::Builder::default() - .plugin(tauri_plugin_clipboard::init()) -} -``` - -```json -// package.json -{ - "dependencies": { - "@tauri-apps/plugin-clipboard-manager": "^2.0.0" - } -} -``` - -```js -import { writeText, readText } from '@tauri-apps/plugin-clipboard-manager'; -await writeText('Tauri is awesome!'); -assert(await readText(), 'Tauri is awesome!'); -``` - -#### Notification - -The `@tauri-apps/api/notification` module has been removed. Use the `@tauri-apps/plugin-notification` plugin instead: - -```toml -# Cargo.toml -[dependencies] -tauri-plugin-notification = "2" -``` - -```rust -fn main() { - tauri::Builder::default() - .plugin(tauri_plugin_notification::init()) -} -``` - -```json -// package.json -{ - "dependencies": { - "@tauri-apps/plugin-notification": "^2.0.0" - } -} -``` - -```js -import { sendNotification } from '@tauri-apps/plugin-notification'; -sendNotification('Tauri is awesome!'); -``` - -#### Window - -The `@tauri-apps/api/window` module has been removed. Use the `@tauri-apps/plugin-window` plugin instead: - -```toml -# Cargo.toml -[dependencies] -tauri-plugin-window = "2" -``` - -```rust -fn main() { - tauri::Builder::default() - .plugin(tauri_plugin_window::init()) -} -``` - -```json -// package.json -{ - "dependencies": { - "@tauri-apps/plugin-window": "^2.0.0" - } -} -``` - -```js -import { appWindow } from '@tauri-apps/plugin-window'; -await appWindow.setTitle('Tauri'); -``` - -## title: Upgrade & Migrate - import Stub from '@components/Stub.astro'; -- From Tauri 1.0 - Electron to Tauri - Flutter to Tauri + +[Upgrade from Tauri 1](./from-tauri-1) From 85dd436b4168ce210ebac21e7af895713a361203 Mon Sep 17 00:00:00 2001 From: Lorenzo Lewis Date: Wed, 9 Aug 2023 18:18:35 +0100 Subject: [PATCH 4/7] refactors Signed-off-by: Lorenzo Lewis --- .../2/guide/upgrade-migrate/from-tauri-1.mdx | 497 ++++++++++++------ 1 file changed, 322 insertions(+), 175 deletions(-) diff --git a/src/content/docs/2/guide/upgrade-migrate/from-tauri-1.mdx b/src/content/docs/2/guide/upgrade-migrate/from-tauri-1.mdx index 78827c0b96..ad38c68d3b 100644 --- a/src/content/docs/2/guide/upgrade-migrate/from-tauri-1.mdx +++ b/src/content/docs/2/guide/upgrade-migrate/from-tauri-1.mdx @@ -3,6 +3,7 @@ title: Migrate from Tauri 1.0 --- import { Tabs, TabItem } from '@astrojs/starlight/components'; +import CommandTabs from '@components/CommandTabs.astro'; This guide walks you through migrating your Tauri 1.0 application to Tauri 2.0. @@ -10,40 +11,18 @@ This guide walks you through migrating your Tauri 1.0 application to Tauri 2.0. The Tauri v2 CLI includes a `migrate` command that automates most of the process and helps you finish the migration: - - - - ```sh - npm install @tauri-apps/cli@latest - npm run tauri migrate - ``` - - - - - ```sh - yarn upgrade @tauri-apps/cli --latest - yarn tauri migrate - ``` - - - - - ```sh - pnpm update @tauri-apps/cli --latest - pnpm tauri migrate - ``` - - - + - ```sh - cargo install tauri-cli - cargo tauri migrate - ``` - - - +{/* TODO: 2.0 */} ## Summary of Changes @@ -58,6 +37,8 @@ Below is a summary of the changes from Tauri 1.0 to Tauri 2.0: - `tauri > updater > dialog` removed. - `tauri > updater > endpoints` moved to `plugins > updater`. +[Tauri 2.0 Configuration API reference](/2/reference/config) + ### New Cargo Features - linux-protocol-body: Enables custom protocol request body parsing, allowing the IPC to use it. Requires webkit2gtk 2.40. @@ -100,7 +81,7 @@ The `@tauri-apps/api` package no longer provides non-core modules. Only the `tau - `@tauri-apps/api/cli` module removed. Use `@tauri-apps/plugin-cli` instead. [Migration](#migrate-to-cli-plugin) - `@tauri-apps/api/clipboard` module removed. Use `@tauri-apps/plugin-clipboard` instead. [Migration](#migrate-to-clipboard-plugin) - `@tauri-apps/api/dialog` module removed. Use `@tauri-apps/plugin-dialog` instead. [Migration](#migrate-to-dialog-plugin) -- `@tauri-apps/api/fs` module removed. Use `@tauri-apps/plugin-fs` instead. [Migration](#migrate-to-filesystem-plugin) +- `@tauri-apps/api/fs` module removed. Use `@tauri-apps/plugin-fs` instead. [Migration](#migrate-to-file-system-plugin) - `@tauri-apps/api/global-shortcut` module removed. Use `@tauri-apps/plugin-global-shortcut` instead. [Migration](#migrate-to-global-shortcut-plugin) - `@tauri-apps/api/http` module removed. Use `@tauri-apps/plugin-http` instead. [Migration](#migrate-to-http-plugin) - `@tauri-apps/api/os` module removed. Use `@tauri-apps/plugin-os` instead. [Migration](#migrate-to-os-plugin) @@ -112,16 +93,20 @@ The `@tauri-apps/api` package no longer provides non-core modules. Only the `tau ## Detailed Migration Steps -### Migrate to CLI Plugin +Common scenarios you may encounter when migrating your Tauri 1.0 app to Tauri 2.0. + +### Migrate to App Plugin + +{/* TODO: Is the Tauri 1.0 Rust equivalent something like tauri::window::Window::hide? */} -The Rust `App::get_cli_matches` function and JavaScript `@tauri-apps/api/cli` module have been removed. Use the `cli` plugin instead: +The JavaScript `@tauri-apps/api/app` APIs have been removed. Use the `@tauri-apps/plugin-app` plugin instead: 1. Add to cargo dependencies: ```toml # Cargo.toml [dependencies] -tauri-plugin-cli = "2" +tauri-plugin-app = "2" ``` 2. Use in JavaScript or Rust project: @@ -132,7 +117,7 @@ tauri-plugin-cli = "2" ```rust fn main() { tauri::Builder::default() - .plugin(tauri_plugin_cli::init()) + .plugin(tauri_plugin_app::init()) } ``` @@ -140,19 +125,22 @@ fn main() { // package.json { "dependencies": { - "@tauri-apps/plugin-cli": "^2.0.0" + "@tauri-apps/plugin-app": "^2.0.0" } } ``` ```js -import { getMatches } from '@tauri-apps/plugin-cli'; -const matches = await getMatches(); +import { show, hide } from '@tauri-apps/plugin-app'; +await hide(); +await show(); ``` +{/* TODO: Rust example */} + ```rust fn main() { use tauri_plugin_cli::CliExt; @@ -168,38 +156,74 @@ fn main() { -### Migrate to Clipboard Plugin +### Migrate to CLI Plugin + +The Rust `App::get_cli_matches` JavaScript `@tauri-apps/api/cli` APIs have been removed. Use the `@tauri-apps/plugin-cli` plugin instead: -`App::clipboard_manager` and `AppHandle::clipboard_manager` APIs have been moved to the clipboard plugin: +1. Add to cargo dependencies: ```toml +# Cargo.toml [dependencies] -tauri-plugin-clipboard = "2" +tauri-plugin-cli = "2" ``` +2. Use in JavaScript or Rust project: + + + + ```rust -use tauri_plugin_clipboard::{ClipboardExt, ClipKind}; -tauri::Builder::default() - .plugin(tauri_plugin_clipboard::init()) - .setup(|app| { - app.clipboard().write(ClipKind::PlainText { - label: None, - text: "Tauri is awesome!".into(), - })?; - Ok(()) - }) +fn main() { + tauri::Builder::default() + .plugin(tauri_plugin_cli::init()) +} ``` +```json +// package.json +{ + "dependencies": { + "@tauri-apps/plugin-cli": "^2.0.0" + } +} +``` + +```js +import { getMatches } from '@tauri-apps/plugin-cli'; +const matches = await getMatches(); +``` + + + + +```rust +fn main() { + use tauri_plugin_cli::CliExt; + tauri::Builder::default() + .plugin(tauri_plugin_cli::init()) + .setup(|app| { + let cli_matches = app.cli().matches()?; + Ok(()) + }) +} +``` + + + + ### Migrate to Clipboard Plugin -The `@tauri-apps/api/clipboard` module has been removed. Use the `@tauri-apps/plugin-clipboard-manager` plugin instead: +The Rust `App::clipboard_manager` and `AppHandle::clipboard_manager` and JavaScript `@tauri-apps/api/clipboard` APIs have been removed. Use the `@tauri-apps/plugin-clipboard-manager` plugin instead: ```toml -# Cargo.toml [dependencies] tauri-plugin-clipboard = "2" ``` + + + ```rust fn main() { tauri::Builder::default() @@ -222,9 +246,30 @@ await writeText('Tauri is awesome!'); assert(await readText(), 'Tauri is awesome!'); ``` + + + +```rust +use tauri_plugin_clipboard::{ClipboardExt, ClipKind}; +tauri::Builder::default() + .plugin(tauri_plugin_clipboard::init()) + .setup(|app| { + app.clipboard().write(ClipKind::PlainText { + label: None, + text: "Tauri is awesome!".into(), + })?; + Ok(()) + }) +``` + + + + ### Migrate to Dialog Plugin -The `@tauri-apps/api/dialog` module has been removed. Use the `@tauri-apps/plugin-dialog` plugin instead: +The Rust `tauri::api::dialog` JavaScript `@tauri-apps/api/dialog` APIs have been removed. Use the `@tauri-apps/plugin-dialog` plugin instead: + +1. Add to cargo dependencies: ```toml # Cargo.toml @@ -232,6 +277,11 @@ The `@tauri-apps/api/dialog` module has been removed. Use the `@tauri-apps/plugi tauri-plugin-dialog = "2" ``` +2. Use in JavaScript or Rust project: + + + + ```rust fn main() { tauri::Builder::default() @@ -260,12 +310,8 @@ const filePath = await save({ }); ``` -### Migrate to Dialog Plugin - -```toml -[dependencies] -tauri-plugin-dialog = "2" -``` + + ```rust use tauri_plugin_dialog::DialogExt; @@ -282,9 +328,14 @@ tauri::Builder::default() }) ``` + + + ### Migrate to File System Plugin -The `@tauri-apps/api/fs` module has been removed. Use the `@tauri-apps/plugin-fs` plugin instead: +The Rust `App::get_cli_matches` JavaScript `@tauri-apps/api/fs` APIs have been removed. Use the [`std::fs`](https://doc.rust-lang.org/std/fs/) for Rust and `@tauri-apps/plugin-fs` plugin for JavaScript instead: + +1. Add to cargo dependencies: ```toml # Cargo.toml @@ -292,6 +343,11 @@ The `@tauri-apps/api/fs` module has been removed. Use the `@tauri-apps/plugin-fs tauri-plugin-fs = "2" ``` +2. Use in JavaScript or Rust project: + + + + ```rust fn main() { tauri::Builder::default() @@ -313,28 +369,19 @@ import { createDir, BaseDirectory } from '@tauri-apps/plugin-fs'; await createDir('db', { dir: BaseDirectory.AppLocalData }); ``` -### Migrate to Global Shortcut Plugin - -`App::global_shortcut_manager` and `AppHandle::global_shortcut_manager` APIs have been moved to the global shortcut plugin: + + -```toml -[dependencies] -tauri-plugin-global-shortcut = "2" -``` +Use the Rust [`std::fs`](https://doc.rust-lang.org/std/fs/) functions. -```rust -use tauri_plugin_global_shortcut::GlobalShortcutExt; -tauri::Builder::default() - .plugin(tauri_plugin_shortcut::init()) - .setup(|app| { - app.global_shortcut().register("CmdOrCtrl+Y")?; - Ok(()) - }) -``` + + ### Migrate to Global Shortcut Plugin -The `@tauri-apps/api/global-shortcut` module has been removed. Use the `@tauri-apps/plugin-global-shortcut` plugin instead: +The Rust `App::global_shortcut_manager` and `AppHandle::global_shortcut_manager` and JavaScript `@tauri-apps/api/global-shortcut` APIs have been removed. Use the `@tauri-apps/plugin-global-shortcut` plugin instead: + +1. Add to cargo dependencies: ```toml # Cargo.toml @@ -342,6 +389,11 @@ The `@tauri-apps/api/global-shortcut` module has been removed. Use the `@tauri-a tauri-plugin-global-shortcut = "2" ``` +2. Use in JavaScript or Rust project: + + + + ```rust fn main() { tauri::Builder::default() @@ -365,25 +417,27 @@ await register('CommandOrControl+Shift+C', () => { }); ``` -### Migrate to HTTP Plugin - -The `tauri::api::http` module has been removed. Use the `http` plugin instead: - -```toml -[dependencies] -tauri-plugin-http = "2" -``` + + ```rust -use tauri_plugin_dialog::{DialogExt, client}; -// `client` is a re-export of `reqwest`. APIs will be available in the future as DialogExt::http +use tauri_plugin_global_shortcut::GlobalShortcutExt; tauri::Builder::default() - .plugin(tauri_plugin_http::init()) + .plugin(tauri_plugin_shortcut::init()) + .setup(|app| { + app.global_shortcut().register("CmdOrCtrl+Y")?; + Ok(()) + }) ``` + + + ### Migrate to HTTP Plugin -The `@tauri-apps/api/http` module has been removed. Use the `@tauri-apps/plugin-http` plugin instead: +The Rust `tauri::api::http` JavaScript `@tauri-apps/api/http` APIs have been removed. Use the `@tauri-apps/plugin-http` plugin instead: + +1. Add to cargo dependencies: ```toml # Cargo.toml @@ -391,6 +445,11 @@ The `@tauri-apps/api/http` module has been removed. Use the `@tauri-apps/plugin- tauri-plugin-http = "2" ``` +2. Use in JavaScript or Rust project: + + + + ```rust fn main() { tauri::Builder::default() @@ -414,9 +473,26 @@ const response = await fetch( ); ``` + + + +{/* TODO: Code example of this one? */} + +```rust +use tauri_plugin_dialog::{DialogExt, client}; +// `client` is a re-export of `reqwest`. APIs will be available in the future as DialogExt::http +tauri::Builder::default() + .plugin(tauri_plugin_http::init()) +``` + + + + ### Migrate to Notification Plugin -The `@tauri-apps/api/notification` module has been removed. Use the `@tauri-apps/plugin-notification` plugin instead: +The Rust `tauri::api::notification` JavaScript `@tauri-apps/api/notification` APIs have been removed. Use the `@tauri-apps/plugin-notification` plugin instead: + +1. Add to cargo dependencies: ```toml # Cargo.toml @@ -424,6 +500,11 @@ The `@tauri-apps/api/notification` module has been removed. Use the `@tauri-apps tauri-plugin-notification = "2" ``` +2. Use in JavaScript or Rust project: + + + + ```rust fn main() { tauri::Builder::default() @@ -445,9 +526,31 @@ import { sendNotification } from '@tauri-apps/plugin-notification'; sendNotification('Tauri is awesome!'); ``` + + + +{/* TODO: Code example on the Rust side */} + +```rust +fn main() { + use tauri_plugin_cli::CliExt; + tauri::Builder::default() + .plugin(tauri_plugin_cli::init()) + .setup(|app| { + let cli_matches = app.cli().matches()?; + Ok(()) + }) +} +``` + + + + ### Migrate to OS Plugin -The `@tauri-apps/api/os` module has been removed. Use the `@tauri-apps/plugin-os` plugin instead: +The Rust `tauri::api::os` JavaScript `@tauri-apps/api/os` APIs have been removed. Use the `@tauri-apps/plugin-os` plugin instead: + +1. Add to cargo dependencies: ```toml # Cargo.toml @@ -455,6 +558,11 @@ The `@tauri-apps/api/os` module has been removed. Use the `@tauri-apps/plugin-os tauri-plugin-os = "2" ``` +2. Use in JavaScript or Rust project: + + + + ```rust fn main() { tauri::Builder::default() @@ -476,9 +584,31 @@ import { arch } from '@tauri-apps/plugin-os'; const architecture = await arch(); ``` + + + +{/* TODO: Rust example */} + +```rust +fn main() { + use tauri_plugin_cli::CliExt; + tauri::Builder::default() + .plugin(tauri_plugin_cli::init()) + .setup(|app| { + let cli_matches = app.cli().matches()?; + Ok(()) + }) +} +``` + + + + ### Migrate to Process Plugin -The `@tauri-apps/api/process` module has been removed. Use the `@tauri-apps/plugin-process` plugin instead: +The Rust `tauri::api::process` JavaScript `@tauri-apps/api/process` APIs have been removed. Use the `@tauri-apps/plugin-process` plugin instead: + +1. Add to cargo dependencies: ```toml # Cargo.toml @@ -486,6 +616,11 @@ The `@tauri-apps/api/process` module has been removed. Use the `@tauri-apps/plug tauri-plugin-process = "2" ``` +2. Use in JavaScript or Rust project: + + + + ```rust fn main() { tauri::Builder::default() @@ -508,9 +643,31 @@ await exit(0); await relaunch(); ``` + + + +{/* TODO: Rust example */} + +```rust +fn main() { + use tauri_plugin_cli::CliExt; + tauri::Builder::default() + .plugin(tauri_plugin_cli::init()) + .setup(|app| { + let cli_matches = app.cli().matches()?; + Ok(()) + }) +} +``` + + + + ### Migrate to Shell Plugin -The `@tauri-apps/api/shell` module has been removed. Use the `@tauri-apps/plugin-shell` plugin instead: +The Rust `tauri::api::shell` JavaScript `@tauri-apps/api/shell` APIs have been removed. Use the `@tauri-apps/plugin-shell` plugin instead: + +1. Add to cargo dependencies: ```toml # Cargo.toml @@ -518,6 +675,11 @@ The `@tauri-apps/api/shell` module has been removed. Use the `@tauri-apps/plugin tauri-plugin-shell = "2" ``` +2. Use in JavaScript or Rust project: + + + + ```rust fn main() { tauri::Builder::default() @@ -541,12 +703,10 @@ const output = await Command.create('echo', 'message').execute(); await open('https://github.com/tauri-apps/tauri'); ``` -### Migrate to Shell Plugin + + -```toml -[dependencies] -tauri-plugin-shell = "2" -``` +{/* TODO: Does this one need to be this complicated or could we simplify it to be similar to the other Rust code blocks? */} ```rust use tauri_plugin_shell::{ShellExt, process::CommandEvent}; @@ -591,34 +751,29 @@ fn main() { } ``` -### Migrate to Updater Plugin - -```toml -[dependencies] -tauri-plugin-updater = "2" -``` - -```rust -fn main() { - tauri::Builder::default() - .plugin(tauri_plugin_updater::Builder::new().build()) -} -``` + + ### Migrate to Updater Plugin -The `@tauri-apps/api/updater` module has been removed. Use the `@tauri-apps/plugin-updater` plugin instead: +The Rust `tauri::updater` and JavaScript `@tauri-apps/api-updater` APIs have been removed. To set a custom updater target with the `@tauri-apps/plugin-updater`: + +1. Add to cargo dependencies: ```toml -# Cargo.toml [dependencies] tauri-plugin-updater = "2" ``` +2. Use in JavaScript of Rust project: + + + + ```rust fn main() { tauri::Builder::default() - .plugin(tauri_plugin_updater::init()) + .plugin(tauri_plugin_updater::Builder::new().build()) } ``` @@ -647,30 +802,10 @@ if (update.response.available) { } ``` -#### Custom Updater Target - -The `tauri::Builder` `updater_target` function has been removed. To set a custom updater target: - -```rust -fn main() { - let mut updater = tauri_plugin_updater::Builder::new(); - #[cfg(target_os = "macos")] - { - updater = updater.target("darwin-universal"); - } - tauri::Builder::default() - .plugin(updater.build()) -} -``` - -#### Check for Updates - -- `tauri::updater` module removed. Use `tauri-plugin-updater` instead. -- `tauri::Builder` `updater_target` function removed. [Migration](#custom-updater-target) -- `App` and `AppHandle` `updater` function removed. [Migration](#check-for-updates) -- `tauri::RunEvent::Updater` removed. The updater state can now be handled in the `app.updater().check().await` return value itself. + + -To check for updates use the `updater` method from `tauri_plugin_updater::UpdaterExt`: +To check for updates: ```rust use tauri_plugin_updater::UpdaterExt; @@ -688,9 +823,28 @@ fn main() { } ``` +To set a custom updater target: + +```rust +fn main() { + let mut updater = tauri_plugin_updater::Builder::new(); + #[cfg(target_os = "macos")] + { + updater = updater.target("darwin-universal"); + } + tauri::Builder::default() + .plugin(updater.build()) +} +``` + + + + ### Migrate to Window Plugin -The `@tauri-apps/api/window` module has been removed. Use the `@tauri-apps/plugin-window` plugin instead: +The Rust `tauri::window` JavaScript `@tauri-apps/api/window` APIs have been removed. Use the `@tauri-apps/plugin-window` plugin instead: + +1. Add to cargo dependencies: ```toml # Cargo.toml @@ -698,6 +852,11 @@ The `@tauri-apps/api/window` module has been removed. Use the `@tauri-apps/plugi tauri-plugin-window = "2" ``` +2. Use in JavaScript or Rust project: + + + + ```rust fn main() { tauri::Builder::default() @@ -719,9 +878,29 @@ import { appWindow } from '@tauri-apps/plugin-window'; await appWindow.setTitle('Tauri'); ``` + + + +{/* TODO: Rust example */} + +```rust +fn main() { + use tauri_plugin_cli::CliExt; + tauri::Builder::default() + .plugin(tauri_plugin_cli::init()) + .setup(|app| { + let cli_matches = app.cli().matches()?; + Ok(()) + }) +} +``` + + + + ### Migrate Path to Tauri Manager -The `tauri::api::path` module functions and `tauri::PathResolver` have been moved to `tauri::Manager::path`: +The Rust `tauri::api::path` module functions and `tauri::PathResolver` have been moved to `tauri::Manager::path`: ```rust use tauri::{path::BaseDirectory, Manager}; @@ -735,35 +914,3 @@ tauri::Builder::default() Ok(()) }) ``` - -#### Migrate to App Plugin - -The `@tauri-apps/api/app` module has been removed. Use the `@tauri-apps/plugin-app` plugin instead: - -```toml -# Cargo.toml -[dependencies] -tauri-plugin-app = "2" -``` - -```rust -fn main() { - tauri::Builder::default() - .plugin(tauri_plugin_app::init()) -} -``` - -```json -// package.json -{ - "dependencies": { - "@tauri-apps/plugin-app": "^2.0.0" - } -} -``` - -```js -import { show, hide } from '@tauri-apps/plugin-app'; -await hide(); -await show(); -``` From 1fd3f6c9ef82afbcc0441b7d48a3f3642790c466 Mon Sep 17 00:00:00 2001 From: Lorenzo Lewis Date: Wed, 9 Aug 2023 18:20:27 +0100 Subject: [PATCH 5/7] add link to migrate cli command Signed-off-by: Lorenzo Lewis --- src/content/docs/2/guide/upgrade-migrate/from-tauri-1.mdx | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/content/docs/2/guide/upgrade-migrate/from-tauri-1.mdx b/src/content/docs/2/guide/upgrade-migrate/from-tauri-1.mdx index ad38c68d3b..f657221f76 100644 --- a/src/content/docs/2/guide/upgrade-migrate/from-tauri-1.mdx +++ b/src/content/docs/2/guide/upgrade-migrate/from-tauri-1.mdx @@ -24,6 +24,8 @@ The Tauri v2 CLI includes a `migrate` command that automates most of the process {/* TODO: 2.0 */} +Learn more about the `migrate` command in the [Command Line Interface reference](/2/reference/cli#migrate) + ## Summary of Changes Below is a summary of the changes from Tauri 1.0 to Tauri 2.0: From bb1d6eefd347e870ca60b2e13728ba9b4a37af03 Mon Sep 17 00:00:00 2001 From: Lucas Nogueira Date: Wed, 9 Aug 2023 18:06:20 -0300 Subject: [PATCH 6/7] add examples --- .../2/guide/upgrade-migrate/from-tauri-1.mdx | 127 ++++++++++++------ 1 file changed, 89 insertions(+), 38 deletions(-) diff --git a/src/content/docs/2/guide/upgrade-migrate/from-tauri-1.mdx b/src/content/docs/2/guide/upgrade-migrate/from-tauri-1.mdx index f657221f76..fd909da2e2 100644 --- a/src/content/docs/2/guide/upgrade-migrate/from-tauri-1.mdx +++ b/src/content/docs/2/guide/upgrade-migrate/from-tauri-1.mdx @@ -99,8 +99,6 @@ Common scenarios you may encounter when migrating your Tauri 1.0 app to Tauri 2. ### Migrate to App Plugin -{/* TODO: Is the Tauri 1.0 Rust equivalent something like tauri::window::Window::hide? */} - The JavaScript `@tauri-apps/api/app` APIs have been removed. Use the `@tauri-apps/plugin-app` plugin instead: 1. Add to cargo dependencies: @@ -141,15 +139,16 @@ await show(); -{/* TODO: Rust example */} - ```rust fn main() { - use tauri_plugin_cli::CliExt; tauri::Builder::default() - .plugin(tauri_plugin_cli::init()) + .plugin(tauri_plugin_app::init()) .setup(|app| { - let cli_matches = app.cli().matches()?; + #[cfg(target_os = "macos")] + { + app.hide()?; + app.show()?; + } Ok(()) }) } @@ -424,6 +423,7 @@ await register('CommandOrControl+Shift+C', () => { ```rust use tauri_plugin_global_shortcut::GlobalShortcutExt; + tauri::Builder::default() .plugin(tauri_plugin_shortcut::init()) .setup(|app| { @@ -478,15 +478,26 @@ const response = await fetch( -{/* TODO: Code example of this one? */} - ```rust -use tauri_plugin_dialog::{DialogExt, client}; -// `client` is a re-export of `reqwest`. APIs will be available in the future as DialogExt::http +use tauri_plugin_dialog::reqwest; + tauri::Builder::default() .plugin(tauri_plugin_http::init()) + .setup(|app| { + let response_data = tauri::async_runtime::block_on(async { + let response = reqwest::get( + "https://raw.githubusercontent.com/tauri-apps/tauri/dev/package.json", + ) + .await + .unwrap(); + response.text().await + })?; + Ok(()) + }) ``` +The HTTP plugin re-exports [reqwest](https://docs.rs/reqwest/latest/reqwest/) so you can check out their documentation for more information. + @@ -531,15 +542,22 @@ sendNotification('Tauri is awesome!'); -{/* TODO: Code example on the Rust side */} - ```rust +use tauri_plugin_notification::{NotificationExt, PermissionState}; + fn main() { - use tauri_plugin_cli::CliExt; tauri::Builder::default() - .plugin(tauri_plugin_cli::init()) + .plugin(tauri_plugin_notification::init()) .setup(|app| { - let cli_matches = app.cli().matches()?; + if app.notification().permission_state()? == PermissionState::Unknown { + app.notification().request_permission()?; + } + if app.notification().permission_state()? == PermissionState::Granted { + app.notification() + .builder() + .body("Tauri is awesome!") + .show()?; + } Ok(()) }) } @@ -589,15 +607,12 @@ const architecture = await arch(); -{/* TODO: Rust example */} - ```rust fn main() { - use tauri_plugin_cli::CliExt; tauri::Builder::default() - .plugin(tauri_plugin_cli::init()) + .plugin(tauri_plugin_os::init()) .setup(|app| { - let cli_matches = app.cli().matches()?; + let os_arch = tauri_plugin_os::arch(); Ok(()) }) } @@ -648,15 +663,15 @@ await relaunch(); -{/* TODO: Rust example */} - ```rust fn main() { - use tauri_plugin_cli::CliExt; tauri::Builder::default() - .plugin(tauri_plugin_cli::init()) + .plugin(tauri_plugin_process::init()) .setup(|app| { - let cli_matches = app.cli().matches()?; + // exit the app with a status code + app.handle().exit(1); + // restart the app + app.handle().restart(); Ok(()) }) } @@ -708,28 +723,64 @@ await open('https://github.com/tauri-apps/tauri'); -{/* TODO: Does this one need to be this complicated or could we simplify it to be similar to the other Rust code blocks? */} +- Open an URL ```rust -use tauri_plugin_shell::{ShellExt, process::CommandEvent}; +use tauri_plugin_shell::ShellExt; + fn main() { tauri::Builder::default() .plugin(tauri_plugin_shell::init()) .setup(|app| { - // open app.shell().open("https://github.com/tauri-apps/tauri", None)?; + Ok(()) + }) +} +``` + +- Spawn a child process and retrieve the status code - // status() +```rust +use tauri_plugin_shell::ShellExt; + +fn main() { + tauri::Builder::default() + .plugin(tauri_plugin_shell::init()) + .setup(|app| { let status = tauri::async_runtime::block_on(async move { app.shell().command("which").args(["ls"]).status().await.unwrap() }); println!("`which` finished with status: {:?}", status.code()); + Ok(()) + }) +} +``` + +- Spawn a child process and capture its output - // output() +```rust +use tauri_plugin_shell::ShellExt; + +fn main() { + tauri::Builder::default() + .plugin(tauri_plugin_shell::init()) + .setup(|app| { let output = tauri::async_runtime::block_on(async move { app.shell().command("echo").args(["TAURI"]).output().await.unwrap() }); assert!(output.status.success()); assert_eq!(String::from_utf8(output.stdout).unwrap(), "TAURI"); + Ok(()) + }) +} +``` - // async - let handle = app.handle(); +- Spawn a child process and read its events asynchronously: + +```rust +use tauri_plugin_shell::{ShellExt, process::CommandEvent}; + +fn main() { + tauri::Builder::default() + .plugin(tauri_plugin_shell::init()) + .setup(|app| { + let handle = app.handle().clone(); tauri::async_runtime::spawn(async move { let (mut rx, mut child) = handle.shell().command("cargo") .args(["tauri", "dev"]) @@ -883,15 +934,15 @@ await appWindow.setTitle('Tauri'); -{/* TODO: Rust example */} - ```rust +use tauri::Manager; + fn main() { - use tauri_plugin_cli::CliExt; tauri::Builder::default() - .plugin(tauri_plugin_cli::init()) + .plugin(tauri_plugin_window::init()) .setup(|app| { - let cli_matches = app.cli().matches()?; + let window = app.get_window("main").unwrap(); + window.set_title("Tauri")?; Ok(()) }) } From b30d783d64a03fd367e4617b404cdbfe3c1bf359 Mon Sep 17 00:00:00 2001 From: Lorenzo Lewis Date: Thu, 10 Aug 2023 07:30:32 +0000 Subject: [PATCH 7/7] change high-level phrasing to upgrade Signed-off-by: GitHub --- src/content/docs/2/guide/upgrade-migrate/from-tauri-1.mdx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/content/docs/2/guide/upgrade-migrate/from-tauri-1.mdx b/src/content/docs/2/guide/upgrade-migrate/from-tauri-1.mdx index fd909da2e2..5bc1a4dcad 100644 --- a/src/content/docs/2/guide/upgrade-migrate/from-tauri-1.mdx +++ b/src/content/docs/2/guide/upgrade-migrate/from-tauri-1.mdx @@ -1,11 +1,11 @@ --- -title: Migrate from Tauri 1.0 +title: Upgrade from Tauri 1.0 --- import { Tabs, TabItem } from '@astrojs/starlight/components'; import CommandTabs from '@components/CommandTabs.astro'; -This guide walks you through migrating your Tauri 1.0 application to Tauri 2.0. +This guide walks you through upgrading your Tauri 1.0 application to Tauri 2.0. ## Automated Migration