const path = require('path')
const { rcedit } = require('rcedit')

exports.default = async function afterPack(context) {
  if (context.electronPlatformName !== 'win32') return

  const exePath = path.join(
    context.appOutDir,
    `${context.packager.appInfo.productFilename}.exe`
  )
  const iconPath = path.resolve(__dirname, '../resources/icon.ico')

  console.log(`[afterPack] Setting icon for ${exePath}`)

  await rcedit(exePath, {
    icon: iconPath,
    'version-string': {
      ProductName: context.packager.appInfo.productName,
      FileDescription: context.packager.appInfo.productName,
      CompanyName: context.packager.appInfo.companyName || '',
    },
  })

  console.log('[afterPack] Icon embedded successfully')
}
