Skip to content

Replace StatusItemView implementation with [NSStatusItem button] #18664

Closed

Description

@MarshallOfSound

Now that we have a supported platform list of >= 10.10 we can use the [NSStatusItem button] instead of the hacks and tricks we use currently.

Activity

  1. self-assigned this
    on Jun 6, 2019
  2. deermichel commented on Jun 20, 2019

    @deermichel
    Contributor

    Tray Migration for macOS Catalina

    Docs: https://electronjs.org/docs/api/tray

    statusItem: NSStatusItem

    Instance Methods

    • destroy
      • not tested, but shouldnt be a problem
    • setImage
      • works via [[statusItem button] setImage]
    • setPressedImage
      • works via [[statusItem button] setAlternateImage]
    • setToolTip
      • works via [[statusItem button] setToolTip]
    • setTitle
      • works via [[statusItem button] setTitle]
      • icon & text position needs to be set using [[statusItem button] setImagePosition]
    • getTitle
      • works via [[statusItem button] title]
    • setHighlightMode
    • setIgnoreDoubleClickEvents
      • no idea about this one... my guess is a custom click handler
    • getIgnoreDoubleClickEvents
      • correlates with setter
    • popUpContextMenu
      • maybe?
    • setContextMenu
      • works somehow via [[statusItem button] setMenu]
      • needs further investigation, e.g. radios, buttons not enabled (see #random channel)
      • [statusItem popUpStatusItemMenu] but did work.. but is deprecated yay
    • getBounds
      • works via [[statusItem button] frame]
    • isDestroyed
      • not tested, but shouldnt be a problem

    Events

    • click
      • defaults to open assigned [[statusItem button] menu]
      • not sure if can be overriden
      • custom view needed for that, workaround?
    • right-click, double-click
      • custom view needed for that, workaround?
    • drop, drop-files, drop-text
      • custom view needed for that, workaround?
    • drag-enter, drag-leave, drag-end
      • custom view needed for that, workaround?
    • mouse-enter, mouse-leave, mouse-move
      • detected using a NSTrackingArea
      • attaching tracking area to [statusItem button] might work

    Especially the events are problematic (at least from my point of knowledge). Also, theres no setter for [statusItem button]. Is there a workaround to change it to a custom NSStatusBarButton - and if so, would that help?

    cc @codebytere @miniak @erickzhao

  3. sindresorhus commented on Jun 21, 2019

    @sindresorhus
    Contributor

    right-click

    You can set what events triggers the .action on a button with sendActionOn:.

    double-click

    You can just check the .clickCount: https://stackoverflow.com/a/16806632/64949

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions