0

私は Dashcode でダッシュボード ウィジェットを作成しており、ある種の更新チェック機能を追加したいと考えています。私はすでにSparkleを調べましたが、AFAICTはこのようなウィジェットには適用できません. 更新チェックを行うために一般的に使用されるライブラリはありますか? それとも独自のシステムを開発する必要がありますか?

非常に簡単なセットアップだけが必要です...新しいバージョンを自動的にチェックすることはプラスになりますが、ユーザーがチェックするためにボタンをクリックする必要がある場合は、それで問題ありません。

4

1 に答える 1

0

「...になる機能はありますか」という限り、私はそれに出くわしていません。

私がしたことは次のとおりです

plist にはウィジェットのバージョンがあり、そこに番号を入力します。たとえば、1.0 とします。アクセスして使用できる必要があります。(コードを参照)理由により、このグローバル 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];
?>

お役に立てれば

于 2010-12-11T11:19:14.907 に答える