♻️ Use MacRunner

This commit is contained in:
Yann Bertrand 2022-08-18 16:13:33 +02:00
parent 1c12043fb2
commit fb8bbd353c
6 changed files with 78 additions and 216 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 38 KiB

After

Width:  |  Height:  |  Size: 32 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 38 KiB

After

Width:  |  Height:  |  Size: 32 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 38 KiB

After

Width:  |  Height:  |  Size: 32 KiB

View file

@ -1,85 +1,39 @@
const delay = require('delay')
const robot = require('robotjs')
const util = require('util')
const exec = util.promisify(require('child_process').exec)
const {
makeAppActive,
moveAndResizeApp,
captureImage,
compressPngImage,
} = require('../../utils')
const MacRunner = require('../../mac-runner')
const { compressPngImage } = require('../../utils')
module.exports = {
run: async (outputPath) => {
console.log(
'> Recording finder NSTableViewDefaultSizeMode with param set to 1'
)
const { stderr: setEnvError } = await exec(
'defaults write NSGlobalDomain NSTableViewDefaultSizeMode -int 1 && killall Finder'
)
if (setEnvError) {
console.error(
'An error occured while setting up the finder NSTableViewDefaultSizeMode command'
)
logRollbackInfo()
throw new Error(setEnvError)
}
await delay(1000)
// Preparation
await makeAppActive('Finder')
robot.keyTap('g', ['command', 'shift'])
await delay(100)
robot.keyTap('right')
robot.keyTap('a', 'command')
robot.keyTap('backspace')
robot.typeString('~/macos-defaults/')
await delay(1000)
robot.keyTap('enter')
await delay(500)
const { width, height } = robot.getScreenSize()
const recordWidth = 720
const recordHeight = 404
const cropArea = {
x: width / 2 - recordWidth / 2,
y: 345,
width: recordWidth,
height: recordHeight,
}
await moveAndResizeApp('Finder', cropArea, height)
await delay(1000)
const screenshot = `${outputPath}/1.png`
// Screenshot
captureImage(
cropArea.x,
height - recordHeight - cropArea.y,
cropArea.width,
cropArea.height
).write(screenshot)
console.log('> Recording finder NSTableViewDefaultSizeMode to 1')
try {
await compressPngImage(screenshot, outputPath, '1')
const runner = new MacRunner()
await runner
.setDefault(
'NSGlobalDomain',
'NSTableViewDefaultSizeMode',
'-int 1',
'1'
)
.killApp('Finder')
.openApp('Finder', '~/macos-defaults')
.activateApp('Finder')
.moveAndResizeApp('Finder', 0, 0, 740, 400)
.captureApp('Finder', `${outputPath}/1.png`)
.deleteDefault('NSGlobalDomain', 'NSTableViewDefaultSizeMode')
.killApp('Finder')
.run()
} catch (runnerError) {
logRollbackInfo()
throw new Error(runnerError)
}
try {
await compressPngImage(`${outputPath}/1.png`, outputPath, '1')
} catch (compressPngImageError) {
logRollbackInfo()
throw new Error(compressPngImageError)
}
const { stderr: deleteEnvError } = await exec(
'defaults delete NSGlobalDomain NSTableViewDefaultSizeMode && killall Finder'
)
if (deleteEnvError) {
console.error(
'An error occured while cleaning the finder NSTableViewDefaultSizeMode environment'
)
logRollbackInfo()
throw new Error(deleteEnvError)
}
await delay(1000)
return { filepath: `${outputPath}/1` }
},
}

View file

