|
| 1 | +/* |
| 2 | +Copyright 2015, 2016 OpenMarket Ltd |
| 3 | +
|
| 4 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +you may not use this file except in compliance with the License. |
| 6 | +You may obtain a copy of the License at |
| 7 | +
|
| 8 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +
|
| 10 | +Unless required by applicable law or agreed to in writing, software |
| 11 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +See the License for the specific language governing permissions and |
| 14 | +limitations under the License. |
| 15 | +*/ |
| 16 | + |
| 17 | +'use strict'; |
| 18 | + |
| 19 | +import React from 'react'; |
| 20 | +import dis from 'matrix-react-sdk/lib/dispatcher'; |
| 21 | +import { _t } from 'matrix-react-sdk/lib/languageHandler'; |
| 22 | +import PlatformPeg from 'matrix-react-sdk/lib/PlatformPeg'; |
| 23 | +import {updateStateEnum} from '../../../vector/platform/VectorBasePlatform'; |
| 24 | +import AccessibleButton from 'matrix-react-sdk/lib/components/views/elements/AccessibleButton'; |
| 25 | + |
| 26 | +export default React.createClass({ |
| 27 | + |
| 28 | + getInitialState: function() { |
| 29 | + return { |
| 30 | + message: 'Checking for an update...', |
| 31 | + done: false, |
| 32 | + }; |
| 33 | + }, |
| 34 | + |
| 35 | + componentWillMount: function() { |
| 36 | + PlatformPeg.get().checkForUpdate().done((state) => { |
| 37 | + if (this._unmounted) return; |
| 38 | + |
| 39 | + console.log('checkForUpdate done, ', state); |
| 40 | + |
| 41 | + // We will be replaced by NewVersionBar |
| 42 | + if (state === updateStateEnum.Ready) return; |
| 43 | + |
| 44 | + let done = true; |
| 45 | + let message; |
| 46 | + switch (state) { |
| 47 | + case updateStateEnum.Error: |
| 48 | + message = 'Error encountered when checking for an update'; |
| 49 | + break; |
| 50 | + case updateStateEnum.NotAvailable: |
| 51 | + message = 'No update found'; |
| 52 | + break; |
| 53 | + case updateStateEnum.Downloading: |
| 54 | + message = 'Update is being downloaded'; |
| 55 | + done = false; |
| 56 | + break; |
| 57 | + } |
| 58 | + |
| 59 | + this.setState({message, done}); |
| 60 | + }); |
| 61 | + }, |
| 62 | + |
| 63 | + componentWillUnmount: function() { |
| 64 | + this._unmounted = true; |
| 65 | + }, |
| 66 | + |
| 67 | + hideToolbar: function() { |
| 68 | + dis.dispatch({ |
| 69 | + action: 'check_updates', |
| 70 | + value: false, |
| 71 | + }); |
| 72 | + }, |
| 73 | + |
| 74 | + render: function() { |
| 75 | + const imgSrc = this.state.done ? 'img/warning.svg' : 'img/spinner.gif'; |
| 76 | + |
| 77 | + return ( |
| 78 | + <div className="mx_MatrixToolbar"> |
| 79 | + <img className="mx_MatrixToolbar_warning" src={imgSrc} width="24" height="23" alt="/!\"/> |
| 80 | + <div className="mx_MatrixToolbar_content"> |
| 81 | + {this.state.message} |
| 82 | + </div> |
| 83 | + <AccessibleButton className="mx_MatrixToolbar_close" onClick={this.hideToolbar}> |
| 84 | + <img src="img/cancel.svg" width="18" height="18" /> |
| 85 | + </AccessibleButton> |
| 86 | + </div> |
| 87 | + ); |
| 88 | + } |
| 89 | +}); |
0 commit comments