C'è un modo standard per controllare gli aggiornamenti in un widget di Dashboard?

StackOverflow https://stackoverflow.com/questions/4369055

  •  09-10-2019
  •  | 
  •  

Domanda

Sto scrivendo un widget di Dashboard in Dashcode, e mi piacerebbe aggiungere una sorta di funzionalità di controllo-per-gli aggiornamenti. Ho già guardato in Sparkle, ma AFAICT non è applicabile ai widget come questo. C'è una libreria di uso comune per un controllo di aggiornamento, o dovrò sviluppare il mio sistema?

Ho solo bisogno di una messa a punto molto semplice ... controllo automatico per le nuove versioni sarebbe un vantaggio, ma se l'utente doveva fare clic su un pulsante per verificare che sarebbe OK con me.

È stato utile?

Soluzione

In quanto "c'è una funzione che ...", allora non l'ho incontrato esso.

Quello che ho fatto è stato il seguente

Nel plist c'è la versione del widget e si mette il numero in là, diciamo 1.0. Quale si dovrebbe essere in grado di accedere e utilizzare. (Vedi codice) Per ragioni non ho e ha aggiunto questa var widget_version globale = "1.4"; e poi aggiornato che quando il widget aggiornato.

Poi su un server accessibile dal web, si crea un file di php (o altro) che ha il numero di versione corrente del widget. Anche in questo caso lascia dire 1.1.

Poi si scrive una funzione javascript che verificherà questa versione widget di corrente contro la versione del server e visualizzare un grafico o un messaggio per informare l'utente. E 'meglio per permettere all'utente di decidere se vogliono aggiornare piuttosto che lo rende automatica.

seguito è riportato il codice che ho usato. Si prega di copiare e o hack come si desidera.

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

Spero che questo aiuti

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top