tauri-apps / tauri

Build smaller, faster, and more secure desktop applications with a web frontend.
https://tauri.app
Apache License 2.0
80.06k stars 2.38k forks source link

feat(macos): dock management api #2358

Open OceanBelongsToMe opened 2 years ago

OceanBelongsToMe commented 2 years ago

Describe the bug

A clear and concise description of what the bug is.

To Reproduce

Steps to reproduce the behavior:

  1. Go to '...'
  2. Click on '....'
  3. Scroll down to '....'
  4. See error

Expected behavior

A clear and concise description of what you expected to happen.

Screenshots

If applicable, add screenshots to help explain your problem.

Platform and Versions (required):

Operating System

Node.js environment
Node.js 
@tauri-apps/cli 
@tauri-apps/api 

Global packages
npm 
yarn 

Rust environment
rustc 
cargo 

App directory structure

App
tauri.rs 
build-type 
CSP 

Additional context

Add any other context about the problem here.

Stack Trace

probablykasper commented 2 years ago

Hard to say what you mean because you didn't say much. Windows don't show up in the macOS Dock, so window.set_skip_taskbar isn't something that works on macOS. If you're talking about hiding the app from the Dock, that's mentioned in https://github.com/tauri-apps/tauri/issues/2258

amrbashir commented 2 years ago

It is not possible for macOS so I will rename this issue to dock management.

amrbashir commented 2 years ago

related to tauri-apps/tao#105

betamos commented 2 years ago

My use case, for whoever is looking at this in the future:

The user can control whether the app runs in (a) both foreground and background or (b) foreground only, using a checkbox:

set_activation_policy almost solves my problem, but:

  1. I can't seem to change it when the app is running, since it's exposed as &mut self on the App struct. (I'm not an expert on MacOS, but it appears this should be allowed, perhaps through the AppHandle?)
  2. When set to Accessory, the dock icon is not shown, even if main window is open. (This appears to be MacOS default, so not expecting it to be overridden by Tauri).
betamos commented 2 years ago

Check out these commits here:

https://github.com/betamos/tauri/commits/betamos-head

(Relies on an unpublished addition to Tao)

I got everything to work except for one issue:

It works well otherwise, and everything I added is platform-gated with cfg(target_os="macos"). It's basically a thin layer on top of MacOS APIs. I'd be happy to contribute but someone should probably vet/approve/feedback the approach first.

Alternative approach

Instead of using archaic terminology such as set_activation_policy, I'd prefer adding simpler APIs that exist on all platforms to avoid having to fiddle with platform-gates in business logic. (I suspect a verbose above approach – such as the one above – will result in cargo-cult copy-pasting, so why not make it simpler from the get-go?). Example:

There's some precedent for this in skip_taskbar, which doesn't apply to MacOS.

probablykasper commented 2 years ago

set_activation_policy is an entirely different thing from showing/hiding the dock icon - Keep in mind there are three different activation policies. If you change the activation policy, you should be aware of what it does, so renaming it could potentially be misleading

betamos commented 2 years ago

Yes, I think only regular and accessory would apply here. Is there any API you would suggest for dock icon control? I only found transformProcessType (which is used by Electron) but it seems racey judging by their workarounds.

https://github.com/electron/electron/blob/b0f315a637b05bc445fc7e6084baa840891c1207/shell/browser/browser_mac.mm#L414

probablykasper commented 2 years ago

People have been mentioning transformProcessType, and it seems like the only option as far as I can tell

PavelLaptev commented 4 months ago

It would be nice to be able to dynamically change the dock icon 🙂