Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: move to muda and tray_icon crates #7535

Merged
merged 130 commits into from
Aug 14, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
130 commits
Select commit Hold shift + click to select a range
262f8f7
refactor: migrate to new crates (`muda` & `tray-icon`)
amrbashir Jul 13, 2023
4734c01
update deps to use git
amrbashir Jul 18, 2023
027c940
add tray getters
amrbashir Jul 18, 2023
d71a11c
fix linux impl
lucasfernog Jul 20, 2023
1a75a13
fix gtk api usage
lucasfernog Jul 20, 2023
6758525
lint
lucasfernog Jul 20, 2023
826a5fc
fix build on macos
lucasfernog Jul 20, 2023
d57635d
disable default features for muda and tray-icon
amrbashir Jul 20, 2023
5b13702
Merge branch 'refactor/muda-migration' of https://github.com/tauri-ap…
amrbashir Jul 20, 2023
eaa17cd
remove default file menu on Linux
amrbashir Jul 20, 2023
0063216
use builder on Linux
amrbashir Jul 20, 2023
ae9423b
move menu/tray handlers setup from runtime to tauri
amrbashir Jul 20, 2023
0c53ebc
remove unused messages
lucasfernog Jul 20, 2023
d1b81bf
Merge remote-tracking branch 'origin/dev' into refactor/muda-migration
lucasfernog Jul 20, 2023
37497a1
revert menu changes and enhance docs
amrbashir Jul 20, 2023
80f4f2e
add show_context_menu function
amrbashir Jul 31, 2023
0b235db
inital work for menu wrapper types
amrbashir Jul 31, 2023
e6fbf76
fix build on macos [skip ci]
lucasfernog Jul 31, 2023
35dca0d
ensure thread safety for context items
amrbashir Jul 31, 2023
dd36a38
finish menu wrapper types
amrbashir Jul 31, 2023
a4391ad
add default menu
amrbashir Aug 1, 2023
1cf5788
add tray icon wrapper types
amrbashir Aug 1, 2023
4cedac2
Merge branch 'dev' into refactor/muda-migration
amrbashir Aug 1, 2023
5c8d40b
fix macos build
lucasfernog Aug 1, 2023
9534f6a
lint
lucasfernog Aug 1, 2023
f5b5aac
small fix on api example
lucasfernog Aug 1, 2023
741a2d7
fix linux build
lucasfernog Aug 1, 2023
ad18aac
change `Builder::tray_icon` to be a function
amrbashir Aug 1, 2023
be77871
Add a getter for apphandle
amrbashir Aug 1, 2023
aef5e96
change it to an owned handle
amrbashir Aug 1, 2023
f888fa0
add `on_menu_event` and `on_tray_even` for `TrayIcon` & fix api example
amrbashir Aug 1, 2023
901fe92
update lock file
amrbashir Aug 1, 2023
400269b
macos fixes
lucasfernog Aug 1, 2023
316d2aa
tray id return raw value
lucasfernog Aug 1, 2023
81250dd
lint
lucasfernog Aug 1, 2023
b02b7b1
private fields
lucasfernog Aug 1, 2023
c65820f
replace show_context_menu_for_* with popup fn
lucasfernog Aug 1, 2023
77a5359
make id return u32 instead of result
lucasfernog Aug 1, 2023
8b07b50
fix doctests
lucasfernog Aug 1, 2023
116f6db
fix unix
lucasfernog Aug 1, 2023
468fd31
remove window menu APIs on macos
lucasfernog Aug 1, 2023
e8ea27b
remove `Builder::tray_icon`, move init to `TrayIcon` type itself
amrbashir Aug 2, 2023
cb62300
Remove `with_` prefix from `TrayIconBuilder`
amrbashir Aug 2, 2023
012a681
move `on_menu/tray_icon_event` from `tauri::Builder` to `App/AppHandle`
amrbashir Aug 2, 2023
6948816
Add `on_menu_event` for `WindowBuilder`
amrbashir Aug 2, 2023
70c0bfc
Add `TrayIcon::on_menu_event` and `TrayIcon::on_tray_icon_event`
amrbashir Aug 2, 2023
8b7739f
fix api example
amrbashir Aug 2, 2023
74cc682
take a `Manager` argument instead of just `AppHandle`
amrbashir Aug 2, 2023
6c7155b
add todo
amrbashir Aug 2, 2023
a9c5244
docs & expose `cleanup_before_exit()`
amrbashir Aug 2, 2023
9d4a676
all tauri handlers return result, make it easier to use `?`
amrbashir Aug 2, 2023
8062ddb
remove `TrayIconAttributes`
amrbashir Aug 2, 2023
64b48c3
add missing submenu methods
amrbashir Aug 2, 2023
aa88466
run menu_for_nsapp on main thread
amrbashir Aug 2, 2023
501dda0
make App::run handler also return a result
amrbashir Aug 2, 2023
a9a6850
fix test
amrbashir Aug 2, 2023
0349a38
add menu item builders
amrbashir Aug 2, 2023
40df0d0
fix tray icon builder docs
amrbashir Aug 2, 2023
dc1b949
pin time crate in CI
amrbashir Aug 2, 2023
f4956f3
fix test-core workflow
amrbashir Aug 2, 2023
3fc7a6a
lints and doctests
amrbashir Aug 2, 2023
1e33d62
update tray-icon [skip ci]
lucasfernog Aug 2, 2023
37bd9e6
fix api example build [skip ci]
lucasfernog Aug 2, 2023
7076ce5
expose `popup` on `ContextMenu` trait
amrbashir Aug 2, 2023
575f5c8
rename `Window::show_context_menu` to `Window::popup_menu`
amrbashir Aug 2, 2023
c846285
remove extranouse result return from `MenuBuilder` and `SubmenuBuilde…
amrbashir Aug 2, 2023
0234a20
revert "adding result return to menu/tray/window event handlers"
amrbashir Aug 2, 2023
6b99f3c
fix deadlock
amrbashir Aug 3, 2023
794a68a
move window menu initalization out of tauri-runtime into tauri crate
amrbashir Aug 3, 2023
209ba58
dedup logic
amrbashir Aug 3, 2023
a325675
remove todo
amrbashir Aug 3, 2023
b1b8756
fix ci file
amrbashir Aug 3, 2023
30561ad
fix unix
amrbashir Aug 3, 2023
c17b8f7
fix macos
lucasfernog Aug 3, 2023
cbf411f
fix api build
lucasfernog Aug 3, 2023
f541c48
expose window menu apis on macOS, no-op
amrbashir Aug 3, 2023
80ea1de
Add missing submenu APIs
amrbashir Aug 3, 2023
4ace7f1
fix macos build
amrbashir Aug 3, 2023
78616b4
update deps [skip ci]
lucasfernog Aug 3, 2023
98e6ff4
lint macos
lucasfernog Aug 3, 2023
b431bc2
hide menu APIs behind `#cfg(desktop)]`
amrbashir Aug 3, 2023
0fd9fdf
update api example lockfile
amrbashir Aug 3, 2023
64e931f
disable menu on left click
lucasfernog Aug 3, 2023
a0103c1
focus window
lucasfernog Aug 3, 2023
b26e3b3
implement migration for config and cargo manifest
lucasfernog Aug 3, 2023
a9c57c7
add menu toggle to api example
lucasfernog Aug 3, 2023
412e940
set default menu on api example
lucasfernog Aug 3, 2023
88af6f1
fix logic
lucasfernog Aug 3, 2023
4d9ce78
fix deadlock on windows
lucasfernog Aug 3, 2023
7513e98
update api dist
lucasfernog Aug 3, 2023
ea4a268
split popup functions
lucasfernog Aug 3, 2023
cb05d42
add popup cmd to api example
lucasfernog Aug 3, 2023
0621382
fix macos
lucasfernog Aug 3, 2023
431ace7
update tray-icon
lucasfernog Aug 3, 2023
2e65ed9
update muda
lucasfernog Aug 3, 2023
1c9d911
clippy
lucasfernog Aug 3, 2023
1a821eb
reuse popup menu
lucasfernog Aug 3, 2023
e0282a3
add `ContextMenu::popup_at`
amrbashir Aug 4, 2023
5203e96
Update core/tauri/src/app.rs
amrbashir Aug 4, 2023
3c01907
Add change files
amrbashir Aug 4, 2023
8baab5a
set windows menu on macOS for default menu
amrbashir Aug 4, 2023
f677e79
remvoe default impls for builders and enhance docs
amrbashir Aug 4, 2023
f479346
export builders
lucasfernog Aug 4, 2023
27c023d
use manager.windows() [skip ci]
lucasfernog Aug 5, 2023
4eb031a
fix macos build
lucasfernog Aug 5, 2023
1bdd397
fix api example build for mobile
lucasfernog Aug 5, 2023
235f34c
Update core/tauri/src/menu/mod.rs
amrbashir Aug 8, 2023
84467d4
change app_handle function to return a reference instead
amrbashir Aug 8, 2023
d9ac3fd
update to muda and tray-icon 0.8
amrbashir Aug 8, 2023
1283773
fix ios and android build
amrbashir Aug 8, 2023
6783501
relax bounds
amrbashir Aug 8, 2023
c71665b
fix macos build
amrbashir Aug 8, 2023
d8f08fa
Merge branch 'dev' into refactor/muda-migration
amrbashir Aug 8, 2023
743e0b6
fix macos build
amrbashir Aug 8, 2023
175c536
update lock file
amrbashir Aug 8, 2023
676c690
simplify comparisons [skip ci]
lucasfernog Aug 10, 2023
32aba4d
fix window and help submenu init logic
lucasfernog Aug 10, 2023
6e43081
Merge remote-tracking branch 'origin/dev' into refactor/muda-migration
lucasfernog Aug 10, 2023
e30ffc5
add tray-icon feature flag
amrbashir Aug 10, 2023
3fb8cf0
add `Submenu::get` and use `PartialEq`
amrbashir Aug 10, 2023
8432965
update jni
lucasfernog Aug 11, 2023
88b418a
update wry [skip ci]
lucasfernog Aug 11, 2023
4f65b26
wry 0.31
lucasfernog Aug 13, 2023
9a62c32
update migration
lucasfernog Aug 13, 2023
2c20d6b
do not enable tray-icon by default
lucasfernog Aug 13, 2023
6842939
enhance docs
lucasfernog Aug 13, 2023
eed1878
Merge branch 'dev' into refactor/muda-migration
lucasfernog Aug 13, 2023
f1f1bf0
fix tray detection
lucasfernog Aug 14, 2023
440d45e
Merge remote-tracking branch 'origin/refactor/muda-migration' into re…
lucasfernog Aug 14, 2023
fb73c96
fix logic
lucasfernog Aug 14, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions core/tauri/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -655,7 +655,7 @@ macro_rules! shared_app_impl {
{
let menu_ = menu.clone();
self.run_on_main_thread(move || {
menu_.inner().init_for_nsapp();
let _ = init_app_menu(&menu_);
})?;
}

Expand Down Expand Up @@ -1451,7 +1451,7 @@ impl<R: Runtime> Builder<R> {
.insert(menu.id().clone(), menu.clone());

#[cfg(target_os = "macos")]
menu.inner().init_for_nsapp();
init_app_menu(&menu)?;

app.manager.menu_lock().replace(menu);
}
Expand Down Expand Up @@ -1527,6 +1527,24 @@ impl<R: Runtime> Builder<R> {
}
}

