From 2103fdde8a44143c1b60e1840eef020cbf693766 Mon Sep 17 00:00:00 2001 From: Zarg <62082797+Zaarrg@users.noreply.github.com> Date: Sat, 18 Jan 2025 13:12:24 +0100 Subject: [PATCH] Fixed being stuck on splash screen - Fixed being stuck on splash screen by adding retry attempts and running initShellCom on DomContentLoad as well. - Fixed installer installing into stremio-4 if stremio 4 is installed. --- src/main.cpp | 70 +++++++++++++++++-- utils/windows/installer/windows-installer.nsi | 19 ++++- 2 files changed, 80 insertions(+), 9 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 9489720..aeca095 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -155,7 +155,8 @@ static ULONG_PTR g_gdiplusToken = 0; // App Ready and Event Queue #define WM_NOTIFY_FLUSH (WM_USER + 101) static std::vector g_pendingMessages; -static bool g_isAppReady = false; +static std::atomic g_isAppReady = false; +static std::atomic g_waitStarted(false); // Updater static std::atomic_bool g_updaterRunning = false; @@ -834,7 +835,7 @@ static void AppStart() j["type"] ="shellVersion"; j["value"] =APP_VERSION; SendToJS(j); - + HideSplash(); for(const auto& pendingMsg : g_pendingMessages) { SendToJS(pendingMsg); } @@ -1699,17 +1700,60 @@ LONG WINAPI ExceptionFilter(EXCEPTION_POINTERS* ExceptionInfo) { // WebView2 // ----------------------------------------------------------------------------- +static void WaitAndRefreshIfNeeded() { + std::thread([](){ + int attempts = 15; // Number of total attempts + int waitTime = 1; // Initial wait time in seconds + + std::this_thread::sleep_for(std::chrono::seconds(waitTime)); + std::cout << "[WEBVIEW]: Checking Web Page state..." << std::endl; + if(!g_isAppReady) { + refreshWeb(true); + } else { + std::cout << "[WEBVIEW]: Web Page ready!" << std::endl; + return; + } + + waitTime++; + + for(int i = 1; i < attempts; ++i) { + std::this_thread::sleep_for(std::chrono::seconds(waitTime)); + std::cout << "[WEBVIEW]: Checking Web Page state..." << std::endl; + if (g_isAppReady) { + std::cout << "[WEBVIEW]: Web Page ready!" << std::endl; + return; + } + std::cout << "[WEBVIEW]: Web Page not ready... Refreshing..." << std::endl; + refreshWeb(true); + waitTime++; + } + + if(!g_isAppReady) { + AppendToCrashLog(L"[WEBVIEW]: Web page could not be loaded after multiple attempts."); + MessageBoxW( + nullptr, + L"Web page could not be loaded after multiple attempts. Make sure the Web UI is reachable. Check Github for more details.", + L"WebView2 Page load fail", + MB_ICONERROR | MB_OK + ); + } + }).detach(); +} + static void SetupWebMessageHandler() { if(!g_webview)return; EventRegistrationToken navToken; g_webview->add_NavigationCompleted( Callback( - [](ICoreWebView2* snd, ICoreWebView2NavigationCompletedEventArgs* args)->HRESULT + [](ICoreWebView2* sender, ICoreWebView2NavigationCompletedEventArgs* args)->HRESULT { - snd->ExecuteScript(L"initShellComm();",nullptr); - if (g_hSplash) { - HideSplash(); + std::cout<<"[WEBVIEW]: Navigation Complete\n"; + if (!g_isAppReady) { + sender->ExecuteScript(L"initShellComm();", nullptr); + } + if (g_hSplash && !g_waitStarted.exchange(true)) { + WaitAndRefreshIfNeeded(); } return S_OK; } @@ -1717,6 +1761,20 @@ static void SetupWebMessageHandler() &navToken ); + EventRegistrationToken domToken; + g_webview->add_DOMContentLoaded( + Callback( + [](ICoreWebView2* sender, IUnknown* args) -> HRESULT { + std::cout<<"[WEBVIEW]: DOM content loaded\n"; + if (!g_isAppReady) { + sender->ExecuteScript(L"initShellComm();", nullptr); + } + return S_OK; + } + ).Get(), + &domToken + ); + EventRegistrationToken contextMenuToken; g_webview->add_ContextMenuRequested( Callback( diff --git a/utils/windows/installer/windows-installer.nsi b/utils/windows/installer/windows-installer.nsi index 01c2646..88d522d 100644 --- a/utils/windows/installer/windows-installer.nsi +++ b/utils/windows/installer/windows-installer.nsi @@ -373,10 +373,24 @@ FunctionEnd ; Install code ; ; ------------------- ; Function .onInit ; check for previous version + ; Read the previous installation directory from registry ReadRegStr $0 HKCU "${UNINSTALL_KEY}" "InstallString" - StrCmp $0 "" done - StrCpy $INSTDIR $0 + ; If registry value is empty, skip version check + StrCmp $0 "" done + + ; Expected installation directory for current major version (Stremio-5) + StrCpy $R1 "$LOCALAPPDATA\Programs\LNV\Stremio-5" + + ; Check if the registry path matches the expected directory + StrCmp $0 $R1 usePrev 0 + ; If it doesn't match, likely an old version, so do not use $0 + Goto done + + usePrev: + ; If registry path matches the expected path, use it + StrCpy $INSTDIR $0 +done: ${GetParameters} $Parameters ClearErrors ${GetOptions} $Parameters "/addon" $R1 @@ -384,7 +398,6 @@ Function .onInit ; check for previous version FileOpen $0 "$INSTDIR\addons.txt" w FileWrite $0 "$R1" FileClose $0 -done: FunctionEnd Section ; App Files