2022-08-18 11:57:18 +00:00
|
|
|
const MacRunner = require('../../mac-runner')
|
|
|
|
const { compressPngImage } = require('../../utils')
|
2020-08-16 12:24:05 +00:00
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
run: async (outputPath) => {
|
|
|
|
console.log('> Recording dock show-recents with param set to true')
|
|
|
|
|
2022-08-18 11:57:18 +00:00
|
|
|
try {
|
|
|
|
const { screenWidth, screenHeight } = MacRunner.getScreenSize()
|
|
|
|
const dockHeight = MacRunner.getDockHeight()
|
|
|
|
|
|
|
|
const runner = new MacRunner()
|
|
|
|
await runner
|
|
|
|
.setDefault('com.apple.dock', 'show-recents', '-bool true', '1')
|
|
|
|
.killApp('Dock')
|
|
|
|
.wait(1000)
|
|
|
|
.captureScreenRect(
|
|
|
|
screenWidth - 740,
|
|
|
|
screenHeight - dockHeight,
|
|
|
|
740,
|
|
|
|
dockHeight,
|
|
|
|
`${outputPath}/true-tmp.png`
|
|
|
|
)
|
|
|
|
.deleteDefault('com.apple.dock', 'show-recents')
|
|
|
|
.killApp('Dock')
|
|
|
|
.run()
|
|
|
|
} catch (runnerError) {
|
2020-08-16 12:24:05 +00:00
|
|
|
logRollbackInfo()
|
2022-08-18 11:57:18 +00:00
|
|
|
throw new Error(runnerError)
|
2020-08-16 12:24:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
2022-08-18 11:57:18 +00:00
|
|
|
await compressPngImage(`${outputPath}/true-tmp.png`, outputPath, 'true')
|
2020-08-16 12:24:05 +00:00
|
|
|
} catch (compressPngImageError) {
|
2021-12-20 20:00:42 +00:00
|
|
|
logRollbackInfo()
|
2020-08-16 12:24:05 +00:00
|
|
|
throw new Error(compressPngImageError)
|
|
|
|
}
|
|
|
|
|
|
|
|
return { filepath: `${outputPath}/true` }
|
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')
|
|
|
|
}
|