cherry-picked 831e2ee8 & 41da74de from upstream
https://nheko.im/nheko-reborn/coeurl/-/commits/master