Skip to content

Commit

Permalink
Clean up sparkle response building
Browse files Browse the repository at this point in the history
Signed-off-by: Claudio Cambra <[email protected]>
  • Loading branch information
claucambra committed May 30, 2024
1 parent 4f55199 commit dbfaa84
Showing 1 changed file with 34 additions and 12 deletions.
46 changes: 34 additions & 12 deletions src/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,27 +108,49 @@ protected function getCurrentTimeStamp() : string {
return (new \DateTime())->format('D, j F y H:m:s O');
}

/**
* Convenience functions to get specific file provider or standard client update information
*/
private function getSparkleUpdateUrl(array $updateVersion) : string {
$updateUrlKey = $this->isFileProvider ? 'fileProviderSparkleDownloadUrl' : 'sparkleDownloadUrl';
return $updateVersion[$updateUrlKey];
}

private function getSparkleUpdateSignature(array $updateVersion) : string {
$updateSignatureKey = $this->isFileProvider ? 'fileProviderSignature' : 'signature';
return $updateVersion[$updateSignatureKey];
}

private function getSparkleUpdateLength(array $updateVersion) : string {
$updateLengthKey = $this->isFileProvider ? 'fileProviderLength' : 'length';
return $updateVersion[$updateLengthKey];
}

/**
* Builds the response for Sparkle (used by the Mac updater)
*
* @param array $updateVersion
* @return string
*/
private function buildSparkleResponse(array $updateVersion) : string {
$sparkleUrl = $this->getSparkleUpdateUrl($updateVersion);
$sparkleSignature = $this->getSparkleUpdateSignature($updateVersion);
$sparkleLength = $this->getSparkleUpdateLength($updateVersion);

$item = !empty($updateVersion) ? '<item>
<title>'.$updateVersion['versionstring'].'</title>
<pubDate>'.$this->getCurrentTimeStamp().'</pubDate>
<enclosure url="'.$updateVersion[$this->isFileProvider ? 'fileProviderSparkleDownloadUrl' : 'sparkleDownloadUrl'].'" sparkle:version="'.$updateVersion['version'].'" type="application/octet-stream" sparkle:edSignature="'.$updateVersion[$this->isFileProvider ? 'fileProviderSignature' : 'signature'].'" length="'.$updateVersion[$this->isFileProvider ? 'fileProviderLength' : 'length'].'"/>
<sparkle:minimumSystemVersion>11.0</sparkle:minimumSystemVersion>
</item>' : '';
$xml = '<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:sparkle="http://www.andymatuschak.org/xml-namespaces/sparkle" xmlns:dc="http://purl.org/dc/elements/1.1/">
<channel>
<title>Download Channel</title>
<description>Most recent changes with links to updates.</description>
<language>en</language>'.$item.'</channel>
<title>'.$updateVersion['versionstring'].'</title>
<pubDate>'.$this->getCurrentTimeStamp().'</pubDate>
<enclosure url="'.$sparkleUrl.'" sparkle:version="'.$updateVersion['version'].'" type="application/octet-stream" sparkle:edSignature="'.$sparkleSignature.'" length="'.$sparkleLength.'"/>
<sparkle:minimumSystemVersion>11.0</sparkle:minimumSystemVersion>
</item>' : '';

return '<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:sparkle="http://www.andymatuschak.org/xml-namespaces/sparkle" xmlns:dc="http://purl.org/dc/elements/1.1/">
<channel>
<title>Download Channel</title>
<description>Most recent changes with links to updates.</description>
<language>en</language>'.$item.'</channel>
</rss>';
return $xml;
}

/**
Expand Down

0 comments on commit dbfaa84

Please sign in to comment.