@@ -10,6 +10,11 @@ namespace {
1010
1111constexpr const wchar_t kSingleInstanceMutexName [] =
1212 L" Local\\ org.getlantern.lantern.single-instance" ;
13+ constexpr const wchar_t kSingleInstanceReadyEventName [] =
14+ L" Local\\ org.getlantern.lantern.window-ready" ;
15+ constexpr DWORD kWindowReadyTimeoutMs = 5000 ;
16+ constexpr DWORD kActivationRetryTimeoutMs = 1000 ;
17+ constexpr DWORD kActivationRetryIntervalMs = 100 ;
1318
1419} // namespace
1520
@@ -21,10 +26,14 @@ int APIENTRY wWinMain(_In_ HINSTANCE instance, _In_opt_ HINSTANCE prev,
2126 CreateAndAttachConsole ();
2227 }
2328
29+ SingleInstanceReadyEvent window_ready (kSingleInstanceReadyEventName );
2430 SingleInstanceLock single_instance (kSingleInstanceMutexName );
2531 if (!single_instance.IsPrimaryInstance ()) {
26- ActivateExistingLanternWindow ();
27- return EXIT_SUCCESS ;
32+ window_ready.Wait (kWindowReadyTimeoutMs );
33+ return ActivateExistingLanternWindowWithRetry (kActivationRetryTimeoutMs ,
34+ kActivationRetryIntervalMs )
35+ ? EXIT_SUCCESS
36+ : EXIT_FAILURE ;
2837 }
2938 if (ActivateExistingLanternWindow ()) {
3039 return EXIT_SUCCESS ;
@@ -48,6 +57,7 @@ int APIENTRY wWinMain(_In_ HINSTANCE instance, _In_opt_ HINSTANCE prev,
4857 return EXIT_FAILURE ;
4958 }
5059 window.SetQuitOnClose (true );
60+ window_ready.Signal ();
5161
5262 ::MSG msg;
5363 while (::GetMessage (&msg, nullptr , 0 , 0 )) {
0 commit comments