-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ea3dc3e
commit 2c3cf46
Showing
3 changed files
with
33 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,50 @@ | ||
import puppeteer from 'puppeteer' | ||
import readline from 'readline' | ||
|
||
import logger from './utils/logger.js' | ||
import startChecking from './check.js' | ||
import { | ||
HIDE_BROWSER, BROWSER_SIZE, | ||
} from '../privateConfig.js' | ||
|
||
// TODO: This isn't working as intended. I'm not sure it's even being invoked. | ||
const shutDown = async (browser) => { | ||
logger.log('🏁 Closing browser...') | ||
await browser.close() | ||
process.exit(0) | ||
let browser | ||
|
||
// TODO: On Windows, there is a long pause between the browser closing and "Closing browser..." | ||
// getting logged. Somehow CTRL+C stops Puppeteer browser before this function runs. | ||
// And why is there such a long pause? | ||
const shutDown = async (code = 0) => { | ||
if (browser) { | ||
logger.log('🏁 Closing browser...') | ||
await browser.close() // TODO: Node doesn't seem to wait for this. | ||
console.log('why doesn\'t this show up?') | ||
} | ||
process.exit(code) | ||
} | ||
|
||
process.on('SIGINT', shutDown) | ||
process.on('SIGQUIT', shutDown) | ||
process.on('SIGTERM', shutDown) | ||
|
||
process.on('exit', () => { | ||
// TODO: Inspect the `code` parameter and log accordingly | ||
logger.log('👋 Shutdown completed! Bye bye!') | ||
}) | ||
|
||
// Here's where the app begins 🚀 | ||
(async () => { | ||
const start = async () => { | ||
logger.log('🚦 Launching browser...') | ||
const { height, width } = BROWSER_SIZE | ||
const browser = await puppeteer.launch({ | ||
browser = await puppeteer.launch({ | ||
headless: HIDE_BROWSER, | ||
defaultViewport: { width, height }, | ||
args: [`--window-size=${width},${height}`] | ||
}) | ||
|
||
process.on('SIGINT', () => shutDown(browser)) | ||
process.on('SIGQUIT', () => shutDown(browser)) | ||
process.on('SIGTERM', () => shutDown(browser)) | ||
|
||
// TODO: Inspect the `code` parameter and log accordingly | ||
process.on('exit', () => { | ||
logger.log('👋 Shutdown completed! Bye bye!') | ||
}); | ||
|
||
try { | ||
startChecking(browser) | ||
} catch (err) { | ||
logger.error('💥 Loop failure:', err) | ||
await shutDown() | ||
process.exit(1) | ||
logger.error('💥 App failure:', err) | ||
await shutDown(1) | ||
} | ||
})(); | ||
} | ||
|
||
start() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
const wait = duration => new Promise(resolve => setTimeout(resolve, duration)) | ||
|
||
export default wait |