Skip to content

Commit

Permalink
Merge pull request #18 from Shopify/better_logging
Browse files Browse the repository at this point in the history
Improve Logging
  • Loading branch information
gurpreetg authored Apr 30, 2020
2 parents 03c1824 + f0f4ada commit cfa8e53
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
2 changes: 2 additions & 0 deletions src/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ function copyModelViewer(){
page.exposeFunction('logInfo', (message) => {
INFO(message)
});

page.on('console', msg => INFO("--- Console output: ", msg.text()));

let t3 = performance.now();
await loadGLBAndScreenshot(page, {
Expand Down
17 changes: 10 additions & 7 deletions src/load-glb-and-screenshot.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,33 @@
module.exports = async (page, {glbPath, outputPath, format, quality, timeout}) => {
return new Promise((resolve, reject) => {
return new Promise(async (resolve, reject) => {
page.exposeFunction('resolvePromise', resolve);
page.exposeFunction('rejectPromise', reject);
page.evaluate(async (browser_glbPath, browser_outputPath, browser_format, browser_quality, timeout) => {
var endTime = Number(new Date()) + timeout;
await page.evaluate(async (browser_glbPath, browser_outputPath, browser_format, browser_quality, timeout) => {
var startTime = Number(new Date());
var endTime = startTime + timeout;

const isTimedOut = function() {
const currentTime = Number(new Date())
const currentTime = Number(new Date());
if (currentTime < endTime) {
window.logInfo(`Waiting ${endTime - currentTime}ms for model to render...`);
}else{
window.logInfo(`--- Waited ${currentTime - startTime}ms for model to render. ${endTime - currentTime}ms left until timeout.`);
} else {
window.rejectPromise('Waited until timeout');
}
}

modelViewer = document.getElementById('snapshot-viewer');
timeoutSet = setInterval(isTimedOut, 1000);

modelViewer.addEventListener('model-visibility', function(){
const visible = event.detail.visible;
if(visible){
window.saveDataUrl(
modelViewer.toDataURL(browser_format, browser_quality),
browser_outputPath,
);
clearTimeout(timeoutSet);
window.resolvePromise();
}
setInterval(isTimedOut, 1000);
});
modelViewer.src = browser_glbPath;
}, glbPath, outputPath, format, quality, timeout);
Expand Down

0 comments on commit cfa8e53

Please sign in to comment.