feat: introduce App::run_return (#12668)

* Introduce `run_return`

* Fix compile error

* Clone web_context

* Refactor to Result API

* Fix clippy

* Impl mock runtime

* Make it desktop-only

* Add changelog entry

* Fix compile error

* Make it semver compatible

* Extend changelog entry

* Undo semver-hack

* Reduce diff

* Remove unnecessary mut

* Make it take `self` by value

* Reduce diff

* Undo diff hack

* Make everything cfg(desktop)

* Rename vars to reduce diff

* Fix clippy

* Extract make_event_handler

* Reduce diff

* Deprecate `App::run_return`

* Update changelog

* Fix compile errors

* Accept reference

* Create event handler first

* Update example

* Update manifest

* Fix example

* Fix example docs

* Call `setup` only upon Ready

* Update changelog entry

* Update docs

* Update changelog

* Add platform-specific note

* update docs

* run_return on mobile

* Apply suggestions from code review

* remove change file

---------

Co-authored-by: Lucas Nogueira <lucas@tauri.app>
This commit is contained in:
Thomas Eizinger
2025-03-16 21:04:22 +11:00
committed by GitHub
parent 7930dde85c
commit 658e5f5d1d
11 changed files with 155 additions and 50 deletions

View File

@@ -1,3 +0,0 @@
# Run Iteration Example
To execute run the following on the root directory of the repository: `cargo run --example run-iteration`.

View File

@@ -0,0 +1,3 @@
# Run Return Example
To execute run the following on the root directory of the repository: `cargo run --example run-return`.

View File

@@ -4,23 +4,18 @@
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
use tauri::Manager;
fn main() {
let mut app = tauri::Builder::default()
let app = tauri::Builder::default()
.build(tauri::generate_context!(
"../../examples/run-iteration/tauri.conf.json"
"../../examples/run-return/tauri.conf.json"
))
.expect("error while building tauri application");
loop {
app.run_iteration(|_app, _event| {
//println!("{:?}", _event);
});
let exit_code = app.run_return(|_app, _event| {
//println!("{:?}", _event);
});
if app.webview_windows().is_empty() {
app.cleanup_before_exit();
break;
}
}
println!("I run after exit");
std::process::exit(exit_code);
}

View File

@@ -1,6 +1,6 @@
{
"$schema": "../../crates/tauri-schema-generator/schemas/config.schema.json",
"productName": "RunIteration",
"productName": "RunReturn",
"version": "0.1.0",
"identifier": "com.tauri.dev",
"build": {