getlantern / systray(Golang) 可以在 Windows 和代码上运行,但不能在 Macos 上运行

问题描述 投票:0回答:1

我正在 Windows 上开发一个 Golang 应用程序,使用 getlantern/systray 库来实现系统托盘功能。在切换到Mac进行开发时,我遇到了一个错误。有没有办法解决这个问题?

func main() {

    onExit := func() {
        os.Exit(0)
    }
    go func() {
        systray.Run(onReady, onExit)
    }()

func onReady() {
    systray.SetIcon(iconData)
    systray.SetTitle("Connectapp")
    systray.SetTooltip("Connectapp")
    mQuit := systray.AddMenuItem("Quit", "Quit the whole app")

    go func() {
        <-mQuit.ClickedCh
        systray.Quit()
    }()
}

在 Windows 上的 Visual Studio Code 中运行“go build”时,我没有遇到错误。但是,在 Visual Studio Code 中在 macOS 上工作时,出现错误,如下所示:

# github.com/getlantern/systray
../../../../go/pkg/mod/github.com/getlantern/[email protected]/systray.go:78:2: undefined: nativeLoop
../../../../go/pkg/mod/github.com/getlantern/[email protected]/systray.go:106:2: undefined: registerSystray
../../../../go/pkg/mod/github.com/getlantern/[email protected]/systray.go:111:14: undefined: quit
../../../../go/pkg/mod/github.com/getlantern/[email protected]/systray.go:136:2: undefined: addSeparator
../../../../go/pkg/mod/github.com/getlantern/[email protected]/systray.go:190:2: undefined: hideMenuItem
../../../../go/pkg/mod/github.com/getlantern/[email protected]/systray.go:195:2: undefined: showMenuItem
../../../../go/pkg/mod/github.com/getlantern/[email protected]/systray.go:220:2: undefined: addOrUpdateMenuItem
macos go system-tray
1个回答
0
投票

cgo 应该启用。

CGO_ENABLED=1

© www.soinside.com 2019 - 2024. All rights reserved.