Skip to content

Commit

Permalink
StateController refactor to agnostify SafeWebview
Browse files Browse the repository at this point in the history
  • Loading branch information
Shou committed May 30, 2017
1 parent 6ba1b44 commit d31ce55
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 20 deletions.
19 changes: 12 additions & 7 deletions lib/gui/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -300,20 +300,25 @@ app.controller('HeaderController', function(SelectionStateModel, OSOpenExternalS

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

$rootScope.$on('$stateChangeSuccess', (event, toState, toParams, fromState) => {
this.previousName = fromState.name;
this.currentName = toState.name;
});

/**
* @summary Get the current state name
* @summary Get the previous state name
* @function
* @public
*
* @returns {String} current state name
* @returns {String} previous state name
*
* @example
* if (StateController.currentName() === 'main') {
* console.log('We are on the main screen!');
* if (StateController.previousName === 'main') {
* console.log('We left the main screen!');
* }
*/
this.currentName = () => {
return $state.current.name;
};
this.previousName = null;

this.currentName = null;

});
13 changes: 10 additions & 3 deletions lib/gui/components/safe-webview/safe-webview.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,13 @@ class SafeWebview extends react.PureComponent {
// Events steal 'this'
this.didFailLoad = _.bind(this.didFailLoad, this);
this.didGetResponseDetails = _.bind(this.didGetResponseDetails, this);

// Make a persistent electron session called 'success-banner'
electron.remote.session.fromPartition('persist:success-banner', {

// Disable the cache for the 'success-banner' session used by the webview
cache: false
});
}

/**
Expand Down Expand Up @@ -99,7 +106,7 @@ class SafeWebview extends react.PureComponent {
* @param {Object} nextProps - upcoming properties
*/
componentWillReceiveProps(nextProps) {
if (this.props.currentStateName === 'success' && nextProps.currentStateName !== 'success') {
if (nextProps.refreshNow && !this.props.refreshNow) {

// Reload the page if it hasn't changed, otherwise reset the source URL,
// because reload interferes with 'src' setting, resetting the 'src' attribute
Expand Down Expand Up @@ -207,9 +214,9 @@ SafeWebview.propTypes = {
src: propTypes.string.isRequired,

/**
* @summary Current Angular $state name
* @summary Refresh the webview
*/
currentStateName: propTypes.string
refreshNow: propTypes.bool

};

Expand Down
7 changes: 0 additions & 7 deletions lib/gui/etcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,6 @@ electron.app.on('ready', () => {
// No menu bar
electron.Menu.setApplicationMenu(null);

// Make a persistent electron session called 'success-banner'
electron.session.fromPartition('persist:success-banner', {

// Disable the cache for the 'success-banner' session used by the webview
cache: false
});

mainWindow = new electron.BrowserWindow({
width: 800,
height: 380,
Expand Down
6 changes: 3 additions & 3 deletions lib/gui/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
<main class="wrapper" ui-view></main>

<footer class="section-footer" ng-controller="StateController as state"
ng-hide="state.currentName() === 'success'">
ng-hide="state.currentName === 'success'">
<svg-icon path="../../../assets/etcher.svg"
width="83px"
height="13px"
Expand All @@ -54,11 +54,11 @@
<div class="section-loader"
ng-controller="StateController as state"
ng-class="{
isFinish: state.currentName() === 'success'
isFinish: state.currentName === 'success'
}">
<safe-webview
src="'https://etcher.io/success-banner/'"
current-state-name="state.currentName()"></safe-webview>
refresh-now="state.previousName === 'success'"></safe-webview>
</div>
</body>
</html>

0 comments on commit d31ce55

Please sign in to comment.