Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Macos 将go应用捆绑为Mac应用,并单击截取图标_Macos_Go - Fatal编程技术网

Macos 将go应用捆绑为Mac应用,并单击截取图标

Macos 将go应用捆绑为Mac应用,并单击截取图标,macos,go,Macos,Go,新版本的被称为uTorrent Web,它是以智能跨平台UI思想开发的。基本上,当您运行应用程序时,它会在OS dock中保留uTorrent图标,并打开一个具有良好界面的浏览器窗口,本地服务器(即应用程序本身)会将其公开。如果您保持应用程序运行,但关闭“浏览器”选项卡,则每当再次单击图标时,它都会在“”上重新打开应用程序UIhttp://127.0.0.1:19575/". 很酷 我试着用Go-on MacOS做同样的事情。所以,我写了这个超级简约的应用程序: package main im

新版本的被称为uTorrent Web,它是以智能跨平台UI思想开发的。基本上,当您运行应用程序时,它会在OS dock中保留uTorrent图标,并打开一个具有良好界面的浏览器窗口,本地服务器(即应用程序本身)会将其公开。如果您保持应用程序运行,但关闭“浏览器”选项卡,则每当再次单击图标时,它都会在“”上重新打开应用程序UIhttp://127.0.0.1:19575/". 很酷

我试着用Go-on MacOS做同样的事情。所以,我写了这个超级简约的应用程序:

package main

import (
    "fmt"
    "net/http"
    "os"
    "os/exec"
    "os/signal"
)

func main() {
    http.HandleFunc("/", HelloServer)
    go http.ListenAndServe(":8080", nil)

    // open the browser
    exec.Command("open", "http://localhost:8080").Start()

    sigchan := make(chan os.Signal, 10)
    signal.Notify(sigchan, os.Interrupt)
    <-sigchan
}

func HelloServer(w http.ResponseWriter, r *http.Request) {
    fmt.Fprint(w, "Hello!")
}
icon.icns
是Mac图标文件,
goapp
是编译的Go应用程序和
Info.plist的内容
是:


Cbundlexecutable
戈普
循环流化床锅炉
icon.icns
CbundleIdentifier
com.pistacchioso
NShighResolutionable
LSUIElement
塔达,它(几乎)起作用了。当我双击目录时,它会启动应用程序,我在dock上看到它的图标,它会在
http://localhost:8080
我看到的是“你好!”

现在,我的问题是:

  • 图标一直上下跳动,好像它还在等待应用程序完全启动。右键单击它并不是说“退出”,而是说“强制退出”。它认为应用程序“卡住了”。如何解决这个问题
  • 我还想提供“再次单击图标打开浏览器选项卡”。如何截获上述MacOS信号
  • Test.app
      /Contents
        Info.plist
        /MacOS
          goapp
        /Resources
          icon.icns
    
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
    <plist version="1.0">
    <dict>
        <key>CFBundleExecutable</key>
        <string>goapp</string>
        <key>CFBundleIconFile</key>
        <string>icon.icns</string>
        <key>CFBundleIdentifier</key>
        <string>com.pistacchioso</string>
        <key>NSHighResolutionCapable</key>
        <true/>
        <key>LSUIElement</key>
        <false/>
    </dict>
    </plist>