2020-08-16 12:24:05 +00:00
|
|
|
const delay = require('delay')
|
|
|
|
const robot = require('robotjs')
|
|
|
|
const util = require('util')
|
|
|
|
const exec = util.promisify(require('child_process').exec)
|
|
|
|
const { captureImage, compressPngImage } = require('../../utils')
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
run: async (outputPath) => {
|
|
|
|
console.log('> Recording dock show-recents with param set to false')
|
|
|
|
|
2020-11-27 12:45:16 +00:00
|
|
|
const { stderr: setEnvError } = await exec(
|
|
|
|
'defaults write com.apple.dock show-recents -bool false && killall Dock'
|
|
|
|
)
|
2020-08-16 12:24:05 +00:00
|
|
|
if (setEnvError) {
|
2020-11-27 12:45:16 +00:00
|
|
|
console.error(
|
|
|
|
'An error occured while setting up the dock show-recents command'
|
|
|
|
)
|
2020-08-16 12:24:05 +00:00
|
|
|
logRollbackInfo()
|
|
|
|
throw new Error(setEnvError)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Preparation
|
|
|
|
await delay(3000)
|
|
|
|
const { width, height } = robot.getScreenSize()
|
|
|
|
const screenshot = `${outputPath}/dock-tmp.png`
|
|
|
|
|
|
|
|
// Screenshot
|
|
|
|
captureImage(width / 2, height - 80, width, 80).write(screenshot)
|
|
|
|
|
|
|
|
try {
|
|
|
|
await compressPngImage(screenshot, outputPath, 'false')
|
|
|
|
} catch (compressPngImageError) {
|
|
|
|
throw new Error(compressPngImageError)
|
|
|
|
}
|
|
|
|
|
|
|
|
return { filepath: `${outputPath}/false` }
|
2020-11-27 12:45:16 +00:00
|
|
|
},
|
2020-08-16 12:24:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function logRollbackInfo() {
|
2020-11-27 12:45:16 +00:00
|
|
|
console.info(
|
|
|
|
'Please manually run this command to make sure everything is properly reset:'
|
|
|
|
)
|
2020-08-16 12:24:05 +00:00
|
|
|
console.info('defaults delete com.apple.dock show-recents && killall Dock')
|
|
|
|
}
|