登录
首页 >  Golang >  Go问答

在 Qt 应用程序中是否可以集成 Sparkle(Golang 绑定)?

来源:stackoverflow

时间:2024-02-27 23:57:25 432浏览 收藏

本篇文章给大家分享《在 Qt 应用程序中是否可以集成 Sparkle(Golang 绑定)?》,覆盖了Golang的常见基础知识,其实一个语言的全部知识点一篇文章是不可能说完的,但希望通过这些问题,让读者对自己的掌握程度有一定的认识(B 数),从而弥补自己的不足,更好的掌握它。

问题内容

我们使用以下方式构建 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
...

一些文章向我展示了如何在 qt 中使用它:

  • http://www.discoversdk.com/knowledge-base/using-sparkle-in-qt
  • https://github.com/sparkle-project/sparkle/issues/1137#issuecomment-336667547

但它适用于 c++/objective c 代码。

可以和golang一起使用吗?如果是这样,怎么办?


解决方案


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

闪光.m:

#import <headers/suupdater.h>

static suupdater* updater = nil;

void sparkle_checkupdates()
{
    if (!updater) {
        updater = [[suupdater sharedupdater] retain];
    }

    [updater setupdatecheckinterval:3600];
    [updater checkforupdatesinbackground];
}

sparkle.go:

// +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 中调用该函数:

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() })

appcast.xml:

<?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>

信息.plist:

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

今天关于《在 Qt 应用程序中是否可以集成 Sparkle(Golang 绑定)?》的内容介绍就到此结束,如果有什么疑问或者建议,可以在golang学习网公众号下多多回复交流;文中若有不正之处,也希望回复留言以告知!

声明:本文转载于:stackoverflow 如有侵犯,请联系study_golang@163.com删除
相关阅读
更多>
最新阅读
更多>
课程推荐
更多>