Skip to content

Commit

Permalink
refactor: move to muda and tray_icon crates (#7535)
Browse files Browse the repository at this point in the history
Co-authored-by: Lucas Nogueira <[email protected]>
Co-authored-by: Lucas Fernandes Nogueira <[email protected]>
Co-authored-by: Lucas Nogueira <[email protected]>
  • Loading branch information
3 people authored Aug 14, 2023
1 parent ec82776 commit 7fb419c
Show file tree
Hide file tree
Showing 79 changed files with 5,818 additions and 4,340 deletions.
5 changes: 5 additions & 0 deletions .changes/config-tray-icon-tooltip.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'tauri-utils': 'minor:feat'
---

Add option to specify a tooltip text for the tray icon in the config.
5 changes: 5 additions & 0 deletions .changes/config-tray-icon.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'tauri-utils': 'major:breaking'
---

`systemTray` config option has been renamed to `trayIcon`.
6 changes: 6 additions & 0 deletions .changes/runtime-create-window-handler.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'tauri-runtime': 'minor:breaking'
'tauri-runtime-wry': 'minor:breaking'
---

`Dispatch::create_window`, `Runtime::create_window` and `RuntimeHandle::create_window` has been changed to accept a 3rd parameter which is a closure that takes `RawWindow` and to be executed right after the window is created and before the webview is added to the window.
5 changes: 5 additions & 0 deletions .changes/runtime-defaultvbox.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'tauri-runtime-wry': 'minor:feat'
---

Add `Dispatch::default_vbox`
6 changes: 6 additions & 0 deletions .changes/runtime-menu-system-tray.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'tauri-runtime': 'major:breaking'
'tauri-runtime-wry': 'major:breaking'
---

System tray and menu related APIs and structs have all been removed and are now implemented in tauri outside of the runtime-space.
6 changes: 6 additions & 0 deletions .changes/runtime-new-args.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'tauri-runtime': 'minor:breaking'
'tauri-runtime-wry': 'minor:breaking'
---

`Runtime::new` and `Runtime::new_any_thread` now accept a `RuntimeInitArgs`.
6 changes: 6 additions & 0 deletions .changes/system-tray-feat.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'tauri-runtime': 'major:breaking'
'tauri-runtime-wry': 'major:breaking'
---

Removed `system-tray` feature flag
5 changes: 5 additions & 0 deletions .changes/tauri-app-handle-ref.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'tauri': 'major:breaking'
---

Changed `App::handle` and `Manager::app_handle` to return a reference to an `AppHandle` instead of an owned value.
5 changes: 5 additions & 0 deletions .changes/tauri-cleanup-before-exit.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'tauri': 'minor:feat'
---

Add `App::cleanup_before_exit` and `AppHandle::cleanup_before_exit` to manually call the cleanup logic. **You should always exit the tauri app immediately after this function returns and not use any tauri-related APIs.**
5 changes: 5 additions & 0 deletions .changes/tauri-defaultvbox.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'tauri': 'minor:feat'
---

On Linux, add `Window::default_vbox` to get a reference to the `gtk::Box` that contains the menu bar and the webview.
5 changes: 5 additions & 0 deletions .changes/tauri-libxdo-feat.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'tauri': 'minor:feat'
---

Add `linux-libxdo` feature flag (disabled by default) to enable linking to `libxdo` which is used to make `Cut`, `Copy`, `Paste` and `SelectAll` native menu items work on Linux.
17 changes: 17 additions & 0 deletions .changes/tauri-menu-tray-refactor.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
'tauri': 'major:breaking'
---

The tray icon and menu have received a huge refactor with a lot of breaking changes in order to add new functionalities and improve the DX around using them and here is an overview of the changes:

- All menu and tray types are now exported from `tauri::menu` and `tauri::tray` modules with new names so make sure to check the new types.
- Removed `tauri::Builder::system_tray`, instead you should use `tauri::tray::TrayIconBuilder` inside `tauri::Builder::setup` hook to create your tray icons.
- Changed `tauri::Builder::menu` to be a function to accomodate for new menu changes, you can passe `tauri::menu::Menu::default` to it to create a default menu.
- Renamed `tauri::Context` methods `system_tray_icon`, `tauri::Context::system_tray_icon_mut` and `tauri::Context::set_system_tray_icon` to `tauri::Context::tray_icon`, `tauri::Context::tray_icon_mut` and `tauri::Context::set_tray_icon` to be consistent with new type names.
- Added `RunEvent::MenuEvent` and `RunEvent::TrayIconEvent`.
- Added `App/AppHandle::set_menu`, `App/AppHandle::remove_menu`, `App/AppHandle::show_menu`, `App/AppHandle::hide_menu` and `App/AppHandle::menu` to access, remove, hide or show the app-wide menu that is used as the global menu on macOS and on all windows that don't have a specific menu set for it on Windows and Linux.
- Added `Window::set_menu`, `Window::remove_menu`, `Window::show_menu`, `Window::hide_menu`, `Window::is_menu_visible` and `Window::menu` to access, remove, hide or show the menu on this window.
- Added `Window::popup_menu` and `Window::popup_menu_at` to show a context menu on the window at the cursor position or at a specific position. You can also popup a context menu using `popup` and `popup_at` methods from `ContextMenu` trait which is implemented for `Menu` and `Submenu` types.
- Added `App/AppHandle::tray`, `App/AppHandle::tray_by_id`, `App/AppHandle::remove_tray` and `App/AppHandle::remove_tray_by_id` to access or remove a registered tray.
- Added `WindowBuilder/App/AppHandle::on_menu_event` to register a new menu event handler.
- Added `App/AppHandle::on_tray_icon_event` to register a new tray event handler.
5 changes: 5 additions & 0 deletions .changes/tauri-nsview.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'tauri': 'minor:feat'
---

On macOS, add `Window::ns_view` to get a pointer to the NSWindow content view.
5 changes: 5 additions & 0 deletions .changes/tauri-run_on_main_thread.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'tauri': 'minor:feat'
---

Expose `run_on_main_thread` method on `App` that is similar to `AppHandle::run_on_main_thread`.
5 changes: 5 additions & 0 deletions .changes/tauri-tray-icon-feat-flag.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'tauri': 'major:breaking'
---

Renamed `system-tray` feature flag to `tray-icon`.
2 changes: 1 addition & 1 deletion .github/workflows/lint-core.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ jobs:
clippy:
- { args: '', key: 'empty' }
- {
args: '--features compression,wry,isolation,custom-protocol,system-tray,test',
args: '--features compression,wry,linux-ipc-protocol,isolation,custom-protocol,tray-icon,test',
key: 'all'
}
- { args: '--features custom-protocol', key: 'custom-protocol' }
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test-core.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ jobs:
key: no-default
}
- {
args: --features compression,wry,isolation,custom-protocol,system-tray,test,
args: --features compression,wry,linux-ipc-protocol,isolation,custom-protocol,tray-icon,test,
key: all
}

