-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(core): remove
Params
and replace with strings (#2191)
* refactor(core): remove `Params` and replace with strings * add tauri-utils to changelog * update default runtime macro to accept type and feature * remove accidental default feature addition * remove changefile todo items that have no futher action * fix clippy warning * update changefile * finish change file * fix splashscreen example * fix markdown typo [skip ci] * remove final uses of `Params` * add license header to new runtime module in tauri-macros * update plugin guide to use runtime instead of params
- Loading branch information
Showing
46 changed files
with
855 additions
and
1,409 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
--- | ||
"tauri": patch | ||
"tauri-runtime": patch | ||
"tauri-runtime-wry": patch | ||
"tauri-macros": patch | ||
"tauri-utils": patch | ||
--- | ||
|
||
`Params` has been removed, along with all the associated types on it. Functions that previously accepted those | ||
associated types now accept strings instead. Type that used a generic parameter `Params` now use `Runtime` instead. If | ||
you use the `wry` feature, then types with a `Runtime` generic parameter should default to `Wry`, letting you omit the | ||
explicit type and let the compiler infer it instead. | ||
|
||
`tauri`: | ||
|
||
* See `Params` note | ||
* If you were using `Params` inside a function parameter or definition, all references to it have been replaced with a | ||
simple runtime that defaults to `Wry`. If you are not using a custom runtime, just remove `Params` from the definition | ||
of functions/items that previously took it. If you are using a custom runtime, you _may_ need to pass the runtime type | ||
to these functions. | ||
* If you were using custom types for `Params` (uncommon and if you don't understand you probably were not using it), all | ||
methods that were previously taking the custom type now takes an `Into<String>` or a `&str`. The types were already | ||
required to be string-able, so just make sure to convert it into a string before passing it in if this breaking change | ||
affects you. | ||
|
||
`tauri-macros`: | ||
|
||
* (internal) Added private `default_runtime` proc macro to allow us to give item definitions a custom runtime only when | ||
the specified feature is enabled. | ||
|
||
`tauri-runtime`: | ||
|
||
* See `Params` note | ||
* Removed `Params`, `MenuId`, `Tag`, `TagRef`. | ||
* Added `menu::{MenuHash, MenuId, MenuIdRef}` as type aliases for the internal type that menu types now use. | ||
* All previous menu items that had a `MenuId` generic now use the underlying `MenuId` type without a generic. | ||
* `Runtime`, `RuntimeHandle`, and `Dispatch` have no more generic parameter on `create_window(...)` and instead use the | ||
`Runtime` type directly | ||
* `Runtime::system_tray` has no more `MenuId` generic and uses the string based `SystemTray` type directly. | ||
* (internal) `CustomMenuItem::id_value()` is now hashed on creation and exposed as the `id` field with type `MenuHash`. | ||
|
||
`tauri-runtime-wry`: | ||
|
||
* See `Params` note | ||
* update menu and runtime related types to the ones changed in `tauri-runtime`. | ||
|
||
`tauri-utils`: | ||
|
||
* `Assets::get` signature has changed to take a `&AssetKey` instead of `impl Into<AssetKey>` to become trait object | ||
safe. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
// Copyright 2019-2021 Tauri Programme within The Commons Conservancy | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// SPDX-License-Identifier: MIT | ||
|
||
use proc_macro2::TokenStream; | ||
use quote::quote; | ||
use syn::parse::{Parse, ParseStream}; | ||
use syn::{parse_quote, DeriveInput, GenericParam, Ident, Token, Type, TypeParam}; | ||
|
||
/// The default runtime type to enable when the provided feature is enabled. | ||
pub(crate) struct Attributes { | ||
default_type: Type, | ||
feature: Ident, | ||
} | ||
|
||
impl Parse for Attributes { | ||
fn parse(input: ParseStream) -> syn::Result<Self> { | ||
let default_type = input.parse()?; | ||
input.parse::<Token![,]>()?; | ||
Ok(Attributes { | ||
default_type, | ||
feature: input.parse()?, | ||
}) | ||
} | ||
} | ||
|
||
pub(crate) fn default_runtime(attributes: Attributes, input: DeriveInput) -> TokenStream { | ||
// create a new copy to manipulate for the wry feature flag | ||
let mut wry = input.clone(); | ||
let wry_runtime = wry | ||
.generics | ||
.params | ||
.last_mut() | ||
.expect("default_runtime requires the item to have at least 1 generic parameter"); | ||
|
||
// set the default value of the last generic parameter to the provided runtime type | ||
match wry_runtime { | ||
GenericParam::Type( | ||
param @ TypeParam { | ||
eq_token: None, | ||
default: None, | ||
.. | ||
}, | ||
) => { | ||
param.eq_token = Some(parse_quote!(=)); | ||
param.default = Some(attributes.default_type); | ||
} | ||
_ => { | ||
panic!("DefaultRuntime requires the last parameter to not have a default value") | ||
} | ||
}; | ||
|
||
let feature = attributes.feature.to_string(); | ||
|
||
quote!( | ||
#[cfg(feature = #feature)] | ||
#wry | ||
|
||
#[cfg(not(feature = #feature))] | ||
#input | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.