Compare commits

...

9 Commits

Author SHA1 Message Date
Chip Reed
d1b5be7a08 fix codegen on non-macOS platforms 2023-02-22 21:34:09 -08:00
Chip Reed
82cd400e55 update schema.json 2023-02-22 21:32:51 -08:00
Chip Reed
89a04e968f update napi generated index.js 2023-02-22 21:32:23 -08:00
Chip Reed
c80158d51f update workspace exclusion comment 2023-02-22 21:24:19 -08:00
Chip Reed
8e43be7ebc merge dev into feat/build-pipeline 2023-02-21 09:06:25 -08:00
Chip Reed
00e2e11a1b fix doctest broken in b93071 2023-02-19 11:59:38 -08:00
Chip Reed
26506cc218 undo accidental import in b93071 2023-02-19 11:42:57 -08:00
Chip Reed
8a11b8f003 only rebuild on plist change if there is a plist 2023-02-19 11:39:47 -08:00
Chip Reed
b930712e84 deprecate generate_context! macro 2023-02-19 11:31:58 -08:00
71 changed files with 583 additions and 425 deletions

View File

@@ -12,11 +12,23 @@ members = [
# integration tests
"core/tests/restart",
"core/tests/app-updater"
"core/tests/app-updater",
"core/tests/tauri-codegen-test",
# simple examples
"examples/commands",
"examples/helloworld",
"examples/isolation",
"examples/multiwindow",
"examples/navigation",
"examples/parent-window",
"examples/splashscreen",
"examples/state",
"examples/streaming",
]
exclude = [
# examples that can be compiled with the tauri CLI
# examples that require NodeJS and/or NPM
"examples/api/src-tauri",
"examples/updater/src-tauri",
"examples/resources/src-tauri",

View File

@@ -720,47 +720,19 @@
},
"Theme": {
"description": "System theme.",
"oneOf": [
{
"description": "Light theme.",
"type": "string",
"enum": [
"Light"
]
},
{
"description": "Dark theme.",
"type": "string",
"enum": [
"Dark"
]
}
"type": "string",
"enum": [
"Light",
"Dark"
]
},
"TitleBarStyle": {
"description": "How the window title bar should be displayed on macOS.",
"oneOf": [
{
"description": "A normal title bar.",
"type": "string",
"enum": [
"Visible"
]
},
{
"description": "Makes the title bar transparent, so the window background color is shown instead.\n\nUseful if you don't need to have actual HTML under the title bar. This lets you avoid the caveats of using `TitleBarStyle::Overlay`. Will be more useful when Tauri lets you set a custom window background color.",
"type": "string",
"enum": [
"Transparent"
]
},
{
"description": "Shows the title bar as a transparent overlay over the window's content.\n\nKeep in mind: - The height of the title bar is different on different OS versions, which can lead to window the controls and title not being where you don't expect. - You need to define a custom drag region to make your window draggable, however due to a limitation you can't drag the window when it's not in focus <https://github.com/tauri-apps/tauri/issues/4316>. - The color of the window title depends on the system theme.",
"type": "string",
"enum": [
"Overlay"
]
}
"type": "string",
"enum": [
"Visible",
"Transparent",
"Overlay"
]
},
"CliConfig": {
@@ -1183,56 +1155,15 @@
},
"BundleType": {
"description": "A bundle referenced by tauri-bundler.",
"oneOf": [
{
"description": "The debian bundle (.deb).",
"type": "string",
"enum": [
"deb"
]
},
{
"description": "The AppImage bundle (.appimage).",
"type": "string",
"enum": [
"appimage"
]
},
{
"description": "The Microsoft Installer bundle (.msi).",
"type": "string",
"enum": [
"msi"
]
},
{
"description": "The NSIS bundle (.exe).",
"type": "string",
"enum": [
"nsis"
]
},
{
"description": "The macOS application bundle (.app).",
"type": "string",
"enum": [
"app"
]
},
{
"description": "The Apple Disk Image bundle (.dmg).",
"type": "string",
"enum": [
"dmg"
]
},
{
"description": "The Tauri updater bundle.",
"type": "string",
"enum": [
"updater"
]
}
"type": "string",
"enum": [
"deb",
"appimage",
"msi",
"nsis",
"app",
"dmg",
"updater"
]
},
"AppImageConfig": {
@@ -1716,28 +1647,11 @@
},
"NSISInstallerMode": {
"description": "Install Modes for the NSIS installer.",
"oneOf": [
{
"description": "Default mode for the installer.\n\nInstall the app by default in a directory that doesn't require Administrator access.\n\nInstaller metadata will be saved under the `HKCU` registry path.",
"type": "string",
"enum": [
"currentUser"
]
},
{
"description": "Install the app by default in the `Program Files` folder directory requires Administrator access for the installation.\n\nInstaller metadata will be saved under the `HKLM` registry path.",
"type": "string",
"enum": [
"perMachine"
]
},
{
"description": "Combines both modes and allows the user to choose at install time whether to install for the current user or per machine. Note that this mode will require Administrator access even if the user wants to install it for the current user only.\n\nInstaller metadata will be saved under the `HKLM` or `HKCU` registry path based on the user's choice.",
"type": "string",
"enum": [
"both"
]
}
"type": "string",
"enum": [
"currentUser",
"perMachine",
"both"
]
},
"AllowlistConfig": {
@@ -2730,28 +2644,11 @@
},
"WindowsUpdateInstallMode": {
"description": "Install modes for the Windows update.",
"oneOf": [
{
"description": "Specifies there's a basic UI during the installation process, including a final dialog box at the end.",
"type": "string",
"enum": [
"basicUi"
]
},
{
"description": "The quiet mode means there's no user interaction required. Requires admin privileges if the installer does (WiX).",
"type": "string",
"enum": [
"quiet"
]
},
{
"description": "Specifies unattended mode, which means the installation only shows a progress bar.",
"type": "string",
"enum": [
"passive"
]
}
"type": "string",
"enum": [
"basicUi",
"quiet",
"passive"
]
},
"SystemTrayConfig": {

View File

@@ -26,13 +26,16 @@ serde = "1"
serde_json = "1"
heck = "0.4"
json-patch = "0.3"
syn = { version = "1", features = ["full", "parsing"], optional = true }
prettyplease = { version = "0.1", optional = true }
# dependencies for Windows targets
tauri-winres = "0.1"
semver = "1"
[features]
codegen = [ "tauri-codegen", "quote" ]
default = [ "codegen" ]
codegen = [ "tauri-codegen", "quote", "dep:syn", "dep:prettyplease" ]
isolation = [ "tauri-codegen/isolation", "tauri-utils/isolation" ]
config-json5 = [ "tauri-utils/config-json5" ]
config-toml = [ "tauri-utils/config-toml" ]

View File

@@ -128,10 +128,12 @@ impl CodegenContext {
}
#[cfg(target_os = "macos")]
println!(
"cargo:rerun-if-changed={}",
config_parent.join("Info.plist").display()
);
{
let plist = config_parent.join("Info.plist");
if plist.exists() {
println!("cargo:rerun-if-changed={}", plist.display());
}
}
let code = context_codegen(ContextData {
dev: self.dev,
@@ -142,6 +144,9 @@ impl CodegenContext {
root: quote::quote!(::tauri),
})?;
//let syn_file = syn::parse2(module)?;
//let pretty = prettyplease::unparse(&syn_file);
// get the full output file path
let out = var("OUT_DIR")
.map(PathBuf::from)

View File

@@ -443,6 +443,15 @@ pub fn try_build(attributes: Attributes) -> Result<()> {
}
}
#[cfg(feature = "codegen")]
{
let mut codegen = CodegenContext::new();
if !has_feature("custom-protocol") {
codegen = codegen.dev();
}
codegen.build();
}
Ok(())
}

View File

@@ -356,11 +356,9 @@ pub fn context_codegen(data: ContextData) -> Result<TokenStream, EmbeddedAssetsE
.expect("failed to write Info.plist");
let info_plist_path = out_path.display().to_string();
quote!({
tauri::embed_plist::embed_info_plist!(#info_plist_path);
})
quote!(tauri::embed_plist::embed_info_plist!(#info_plist_path))
} else {
quote!(())
quote!()
};
#[cfg(not(target_os = "macos"))]
let info_plist = quote!(());
@@ -440,17 +438,20 @@ pub fn context_codegen(data: ContextData) -> Result<TokenStream, EmbeddedAssetsE
#[cfg(not(feature = "shell-scope"))]
let shell_scope_config = quote!();
Ok(quote!(#root::Context::new(
#config,
::std::sync::Arc::new(#assets),
#default_window_icon,
#app_icon,
#system_tray_icon,
#package_info,
#info_plist,
#pattern,
#shell_scope_config
)))
Ok(quote!({
#info_plist;
#root::Context::new(
#config,
::std::sync::Arc::new(#assets),
#default_window_icon,
#app_icon,
#system_tray_icon,
#package_info,
(),
#pattern,
#shell_scope_config
)
}))
}
fn ico_icon<P: AsRef<Path>>(

View File

@@ -1,4 +1,4 @@
// Copyright 2019-2023 Tauri Programme within The Commons Conservancy
// Copyright 2019-2022 Tauri Programme within The Commons Conservancy
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: MIT
@@ -409,15 +409,17 @@ impl ToTokens for EmbeddedAssets {
},));
}
let csp_hash = quote!(::tauri::utils::assets::CspHash);
let mut global_hashes = TokenStream::new();
for script_hash in &self.csp_hashes.scripts {
let hash = script_hash.as_str();
global_hashes.append_all(quote!(CspHash::Script(#hash),));
global_hashes.append_all(quote!(#csp_hash::Script(#hash),));
}
for style_hash in &self.csp_hashes.styles {
let hash = style_hash.as_str();
global_hashes.append_all(quote!(CspHash::Style(#hash),));
global_hashes.append_all(quote!(#csp_hash::Style(#hash),));
}
let mut html_hashes = TokenStream::new();
@@ -426,15 +428,14 @@ impl ToTokens for EmbeddedAssets {
let mut value = TokenStream::new();
for script_hash in hashes {
let hash = script_hash.as_str();
value.append_all(quote!(CspHash::Script(#hash),));
value.append_all(quote!(#csp_hash::Script(#hash),));
}
html_hashes.append_all(quote!(#key => &[#value],));
}
// we expect phf related items to be in path when generating the path code
tokens.append_all(quote! {{
#[allow(unused)]
use ::tauri::utils::assets::{CspHash, EmbeddedAssets, phf, phf::phf_map};
use ::tauri::utils::assets::{EmbeddedAssets, phf, phf::phf_map};
EmbeddedAssets::new(phf_map! { #assets }, &[#global_hashes], phf_map! { #html_hashes })
}});
}

View File

@@ -56,6 +56,7 @@ pub fn generate_handler(item: TokenStream) -> TokenStream {
/// The output of this macro is managed internally by Tauri,
/// and should not be accessed directly on normal applications.
/// It may have breaking changes in the future.
#[deprecated]
#[proc_macro]
pub fn generate_context(items: TokenStream) -> TokenStream {
// this macro is exported from the context module

View File

@@ -124,6 +124,7 @@ tauri = { path = ".", default-features = false, features = [ "wry" ] }
tokio-test = "0.4.2"
tokio = { version = "1", features = [ "full" ] }
cargo_toml = "0.11"
tauri-codegen-test = { path = "../tests/tauri-codegen-test" }
[features]
default = [ "wry", "compression", "objc-exception" ]
@@ -295,42 +296,3 @@ config-json5 = [ "tauri-macros/config-json5" ]
config-toml = [ "tauri-macros/config-toml" ]
icon-ico = [ "infer", "ico" ]
icon-png = [ "infer", "png" ]
[[example]]
name = "commands"
path = "../../examples/commands/main.rs"
[[example]]
name = "helloworld"
path = "../../examples/helloworld/main.rs"
[[example]]
name = "multiwindow"
path = "../../examples/multiwindow/main.rs"
required-features = [ "window-create" ]
[[example]]
name = "parent-window"
path = "../../examples/parent-window/main.rs"
[[example]]
name = "navigation"
path = "../../examples/navigation/main.rs"
required-features = [ "window-create" ]
[[example]]
name = "splashscreen"
path = "../../examples/splashscreen/main.rs"
[[example]]
name = "state"
path = "../../examples/state/main.rs"
[[example]]
name = "streaming"
path = "../../examples/streaming/main.rs"
[[example]]
name = "isolation"
path = "../../examples/isolation/main.rs"
required-features = [ "isolation" ]

View File

@@ -379,9 +379,14 @@ pub mod blocking {
///
/// # Examples
///
/// ```ignore
/// let context = tauri::tauri_build_context!();
/// ```
///
/// ```rust,no_run
/// # let context = tauri_codegen_test::context();
/// use tauri::api::dialog::blocking::ask;
/// # let app = tauri::Builder::default().build(tauri::generate_context!("test/fixture/src-tauri/tauri.conf.json")).unwrap();
/// # let app = tauri::Builder::default().build(context).unwrap();
/// # let window = tauri::Manager::get_window(&app, "main").unwrap();
/// let answer = ask(Some(&window), "Tauri", "Is Tauri awesome?");
/// // do something with `answer`
@@ -402,9 +407,14 @@ pub mod blocking {
///
/// # Examples
///
/// ```ignore
/// let context = tauri::tauri_build_context!();
/// ```
///
/// ```rust,no_run
/// # let context = tauri_codegen_test::context();
/// use tauri::api::dialog::blocking::confirm;
/// # let app = tauri::Builder::default().build(tauri::generate_context!("test/fixture/src-tauri/tauri.conf.json")).unwrap();
/// # let app = tauri::Builder::default().build(context).unwrap();
/// # let window = tauri::Manager::get_window(&app, "main").unwrap();
/// let answer = confirm(Some(&window), "Tauri", "Are you sure?");
/// // do something with `answer`
@@ -425,9 +435,14 @@ pub mod blocking {
///
/// # Examples
///
/// ```ignore
/// let context = tauri::tauri_build_context!();
/// ```
///
/// ```rust,no_run
/// # let context = tauri_codegen_test::context();
/// use tauri::api::dialog::blocking::message;
/// # let app = tauri::Builder::default().build(tauri::generate_context!("test/fixture/src-tauri/tauri.conf.json")).unwrap();
/// # let app = tauri::Builder::default().build(context).unwrap();
/// # let window = tauri::Manager::get_window(&app, "main").unwrap();
/// message(Some(&window), "Tauri", "Tauri is awesome!");
/// ```
@@ -479,10 +494,15 @@ mod nonblocking {
///
/// # Examples
///
/// ```ignore
/// let context = tauri::tauri_build_context!();
/// ```
///
/// ```rust,no_run
/// # let context = tauri_codegen_test::context();
/// use tauri::api::dialog::FileDialogBuilder;
/// tauri::Builder::default()
/// .build(tauri::generate_context!("test/fixture/src-tauri/tauri.conf.json"))
/// .build(context)
/// .expect("failed to build tauri app")
/// .run(|_app, _event| {
/// FileDialogBuilder::new().pick_file(|file_path| {
@@ -503,10 +523,15 @@ mod nonblocking {
///
/// # Examples
///
/// ```ignore
/// let context = tauri::tauri_build_context!();
/// ```
///
/// ```rust,no_run
/// # let context = tauri_codegen_test::context();
/// use tauri::api::dialog::FileDialogBuilder;
/// tauri::Builder::default()
/// .build(tauri::generate_context!("test/fixture/src-tauri/tauri.conf.json"))
/// .build(context)
/// .expect("failed to build tauri app")
/// .run(|_app, _event| {
/// FileDialogBuilder::new().pick_files(|file_paths| {
@@ -529,10 +554,15 @@ mod nonblocking {
///
/// # Examples
///
/// ```ignore
/// let context = tauri::tauri_build_context!();
/// ```
///
/// ```rust,no_run
/// # let context = tauri_codegen_test::context();
/// use tauri::api::dialog::FileDialogBuilder;
/// tauri::Builder::default()
/// .build(tauri::generate_context!("test/fixture/src-tauri/tauri.conf.json"))
/// .build(context)
/// .expect("failed to build tauri app")
/// .run(|_app, _event| {
/// FileDialogBuilder::new().pick_folder(|folder_path| {
@@ -553,10 +583,15 @@ mod nonblocking {
///
/// # Examples
///
/// ```ignore
/// let context = tauri::tauri_build_context!();
/// ```
///
/// ```rust,no_run
/// # let context = tauri_codegen_test::context();
/// use tauri::api::dialog::FileDialogBuilder;
/// tauri::Builder::default()
/// .build(tauri::generate_context!("test/fixture/src-tauri/tauri.conf.json"))
/// .build(context)
/// .expect("failed to build tauri app")
/// .run(|_app, _event| {
/// FileDialogBuilder::new().pick_folders(|file_paths| {
@@ -580,10 +615,16 @@ mod nonblocking {
///
/// # Examples
///
/// ```ignore
/// let context = tauri::tauri_build_context!();
/// ```
///
/// ```rust,no_run
/// # let context = tauri_codegen_test::context();
/// use tauri::api::dialog::FileDialogBuilder;
///
/// tauri::Builder::default()
/// .build(tauri::generate_context!("test/fixture/src-tauri/tauri.conf.json"))
/// .build(context)
/// .expect("failed to build tauri app")
/// .run(|_app, _event| {
/// FileDialogBuilder::new().save_file(|file_path| {
@@ -617,9 +658,14 @@ mod nonblocking {
///
/// # Examples
///
/// ```ignore
/// let context = tauri::tauri_build_context!();
/// ```
///
/// ```rust,no_run
/// # let context = tauri_codegen_test::context();
/// use tauri::api::dialog::ask;
/// # let app = tauri::Builder::default().build(tauri::generate_context!("test/fixture/src-tauri/tauri.conf.json")).unwrap();
/// # let app = tauri::Builder::default().build(context).unwrap();
/// # let window = tauri::Manager::get_window(&app, "main").unwrap();
/// ask(Some(&window), "Tauri", "Is Tauri awesome?", |answer| {
/// // do something with `answer`
@@ -649,9 +695,14 @@ mod nonblocking {
///
/// # Examples
///
/// ```ignore
/// let context = tauri::tauri_build_context!();
/// ```
///
/// ```rust,no_run
/// # let context = tauri_codegen_test::context();
/// use tauri::api::dialog::confirm;
/// # let app = tauri::Builder::default().build(tauri::generate_context!("test/fixture/src-tauri/tauri.conf.json")).unwrap();
/// # let app = tauri::Builder::default().build(context).unwrap();
/// # let window = tauri::Manager::get_window(&app, "main").unwrap();
/// confirm(Some(&window), "Tauri", "Are you sure?", |answer| {
/// // do something with `answer`
@@ -681,9 +732,14 @@ mod nonblocking {
///
/// # Examples
///
/// ```ignore
/// let context = tauri::tauri_build_context!();
/// ```
///
/// ```rust,no_run
/// # let context = tauri_codegen_test::context();
/// use tauri::api::dialog::message;
/// # let app = tauri::Builder::default().build(tauri::generate_context!("test/fixture/src-tauri/tauri.conf.json")).unwrap();
/// # let app = tauri::Builder::default().build(context).unwrap();
/// # let window = tauri::Manager::get_window(&app, "main").unwrap();
/// message(Some(&window), "Tauri", "Tauri is awesome!");
/// ```

View File

@@ -12,12 +12,17 @@ use std::path::MAIN_SEPARATOR as SEP;
/// Allows you to construct a Notification data and send it.
///
/// # Examples
///
/// ```ignore
/// let context = tauri::tauri_build_context!();
/// ```
///
/// ```rust,no_run
/// # let context = tauri_codegen_test::context();
/// use tauri::api::notification::Notification;
/// // first we build the application to access the Tauri configuration
/// let app = tauri::Builder::default()
/// // on an actual app, remove the string argument
/// .build(tauri::generate_context!("test/fixture/src-tauri/tauri.conf.json"))
/// .build(context)
/// .expect("error while building tauri application");
///
/// // shows a notification with the given title and body
@@ -76,11 +81,14 @@ impl Notification {
///
/// # Examples
///
/// ```no_run
/// ```ignore
/// let context = tauri::tauri_build_context!();
/// ```
///
/// ```rust,no_run
/// # let context = tauri_codegen_test::context();
/// use tauri::api::notification::Notification;
///
/// // on an actual app, remove the string argument
/// let context = tauri::generate_context!("test/fixture/src-tauri/tauri.conf.json");
/// Notification::new(&context.config().tauri.bundle.identifier)
/// .title("Tauri")
/// .body("Tauri is awesome!")
@@ -140,11 +148,14 @@ impl Notification {
///
/// # Examples
///
/// ```no_run
/// ```ignore
/// let context = tauri::tauri_build_context!();
/// ```
///
/// ```rust,no_run
/// # let context = tauri_codegen_test::context();
/// use tauri::api::notification::Notification;
///
/// // on an actual app, remove the string argument
/// let context = tauri::generate_context!("test/fixture/src-tauri/tauri.conf.json");
/// let identifier = context.config().tauri.bundle.identifier.clone();
///
/// tauri::Builder::default()

View File

@@ -230,10 +230,14 @@ pub fn parse<P: AsRef<Path>>(
///
/// ## Before initializing the application
///
/// ```ignore
/// let context = tauri::tauri_build_context!();
/// ```
///
/// ```rust,no_run
/// # let context = tauri_codegen_test::context();
/// use tauri::{api::path::{BaseDirectory, resolve_path}, Env};
/// // on an actual app, remove the string argument
/// let context = tauri::generate_context!("test/fixture/src-tauri/tauri.conf.json");
///
/// let path = resolve_path(
/// context.config(),
/// context.package_info(),

View File

@@ -786,10 +786,14 @@ impl<R: Runtime> App<R> {
/// Sets the activation policy for the application. It is set to `NSApplicationActivationPolicyRegular` by default.
///
/// # Examples
/// ```,no_run
/// ```ignore
/// let context = tauri::tauri_build_context!();
/// ```
///
/// ```rust,no_run
/// # let context = tauri_codegen_test::context();
/// let mut app = tauri::Builder::default()
/// // on an actual app, remove the string argument
/// .build(tauri::generate_context!("test/fixture/src-tauri/tauri.conf.json"))
/// .build(context)
/// .expect("error while building tauri application");
/// #[cfg(target_os = "macos")]
/// app.set_activation_policy(tauri::ActivationPolicy::Accessory);
@@ -816,10 +820,14 @@ impl<R: Runtime> App<R> {
/// - ** Linux / macOS / iOS / Android**: Unsupported.
///
/// # Examples
/// ```,no_run
/// ```ignore
/// let context = tauri::tauri_build_context!();
/// ```
///
/// ```rust,no_run
/// # let context = tauri_codegen_test::context();
/// let mut app = tauri::Builder::default()
/// // on an actual app, remove the string argument
/// .build(tauri::generate_context!("test/fixture/src-tauri/tauri.conf.json"))
/// .build(context)
/// .expect("error while building tauri application");
/// app.set_device_event_filter(tauri::DeviceEventFilter::Always);
/// app.run(|_app_handle, _event| {});
@@ -857,11 +865,16 @@ impl<R: Runtime> App<R> {
/// Runs the application.
///
/// # Examples
/// ```,no_run
/// ```ignore
/// let context = tauri::tauri_build_context!();
/// ```
///
/// ```rust,no_run
/// # let context = tauri_codegen_test::context();
/// let app = tauri::Builder::default()
/// // on an actual app, remove the string argument
/// .build(tauri::generate_context!("test/fixture/src-tauri/tauri.conf.json"))
/// .build(context)
/// .expect("error while building tauri application");
///
/// app.run(|_app_handle, event| match event {
/// tauri::RunEvent::ExitRequested { api, .. } => {
/// api.prevent_exit();
@@ -895,11 +908,16 @@ impl<R: Runtime> App<R> {
/// Additionally, the cleanup calls [AppHandle#remove_system_tray](`AppHandle#method.remove_system_tray`) (Windows only).
///
/// # Examples
/// ```no_run
/// ```ignore
/// let context = tauri::tauri_build_context!();
/// ```
///
/// ```rust,no_run
/// # let context = tauri_codegen_test::context();
/// let mut app = tauri::Builder::default()
/// // on an actual app, remove the string argument
/// .build(tauri::generate_context!("test/fixture/src-tauri/tauri.conf.json"))
/// .build(context)
/// .expect("error while building tauri application");
///
/// loop {
/// let iteration = app.run_iteration();
/// if iteration.window_count == 0 {
@@ -974,10 +992,14 @@ impl<R: Runtime> App<R> {
/// Builds a Tauri application.
///
/// # Examples
/// ```,no_run
/// ```ignore
/// let context = tauri::tauri_build_context!();
/// ```
///
/// ```rust,no_run
/// # let context = tauri_codegen_test::context();
/// tauri::Builder::default()
/// // on an actual app, remove the string argument
/// .run(tauri::generate_context!("test/fixture/src-tauri/tauri.conf.json"))
/// .run(context)
/// .expect("error while running tauri application");
/// ```
#[allow(clippy::type_complexity)]
@@ -1223,7 +1245,12 @@ impl<R: Runtime> Builder<R> {
///
/// Since the managed state is global and must be [`Send`] + [`Sync`], mutations can only happen through interior mutability:
///
/// ```,no_run
/// ```ignore
/// let context = tauri::tauri_build_context!();
/// ```
///
/// ```rust,no_run
/// # let context = tauri_codegen_test::context();
/// use std::{collections::HashMap, sync::Mutex};
/// use tauri::State;
/// // here we use Mutex to achieve interior mutability
@@ -1251,14 +1278,18 @@ impl<R: Runtime> Builder<R> {
/// .manage(Storage { store: Default::default() })
/// .manage(DbConnection { db: Default::default() })
/// .invoke_handler(tauri::generate_handler![connect, storage_insert])
/// // on an actual app, remove the string argument
/// .run(tauri::generate_context!("test/fixture/src-tauri/tauri.conf.json"))
/// .run(context)
/// .expect("error while running tauri application");
/// ```
///
/// # Examples
///
/// ```,no_run
/// ```ignore
/// let context = tauri::tauri_build_context!();
/// ```
///
/// ```rust,no_run
/// # let context = tauri_codegen_test::context();
/// use tauri::State;
///
/// struct MyInt(isize);
@@ -1278,8 +1309,7 @@ impl<R: Runtime> Builder<R> {
/// .manage(MyInt(10))
/// .manage(MyString("Hello, managed state!".to_string()))
/// .invoke_handler(tauri::generate_handler![int_command, string_command])
/// // on an actual app, remove the string argument
/// .run(tauri::generate_context!("test/fixture/src-tauri/tauri.conf.json"))
/// .run(context)
/// .expect("error while running tauri application");
/// ```
#[must_use]

View File

@@ -555,6 +555,68 @@ impl<A: Assets> Context<A> {
&self.shell_scope
}
#[doc(hidden)]
#[inline(always)]
#[allow(clippy::type_complexity)]
pub fn into_parts(
self,
) -> (
Config,
Arc<A>,
//Option<Icon>,
Option<Vec<u8>>,
//Option<Icon>,
PackageInfo,
//Pattern,
) {
(
self.config,
self.assets,
//self.default_window_icon,
self.app_icon,
//self.system_tray_icon,
self.package_info,
//self.pattern,
)
}
#[doc(hidden)]
#[inline(always)]
#[allow(clippy::type_complexity)]
pub fn from_parts(
(
config,
assets,
/*default_window_icon,*/ app_icon,
/*system_tray_icon,*/ package_info,
//pattern,
): (
Config,
Arc<A>,
//Option<Icon>,
Option<Vec<u8>>,
//Option<Icon>,
PackageInfo,
//Pattern,
),
) -> Self {
Self {
config,
assets,
default_window_icon: None,
app_icon,
system_tray_icon: None,
package_info,
_info_plist: (),
pattern: Pattern::Brownfield(::std::marker::PhantomData),
#[cfg(shell_scope)]
shell_scope: scope::ShellScopeConfig {
open: Default::default(),
scopes: Default::default(),
},
}
}
/// Create a new [`Context`] from the minimal required items.
#[inline(always)]
#[allow(clippy::too_many_arguments)]
@@ -664,7 +726,12 @@ pub trait Manager<R: Runtime>: sealed::ManagerBase<R> {
///
/// Since the managed state is global and must be [`Send`] + [`Sync`], mutations can only happen through interior mutability:
///
/// ```ignore
/// let context = tauri::tauri_build_context!();
/// ```
///
/// ```rust,no_run
/// # let context = tauri_codegen_test::context();
/// use std::{collections::HashMap, sync::Mutex};
/// use tauri::State;
/// // here we use Mutex to achieve interior mutability
@@ -692,14 +759,17 @@ pub trait Manager<R: Runtime>: sealed::ManagerBase<R> {
/// .manage(Storage { store: Default::default() })
/// .manage(DbConnection { db: Default::default() })
/// .invoke_handler(tauri::generate_handler![connect, storage_insert])
/// // on an actual app, remove the string argument
/// .run(tauri::generate_context!("test/fixture/src-tauri/tauri.conf.json"))
/// .run(context)
/// .expect("error while running tauri application");
/// ```
///
/// # Examples
/// ```ignore
/// let context = tauri::tauri_build_context!();
/// ```
///
/// ```rust,no_run
/// # let context = tauri_codegen_test::context();
/// use tauri::{Manager, State};
///
/// struct MyInt(isize);
@@ -731,7 +801,7 @@ pub trait Manager<R: Runtime>: sealed::ManagerBase<R> {
/// })
/// .invoke_handler(tauri::generate_handler![int_command, string_command])
/// // on an actual app, remove the string argument
/// .run(tauri::generate_context!("test/fixture/src-tauri/tauri.conf.json"))
/// .run(context)
/// .expect("error while running tauri application");
/// ```
fn manage<T>(&self, state: T) -> bool

View File

@@ -1056,13 +1056,13 @@ impl<R: Runtime> WindowManager<R> {
#[cfg(test)]
mod test {
use crate::{generate_context, plugin::PluginStore, StateManager, Wry};
use crate::{plugin::PluginStore, StateManager, Wry};
use super::WindowManager;
#[test]
fn check_get_url() {
let context = generate_context!("test/fixture/src-tauri/tauri.conf.json", crate);
let context = crate::Context::from_parts(tauri_codegen_test::context().into_parts());
let manager: WindowManager<Wry> = WindowManager::with_handlers(
context,
PluginStore::default(),

View File

@@ -14,11 +14,16 @@
//!
//! To listen to the updater events, for example to check for error messages, you need to use [`RunEvent::Updater`](crate::RunEvent) in [`App::run`](crate::App#method.run).
//!
//! ```no_run
//! ```ignore
//! let context = tauri::tauri_build_context!();
//! ```
//!
//! ```rust,no_run
//! # let context = tauri_codegen_test::context();
//! let app = tauri::Builder::default()
//! // on an actual app, remove the string argument
//! .build(tauri::generate_context!("test/fixture/src-tauri/tauri.conf.json"))
//! .build(context)
//! .expect("error while building tauri application");
//!
//! app.run(|_app_handle, event| match event {
//! tauri::RunEvent::Updater(updater_event) => {
//! match updater_event {

View File

@@ -5,7 +5,7 @@
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
fn main() {
let mut context = tauri::generate_context!();
let mut context = tauri::tauri_build_context!();
if std::env::var("TARGET").unwrap_or_default() == "nsis" {
context.config_mut().tauri.updater.windows.installer_args = vec![format!(
"/D={}",

View File

@@ -0,0 +1,10 @@
[package]
name = "tauri-codegen-test"
version = "0.1.0"
edition = "2021"
[build-dependencies]
tauri-build = { path = "../../tauri-build" }
[dependencies]
tauri = { path = "../../tauri" }

View File

@@ -0,0 +1,7 @@
// Copyright 2019-2022 Tauri Programme within The Commons Conservancy
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: MIT
fn main() {
tauri_build::build()
}

View File

Before

Width:  |  Height:  |  Size: 85 KiB

After

Width:  |  Height:  |  Size: 85 KiB

View File

Before

Width:  |  Height:  |  Size: 56 KiB

After

Width:  |  Height:  |  Size: 56 KiB

View File

Before

Width:  |  Height:  |  Size: 974 B

After

Width:  |  Height:  |  Size: 974 B

View File

@@ -0,0 +1,3 @@
pub fn context() -> tauri::Context<tauri::utils::assets::EmbeddedAssets> {
tauri::tauri_build_context!()
}

View File

@@ -0,0 +1,27 @@
{
"$schema": "../../../core/config-schema/schema.json",
"build": {
"distDir": "./dist",
"devPath": "http://localhost:4000"
},
"tauri": {
"bundle": {
"identifier": "studio.tauri.example",
"active": true
},
"allowlist": {
"all": false
},
"windows": [
{
"title": "Tauri App"
}
],
"security": {
"csp": "default-src blob: data: filesystem: ws: wss: http: https: tauri: 'unsafe-eval' 'unsafe-inline' 'self'"
},
"updater": {
"active": false
}
}
}

View File

@@ -0,0 +1,12 @@
[package]
name = "commands"
version = "0.1.0"
edition = "2021"
rust-version = "1.59"
[build-dependencies]
tauri-build = { path = "../../core/tauri-build" }
[dependencies]
tauri = { path = "../../core/tauri" }
serde = "1"

View File

@@ -0,0 +1,7 @@
// Copyright 2019-2022 Tauri Programme within The Commons Conservancy
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: MIT
fn main() {
tauri_build::build()
}

View File

@@ -252,8 +252,6 @@ fn main() {
future_simple_command_with_result,
async_stateful_command_with_result,
])
.run(tauri::generate_context!(
"../../examples/commands/tauri.conf.json"
))
.run(tauri::tauri_build_context!())
.expect("error while running tauri application");
}

View File

@@ -0,0 +1,10 @@
[package]
name = "helloworld"
version = "0.1.0"
edition = "2021"
[build-dependencies]
tauri-build = { path = "../../core/tauri-build" }
[dependencies]
tauri = { path = "../../core/tauri" }

View File

@@ -0,0 +1,7 @@
// Copyright 2019-2022 Tauri Programme within The Commons Conservancy
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: MIT
fn main() {
tauri_build::build()
}

View File

@@ -4,10 +4,11 @@
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
//include!(concat!(env!("OUT_DIR"), "/tauri-build-context.rs"));
fn main() {
tauri::Builder::default()
.run(tauri::generate_context!(
"../../examples/helloworld/tauri.conf.json"
))
.run(tauri::tauri_build_context!())
//.run(__tauri_build_context::context())
.expect("error while running tauri application");
}

View File

@@ -0,0 +1,10 @@
[package]
name = "isolation"
version = "0.1.0"
edition = "2021"
[build-dependencies]
tauri-build = { path = "../../core/tauri-build", features = ["isolation"] }
[dependencies]
tauri = { path = "../../core/tauri", features = ["isolation"] }

View File

@@ -0,0 +1,7 @@
// Copyright 2019-2022 Tauri Programme within The Commons Conservancy
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: MIT
fn main() {
tauri_build::build()
}

View File

@@ -11,17 +11,9 @@ fn ping() {
dbg!(format!("ping: {:?}", Instant::now()));
}
#[cfg(not(feature = "isolation"))]
fn main() {
compile_error!("Feature `isolation` is required to run this example");
}
#[cfg(feature = "isolation")]
fn main() {
tauri::Builder::default()
.invoke_handler(tauri::generate_handler![ping])
.run(tauri::generate_context!(
"../../examples/isolation/tauri.conf.json"
))
.run(tauri::tauri_build_context!())
.expect("error while running tauri application");
}

View File

@@ -0,0 +1,10 @@
[package]
name = "multiwindow"
version = "0.1.0"
edition = "2021"
[build-dependencies]
tauri-build = { path = "../../core/tauri-build" }
[dependencies]
tauri = { path = "../../core/tauri", features = ["window-create"] }

View File

@@ -0,0 +1,7 @@
// Copyright 2019-2022 Tauri Programme within The Commons Conservancy
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: MIT
fn main() {
tauri_build::build()
}

View File

@@ -28,8 +28,6 @@ fn main() {
let _window = builder.title("Tauri - Rust").build()?;
Ok(())
})
.run(tauri::generate_context!(
"../../examples/multiwindow/tauri.conf.json"
))
.run(tauri::tauri_build_context!())
.expect("failed to run tauri application");
}

View File

@@ -0,0 +1,10 @@
[package]
name = "navigation"
version = "0.1.0"
edition = "2021"
[build-dependencies]
tauri-build = { path = "../../core/tauri-build" }
[dependencies]
tauri = { path = "../../core/tauri", features = ["window-create"] }

View File

@@ -0,0 +1,7 @@
// Copyright 2019-2022 Tauri Programme within The Commons Conservancy
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: MIT
fn main() {
tauri_build::build()
}

View File

@@ -6,8 +6,6 @@
fn main() {
tauri::Builder::default()
.run(tauri::generate_context!(
"../../examples/navigation/tauri.conf.json"
))
.run(tauri::tauri_build_context!())
.expect("error while running tauri application");
}

View File

@@ -0,0 +1,10 @@
[package]
name = "parent-window"
version = "0.1.0"
edition = "2021"
[build-dependencies]
tauri-build = { path = "../../core/tauri-build" }
[dependencies]
tauri = { path = "../../core/tauri" }

View File

@@ -0,0 +1,7 @@
// Copyright 2019-2022 Tauri Programme within The Commons Conservancy
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: MIT
fn main() {
tauri_build::build()
}

View File

@@ -36,8 +36,6 @@ fn main() {
.build()?;
Ok(())
})
.run(tauri::generate_context!(
"../../examples/parent-window/tauri.conf.json"
))
.run(tauri::tauri_build_context!())
.expect("failed to run tauri application");
}

View File

@@ -37,6 +37,6 @@ fn main() {
Ok(())
})
.run(tauri::generate_context!())
.run(tauri::tauri_build_context!())
.expect("error while running tauri application");
}

View File

@@ -36,6 +36,6 @@ fn main() {
Ok(())
})
.run(tauri::generate_context!())
.run(tauri::tauri_build_context!())
.expect("error while running tauri application");
}

View File

@@ -0,0 +1,10 @@
[package]
name = "splashscreen"
version = "0.1.0"
edition = "2021"
[build-dependencies]
tauri-build = { path = "../../core/tauri-build" }
[dependencies]
tauri = { path = "../../core/tauri" }

View File

@@ -0,0 +1,7 @@
// Copyright 2019-2022 Tauri Programme within The Commons Conservancy
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: MIT
fn main() {
tauri_build::build()
}

View File

@@ -83,7 +83,7 @@ mod ui {
}
fn context() -> tauri::Context<tauri::utils::assets::EmbeddedAssets> {
tauri::generate_context!("../../examples/splashscreen/tauri.conf.json")
tauri::tauri_build_context!()
}
fn main() {

10
examples/state/Cargo.toml Normal file
View File

@@ -0,0 +1,10 @@
[package]
name = "state"
version = "0.1.0"
edition = "2021"
[build-dependencies]
tauri-build = { path = "../../core/tauri-build" }
[dependencies]
tauri = { path = "../../core/tauri" }

7
examples/state/build.rs Normal file
View File

@@ -0,0 +1,7 @@
// Copyright 2019-2022 Tauri Programme within The Commons Conservancy
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: MIT
fn main() {
tauri_build::build()
}

View File

@@ -78,8 +78,6 @@ fn main() {
disconnect,
connection_send
])
.run(tauri::generate_context!(
"../../examples/state/tauri.conf.json"
))
.run(tauri::tauri_build_context!())
.expect("error while running tauri application");
}

View File

@@ -0,0 +1,11 @@
[package]
name = "streaming"
version = "0.1.0"
edition = "2021"
[build-dependencies]
tauri-build = { path = "../../core/tauri-build" }
[dependencies]
tauri = { path = "../../core/tauri" }
percent-encoding = "2"

View File

@@ -0,0 +1,7 @@
// Copyright 2019-2022 Tauri Programme within The Commons Conservancy
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: MIT
fn main() {
tauri_build::build()
}

View File

@@ -107,9 +107,7 @@ fn main() {
response.mimetype("video/mp4").status(status_code).body(buf)
})
.run(tauri::generate_context!(
"../../examples/streaming/tauri.conf.json"
))
.run(tauri::tauri_build_context!())
.expect("error while running tauri application");
}

View File

@@ -10,6 +10,6 @@
#[no_mangle]
pub extern "C" fn run_tauri() {
tauri::Builder::default()
.run(tauri::generate_context!("./tauri.conf.json"))
.run(tauri::tauri_build_context!())
.expect("error while running tauri application");
}

View File

@@ -12,6 +12,6 @@ fn my_custom_command(argument: String) {
fn main() {
tauri::Builder::default()
.invoke_handler(tauri::generate_handler![my_custom_command])
.run(tauri::generate_context!())
.run(tauri::tauri_build_context!())
.expect("error while running tauri application");
}

View File

@@ -12,6 +12,6 @@ fn greet(window: tauri::Window, name: String) {
fn main() {
tauri::Builder::default()
.invoke_handler(tauri::generate_handler![greet])
.run(tauri::generate_context!())
.run(tauri::tauri_build_context!())
.expect("error while running tauri application");
}

View File

@@ -7,6 +7,6 @@
fn main() {
core_api::run();
tauri::Builder::default()
.run(tauri::generate_context!())
.run(tauri::tauri_build_context!())
.expect("error while running tauri application");
}

View File

@@ -12,6 +12,6 @@ fn app_completed_successfully() {
fn main() {
tauri::Builder::default()
.invoke_handler(tauri::generate_handler![app_completed_successfully])
.run(tauri::generate_context!())
.run(tauri::tauri_build_context!())
.expect("error while running tauri application");
}

View File

@@ -12,6 +12,6 @@ fn app_should_close(exit_code: i32) {
fn main() {
tauri::Builder::default()
.invoke_handler(tauri::generate_handler![app_should_close])
.run(tauri::generate_context!())
.run(tauri::tauri_build_context!())
.expect("error while running tauri application");
}

View File

@@ -12,6 +12,6 @@ fn app_loaded_successfully() {
fn main() {
tauri::Builder::default()
.invoke_handler(tauri::generate_handler![app_loaded_successfully])
.run(tauri::generate_context!())
.run(tauri::tauri_build_context!())
.expect("error while running tauri application");
}

View File

@@ -15,7 +15,8 @@ function isMusl() {
// For Node 10
if (!process.report || typeof process.report.getReport !== 'function') {
try {
return readFileSync('/usr/bin/ldd', 'utf8').includes('musl')
const lddPath = require('child_process').execSync('which ldd').toString().trim();
return readFileSync(lddPath, 'utf8').includes('musl')
} catch (e) {
return true
}
@@ -105,6 +106,15 @@ switch (platform) {
}
break
case 'darwin':
localFileExisted = existsSync(join(__dirname, 'cli.darwin-universal.node'))
try {
if (localFileExisted) {
nativeBinding = require('./cli.darwin-universal.node')
} else {
nativeBinding = require('@tauri-apps/cli-darwin-universal')
}
break
} catch {}
switch (arch) {
case 'x64':
localFileExisted = existsSync(join(__dirname, 'cli.darwin-x64.node'))

View File

@@ -19,6 +19,6 @@ fn main() {
window.eval("window.onTauriInit()").unwrap();
})
.invoke_handler(tauri::generate_handler![exit])
.run(tauri::generate_context!())
.run(tauri::tauri_build_context!())
.expect("error encountered while running tauri application");
}

View File

@@ -720,47 +720,19 @@
},
"Theme": {
"description": "System theme.",
"oneOf": [
{
"description": "Light theme.",
"type": "string",
"enum": [
"Light"
]
},
{
"description": "Dark theme.",
"type": "string",
"enum": [
"Dark"
]
}
"type": "string",
"enum": [
"Light",
"Dark"
]
},
"TitleBarStyle": {
"description": "How the window title bar should be displayed on macOS.",
"oneOf": [
{
"description": "A normal title bar.",
"type": "string",
"enum": [
"Visible"
]
},
{
"description": "Makes the title bar transparent, so the window background color is shown instead.\n\nUseful if you don't need to have actual HTML under the title bar. This lets you avoid the caveats of using `TitleBarStyle::Overlay`. Will be more useful when Tauri lets you set a custom window background color.",
"type": "string",
"enum": [
"Transparent"
]
},
{
"description": "Shows the title bar as a transparent overlay over the window's content.\n\nKeep in mind: - The height of the title bar is different on different OS versions, which can lead to window the controls and title not being where you don't expect. - You need to define a custom drag region to make your window draggable, however due to a limitation you can't drag the window when it's not in focus <https://github.com/tauri-apps/tauri/issues/4316>. - The color of the window title depends on the system theme.",
"type": "string",
"enum": [
"Overlay"
]
}
"type": "string",
"enum": [
"Visible",
"Transparent",
"Overlay"
]
},
"CliConfig": {
@@ -1183,56 +1155,15 @@
},
"BundleType": {
"description": "A bundle referenced by tauri-bundler.",
"oneOf": [
{
"description": "The debian bundle (.deb).",
"type": "string",
"enum": [
"deb"
]
},
{
"description": "The AppImage bundle (.appimage).",
"type": "string",
"enum": [
"appimage"
]
},
{
"description": "The Microsoft Installer bundle (.msi).",
"type": "string",
"enum": [
"msi"
]
},
{
"description": "The NSIS bundle (.exe).",
"type": "string",
"enum": [
"nsis"
]
},
{
"description": "The macOS application bundle (.app).",
"type": "string",
"enum": [
"app"
]
},
{
"description": "The Apple Disk Image bundle (.dmg).",
"type": "string",
"enum": [
"dmg"
]
},
{
"description": "The Tauri updater bundle.",
"type": "string",
"enum": [
"updater"
]
}
"type": "string",
"enum": [
"deb",
"appimage",
"msi",
"nsis",
"app",
"dmg",
"updater"
]
},
"AppImageConfig": {
@@ -1716,28 +1647,11 @@
},
"NSISInstallerMode": {
"description": "Install Modes for the NSIS installer.",
"oneOf": [
{
"description": "Default mode for the installer.\n\nInstall the app by default in a directory that doesn't require Administrator access.\n\nInstaller metadata will be saved under the `HKCU` registry path.",
"type": "string",
"enum": [
"currentUser"
]
},
{
"description": "Install the app by default in the `Program Files` folder directory requires Administrator access for the installation.\n\nInstaller metadata will be saved under the `HKLM` registry path.",
"type": "string",
"enum": [
"perMachine"
]
},
{
"description": "Combines both modes and allows the user to choose at install time whether to install for the current user or per machine. Note that this mode will require Administrator access even if the user wants to install it for the current user only.\n\nInstaller metadata will be saved under the `HKLM` or `HKCU` registry path based on the user's choice.",
"type": "string",
"enum": [
"both"
]
}
"type": "string",
"enum": [
"currentUser",
"perMachine",
"both"
]
},
"AllowlistConfig": {
@@ -2730,28 +2644,11 @@
},
"WindowsUpdateInstallMode": {
"description": "Install modes for the Windows update.",
"oneOf": [
{
"description": "Specifies there's a basic UI during the installation process, including a final dialog box at the end.",
"type": "string",
"enum": [
"basicUi"
]
},
{
"description": "The quiet mode means there's no user interaction required. Requires admin privileges if the installer does (WiX).",
"type": "string",
"enum": [
"quiet"
]
},
{
"description": "Specifies unattended mode, which means the installation only shows a progress bar.",
"type": "string",
"enum": [
"passive"
]
}
"type": "string",
"enum": [
"basicUi",
"quiet",
"passive"
]
},
"SystemTrayConfig": {

View File

@@ -3,6 +3,6 @@
fn main() {
tauri::Builder::default()
.run(tauri::generate_context!())
.run(tauri::tauri_build_context!())
.expect("error while running tauri application");
}

View File

@@ -4,6 +4,6 @@
fn main() {
tauri::Builder::default()
.plugin(tauri_plugin_{{ plugin_name_snake_case }}::init())
.run(tauri::generate_context!())
.run(tauri::tauri_build_context!())
.expect("error while running tauri application");
}

View File

@@ -11,6 +11,6 @@ fn main() {
tauri::Builder::default()
.invoke_handler(tauri::generate_handler![greet])
.plugin(tauri_plugin_{{ plugin_name_snake_case }}::init())
.run(tauri::generate_context!())
.run(tauri::tauri_build_context!())
.expect("error while running tauri application");
}