@ -1,85 +1,39 @@
const delay = require('delay')
const robot = require('robotjs')
const util = require('util')
const exec = util.promisify(require('child_process').exec)
const {
makeAppActive,
moveAndResizeApp,
captureImage,
compressPngImage,
} = require('../../utils')
const MacRunner = require('../../mac-runner')
const { compressPngImage } = require('../../utils')
module.exports = {
run: async (outputPath) => {
console.log(
'> Recording finder NSTableViewDefaultSizeMode with param set to 2'
)
const { stderr: setEnvError } = await exec(
'defaults write NSGlobalDomain NSTableViewDefaultSizeMode -int 2 && killall Finder'
)
if (setEnvError) {
console.error(
'An error occured while setting up the finder NSTableViewDefaultSizeMode command'
)
logRollbackInfo()
throw new Error(setEnvError)
}
await delay(1000)
// Preparation
await makeAppActive('Finder')
robot.keyTap('g', ['command', 'shift'])
await delay(100)
robot.keyTap('right')
robot.keyTap('a', 'command')
robot.keyTap('backspace')
robot.typeString('~/macos-defaults/')
await delay(1000)
robot.keyTap('enter')
await delay(500)
const { width, height } = robot.getScreenSize()
const recordWidth = 720
const recordHeight = 404
const cropArea = {
x: width / 2 - recordWidth / 2,
y: 345,
width: recordWidth,
height: recordHeight,
}
await moveAndResizeApp('Finder', cropArea, height)
await delay(1000)
const screenshot = `${outputPath}/2.png`
// Screenshot
captureImage(
cropArea.x,
height - recordHeight - cropArea.y,
cropArea.width,
cropArea.height
).write(screenshot)
console.log('> Recording finder NSTableViewDefaultSizeMode to 2')
try {
await compressPngImage(screenshot, outputPath, '2')
const runner = new MacRunner()
await runner
.setDefault(
'NSGlobalDomain',
'NSTableViewDefaultSizeMode',
'-int 2',
'2'
)
.killApp('Finder')
.openApp('Finder', '~/macos-defaults')
.activateApp('Finder')
.moveAndResizeApp('Finder', 0, 0, 740, 400)
.captureApp('Finder', `${outputPath}/2.png`)
.deleteDefault('NSGlobalDomain', 'NSTableViewDefaultSizeMode')
.killApp('Finder')
.run()
} catch (runnerError) {
logRollbackInfo()
throw new Error(runnerError)
}
try {
await compressPngImage(`${outputPath}/2.png`, outputPath, '2')
} catch (compressPngImageError) {
logRollbackInfo()
throw new Error(compressPngImageError)
}
const { stderr: deleteEnvError } = await exec(
'defaults delete NSGlobalDomain NSTableViewDefaultSizeMode && killall Finder'
)
if (deleteEnvError) {
console.error(
'An error occured while cleaning the finder NSTableViewDefaultSizeMode environment'
)
logRollbackInfo()
throw new Error(deleteEnvError)
}
await delay(1000)
return { filepath: `${outputPath}/2` }
},
}

View file

@ -1,85 +1,39 @@
const delay = require('delay')
const robot = require('robotjs')
const util = require('util')
const exec = util.promisify(require('child_process').exec)
const {
makeAppActive,
moveAndResizeApp,
captureImage,
compressPngImage,
} = require('../../utils')
const MacRunner = require('../../mac-runner')
const { compressPngImage } = require('../../utils')
module.exports = {
run: async (outputPath) => {
console.log(
'> Recording finder NSTableViewDefaultSizeMode with param set to 3'
)
const { stderr: setEnvError } = await exec(
'defaults write NSGlobalDomain NSTableViewDefaultSizeMode -int 3 && killall Finder'
)
if (setEnvError) {
console.error(
'An error occured while setting up the finder NSTableViewDefaultSizeMode command'
)
logRollbackInfo()
throw new Error(setEnvError)
}
await delay(1000)
// Preparation
await makeAppActive('Finder')
robot.keyTap('g', ['command', 'shift'])
await delay(100)
robot.keyTap('right')
robot.keyTap('a', 'command')
robot.keyTap('backspace')
robot.typeString('~/macos-defaults/')
await delay(1000)
robot.keyTap('enter')
await delay(500)
const { width, height } = robot.getScreenSize()
const recordWidth = 720
const recordHeight = 404
const cropArea = {
x: width / 2 - recordWidth / 2,
y: 345,
width: recordWidth,
height: recordHeight,
}
await moveAndResizeApp('Finder', cropArea, height)
await delay(1000)
const screenshot = `${outputPath}/3.png`
// Screenshot
captureImage(
cropArea.x,
height - recordHeight - cropArea.y,
cropArea.width,
cropArea.height
).write(screenshot)
console.log('> Recording finder NSTableViewDefaultSizeMode to 3')
try {
await compressPngImage(screenshot, outputPath, '3')
const runner = new MacRunner()
await runner
.setDefault(
'NSGlobalDomain',
'NSTableViewDefaultSizeMode',
'-int 3',
'3'
)
.killApp('Finder')
.openApp('Finder', '~/macos-defaults')
.activateApp('Finder')
.moveAndResizeApp('Finder', 0, 0, 740, 400)
.captureApp('Finder', `${outputPath}/3.png`)
.deleteDefault('NSGlobalDomain', 'NSTableViewDefaultSizeMode')
.killApp('Finder')
.run()
} catch (runnerError) {
logRollbackInfo()
throw new Error(runnerError)
}
try {
await compressPngImage(`${outputPath}/3.png`, outputPath, '3')
} catch (compressPngImageError) {
logRollbackInfo()
throw new Error(compressPngImageError)
}
const { stderr: deleteEnvError } = await exec(
'defaults delete NSGlobalDomain NSTableViewDefaultSizeMode && killall Finder'
)
if (deleteEnvError) {
console.error(
'An error occured while cleaning the finder NSTableViewDefaultSizeMode environment'
)
logRollbackInfo()
throw new Error(deleteEnvError)
}
await delay(1000)
return { filepath: `${outputPath}/3` }
},
}