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

feat: add set_dock_visibility method #1058

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open

Conversation

1111mp
Copy link

@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
Signed-off-by: The1111mp <[email protected]>
Copy link
Contributor

Package Changes Through 82a4864

There are 1 changes which include tao with minor

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.31.1 0.32.0

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


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

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
1 participant