You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
🛠 Feature Request: Auto-open PDFs after download for WhatsApp & other services
📌 Background
Ferdium automatically downloads PDFs, but it does not open them directly.
In services like WhatsApp, it would be very convenient if PDFs would immediately open after download, without requiring the user to manually navigate to the file.
With the help of @chatgpt, I have developed a script that does exactly that! 🚀
🔧 How does the script work?
✅ Automatically detects when a PDF file is downloaded
✅ Waits until the file is fully saved before opening it
✅ Opens the PDF automatically with the default PDF viewer (e.g., Atril)
✅ Prevents duplicate or premature openings
✅ Dynamically loads the download folder from settings.json, making it flexible for all users
📝 Full script for user.js:
// Module importsconst{ execFile }=require("child_process");constfs=require("fs");constpath=require("path");// Read the download path from Ferdium settingsconstsettingsPath=path.join(process.env.HOME,".config/Ferdium/config/settings.json");// Default download folder (fallback)letDOWNLOAD_FOLDER=path.join(process.env.HOME,"Downloads");// Check if settings.json exists and contains a download pathif(fs.existsSync(settingsPath)){try{constsettings=JSON.parse(fs.readFileSync(settingsPath,"utf-8"));if(settings.downloadFolderPath){DOWNLOAD_FOLDER=settings.downloadFolderPath;}}catch(err){console.error(`❌ Error reading settings file: ${err.message}`);}}letlastOpenedFile="";// Variable to store the last opened file// Watch for new downloads and open PDFs, but only ONCEfs.watch(DOWNLOAD_FOLDER,(eventType,filename)=>{if(eventType==="rename"&&filename.toLowerCase().endsWith(".pdf")){constfilePath=path.join(DOWNLOAD_FOLDER,filename);// Skip if the file has already been openedif(filePath===lastOpenedFile){console.log(`⏳ PDF was already opened, skipping: ${filePath}`);return;}// Wait until the file is completely downloadedletretries=20;// Max wait time: 10 seconds (20 x 500ms)constcheckFileReady=setInterval(()=>{if(fs.existsSync(filePath)&&fs.statSync(filePath).size>0){clearInterval(checkFileReady);// Stop waitinglastOpenedFile=filePath;// Mark the file as openedconsole.log(`📂 PDF downloaded: ${filePath}`);execFile("atril",[filePath],(error,stdout,stderr)=>{if(error){console.error(`❌ Error opening PDF: ${error.message}`);return;}console.log(`📖 PDF successfully opened with Atril: ${filePath}`);});}elseif(retries<=0){clearInterval(checkFileReady);console.log(`⚠️ File was not fully downloaded after 10 seconds: ${filePath}`);}retries--;},500);// Check every 500ms}});
The text was updated successfully, but these errors were encountered:
This script is currently optimized for Linux and the Atril PDF viewer.
If this feature is implemented officially, it might be useful to make the PDF viewer configurable or detect the default PDF application dynamically.
🛠 Feature Request: Auto-open PDFs after download for WhatsApp & other services
📌 Background
Ferdium automatically downloads PDFs, but it does not open them directly.
In services like WhatsApp, it would be very convenient if PDFs would immediately open after download, without requiring the user to manually navigate to the file.
With the help of @chatgpt, I have developed a script that does exactly that! 🚀
🔧 How does the script work?
✅ Automatically detects when a PDF file is downloaded
✅ Waits until the file is fully saved before opening it
✅ Opens the PDF automatically with the default PDF viewer (e.g., Atril)
✅ Prevents duplicate or premature openings
✅ Dynamically loads the download folder from
settings.json
, making it flexible for all users📝 Full script for
user.js
:The text was updated successfully, but these errors were encountered: