2020-09-05 19:06:24 +00:00
|
|
|
const aperture = require('aperture')()
|
|
|
|
const delay = require('delay')
|
|
|
|
const robot = require('robotjs')
|
|
|
|
const util = require('util')
|
|
|
|
const exec = util.promisify(require('child_process').exec)
|
2020-11-27 12:45:16 +00:00
|
|
|
const {
|
|
|
|
makeAppActive,
|
|
|
|
moveAndResizeApp,
|
|
|
|
compressVideo,
|
|
|
|
} = require('../../utils')
|
2020-09-05 19:06:24 +00:00
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
run: async (outputPath) => {
|
|
|
|
console.log('> Recording dock mineffect with param set to scale')
|
|
|
|
|
2020-11-27 12:45:16 +00:00
|
|
|
const { stderr: setEnvError } = await exec(
|
|
|
|
'defaults write com.apple.dock mineffect -string scale && killall Dock'
|
|
|
|
)
|
2020-09-05 19:06:24 +00:00
|
|
|
if (setEnvError) {
|
2020-11-27 12:45:16 +00:00
|
|
|
console.error(
|
|
|
|
'An error occured while setting up the dock mineffect command'
|
|
|
|
)
|
2020-09-05 19:06:24 +00:00
|
|
|
logRollbackInfo()
|
|
|
|
throw new Error(setEnvError)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Preparation
|
|
|
|
await makeAppActive('System Preferences')
|
|
|
|
|
|
|
|
const { width, height } = robot.getScreenSize()
|
|
|
|
const pos1 = { x: width - 682, y: height - 695 }
|
|
|
|
const pos2 = { x: width - 110, y: height - 50 }
|
|
|
|
const recordWidth = 750
|
|
|
|
const recordHeight = 750
|
|
|
|
const cropArea = {
|
2020-11-27 12:45:16 +00:00
|
|
|
x: width - recordWidth,
|
|
|
|
y: 0,
|
|
|
|
width: recordWidth,
|
|
|
|
height: recordHeight,
|
2020-09-05 19:06:24 +00:00
|
|
|
}
|
2020-09-30 19:20:11 +00:00
|
|
|
const windowCropArea = {
|
2020-11-27 12:45:16 +00:00
|
|
|
x: cropArea.x + 21,
|
|
|
|
y: 156,
|
|
|
|
width: 668,
|
|
|
|
height: 568,
|
2020-09-30 19:20:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
await moveAndResizeApp('System Preferences', windowCropArea, height)
|
2020-09-05 19:06:24 +00:00
|
|
|
|
|
|
|
robot.moveMouse(pos1.x, pos1.y)
|
|
|
|
|
|
|
|
// Action!
|
|
|
|
await aperture.startRecording({ highlightClicks: true, cropArea })
|
|
|
|
|
|
|
|
robot.mouseClick()
|
|
|
|
await delay(100)
|
|
|
|
robot.moveMouseSmooth(pos2.x, pos2.y, 2)
|
|
|
|
await delay(400)
|
|
|
|
robot.mouseClick()
|
|
|
|
await delay(400)
|
|
|
|
robot.moveMouseSmooth(pos1.x, pos1.y, 2)
|
|
|
|
await delay(200)
|
|
|
|
|
|
|
|
const fp = await aperture.stopRecording()
|
|
|
|
// End recording
|
|
|
|
|
|
|
|
robot.keyTap('q', 'command')
|
|
|
|
|
|
|
|
try {
|
|
|
|
await compressVideo(fp, outputPath, 'scale')
|
|
|
|
} catch (compressVideoError) {
|
|
|
|
logRollbackInfo()
|
|
|
|
throw new Error(compressVideoError)
|
|
|
|
}
|
|
|
|
|
2020-11-27 12:45:16 +00:00
|
|
|
const { stderr: deleteEnvError } = await exec(
|
|
|
|
'defaults delete com.apple.dock mineffect && killall Dock'
|
|
|
|
)
|
2020-09-05 19:06:24 +00:00
|
|
|
if (deleteEnvError) {
|
2020-11-27 12:45:16 +00:00
|
|
|
console.error(
|
|
|
|
'An error occured while cleaning the dock mineffect environment'
|
|
|
|
)
|
2020-09-05 19:06:24 +00:00
|
|
|
logRollbackInfo()
|
|
|
|
throw new Error(deleteEnvError)
|
|
|
|
}
|
|
|
|
|
|
|
|
return { filepath: `${outputPath}/scale`, isVideo: true }
|
2020-11-27 12:45:16 +00:00
|
|
|
},
|
2020-09-05 19:06:24 +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-09-05 19:06:24 +00:00
|
|
|
console.info('defaults delete com.apple.dock mineffect && killall Dock')
|
|
|
|
}
|