2020-12-22 17:55:28 +00:00
|
|
|
const MacRunner = require('../../mac-runner')
|
|
|
|
const util = require('util')
|
|
|
|
const exec = util.promisify(require('child_process').exec)
|
|
|
|
const { compressPngImage } = require('../../utils')
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
run: async (outputPath) => {
|
|
|
|
console.log('> Recording TextEdit opens rich text files to true')
|
|
|
|
|
|
|
|
try {
|
2021-12-20 19:58:38 +00:00
|
|
|
const fileName = '/tmp/lorem.txt'
|
2020-12-22 17:55:28 +00:00
|
|
|
await manageFile(fileName, true)
|
2021-12-20 19:58:38 +00:00
|
|
|
await addContentToFile(fileName, '')
|
2020-12-22 17:55:28 +00:00
|
|
|
|
|
|
|
const runner = new MacRunner()
|
|
|
|
await runner
|
2021-12-20 19:58:38 +00:00
|
|
|
.setDefault('com.apple.TextEdit', 'RichText', '-bool false', '0')
|
2020-12-22 17:55:28 +00:00
|
|
|
.openApp('TextEdit', fileName)
|
2022-08-18 14:12:33 +00:00
|
|
|
.moveAndResizeApp('TextEdit', 0, 0, 740, 400)
|
2020-12-22 17:55:28 +00:00
|
|
|
.captureApp('TextEdit', `${outputPath}/false.png`)
|
2021-12-20 19:58:38 +00:00
|
|
|
.deleteDefault('com.apple.TextEdit', 'RichText')
|
|
|
|
.killApp('TextEdit')
|
2020-12-22 17:55:28 +00:00
|
|
|
.run()
|
|
|
|
|
2021-12-20 19:58:38 +00:00
|
|
|
await manageFile(fileName, false)
|
2020-12-22 17:55:28 +00:00
|
|
|
} catch (runnerError) {
|
|
|
|
throw new Error(runnerError)
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
await compressPngImage(`${outputPath}/false.png`, outputPath, 'false')
|
|
|
|
} catch (compressPngImageError) {
|
|
|
|
throw new Error(compressPngImageError)
|
|
|
|
}
|
|
|
|
|
|
|
|
return { filepath: `${outputPath}/false` }
|
2021-12-20 19:58:38 +00:00
|
|
|
},
|
2020-12-22 17:55:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
async function manageFile(filename, create) {
|
|
|
|
console.log(` Command: ${create ? 'create' : 'remove'} ${filename}`)
|
|
|
|
const { stderr: mngFile } = await exec(
|
2023-09-24 16:47:43 +00:00
|
|
|
`${create ? 'touch' : 'rm -f'} ${filename}`,
|
2020-12-22 17:55:28 +00:00
|
|
|
)
|
|
|
|
if (mngFile) {
|
2021-12-20 19:58:38 +00:00
|
|
|
console.error('An error occured while working with a file')
|
2020-12-22 17:55:28 +00:00
|
|
|
throw new Error(mngFile)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
async function addContentToFile(filename, content) {
|
|
|
|
console.log(` Command: add content to ${filename}`)
|
|
|
|
const { stderr: mngFile } = await exec(
|
|
|
|
`cat > ${filename} << EOF
|
|
|
|
${content}
|
2023-09-24 16:47:43 +00:00
|
|
|
EOF`,
|
2020-12-22 17:55:28 +00:00
|
|
|
)
|
|
|
|
if (mngFile) {
|
2021-12-20 19:58:38 +00:00
|
|
|
console.error('An error occured while working with a file')
|
2020-12-22 17:55:28 +00:00
|
|
|
throw new Error(mngFile)
|
|
|
|
}
|
|
|
|
}
|