How to track exporting scene as FBX and closing current scene and Blender itself

Hello, I’m writing a plugin that renames textures on the user’s disk before exporting - it works fine, but I need to revert everything back after exporting to FBX. I can’t find anywhere a way to call my function after a successful FBX export (when the user clicked File->Export->FBX (.fbx)->Export FBX) - how can I track/detec this?

And also for security it would be great if the user accidentally closes Blender or close/switch current scene to automatically rename the textures back, but I also didn’t find any operators in the API for this.

There’s no hooks to export, only monkey patching or creating your own export operator. See Rename objects before FBX export

See Hook Preferences > Addons > MYADDON > Remove - #6 by Duthomhas regarding possible Blender exit callbacks.

Hi.

Hello, I’m writing a plugin that renames textures on the user’s disk before exporting

No, don’t do that.

If you must have specific names for the textures, create copies of the original files and delete the copies once you are done. Use the user’s temporary directory if necessary to make the copies and build the FBX file.
⟶ The temporary directory is located at bpy.app.tempdir.

Once your script finishes it can delete the temporary files it created.

tl;dr:
Don’t modify user’s input data. The user has provided you access to that data with the expectation that it is input to your script. Don’t break the user’s expectation there — user has not authorized you to modify that data!