macos-defaults/record/dock
Yann Bertrand 0d10e1513e 🚨 Run prettier v3
2023-08-18 16:33:51 +02:00
..
autohide-delay 🚨 Run prettier v3 2023-08-18 16:33:51 +02:00
autohide-time-modifier 🚨 Run prettier v3 2023-08-18 16:33:51 +02:00
mineffect 🚨 Run prettier v3 2023-08-18 16:33:51 +02:00
orientation 🚨 Run prettier v3 2023-08-18 16:33:51 +02:00
show-recents 🚨 Run prettier v3 2023-08-18 16:33:51 +02:00
tilesize 🚨 Run prettier v3 2023-08-18 16:33:51 +02:00
readme.js 🚨 Run prettier v3 2023-08-18 16:33:51 +02:00

const MacRunner = require('../mac-runner')
const { compressPngImage } = require('../utils')

module.exports = {
  run: async (outputPath) => {
    console.log('> Recording dock readme screenshot')

    try {
      const { screenWidth, screenHeight } = MacRunner.getScreenSize()
      const dockHeight = MacRunner.getDockHeight()

      const runner = new MacRunner()
      await runner
        .captureScreenRect(
          0,
          screenHeight - dockHeight,
          screenWidth,
          dockHeight,
          `${outputPath}/dock-tmp.png`,
        )
        .run()
    } catch (runnerError) {
      throw new Error(runnerError)
    }

    try {
      await compressPngImage(`${outputPath}/dock-tmp.png`, outputPath, 'dock')
    } catch (compressPngImageError) {
      throw new Error(compressPngImageError)
    }

    return { filepath: `${outputPath}/dock` }
  },
}