UniWebViewAuthenticationSessionEditorCleanup.cs 989 B

12345678910111213141516171819202122232425262728
  1. #if UNITY_EDITOR_OSX
  2. using System;
  3. using System.Runtime.InteropServices;
  4. using UnityEditor;
  5. [InitializeOnLoad]
  6. internal static class UniWebViewAuthenticationSessionEditorCleanup {
  7. static UniWebViewAuthenticationSessionEditorCleanup() {
  8. EditorApplication.playModeStateChanged += InvalidateNativeSessionsOnPlayModeExit;
  9. }
  10. private static void InvalidateNativeSessionsOnPlayModeExit(PlayModeStateChange state) {
  11. if (state != PlayModeStateChange.ExitingPlayMode) {
  12. return;
  13. }
  14. try {
  15. uv_authenticationInvalidateAll();
  16. } catch (Exception e) when (e is DllNotFoundException || e is EntryPointNotFoundException) {
  17. // The macOS bundle is missing from the project, or an older bundle without this
  18. // entry point is still loaded in the editor. There is nothing to clean up then.
  19. }
  20. }
  21. [DllImport("UniWebView")]
  22. private static extern void uv_authenticationInvalidateAll();
  23. }
  24. #endif