From 6e3c255fa7cb0b15e8db7a38dc0108ec471beee0 Mon Sep 17 00:00:00 2001 From: Matthew Taylor Date: Fri, 16 Jun 2017 10:11:58 -0400 Subject: [PATCH] Make version dependent on xml call Fixes #1351 by including a call to `version.xml` to get the most up-to-date offline build version, defaulting to the current version, `456.0.3`. This also fixes #1352 by switching the route to `/download`, with a redirect from `/scratch2download/` --- src/routes.json | 10 ++++++-- src/views/download/download.jsx | 44 +++++++++++++++++++++++++++++---- src/views/download/l10n.json | 2 +- 3 files changed, 48 insertions(+), 8 deletions(-) diff --git a/src/routes.json b/src/routes.json index 49adc172d..ef64a6b38 100644 --- a/src/routes.json +++ b/src/routes.json @@ -168,8 +168,8 @@ }, { "name": "download", - "pattern": "^/scratch2download/", - "routeAlias": "/scratch2download/?$", + "pattern": "^/download/", + "routeAlias": "/download/?$", "view": "download/download", "title": "Scratch Offline Editor" }, @@ -252,6 +252,12 @@ "routeAlias": "/explore(?!/ajax)", "redirect": "/explore/studios/all" }, + { + "name": "download-redirect", + "pattern": "^/scratch2download/?$", + "routeAlias": "/scratch2download", + "view": "/download" + }, { "name": "microworld-art", "pattern": "^/microworlds/art", diff --git a/src/views/download/download.jsx b/src/views/download/download.jsx index 1a6cffad3..a80447e03 100644 --- a/src/views/download/download.jsx +++ b/src/views/download/download.jsx @@ -4,6 +4,7 @@ var render = require('../../lib/render.jsx'); var FormattedHTMLMessage = require('react-intl').FormattedHTMLMessage; var FormattedMessage = require('react-intl').FormattedMessage; +var api = require('../../lib/api'); var Page = require('../../components/page/www/page.jsx'); var TitleBanner = require('../../components/title-banner/title-banner.jsx'); var FlexRow = require('../../components/flex-row/flex-row.jsx'); @@ -14,7 +15,33 @@ require('../../components/forms/button.scss'); var Download = React.createClass({ type: 'Download', + getInitialState: function () { + return { + swfVersion: '456.0.3' + }; + }, + componentDidMount: function () { + api({ + host: '', + uri: '/scratchr2/static/sa/version.xml', + responseType: 'string' + }, function (err, body) { + if (err) return; + + var doc = new DOMParser().parseFromString(body, 'text/xml'); + return this.setState({ + swfVersion: doc.getElementsByTagName('versionNumber')[0].childNodes[0].nodeValue + }); + }.bind(this)); + }, render: function () { + var downloadUrls = { + mac: '/scratchr2/static/sa/Scratch-'+ this.state.swfVersion + '.dmg', + mac105: '/scratchr2/static/sa/Scratch-'+ this.state.swfVersion + '.air', + windows: '/scratchr2/static/sa/Scratch-'+ this.state.swfVersion + '.exe', + linux: '/scratchr2/static/sa/Scratch-'+ this.state.swfVersion + '.air' + }; + return (
@@ -95,25 +122,25 @@ var Download = React.createClass({
  • - - {' '} + {' '}
  • - - {' '} + {' '}
  • - - {' '} + {' '}
  • - - {' '} + {' '}
  • @@ -150,7 +177,14 @@ var Download = React.createClass({

    -

    +

    + +

    diff --git a/src/views/download/l10n.json b/src/views/download/l10n.json index f9f69db90..63910a7ee 100644 --- a/src/views/download/l10n.json +++ b/src/views/download/l10n.json @@ -19,7 +19,7 @@ "download.scratchCards": "Scratch Cards", "download.updatesTitle": "Updates", "download.updatesBody": "The Offline Editor can update itself (with user permission). It will check for updates at startup or you can use the \"Check for updates\" command in the file menu.", - "download.currentVersion": "The current version is 454.", + "download.currentVersion": "The current version is {version}.", "download.otherVersionsTitle": "Other Versions of Scratch", "download.otherVersionsOlder": "If you have an older computer, or cannot install the Scratch 2.0 offline editor, you can try installing Scratch 1.4.", "download.otherVersionsAdmin": "If you are a network administrator: a Scratch 2.0 MSI has been created and maintained by a member of the community and hosted for public download here.",