#[cfg(target_os = "macos")]
fn init_app_menu<R: Runtime>(menu: &Menu<R>) -> crate::Result<()> {
menu.inner().init_for_nsapp();

if let Some(window_menu) = menu.get(crate::menu::WINDOW_SUBMENU_ID) {
if let Some(m) = window_menu.as_submenu() {
m.set_as_windows_menu_for_nsapp()?;
}
}
if let Some(help_menu) = menu.get(crate::menu::HELP_SUBMENU_ID) {
amrbashir marked this conversation as resolved.
Show resolved Hide resolved
if let Some(m) = help_menu.as_submenu() {
m.set_as_help_menu_for_nsapp()?;
}
}

Ok(())
}

unsafe impl<R: Runtime> HasRawDisplayHandle for AppHandle<R> {
fn raw_display_handle(&self) -> raw_window_handle::RawDisplayHandle {
self.runtime_handle.raw_display_handle()
Expand Down
27 changes: 19 additions & 8 deletions core/tauri/src/menu/menu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ use crate::{run_main_thread, AppHandle, Manager, Position, Runtime};
use muda::ContextMenu;
use muda::{AboutMetadata, MenuId};

/// Expected submenu id of the Window menu for macOS.
pub const WINDOW_SUBMENU_ID: &str = "__tauri_window_menu__";
/// Expected submenu id of the Help menu for macOS.
pub const HELP_SUBMENU_ID: &str = "__tauri_help_menu__";

/// A type that is either a menu bar on the window
/// on Windows and Linux or as a global menu in the menubar on macOS.
pub struct Menu<R: Runtime> {
Expand Down Expand Up @@ -143,8 +148,9 @@ impl<R: Runtime> Menu<R> {
..Default::default()
};

let window_menu = Submenu::with_items(
let window_menu = Submenu::with_id_and_items(
app_handle,
WINDOW_SUBMENU_ID,
"Window",
true,
&[
Expand All @@ -156,8 +162,9 @@ impl<R: Runtime> Menu<R> {
],
)?;

let help_menu = Submenu::with_items(
let help_menu = Submenu::with_id_and_items(
app_handle,
HELP_SUBMENU_ID,
"Help",
true,
&[
Expand Down Expand Up @@ -228,12 +235,6 @@ impl<R: Runtime> Menu<R> {
],
)?;

#[cfg(target_os = "macos")]
{
window_menu.set_as_windows_menu_for_nsapp()?;
help_menu.set_as_help_menu_for_nsapp()?;
}

Ok(menu)
}

Expand Down Expand Up @@ -342,6 +343,16 @@ impl<R: Runtime> Menu<R> {
.map_err(Into::into)
}

/// Retrieves the menu item matching the given identifier.
pub fn get<I: Into<MenuId>>(&self, id: I) -> Option<MenuItemKind<R>> {
amrbashir marked this conversation as resolved.
Show resolved Hide resolved
amrbashir marked this conversation as resolved.
Show resolved Hide resolved
let id = id.into();
self
.items()
.unwrap_or_default()
.into_iter()
.find(|i| i.id() == &id)
}

/// Returns a list of menu items that has been added to this menu.
pub fn items(&self) -> crate::Result<Vec<MenuItemKind<R>>> {
let handle = self.app_handle.clone();
Expand Down
2 changes: 1 addition & 1 deletion core/tauri/src/menu/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ mod submenu;
pub use builders::*;
pub use check::CheckMenuItem;
pub use icon::IconMenuItem;
pub use menu::Menu;
pub use menu::{Menu, HELP_SUBMENU_ID, WINDOW_SUBMENU_ID};
pub use normal::MenuItem;
pub use predefined::PredefinedMenuItem;
pub use submenu::Submenu;
Expand Down