const fs = require('fs');
const path = require('path');
const { execSync } = require('child_process');

const desktopPath = path.join(process.env.USERPROFILE, 'Desktop');
const targetHtml = path.join(__dirname, 'index.html');
const browserPath = 'C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe';

const vbsScript = path.join(__dirname, 'create_lnk.vbs');
const vbsContent = `
Set WshShell = CreateObject("WScript.Shell")
strDesktop = WshShell.SpecialFolders("Desktop")
Set oShortcut = WshShell.CreateShortcut(strDesktop & "\\Quran App.lnk")
oShortcut.TargetPath = "${browserPath.replace(/\\/g, '\\\\')}"
oShortcut.Arguments = "--app=""file:///${targetHtml.replace(/\\/g, '/') }"""
oShortcut.WorkingDirectory = "${__dirname.replace(/\\/g, '\\\\')}"
oShortcut.Description = "تطبيق القرآن الكريم والأذكار"
oShortcut.IconLocation = "shell32.dll,277"
oShortcut.Save
`;

fs.writeFileSync(vbsScript, vbsContent, 'utf8');
execSync(`cscript //nologo "${vbsScript}"`);
console.log('Shortcut updated with book icon!');
