get a relay that when supplied with power will latch for a second or so, then shut off. trigger this with your ignition wire.
use the sunroof trigger wire to activate the mirror retract action, as there is obviously something monitoring the off status of your ignition and shutting your sunroof in response.
make sure you use a diode to prevent your sunroof close button from closing your mirrors along with it.