Skip to content

Conversation

@1111mp
Copy link
Contributor

@1111mp 1111mp commented Feb 14, 2025

Add set_dock_visibility method to support setting the visibility of the application in the dock.
Close #105

As mentioned here, refer to Electron to implement set_dock_visibility method.

This is my first PR, so there are some issues that need further confirmation:

  • Does the implementation of set_dock_visibility need to be completely consistent with set_activation_policy. For example, we don’t need to do anything extra here: https://github.com/1111mp/tao/blob/c4d0f0555fb0f65993fa4f7b944c45465ed14211/src/platform_impl/macos/app_delegate.rs#L32
    pub struct AuxDelegateState {
        /// We store this value in order to be able to defer setting the activation policy until
        /// after the app has finished launching. If the activation policy is set earlier, the
        /// menubar is initially unresponsive on macOS 10.15 for example.
        pub activation_policy: ActivationPolicy,
    
        /// Whether the application is visible in the dock.
        pub dock_visibility: bool,
    
        pub activate_ignoring_other_apps: bool,
    }
  • Does the implementation of set_dock_show need to be exactly the same as Electron. At present, I am testing locally that the display and hiding of docker are consistent with the behavior of Electron. More extensive testing may be needed...

This is my local demo:
Screen Recording 2025-02-14 at 21 29 41

Should the icon change only occur in the local environment? I pointed tauri and tao directly to the local code by patch.crates-io and then started the demo project.

[patch.crates-io]
tauri = { path = "../../tauri/crates/tauri" }
tao = { path = "../../tao" }

Demo code:

// Learn more about Tauri commands at https://tauri.app/develop/calling-rust/
#[tauri::command]
fn greet(name: &str) -> String {
    format!("Hello, {}! You've been greeted from Rust!", name)
}

#[tauri::command]
fn set_dock_visibility(app_handle: tauri::AppHandle, visible: bool) {
    let _ = app_handle.set_dock_visibility(visible);
    // let _ = app_handle.set_dock_visibility(true);
    // let _ = app_handle.set_dock_visibility(false);
    // let _ = app_handle.set_dock_visibility(true);
    // let _ = app_handle.set_dock_visibility(false);
}

#[cfg_attr(mobile, tauri::mobile_entry_point)]
pub fn run() {
    let builder = tauri::Builder::default()
        .plugin(tauri_plugin_opener::init())
        .setup(|app| {
            // app.set_activation_policy(tauri::ActivationPolicy::Regular);
            // app.set_dock_visibility(false);
            Ok(())
        })
        .invoke_handler(tauri::generate_handler![greet, set_dock_visibility]);

    let app = builder.build(tauri::generate_context!()).unwrap();

    app.run(|app, err| match err {
        tauri::RunEvent::ExitRequested { api, .. } => {
            api.prevent_exit();
            let _ = app.set_dock_visibility(false);
        }
        _ => {}
    });
}

This is my first time to submit a PR. If I have any mistakes, please feel free to correct me. Thank you.

@1111mp 1111mp requested a review from a team as a code owner February 14, 2025 13:40
@github-actions
Copy link
Contributor

github-actions bot commented Feb 15, 2025

Package Changes Through aca837c

There are 1 changes which include tao with patch

Planned Package Versions

The following package releases are the planned based on the context of changes in this pull request.

package current next
tao 0.32.7 0.32.8

Add another change file through the GitHub UI by following this link.


Read about change files or the docs at github.com/jbolda/covector

Signed-off-by: The1111mp <The1111mp@outlook.com>
Signed-off-by: The1111mp <The1111mp@outlook.com>
@lucasfernog
Copy link
Member

Should the icon change only occur in the local environment? I pointed tauri and tao directly to the local code by patch.crates-io and then started the demo project.

yeah that's a dev-only thing we'll need to fix on the tauri side later

Copy link
Member

@lucasfernog lucasfernog left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pretty good - let's wait and see if we need to port any of the electron patches

@lucasfernog lucasfernog merged commit b863d49 into tauri-apps:dev Mar 7, 2025
2 of 18 checks passed
@github-actions github-actions bot mentioned this pull request Mar 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

macOS: Dock management

2 participants