mirror of
https://github.com/tauri-apps/tauri.git
synced 2024-12-24 19:25:12 +03:00
Co-authored-by: Lucas Nogueira <lucas@tauri.studio>
This commit is contained in:
parent
0fa745344e
commit
9105588373
5
.changes/builder-default-menu-macos.md
Normal file
5
.changes/builder-default-menu-macos.md
Normal file
@ -0,0 +1,5 @@
|
||||
---
|
||||
"tauri": patch
|
||||
---
|
||||
|
||||
`tauri::Builder` will now include a default menu for macOS without explicitly using `Menu::os_default`, you can still override it through `tauri::Builder::menu` or remove it using `tauri::Builder::enable_macos_default_menu(false)`.
|
6
.changes/cli-remove-menu-from-template.md
Normal file
6
.changes/cli-remove-menu-from-template.md
Normal file
@ -0,0 +1,6 @@
|
||||
---
|
||||
"cli.rs": patch
|
||||
"cli.js": patch
|
||||
---
|
||||
|
||||
Changed the app template to not set the default app menu as it is now set automatically on macOS which is the platform that needs a menu to function properly.
|
@ -866,6 +866,10 @@ pub struct Builder<R: Runtime> {
|
||||
/// The menu set to all windows.
|
||||
menu: Option<Menu>,
|
||||
|
||||
/// Enable macOS default menu creation.
|
||||
#[allow(unused)]
|
||||
enable_macos_default_menu: bool,
|
||||
|
||||
/// Menu event handlers that listens to all windows.
|
||||
menu_event_listeners: Vec<GlobalMenuEventListener<R>>,
|
||||
|
||||
@ -902,6 +906,7 @@ impl<R: Runtime> Builder<R> {
|
||||
uri_scheme_protocols: Default::default(),
|
||||
state: StateManager::new(),
|
||||
menu: None,
|
||||
enable_macos_default_menu: true,
|
||||
menu_event_listeners: Vec::new(),
|
||||
window_event_listeners: Vec::new(),
|
||||
#[cfg(feature = "system-tray")]
|
||||
@ -1332,6 +1337,11 @@ impl<R: Runtime> Builder<R> {
|
||||
/// Builds the application.
|
||||
#[allow(clippy::type_complexity)]
|
||||
pub fn build<A: Assets>(mut self, context: Context<A>) -> crate::Result<App<R>> {
|
||||
#[cfg(target_os = "macos")]
|
||||
if self.menu.is_none() && self.enable_macos_default_menu {
|
||||
self.menu = Some(Menu::os_default(&context.package_info().name));
|
||||
}
|
||||
|
||||
#[cfg(feature = "system-tray")]
|
||||
let system_tray_icon = context.system_tray_icon.clone();
|
||||
|
||||
|
@ -157,13 +157,7 @@ fn borrow_cmd_async(argument: &str) -> &str {
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let context = tauri::generate_context!("../../examples/commands/tauri.conf.json");
|
||||
tauri::Builder::default()
|
||||
.menu(if cfg!(target_os = "macos") {
|
||||
tauri::Menu::os_default(&context.package_info().name)
|
||||
} else {
|
||||
tauri::Menu::default()
|
||||
})
|
||||
.manage(MyState {
|
||||
value: 0,
|
||||
label: "Tauri!".into(),
|
||||
@ -193,6 +187,8 @@ fn main() {
|
||||
future_simple_command_with_result,
|
||||
async_stateful_command_with_result,
|
||||
])
|
||||
.run(context)
|
||||
.run(tauri::generate_context!(
|
||||
"../../examples/commands/tauri.conf.json"
|
||||
))
|
||||
.expect("error while running tauri application");
|
||||
}
|
||||
|
@ -8,13 +8,9 @@
|
||||
)]
|
||||
|
||||
fn main() {
|
||||
let context = tauri::generate_context!("../../examples/helloworld/tauri.conf.json");
|
||||
tauri::Builder::default()
|
||||
.menu(if cfg!(target_os = "macos") {
|
||||
tauri::Menu::os_default(&context.package_info().name)
|
||||
} else {
|
||||
tauri::Menu::default()
|
||||
})
|
||||
.run(context)
|
||||
.run(tauri::generate_context!(
|
||||
"../../examples/helloworld/tauri.conf.json"
|
||||
))
|
||||
.expect("error while running tauri application");
|
||||
}
|
||||
|
@ -21,14 +21,10 @@ fn main() {
|
||||
|
||||
#[cfg(feature = "isolation")]
|
||||
fn main() {
|
||||
let context = tauri::generate_context!("../../examples/isolation/tauri.conf.json");
|
||||
tauri::Builder::default()
|
||||
.menu(if cfg!(target_os = "macos") {
|
||||
tauri::Menu::os_default(&context.package_info().name)
|
||||
} else {
|
||||
tauri::Menu::default()
|
||||
})
|
||||
.invoke_handler(tauri::generate_handler![ping])
|
||||
.run(context)
|
||||
.run(tauri::generate_context!(
|
||||
"../../examples/isolation/tauri.conf.json"
|
||||
))
|
||||
.expect("error while running tauri application");
|
||||
}
|
||||
|
@ -10,13 +10,7 @@
|
||||
use tauri::WindowBuilder;
|
||||
|
||||
fn main() {
|
||||
let context = tauri::generate_context!("../../examples/multiwindow/tauri.conf.json");
|
||||
tauri::Builder::default()
|
||||
.menu(if cfg!(target_os = "macos") {
|
||||
tauri::Menu::os_default(&context.package_info().name)
|
||||
} else {
|
||||
tauri::Menu::default()
|
||||
})
|
||||
.on_page_load(|window, _payload| {
|
||||
let label = window.label().to_string();
|
||||
window.listen("clicked".to_string(), move |_payload| {
|
||||
@ -33,6 +27,8 @@ fn main() {
|
||||
.build()?;
|
||||
Ok(())
|
||||
})
|
||||
.run(context)
|
||||
.run(tauri::generate_context!(
|
||||
"../../examples/multiwindow/tauri.conf.json"
|
||||
))
|
||||
.expect("failed to run tauri application");
|
||||
}
|
||||
|
@ -8,13 +8,9 @@
|
||||
)]
|
||||
|
||||
fn main() {
|
||||
let context = tauri::generate_context!("../../examples/navigation/tauri.conf.json");
|
||||
tauri::Builder::default()
|
||||
.menu(if cfg!(target_os = "macos") {
|
||||
tauri::Menu::os_default(&context.package_info().name)
|
||||
} else {
|
||||
tauri::Menu::default()
|
||||
})
|
||||
.run(context)
|
||||
.run(tauri::generate_context!(
|
||||
"../../examples/navigation/tauri.conf.json"
|
||||
))
|
||||
.expect("error while running tauri application");
|
||||
}
|
||||
|
@ -24,13 +24,7 @@ async fn create_child_window(id: String, window: Window) {
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let context = tauri::generate_context!("../../examples/parent-window/tauri.conf.json");
|
||||
tauri::Builder::default()
|
||||
.menu(if cfg!(target_os = "macos") {
|
||||
tauri::Menu::os_default(&context.package_info().name)
|
||||
} else {
|
||||
tauri::Menu::default()
|
||||
})
|
||||
.on_page_load(|window, _payload| {
|
||||
let label = window.label().to_string();
|
||||
window.listen("clicked".to_string(), move |_payload| {
|
||||
@ -45,6 +39,8 @@ fn main() {
|
||||
.build()?;
|
||||
Ok(())
|
||||
})
|
||||
.run(context)
|
||||
.run(tauri::generate_context!(
|
||||
"../../examples/parent-window/tauri.conf.json"
|
||||
))
|
||||
.expect("failed to run tauri application");
|
||||
}
|
||||
|
@ -13,14 +13,7 @@ fn main() {
|
||||
Manager,
|
||||
};
|
||||
|
||||
let context = tauri::generate_context!();
|
||||
|
||||
tauri::Builder::default()
|
||||
.menu(if cfg!(target_os = "macos") {
|
||||
tauri::Menu::os_default(&context.package_info().name)
|
||||
} else {
|
||||
tauri::Menu::default()
|
||||
})
|
||||
.setup(move |app| {
|
||||
let window = app.get_window("main").unwrap();
|
||||
let script_path = app
|
||||
@ -47,6 +40,6 @@ fn main() {
|
||||
|
||||
Ok(())
|
||||
})
|
||||
.run(context)
|
||||
.run(tauri::generate_context!())
|
||||
.expect("error while running tauri application");
|
||||
}
|
||||
|
@ -13,13 +13,7 @@ use tauri::{
|
||||
};
|
||||
|
||||
fn main() {
|
||||
let context = tauri::generate_context!();
|
||||
tauri::Builder::default()
|
||||
.menu(if cfg!(target_os = "macos") {
|
||||
tauri::Menu::os_default(&context.package_info().name)
|
||||
} else {
|
||||
tauri::Menu::default()
|
||||
})
|
||||
.setup(|app| {
|
||||
let window = app.get_window("main").unwrap();
|
||||
tauri::async_runtime::spawn(async move {
|
||||
@ -45,6 +39,6 @@ fn main() {
|
||||
|
||||
Ok(())
|
||||
})
|
||||
.run(context)
|
||||
.run(tauri::generate_context!())
|
||||
.expect("error while running tauri application");
|
||||
}
|
||||
|
@ -17,13 +17,7 @@ mod rust {
|
||||
fn close_splashscreen() {}
|
||||
|
||||
pub fn main() {
|
||||
let context = tauri::generate_context!("../../examples/splashscreen/tauri.conf.json");
|
||||
tauri::Builder::default()
|
||||
.menu(if cfg!(target_os = "macos") {
|
||||
tauri::Menu::os_default(&context.package_info().name)
|
||||
} else {
|
||||
tauri::Menu::default()
|
||||
})
|
||||
.setup(|app| {
|
||||
let splashscreen_window = app.get_window("splashscreen").unwrap();
|
||||
let main_window = app.get_window("main").unwrap();
|
||||
@ -40,7 +34,9 @@ mod rust {
|
||||
Ok(())
|
||||
})
|
||||
.invoke_handler(tauri::generate_handler![close_splashscreen])
|
||||
.run(context)
|
||||
.run(tauri::generate_context!(
|
||||
"../../examples/splashscreen/tauri.conf.json"
|
||||
))
|
||||
.expect("failed to run app");
|
||||
}
|
||||
}
|
||||
|
@ -69,13 +69,7 @@ fn db_read(key: String, db: State<'_, Database>) -> Option<String> {
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let context = tauri::generate_context!("../../examples/state/tauri.conf.json");
|
||||
tauri::Builder::default()
|
||||
.menu(if cfg!(target_os = "macos") {
|
||||
tauri::Menu::os_default(&context.package_info().name)
|
||||
} else {
|
||||
tauri::Menu::default()
|
||||
})
|
||||
.manage(Counter(AtomicUsize::new(0)))
|
||||
.manage(Database(Default::default()))
|
||||
.manage(Connection(Default::default()))
|
||||
@ -87,6 +81,8 @@ fn main() {
|
||||
disconnect,
|
||||
connection_send
|
||||
])
|
||||
.run(context)
|
||||
.run(tauri::generate_context!(
|
||||
"../../examples/state/tauri.conf.json"
|
||||
))
|
||||
.expect("error while running tauri application");
|
||||
}
|
||||
|
@ -38,14 +38,7 @@ fn main() {
|
||||
assert!(video_file.exists());
|
||||
}
|
||||
|
||||
let context = tauri::generate_context!("../../examples/streaming/tauri.conf.json");
|
||||
|
||||
tauri::Builder::default()
|
||||
.menu(if cfg!(target_os = "macos") {
|
||||
tauri::Menu::os_default(&context.package_info().name)
|
||||
} else {
|
||||
tauri::Menu::default()
|
||||
})
|
||||
.register_uri_scheme_protocol("stream", move |_app, request| {
|
||||
// prepare our response
|
||||
let mut response = ResponseBuilder::new();
|
||||
@ -119,6 +112,8 @@ fn main() {
|
||||
|
||||
response.mimetype("video/mp4").status(status_code).body(buf)
|
||||
})
|
||||
.run(context)
|
||||
.run(tauri::generate_context!(
|
||||
"../../examples/streaming/tauri.conf.json"
|
||||
))
|
||||
.expect("error while running tauri application");
|
||||
}
|
||||
|
@ -12,13 +12,7 @@
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn run_tauri() {
|
||||
let context = tauri::generate_context!("./tauri.conf.json");
|
||||
tauri::Builder::default()
|
||||
.menu(if cfg!(target_os = "macos") {
|
||||
tauri::Menu::os_default(&context.package_info().name)
|
||||
} else {
|
||||
tauri::Menu::default()
|
||||
})
|
||||
.run(context)
|
||||
.run(tauri::generate_context!("./tauri.conf.json"))
|
||||
.expect("error while running tauri application");
|
||||
}
|
||||
|
@ -13,14 +13,8 @@ fn my_custom_command(argument: String) {
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let context = tauri::generate_context!();
|
||||
tauri::Builder::default()
|
||||
.menu(if cfg!(target_os = "macos") {
|
||||
tauri::Menu::os_default(&context.package_info().name)
|
||||
} else {
|
||||
tauri::Menu::default()
|
||||
})
|
||||
.invoke_handler(tauri::generate_handler![my_custom_command])
|
||||
.run(context)
|
||||
.run(tauri::generate_context!())
|
||||
.expect("error while running tauri application");
|
||||
}
|
||||
|
@ -4,13 +4,7 @@
|
||||
)]
|
||||
|
||||
fn main() {
|
||||
let context = tauri::generate_context!();
|
||||
tauri::Builder::default()
|
||||
.menu(if cfg!(target_os = "macos") {
|
||||
tauri::Menu::os_default(&context.package_info().name)
|
||||
} else {
|
||||
tauri::Menu::default()
|
||||
})
|
||||
.run(context)
|
||||
.run(tauri::generate_context!())
|
||||
.expect("error while running tauri application");
|
||||
}
|
||||
|
@ -4,14 +4,8 @@
|
||||
)]
|
||||
|
||||
fn main() {
|
||||
let context = tauri::generate_context!();
|
||||
tauri::Builder::default()
|
||||
.menu(if cfg!(target_os = "macos") {
|
||||
tauri::Menu::os_default(&context.package_info().name)
|
||||
} else {
|
||||
tauri::Menu::default()
|
||||
})
|
||||
.plugin(tauri_plugin_{{ plugin_name_snake_case }}::init())
|
||||
.run(context)
|
||||
.run(tauri::generate_context!())
|
||||
.expect("error while running tauri application");
|
||||
}
|
||||
|
@ -4,14 +4,8 @@
|
||||
)]
|
||||
|
||||
fn main() {
|
||||
let context = tauri::generate_context!();
|
||||
tauri::Builder::default()
|
||||
.menu(if cfg!(target_os = "macos") {
|
||||
tauri::Menu::os_default(&context.package_info().name)
|
||||
} else {
|
||||
tauri::Menu::default()
|
||||
})
|
||||
.plugin(tauri_plugin_{{ plugin_name_snake_case }}::init())
|
||||
.run(context)
|
||||
.run(tauri::generate_context!())
|
||||
.expect("failed to run app");
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user