If the main purpose is to apply for a patent, obviously, it is best to wait until the substantive examination is over and the Intellectual Property Office has not found a reason for rejection before publishing the paper.
In this way, there is no problem that publishing papers leads to leaks before patent publication.