ダッシュボードウィジェットで更新をチェックする標準的な方法はありますか?
質問
ダッシュコードでダッシュボードウィジェットを書いています。何らかのチェックアップデート機能を追加したいと思います。私はすでにSparkleを調べましたが、このようなウィジェットには適用されていません。更新チェックを行うための一般的に使用されるライブラリはありますか、それとも自分のシステムを開発する必要がありますか?
非常にシンプルなセットアップのみが必要です...新しいバージョンを自動的にチェックすることはプラスになりますが、ユーザーが私に問題があるかどうかを確認するためにボタンをクリックする必要がある場合。
解決
「そうなる関数はありますか...」として、私はそれに出くわしませんでした。
私がしたことは次のとおりでした
プリストにはウィジェットのバージョンがあり、そこに番号を入れます。アクセスして使用できるはずです。 (コードを参照)私はそうしなかった理由で、このグローバルvar widget_version = "1.4"を追加しました。そして、ウィジェットが更新されたときに更新しました。
次に、Webがアクセスできるサーバーで、ウィジェットの現在のバージョンの数を持つPHP(または何でも)ファイルを作成します。繰り返しますが、1.1としましょう。
次に、この現在のウィジェットバージョンをサーバーバージョンに対してチェックし、グラフィックまたはメッセージを表示してユーザーに表示するよりも、JavaScript関数を書き込みます。ユーザーに自動にするのではなく、アップグレードするかどうかを決定させるのが最善です。
以下は私が使用したコードです。必要に応じてコピーしてハッキングしてください。
function getSoftwareUpdate() {
// so use the built in CURL to do a REST call n.b. in widget preference you will need to check 'allow network access'
var softwareUpdate = widget.system("/usr/bin/curl 'http://api.yourserver.com/widget/wfccupdate.php'", null).outputString;
//alert(softwareUpdate); // tells you the function has been called
//alert("the update number from the REST " + softwareUpdate); // for debugging will show the key
// in main.js add this line
// var widget_version = "1.4"; // this is changed when you update the widget code for new release
// yes it's a global variable and bad but i was in a hurry
// the following line should get the widget number but for some reason i didn't do it
// localVersion = widget.preferenceForKey(preferenceForKey);
//alert("the internal preference key " + widget_version);
// then check to see if they match
if(softwareUpdate == widget_version)
{ hide_update('softwareupdate')
}
else
{show_update('softwareupdate')
}
}
function hide_update(el) { // hide the update graphic
if(document.getElementById(el))
{
if(document.getElementById(el).style.display != "none")
document.getElementById(el).style.display = "none";
}
}
function show_update(el) { // show the update graphic
if(document.getElementById(el)) {
if(document.getElementById(el).style.display == "none")
document.getElementById(el).style.display = "block";
}
}
// this is the php that is called by curl and acts as REST
<?php
// data
$UPDATE_database = <<<_UPDATE_
<?xml version="1.0" encoding="utf-8" ?>
<update>
<widgetversion>1.1</widgetversion>
</update>
_UPDATE_;
// load data
$xml = simplexml_load_string($UPDATE_database);
$result = $xml->xpath("widgetversion");
print $result[0];
?>
お役に立てれば
所属していません StackOverflow