I have found this power latch circuit online and I'm complete noob when it comes to electronics, I'm good at programming, since I had a lot of experiences with HTML and different Javascript frameworks in the past. So I'm wondering what i should change here in order to control my ESP32 like this:
SPST button switch that will control the power of the device
When this button is in ON position, it should power on my device
When this button goes to OFF position it should trigger some code before shutting itself off
That isn't exactly a power latch description. Check the circuit by the same name at https://electronoobs.com/eng_circuitos_tut61.php. Bonus tip, change the switch to a MOSFET and gate it with a genuine RTC.