Expand Down
1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ exclude = [
# examples that can be compiled with the tauri CLI
"examples/api/src-tauri",
"examples/resources/src-tauri",
"examples/sidecar/src-tauri",
"examples/web/core",
"examples/file-associations/src-tauri",
"examples/workspace",
Expand Down
7 changes: 6 additions & 1 deletion core/tauri-build/src/allowlist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,12 @@ pub fn check(config: &Config, manifest: &mut Manifest) -> Result<()> {
name: "tauri".into(),
alias: None,
kind: DependencyKind::Normal,
all_cli_managed_features: Some(TauriConfig::all_features()),
all_cli_managed_features: Some(
TauriConfig::all_features()
.into_iter()
.filter(|f| f != &"tray-icon")
.collect(),
),
expected_features: config
.tauri
.features()
Expand Down
2 changes: 1 addition & 1 deletion core/tauri-build/src/codegen/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ impl CodegenContext {
config_parent.join(icon).display()
);
}
if let Some(tray_icon) = config.tauri.system_tray.as_ref().map(|t| &t.icon_path) {
if let Some(tray_icon) = config.tauri.tray_icon.as_ref().map(|t| &t.icon_path) {
println!(
"cargo:rerun-if-changed={}",
config_parent.join(tray_icon).display()
Expand Down
10 changes: 4 additions & 6 deletions core/tauri-build/src/mobile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ fn insert_into_xml(xml: &str, block_identifier: &str, parent_tag: &str, contents
rewritten.push(line.to_string());
}

rewritten.join("\n").to_string()
rewritten.join("\n")
}

pub fn update_android_manifest(block_identifier: &str, parent: &str, insert: String) -> Result<()> {
Expand Down Expand Up @@ -294,16 +294,14 @@ dependencies {"
mod tests {
#[test]
fn insert_into_xml() {
let manifest = format!(
r#"<manifest>
let manifest = r#"<manifest>
<application>
<intent-filter>
</intent-filter>
</application>
</manifest>"#
);
</manifest>"#;
let id = "tauritest";
let new = super::insert_into_xml(&manifest, id, "application", "<something></something>");
let new = super::insert_into_xml(manifest, id, "application", "<something></something>");

let block_id_comment = super::xml_block_comment(id);
let expected = format!(
Expand Down
2 changes: 1 addition & 1 deletion core/tauri-codegen/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Tauri apps can have custom menus and have tray-type interfaces. They can be upda

## This module

- Embed, hash, and compress assets, including icons for the app as well as the system-tray.
- Embed, hash, and compress assets, including icons for the app as well as the tray icon.
- Parse `tauri.conf.json` at compile time and generate the Config struct.

To learn more about the details of how all of these pieces fit together, please consult this [ARCHITECTURE.md](https://github.com/tauri-apps/tauri/blob/dev/ARCHITECTURE.md) document.
Expand Down
24 changes: 11 additions & 13 deletions core/tauri-codegen/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,17 +264,15 @@ pub fn context_codegen(data: ContextData) -> Result<TokenStream, EmbeddedAssetsE
);
png_icon(&root, &out_dir, icon_path).map(|i| quote!(::std::option::Option::Some(#i)))?
}
} else if target == Target::Linux {
// handle default window icons for Linux targets
} else {
// handle default window icons for Unix targets
let icon_path = find_icon(
&config,
&config_parent,
|i| i.ends_with(".png"),
"icons/icon.png",
);
png_icon(&root, &out_dir, icon_path).map(|i| quote!(::std::option::Option::Some(#i)))?
} else {
quote!(::std::option::Option::None)
}
};

Expand Down Expand Up @@ -319,16 +317,16 @@ pub fn context_codegen(data: ContextData) -> Result<TokenStream, EmbeddedAssetsE
}
);

let with_system_tray_icon_code = if target.is_desktop() {
if let Some(tray) = &config.tauri.system_tray {
let system_tray_icon_path = config_parent.join(&tray.icon_path);
let ext = system_tray_icon_path.extension();
let with_tray_icon_code = if target.is_desktop() {
if let Some(tray) = &config.tauri.tray_icon {
let tray_icon_icon_path = config_parent.join(&tray.icon_path);
let ext = tray_icon_icon_path.extension();
if ext.map_or(false, |e| e == "ico") {
ico_icon(&root, &out_dir, system_tray_icon_path)
.map(|i| quote!(context.set_system_tray_icon(#i);))?
ico_icon(&root, &out_dir, tray_icon_icon_path)
.map(|i| quote!(context.set_tray_icon(#i);))?
} else if ext.map_or(false, |e| e == "png") {
png_icon(&root, &out_dir, system_tray_icon_path)
.map(|i| quote!(context.set_system_tray_icon(#i);))?
png_icon(&root, &out_dir, tray_icon_icon_path)
.map(|i| quote!(context.set_tray_icon(#i);))?
} else {
quote!(compile_error!(
"The tray icon extension must be either `.ico` or `.png`."
Expand Down Expand Up @@ -432,7 +430,7 @@ pub fn context_codegen(data: ContextData) -> Result<TokenStream, EmbeddedAssetsE
#info_plist,
#pattern,
);
#with_system_tray_icon_code
#with_tray_icon_code
context
}))
}
Expand Down
2 changes: 1 addition & 1 deletion core/tauri-codegen/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

//! [![](https://github.com/tauri-apps/tauri/raw/dev/.github/splash.png)](https://tauri.app)
//!
//! - Embed, hash, and compress assets, including icons for the app as well as the system-tray.
//! - Embed, hash, and compress assets, including icons for the app as well as the tray icon.
//! - Parse `tauri.conf.json` at compile time and generate the Config struct.

#![doc(
Expand Down
21 changes: 14 additions & 7 deletions core/tauri-config-schema/schema.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "Config",
"description": "The Tauri configuration object. It is read from a file where you can define your frontend assets, configure the bundler and define a system tray.\n\nThe configuration file is generated by the [`tauri init`](https://tauri.app/v1/api/cli#init) command that lives in your Tauri application source directory (src-tauri).\n\nOnce generated, you may modify it at will to customize your Tauri application.\n\n## File Formats\n\nBy default, the configuration is defined as a JSON file named `tauri.conf.json`.\n\nTauri also supports JSON5 and TOML files via the `config-json5` and `config-toml` Cargo features, respectively. The JSON5 file name must be either `tauri.conf.json` or `tauri.conf.json5`. The TOML file name is `Tauri.toml`.\n\n## Platform-Specific Configuration\n\nIn addition to the default configuration file, Tauri can read a platform-specific configuration from `tauri.linux.conf.json`, `tauri.windows.conf.json`, `tauri.macos.conf.json`, `tauri.android.conf.json` and `tauri.ios.conf.json` (or `Tauri.linux.toml`, `Tauri.windows.toml`, `Tauri.macos.toml`, `Tauri.android.toml` and `Tauri.ios.toml` if the `Tauri.toml` format is used), which gets merged with the main configuration object.\n\n## Configuration Structure\n\nThe configuration is composed of the following objects:\n\n- [`package`](#packageconfig): Package settings - [`tauri`](#tauriconfig): The Tauri config - [`build`](#buildconfig): The build configuration - [`plugins`](#pluginconfig): The plugins config\n\n```json title=\"Example tauri.config.json file\" { \"build\": { \"beforeBuildCommand\": \"\", \"beforeDevCommand\": \"\", \"devPath\": \"../dist\", \"distDir\": \"../dist\" }, \"package\": { \"productName\": \"tauri-app\", \"version\": \"0.1.0\" }, \"tauri\": { \"bundle\": {}, \"security\": { \"csp\": null }, \"windows\": [ { \"fullscreen\": false, \"height\": 600, \"resizable\": true, \"title\": \"Tauri App\", \"width\": 800 } ] } } ```",
"description": "The Tauri configuration object. It is read from a file where you can define your frontend assets, configure the bundler and define a tray icon.\n\nThe configuration file is generated by the [`tauri init`](https://tauri.app/v1/api/cli#init) command that lives in your Tauri application source directory (src-tauri).\n\nOnce generated, you may modify it at will to customize your Tauri application.\n\n## File Formats\n\nBy default, the configuration is defined as a JSON file named `tauri.conf.json`.\n\nTauri also supports JSON5 and TOML files via the `config-json5` and `config-toml` Cargo features, respectively. The JSON5 file name must be either `tauri.conf.json` or `tauri.conf.json5`. The TOML file name is `Tauri.toml`.\n\n## Platform-Specific Configuration\n\nIn addition to the default configuration file, Tauri can read a platform-specific configuration from `tauri.linux.conf.json`, `tauri.windows.conf.json`, `tauri.macos.conf.json`, `tauri.android.conf.json` and `tauri.ios.conf.json` (or `Tauri.linux.toml`, `Tauri.windows.toml`, `Tauri.macos.toml`, `Tauri.android.toml` and `Tauri.ios.toml` if the `Tauri.toml` format is used), which gets merged with the main configuration object.\n\n## Configuration Structure\n\nThe configuration is composed of the following objects:\n\n- [`package`](#packageconfig): Package settings - [`tauri`](#tauriconfig): The Tauri config - [`build`](#buildconfig): The build configuration - [`plugins`](#pluginconfig): The plugins config\n\n```json title=\"Example tauri.config.json file\" { \"build\": { \"beforeBuildCommand\": \"\", \"beforeDevCommand\": \"\", \"devPath\": \"../dist\", \"distDir\": \"../dist\" }, \"package\": { \"productName\": \"tauri-app\", \"version\": \"0.1.0\" }, \"tauri\": { \"bundle\": {}, \"security\": { \"csp\": null }, \"windows\": [ { \"fullscreen\": false, \"height\": 600, \"resizable\": true, \"title\": \"Tauri App\", \"width\": 800 } ] } } ```",
"type": "object",
"properties": {
"$schema": {
Expand Down Expand Up @@ -223,11 +223,11 @@
}
]
},
"systemTray": {
"description": "Configuration for app system tray.",
"trayIcon": {
"description": "Configuration for app tray icon.",
"anyOf": [
{
"$ref": "#/definitions/SystemTrayConfig"
"$ref": "#/definitions/TrayIconConfig"
},
{
"type": "null"
Expand Down Expand Up @@ -2065,15 +2065,15 @@
}
]
},
"SystemTrayConfig": {
"description": "Configuration for application system tray icon.\n\nSee more: https://tauri.app/v1/api/config#systemtrayconfig",
"TrayIconConfig": {
"description": "Configuration for application tray icon.\n\nSee more: https://tauri.app/v1/api/config#trayiconconfig",
"type": "object",
"required": [
"iconPath"
],
"properties": {
"iconPath": {
"description": "Path to the default icon to use on the system tray.",
"description": "Path to the default icon to use for the tray icon.",
"type": "string"
},
"iconAsTemplate": {
Expand All @@ -2092,6 +2092,13 @@
"string",
"null"
]
},
"tooltip": {
"description": "Tray icon tooltip on Windows and macOS",
"type": [
"string",
"null"
]
}
},
"additionalProperties": false
Expand Down
11 changes: 5 additions & 6 deletions core/tauri-runtime-wry/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ rust-version = { workspace = true }
features = [ "dox" ]

[dependencies]
wry = { version = "0.30", default-features = false, features = [ "file-drop", "protocol" ] }
wry = { version = "0.31", default-features = false, features = [ "file-drop", "protocol" ] }
tauri-runtime = { version = "0.13.0-alpha.6", path = "../tauri-runtime" }
tauri-utils = { version = "2.0.0-alpha.6", path = "../tauri-utils" }
uuid = { version = "1", features = [ "v4" ] }
Expand All @@ -26,9 +26,9 @@ raw-window-handle = "0.5"
[target."cfg(windows)".dependencies]
webview2-com = "0.25"

[target."cfg(windows)".dependencies.windows]
version = "0.48"
features = [ "Win32_Foundation" ]
[target."cfg(windows)".dependencies.windows]
version = "0.48"
features = [ "Win32_Foundation" ]

[target."cfg(any(target_os = \"linux\", target_os = \"dragonfly\", target_os = \"freebsd\", target_os = \"openbsd\", target_os = \"netbsd\"))".dependencies]
gtk = { version = "0.16", features = [ "v3_24" ] }
Expand All @@ -39,12 +39,11 @@ percent-encoding = "2.1"
cocoa = "0.24"

[target."cfg(target_os = \"android\")".dependencies]
jni = "0.20"
jni = "0.21"

[features]
dox = [ "wry/dox" ]
devtools = [ "wry/devtools", "tauri-runtime/devtools" ]
system-tray = [ "tauri-runtime/system-tray", "wry/tray" ]
macos-private-api = [
"wry/fullscreen",
"wry/transparent",
Expand Down
Loading

0 comments on commit 7fb419c

Please sign in to comment.