From 7b43187c8d595fd0aa82361a0015033b78dc3817 Mon Sep 17 00:00:00 2001 From: Henry Whitaker Date: Fri, 10 Apr 2020 18:45:15 +0100 Subject: [PATCH] Finished UI for updater --- app/Helpers/UpdateHelper.php | 12 ++++++ app/Http/Controllers/UpdateController.php | 15 ++----- changelog.json | 2 +- config/speedtest.php | 2 +- public/js/app.js | 50 +++++++++++++++++++++- resources/js/components/Home/Version.js | 51 ++++++++++++++++++++++- 6 files changed, 116 insertions(+), 16 deletions(-) diff --git a/app/Helpers/UpdateHelper.php b/app/Helpers/UpdateHelper.php index 3fe46756..1a39b23d 100644 --- a/app/Helpers/UpdateHelper.php +++ b/app/Helpers/UpdateHelper.php @@ -146,6 +146,7 @@ class UpdateHelper { $this->deleteExcluded($dir); $this->backupCurrent(); $this->moveFiles(); + $this->clearup(); Log::info('Successfully applied update'); } @@ -282,4 +283,15 @@ class UpdateHelper { } } } + + private function clearup() + { + try { + File::deleteDirectory('/tmp/'.$this->repo.'-update/'); + Log::info('Deleted download directory'); + } catch(Exception $e) { + Log::error('Failed cleaning up update'); + Log::error($e); + } + } } diff --git a/app/Http/Controllers/UpdateController.php b/app/Http/Controllers/UpdateController.php index 6e680c4f..bc2b132c 100644 --- a/app/Http/Controllers/UpdateController.php +++ b/app/Http/Controllers/UpdateController.php @@ -53,16 +53,9 @@ class UpdateController extends Controller { $cp = Updater::updateFiles(); - if($cp) { - return response()->json([ - 'method' => 'copy latest version', - 'success' => $cp, - ], 200); - } else { - return response()->json([ - 'method' => 'copy latest version', - 'success' => false, - ], 500); - } + return response()->json([ + 'method' => 'copy latest version', + 'success' => $cp, + ], 200); } } diff --git a/changelog.json b/changelog.json index c8c6d749..dbe20fb4 100644 --- a/changelog.json +++ b/changelog.json @@ -1,7 +1,7 @@ { "1.2.0": [ { - "description": "Added an updating mechainism within the app.", + "description": "Added an updating mechainism within the app to keep code up to date.", "link": "" } ], diff --git a/config/speedtest.php b/config/speedtest.php index 3c87f73f..b1e89675 100644 --- a/config/speedtest.php +++ b/config/speedtest.php @@ -7,7 +7,7 @@ return [ |-------------------------------------------------------------------------- */ - 'version' => '1.1.0', + 'version' => '1.2.0', /* |-------------------------------------------------------------------------- diff --git a/public/js/app.js b/public/js/app.js index 1346259e..99cf6633 100644 --- a/public/js/app.js +++ b/public/js/app.js @@ -127865,6 +127865,7 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope + var Version = /*#__PURE__*/function (_Component) { _inherits(Version, _Component); @@ -127907,11 +127908,48 @@ var Version = /*#__PURE__*/function (_Component) { }); }); + _defineProperty(_assertThisInitialized(_this), "updateApp", function () { + _this.setState({ + showProgress: true, + updateProgress: 0 + }); + + react_toastify__WEBPACK_IMPORTED_MODULE_3__["toast"].info('Downloading update'); + axios__WEBPACK_IMPORTED_MODULE_2___default.a.get('/api/update/download').then(function (resp) { + _this.setState({ + updateProgress: 50 + }); + + react_toastify__WEBPACK_IMPORTED_MODULE_3__["toast"].info('Extracting update'); + axios__WEBPACK_IMPORTED_MODULE_2___default.a.get('/api/speedtest/extract').then(function (resp) { + _this.setState({ + updateProgress: 75 + }); + + react_toastify__WEBPACK_IMPORTED_MODULE_3__["toast"].info('Applying update'); + axios__WEBPACK_IMPORTED_MODULE_2___default.a.get('/api/update/move').then(function (resp) { + _this.setState({ + updateProgress: 100 + }); + + react_toastify__WEBPACK_IMPORTED_MODULE_3__["toast"].success('Update successful. Refreshing your page...'); + setTimeout(function () { + location.reload(true); + }, 5000); + }); + }); + })["catch"](function (err) { + react_toastify__WEBPACK_IMPORTED_MODULE_3__["toast"].error('Something went wrong...'); + }); + }); + _this.state = { version: document.querySelector('meta[name="version"]').content, update: false, modalShow: false, - changelog: [] + changelog: [], + showProgress: false, + updateProgress: 0 }; return _this; } @@ -127928,6 +127966,8 @@ var Version = /*#__PURE__*/function (_Component) { var update = this.state.update; var modalShow = this.state.modalShow; var changelog = this.state.changelog; + var showProgress = this.state.showProgress; + var updateProgress = this.state.updateProgress; if (update === false) { return /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default.a.createElement("p", { @@ -127961,7 +128001,13 @@ var Version = /*#__PURE__*/function (_Component) { rel: "noopener noreferer" }, e.description)); } - }))))); + })), showProgress && /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default.a.createElement("div", null, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default.a.createElement("p", null, "Update progress:"), /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default.a.createElement(react_bootstrap__WEBPACK_IMPORTED_MODULE_4__["ProgressBar"], { + animated: true, + now: updateProgress + })), !showProgress && /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default.a.createElement(react_bootstrap__WEBPACK_IMPORTED_MODULE_4__["Button"], { + variant: "primary", + onClick: this.updateApp + }, "Update")))); } } }]); diff --git a/resources/js/components/Home/Version.js b/resources/js/components/Home/Version.js index b7f982c8..8ea1e224 100644 --- a/resources/js/components/Home/Version.js +++ b/resources/js/components/Home/Version.js @@ -2,7 +2,8 @@ import React, { Component } from 'react'; import ReactDOM from 'react-dom'; import Axios from 'axios'; import { toast } from 'react-toastify'; -import { Modal } from 'react-bootstrap'; +import { Modal, ProgressBar } from 'react-bootstrap'; +import { Button } from 'react-bootstrap'; export default class Version extends Component { constructor(props) { @@ -13,6 +14,8 @@ export default class Version extends Component { update: false, modalShow: false, changelog: [], + showProgress: false, + updateProgress: 0, }; } @@ -51,11 +54,48 @@ export default class Version extends Component { }); } + updateApp = () => { + this.setState({ + showProgress: true, + updateProgress: 0, + }); + toast.info('Downloading update'); + Axios.get('/api/update/download') + .then((resp) => { + this.setState({ + updateProgress: 50, + }); + toast.info('Extracting update'); + Axios.get('/api/speedtest/extract') + .then((resp) => { + this.setState({ + updateProgress: 75, + }); + toast.info('Applying update'); + Axios.get('/api/update/move') + .then((resp) => { + this.setState({ + updateProgress: 100, + }); + toast.success('Update successful. Refreshing your page...'); + setTimeout(function() { + location.reload(true); + }, 5000); + }) + }) + }) + .catch((err) => { + toast.error('Something went wrong...'); + }) + } + render() { var version = this.state.version; var update = this.state.update; var modalShow = this.state.modalShow; var changelog = this.state.changelog; + var showProgress = this.state.showProgress; + var updateProgress = this.state.updateProgress; if(update === false) { return ( @@ -84,6 +124,15 @@ export default class Version extends Component { } })} + {showProgress && +
+

Update progress:

+ +
+ } + {!showProgress && + + }