Skip to content

Commit

Permalink
feat(GUI): reset webview after navigating away
Browse files Browse the repository at this point in the history
We reload and reset the webview to its original URL when the user
navigates away from the success screen.

Changelog-Entry: Reset webview after navigating away from success
screen.
  • Loading branch information
Shou committed May 15, 2017
1 parent 3203eb5 commit 9fe0e4d
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
9 changes: 8 additions & 1 deletion lib/gui/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -298,11 +298,18 @@ app.controller('HeaderController', function(SelectionStateModel, OSOpenExternalS

});

app.controller('StateController', function($state) {
app.controller('StateController', function($rootScope, $state) {

/**
* @param {string} state - state page
*/
this.is = $state.is;

/**
* @param {function} func - function to pass $rootScope to
*/
this.onStateChange = (func) => {
$rootScope.$on('$stateChangeSuccess', func);
};

});
15 changes: 14 additions & 1 deletion lib/gui/components/safe-webview/safe-webview.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,14 @@ class SafeWebview extends react.PureComponent {
this.refs.webview.addEventListener('new-window', this.constructor.newWindow);
this.refs.webview.addEventListener('console-message', this.constructor.consoleMessage);

if (this.props.onStateChange) {
this.props.onStateChange((event, toState, toParams, fromState) => {
if (fromState.name === 'success' && this.state.shouldLoad) {
this.refs.webview.src = this.props.src;
this.refs.webview.reload();
}
});
}
}
}

Expand Down Expand Up @@ -164,7 +172,12 @@ SafeWebview.propTypes = {
/**
* @summary The website source URL
*/
src: propTypes.string.isRequired
src: propTypes.string.isRequired,

/**
* @summary Inject Angular functionality
*/
onStateChange: propTypes.func

};

Expand Down
3 changes: 2 additions & 1 deletion lib/gui/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@
isFinish: state.is('success')
}">
<safe-webview
src="'https://etcher.io/success-banner/'"></safe-webview>
src="'https://etcher.io/success-banner/'"
on-state-change="state.onStateChange"></safe-webview>
</div>
</body>
</html>

0 comments on commit 9fe0e4d

Please sign in to comment.