代码之家  ›  专栏  ›  技术社区  ›  quanta

可以在Qt(Golang bindings)应用程序中使用Sparkle吗?

  •  0
  • quanta  · 技术社区  · 6 年前

    我们使用以下方法构建Qt应用程序: https://github.com/therecipe/qt . https://sparkle-project.org

    /Applications/VLC.app/Contents/Frameworks/Sparkle.framework
    /Applications/Adium.app/Contents/Frameworks/Sparkle.framework
    /Applications/TeamViewer.app/Contents/Frameworks/Sparkle.framework
    /Applications/Docker.app/Contents/Frameworks/Sparkle.framework
    ...
    

    但它是针对C++/目标C代码的。

    可以与Golang一起使用吗?如果是,怎么做?

    1 回复  |  直到 6 年前
        1
  •  1
  •   quanta    6 年前

    https://github.com/therecipe/qt/issues/743#issuecomment-444689169

    #import <Headers/SUUpdater.h>
    
    static SUUpdater* updater = nil;
    
    void sparkle_checkUpdates()
    {
        if (!updater) {
            updater = [[SUUpdater sharedUpdater] retain];
        }
    
        [updater setUpdateCheckInterval:3600];
        [updater checkForUpdatesInBackground];
    }
    

    // +build darwin windows
    
    package main
    
    /*
    #cgo CFLAGS: -I ${SRCDIR}/Sparkle.framework
    #cgo LDFLAGS: -F ${SRCDIR} -framework Sparkle
    
    void sparkle_checkUpdates();
    */
    import "C"
    
    func sparkle_checkUpdates() {
        C.sparkle_checkUpdates()
    }
    

    而且 main.go ,称之为func:

    action := widgets.NewQMenuBar(nil).AddMenu2("").AddAction("Check for Updates...")
    // http://doc.qt.io/qt-5/qaction.html#MenuRole-enum
    action.SetMenuRole(widgets.QAction__ApplicationSpecificRole)
    action.ConnectTriggered(func(bool) { sparkle_checkUpdates() })
    

    <?xml version="1.0" standalone="yes"?>
    <rss xmlns:sparkle="http://www.andymatuschak.org/xml-namespaces/sparkle" version="2.0">
      <channel>
        <title>Premium VPN</title>
        <item>
          <title>1.0.0.2905</title>
          <pubDate>Tue, 11 Dec 2018 11:09:10 +0800</pubDate>
          <sparkle:minimumSystemVersion>10.7</sparkle:minimumSystemVersion>
          <enclosure url="https://example.com/x.zip" sparkle:version="1.0.0.2905" sparkle:shortVersionString="1.0.0.2905" sparkle:edSignature="$(/path/to/Sparkle/bin/sign_update)" length="104408678" type="application/octet-stream"/>
        </item>
      </channel>
    </rss>
    

    Info.plist:

    <key>SUFeedURL</key>
    <string>https://example.com/appcast.xml</string>
    <key>SUPublicEDKey</key>
    <string>$(/path/to/Sparkle/bin/generate_keys)</string>