atom / markdown-preview

📝 Markdown preview in Atom
MIT License
1.23k stars 358 forks source link

Use atom.packages.hasActivatedInitialPackages #515

Closed 50Wliu closed 6 years ago

50Wliu commented 6 years ago

Requirements

Description of the Change

I assume that the point of the atom.workspace? check was to try to wait until Atom was done loading before checking for text editors. However, the workspace may be loaded before text editors are deserialized. Therefore I rely on atom.packages.hasActivatedInitialPackages, which is the same thing that would happen if atom.workspace did not exist. This means that when reloading or closing/reopening Atom with a Markdown Preview open, the preview will continue to live update as it can find its existing editor. Before, it would become orphaned and rely on the backup file system events instead (due to atom.workspace.getTextEditors() being an empty array on startup).

Alternate Designs

Relying on package activation seems a bit weird. However, there doesn't seem to be a way to get whether the workspace has fully loaded or not, so this seems like a good alternative.

Benefits

Less cases of unnecessary preview orphanage.

Possible Drawbacks

None.

Applicable Issues

N/A

I wasn't able to test for this because I had to globally spy on atom.packages.hasActivatedInitialPackages, and also because the only way to truly test this would be to simulate an entire Atom restart.