LoginSignup
1
3

More than 1 year has passed since last update.

macOSアプリケーションの更新フレームワークSparkleの使い方

Last updated at Posted at 2021-12-31

概要

  • SparkleはオープンソースのmacOSアプリケーション用アップデート・フレームワークです。
  • 今回更新用のファイルをGitHubに置くという想定で導入してみようと思います。

参考

オープンソースのmacOSアプリケーション用アップデート・フレームワーク「Sparkle 2.0.0」がリリース。
v1.25.0-rc1から進められていたSwift Package Managerでの管理も可能になっている

GitHub

実装

SandBoxの解除

  • 今回Sandboxは解除する前提で進めます。

Swift Packager Managerでの導入

StoryBoardで設定画面の作成

更新確認ボタンの作成

  • Objectを追加。

  • ObjectのクラスをSPUStandardUpdaterControllerに設定。

  • ボタンのアクションにcheckForUpdates:を設定。

  • ボタンを押してアクションの紐付けを確認します。
    • まだ更新の設定をしていないので当然エラーが表示されますがOKです。

自動更新の有無のチェックボックスの作成

  • CotEditorのような自動的にアップデートを確認のチェックボックスを実装します。
image
  • 下記のEnable automatic checkingを参照し、下図の通り設定。
  • チェック状態はライブラリ側で管理してくれているらしく、アプリケーション側で気にする必要はないようです。

Spackle用の秘密鍵・公開鍵の作成

  • sparkle-project/Sparkle: Releasesから下記をダウンロード。
  • 秘密鍵・公開鍵作成をするためのスクリプトなどが含まれています。

  • 解答したフォルダ内の./bin/generate_keysを実行。
  • 公開鍵がコンソール上に表示されるので控えておきます。

  • また同時に秘密鍵がKeyChainに登録されています。
  • PCを移行する際は./bin/generate_keys -x private-key-file./bin/generate_keys -f private-key-fileでそれぞれエクスポート・インポートする。

  • 公開鍵をInfo.plistSUPublicEDKeyのキーとして記載します。

appcast.xmlのURLの紐付け

  • 今回、更新情報を記載するファイルappcast.xmlは下記に配置します。
image
  • URLとしては以下の通り。
https://raw.githubusercontent.com/pommdau/SparkleDemoWithSPM/main/appcast.xml
  • このURLをInfo.plistSUFeedURLをキーとして記載します。

更新用アプリケーションのビルドとdmgの作成

  • 更新用のアプリケーションとして、適当にバージョンを上げてビルド。

  • dmgの作成。

hdiutil create -srcfolder "${source_folder_name}" -format UDZO -fs HFS+ \
  -volname "${dmg_folder_name}" "${dmg_folder_name}.dmg"

(e.g.)
ikeh@HIROKInoMacBook-Pro SparkleDemoWithSPM_GitHub % cd /Users/ikeh/Programming/Swift/SparkleDemoWithSPM_GitHub/TempForUpdateProgram
ikeh@HIROKInoMacBook-Pro TempForUpdateProgram % hdiutil create -srcfolder "SparkleDemoWithSPM.app" -format UDZO -fs HFS+ \
  -volname "SparkleDemoWithSPM" "SparkleDemoWithSPM_2.0.0.0.dmg"
...............................
created: /Users/ikeh/Programming/Swift/SparkleDemoWithSPM_GitHub/TempForUpdateProgram/SparkleDemoWithSPM_2.0.0.0.dmg

appcast.xmlのコンテンツ作成

  • dmgの配置したフォルダを対象に./bin/generate_appcastを実行すると、そのフォルダにappcast.xmlが作成される。
./bin/generate_appcast /path/to/your/updates_folder/

(e.g.)
/Users/ikeh/Programming/Swift/SparkleDemoWithSPM/From_GitHub/Sparkle-2.0.0/bin/generate_appcast /Users/ikeh/Programming/Swift/SparkleDemoWithSPM_GitHub/TempForUpdateProgram
Wrote 1 new update and updated 0 existing updates
  • appcast.xmlの中身は例えば以下の通り。
<?xml version="1.0" standalone="yes"?>
<rss xmlns:sparkle="http://www.andymatuschak.org/xml-namespaces/sparkle" version="2.0">
    <channel>
        <title>SparkleDemoWithSPM</title>
        <item>
            <title>2.0.0</title>
            <pubDate>Fri, 31 Dec 2021 17:02:05 +0900</pubDate>
            <sparkle:version>2.0.0.0</sparkle:version>
            <sparkle:shortVersionString>2.0.0</sparkle:shortVersionString>
            <sparkle:minimumSystemVersion>12.1</sparkle:minimumSystemVersion>
            <enclosure url="https://raw.githubusercontent.com/pommdau/SparkleDemoWithSPM/main/SparkleDemoWithSPM_2.0.0.0.dmg" length="1280118" type="application/octet-stream" sparkle:edSignature="WTsROa2mMSWXpnTXaFredBaYgPXPVaYYDXBx98jNnvpVBN9WyAD0feCPH+AXrsUfpnM9Keevy18LPyTQ6Xe6Bg=="/>
        </item>
    </channel>
</rss>
  • 下記に更新対象のdmgが置かれているURLが記載されており、デフォルトではappcast.xmlと同じ階層が指定されるみたいです。
<enclosure url="https://raw.githubusercontent.com/pommdau/SparkleDemoWithSPM/main/SparkleDemoWithSPM_2.0.0.0.dmg" length="1280118" type="application/octet-stream" sparkle:edSignature="WTsROa2mMSWXpnTXaFredBaYgPXPVaYYDXBx98jNnvpVBN9WyAD0feCPH+AXrsUfpnM9Keevy18LPyTQ6Xe6Bg=="/>

  • appcast.xmlのURLを上記のものに置き換えます。
-<enclosure url="https://raw.githubusercontent.com/pommdau/SparkleDemoWithSPM/main/SparkleDemoWithSPM_2.0.0.0.dmg" length="1280118" type="application/octet-stream" sparkle:edSignature="WTsROa2mMSWXpnTXaFredBaYgPXPVaYYDXBx98jNnvpVBN9WyAD0feCPH+AXrsUfpnM9Keevy18LPyTQ6Xe6Bg=="/>
+<enclosure url="https://github.com/pommdau/SparkleDemoWithSPM/releases/download/2.0.0/SparkleDemoWithSPM_2.0.0.dmg" length="1280118" type="application/octet-stream" sparkle:edSignature="WTsROa2mMSWXpnTXaFredBaYgPXPVaYYDXBx98jNnvpVBN9WyAD0feCPH+AXrsUfpnM9Keevy18LPyTQ6Xe6Bg=="/>
  • 更新したappcast.xmlをGitHubにPushして準備完了。

動作確認

  • Check for UPdates...を選択。
image
  • アップデートがある旨の通知。
image image image
  • ちゃんと更新されていることがわかります!
image

改善点

  • 公開用リポジトリ名はCotEditorに倣ってsparkle-demo-with-spm.github.ioのようにしたらいいのかなと思います。
  • またappcast.xmlのURLをいちいちGitHubのReleasesに書き換えるのが面倒なので、いい方法を考えたい所です。
1
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
3