Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Store state of lighthouse in extension while running. #1185

Merged
merged 2 commits into from
Dec 30, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 29 additions & 2 deletions lighthouse-extension/app/src/lighthouse-background.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ const ReportGenerator = require('../../../lighthouse-core/report/report-generato
const STORAGE_KEY = 'lighthouse_audits';
const _flatten = arr => [].concat(...arr);

let lighthouseIsRunning = false;
let latestStatusLog = [];

/**
* Filter out any unrequested aggregations from the config. If any audits are
* no longer needed by any remaining aggregations, filter out those as well.
Expand Down Expand Up @@ -87,8 +90,19 @@ window.runLighthouseForConnection = function(connection, url, options, requested
// Add url and config to fresh options object.
const runOptions = Object.assign({}, options, {url, config});

lighthouseIsRunning = true;

// Run Lighthouse.
return Runner.run(connection, runOptions);
return Runner.run(connection, runOptions)
.then(result => {
lighthouseIsRunning = false;

return result;
})
.catch(err => {
lighthouseIsRunning = false;
throw err;
});
};

/**
Expand Down Expand Up @@ -213,7 +227,20 @@ window.loadSelectedAggregations = function() {
};

window.listenForStatus = function(callback) {
log.events.addListener('status', callback);
log.events.addListener('status', function(log) {
latestStatusLog = log;
callback(log);
});

// Show latest saved status log to give immediate feedback
// when reopening the popup message when lighthouse is running
if (lighthouseIsRunning && latestStatusLog) {
callback(latestStatusLog);
}
};

window.isRunning = function() {
return lighthouseIsRunning;
};

if (window.chrome && chrome.runtime) {
Expand Down
4 changes: 4 additions & 0 deletions lighthouse-extension/app/src/popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,10 @@ document.addEventListener('DOMContentLoaded', _ => {
return frag;
}

if (background.isRunning()) {
startSpinner();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not super familiar with the code here, but i'm assuming we're already stopping the spinner everywhere we need to? :)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes whenever runner fails promise then or catch than we do a stopSpinner. Not sure if Start and Stop spinner is still a good name for it. Maybe something a long the lines of showProcessPage or just showProcess?

}

background.listenForStatus(logstatus);
background.loadSelectedAggregations().then(aggregations => {
const frag = generateOptionsList(optionsList, aggregations);
Expand Down