Skip to content

[windows] if several menu items are hidden, showing them gets the absolute index #72

@kalikaneko

Description

@kalikaneko

this might be a corner case, but it's actually a case we're using that's buggy on windows:

  1. Have several adjacent menu items hidden right from the beginning.
  2. when one of them is shown, the position in which the item is aded (being absolute) can be below menu items that were added afterwards.

I'm unsure about what strategy will be better to cope with this. I was thinking about adding a public method to optionally force a menuID.

here's a snippet that demonstrates this:

package main

import (
        "fmt"
        "io/ioutil"
        "time"

        "github.com/getlantern/systray"
        "github.com/getlantern/systray/example/icon"
)

func main() {
        onExit := func() {
                fmt.Println("Starting onExit")
                now := time.Now()
                ioutil.WriteFile(fmt.Sprintf(`on_exit_%d.txt`, now.UnixNano()), []byte(now.String()), 0644)
                fmt.Println("Finished onExit")
        }
        systray.Run(onReady, onExit)
}

func onReady() {
        systray.SetIcon(icon.Data)
        systray.SetTitle("Awesome App")
        systray.SetTooltip("Lantern")
        mQuitOrig := systray.AddMenuItem("Quit", "Quit the whole app")


        mHidden1 := systray.AddMenuItem("Hide1", "Hide 1")
        mHidden1.Hide()
        mHidden2 := systray.AddMenuItem("Hide2", "Hide 2")
        mHidden2.Hide()
        mHidden3 := systray.AddMenuItem("Hide3", "Hide 3")
        mHidden3.Hide()

        mDummy := systray.AddMenuItem("hide button should be above me", "dummy button")
        mDummy.SetTooltip("dummy button")


        go func() {
                <-mQuitOrig.ClickedCh
                fmt.Println("Requesting quit")
                systray.Quit()
                fmt.Println("Finished quitting")
        }()

        go func() {
                systray.SetIcon(icon.Data)
                systray.SetTitle("Awesome App")
                systray.AddSeparator()

                mShowHide := systray.AddMenuItem("Show", "Show/Hide a few menu items")
                shown := false
                for {
                        select {
                        case <-mShowHide.ClickedCh:
                                if shown {
                                        mShowHide.SetTitle("Show")
                                        mShowHide.SetTooltip("Show previously hidden menu items")
                                        mHidden3.Hide()
                                        shown = false
                                } else {
                                        mShowHide.SetTitle("Hide")
                                        mShowHide.SetTooltip("Hide a few menu items")
                                        mHidden3.Show()
                                        shown = true
                                }
                        }
                }
        }()
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions