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(macos): dock management api #2358

Open
OceanBelongsToMe opened this issue Aug 5, 2021 · 10 comments
Open

feat(macos): dock management api #2358

OceanBelongsToMe opened this issue Aug 5, 2021 · 10 comments
Labels
status: upstream This issue is blocked by upstream dependencies and we need to wait or contribute upstream fixes type: feature request

Comments

@OceanBelongsToMe
Copy link

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
Copy link
Member

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 #2258

@amrbashir
Copy link
Member

amrbashir commented Aug 11, 2021

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

@amrbashir amrbashir changed the title window.set_skip_taskbar for macos!!! feat: doc management api for macOS Aug 11, 2021
@amrbashir
Copy link
Member

related to tauri-apps/tao#105

@amrbashir amrbashir changed the title feat: doc management api for macOS feat(macos): dock management api Aug 12, 2021
@amrbashir amrbashir added status: upstream This issue is blocked by upstream dependencies and we need to wait or contribute upstream fixes and removed status: waiting labels Oct 30, 2021
@betamos
Copy link
Contributor

betamos commented Jan 25, 2022

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:

  • Tray icon is shown if and only if background mode is enabled.
  • Dock icon is always shown when main window is open.
  • Dock icon is hidden if main window is closed, under mode (a).

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
Copy link
Contributor

betamos commented Feb 8, 2022

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:

  • User persists app in dock (either through "Show recent" or by adding it manually to the dock)
  • Set activation policy to accessory/prohibited (disables icon, but doesn't remove it)
  • Click icon (this doesn't show the app automatically, and there's no way to intercept the event atm, see Support activate event on macOS tao#218)

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:

  • show/hide_dock_icon
  • show/hide_application
  • or possibly combined in a show_all/hide_all with one or two params that does the right thing for all platforms - in most cases

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

@probablykasper
Copy link
Member

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
Copy link
Contributor

betamos commented Feb 8, 2022

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
Copy link
Member

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

@PavelLaptev
Copy link

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

@thewh1teagle
Copy link
Contributor

Hey
What's the status of this feature?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: upstream This issue is blocked by upstream dependencies and we need to wait or contribute upstream fixes type: feature request
Projects
Status: 📬Proposal
Development

No branches or pull requests

7 participants