diff --git a/src/core/globals.cpp b/src/core/globals.cpp index cc82499..8c54d3f 100644 --- a/src/core/globals.cpp +++ b/src/core/globals.cpp @@ -66,8 +66,8 @@ int g_pulseDirection = -1; ULONG_PTR g_gdiplusToken = 0; // Pending messages -std::vector g_inboundMessages; std::vector g_outboundMessages; +std::wstring g_launchProtocol; std::atomic g_isAppReady = false; std::atomic g_waitStarted(false); diff --git a/src/core/globals.h b/src/core/globals.h index b856960..f6a396d 100644 --- a/src/core/globals.h +++ b/src/core/globals.h @@ -119,8 +119,8 @@ extern ULONG_PTR g_gdiplusToken; // App Ready and Event Queue #define WM_NOTIFY_FLUSH (WM_USER + 101) -extern std::vector g_inboundMessages; extern std::vector g_outboundMessages; +extern std::wstring g_launchProtocol; extern std::atomic g_isAppReady; extern std::atomic g_waitStarted; diff --git a/src/main.cpp b/src/main.cpp index e208696..5714b01 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -61,9 +61,11 @@ int main(int argc, char* argv[]) } // single instance - if(!CheckSingleInstance(argc, argv)){ + std::wstring launchProtocol; + if(!CheckSingleInstance(argc, argv, launchProtocol)){ return 0; } + g_launchProtocol = launchProtocol; // check stremio-runtime duplicates std::vector processesToCheck={L"stremio.exe", L"stremio-runtime.exe"}; diff --git a/src/node/server.cpp b/src/node/server.cpp index 035bafa..12ada12 100644 --- a/src/node/server.cpp +++ b/src/node/server.cpp @@ -24,8 +24,9 @@ static void NodeOutputThreadProc() bool StartNodeServer() { - std::wstring exePath = L"stremio-runtime.exe"; - std::wstring scriptPath = L"server.js"; + std::wstring exeDir = GetExeDirectory(); + std::wstring exePath = exeDir + L"\\stremio-runtime.exe"; + std::wstring scriptPath = exeDir + L"\\server.js"; if(!FileExists(exePath)){ AppendToCrashLog(L"[NODE]: Missing stremio-runtime.exe"); return false; diff --git a/src/ui/mainwindow.cpp b/src/ui/mainwindow.cpp index fb5838a..abe905b 100644 --- a/src/ui/mainwindow.cpp +++ b/src/ui/mainwindow.cpp @@ -40,7 +40,7 @@ bool FocusExistingInstance(const std::wstring &protocolArg) return false; } -bool CheckSingleInstance(int argc, char* argv[]) +bool CheckSingleInstance(int argc, char* argv[], std::wstring &outProtocolArg) { g_hMutex = CreateMutexW(nullptr, FALSE, L"SingleInstanceMtx_StremioWebShell"); if(!g_hMutex){ @@ -65,6 +65,7 @@ bool CheckSingleInstance(int argc, char* argv[]) FocusExistingInstance(protocolArg); return false; } + outProtocolArg = protocolArg; return true; } @@ -204,7 +205,7 @@ void HandleEvent(const std::string &ev, std::vector &args) refreshWeb(args.size()>0 && args[0]=="all"); } else if(ev=="app-error"){ if(!args.empty() && args.size()>0 && args[0] == "shellComm"){ - if(g_hSplash && !g_waitStarted.exchange(true)){ + if(!g_isAppReady && !g_waitStarted.exchange(true)){ WaitAndRefreshIfNeeded(); } } @@ -329,6 +330,15 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) SendToJS(pendingMsg["type"], pendingMsg); } g_outboundMessages.clear(); + + if(!g_launchProtocol.empty()) { + COPYDATASTRUCT cds; + cds.dwData = 1; + cds.cbData = static_cast((g_launchProtocol.size()+1) * sizeof(wchar_t)); + cds.lpData = (PVOID)g_launchProtocol.c_str(); + SendMessage(g_hWnd, WM_COPYDATA, (WPARAM)g_hWnd, (LPARAM)&cds); + g_launchProtocol.clear(); + } } break; } @@ -430,6 +440,12 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) j["path"] = utf8FilePath; SendToJS("OpenFile", j); } + } else if (receivedUrl.rfind(L"stremio://detail", 0) == 0) { + std::string utf8Url = WStringToUtf8(receivedUrl); + json j; + j["type"] = "ReplaceLocation"; + j["path"] = utf8Url; + SendToJS("ReplaceLocation", j); } else if (receivedUrl.rfind(L"stremio://", 0) == 0) { // Handle stremio:// protocol std::string utf8Url = WStringToUtf8(receivedUrl); diff --git a/src/ui/mainwindow.h b/src/ui/mainwindow.h index a131f3a..f2cb419 100644 --- a/src/ui/mainwindow.h +++ b/src/ui/mainwindow.h @@ -8,7 +8,7 @@ LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); // Helper for single-instance -bool CheckSingleInstance(int argc, char* argv[]); +bool CheckSingleInstance(int argc, char* argv[], std::wstring &outProtocolArg); bool FocusExistingInstance(const std::wstring& protocolArg); // Our "ToggleFullScreen" logic diff --git a/src/webview/webview.cpp b/src/webview/webview.cpp index 277c31a..d2cc0d0 100644 --- a/src/webview/webview.cpp +++ b/src/webview/webview.cpp @@ -33,10 +33,16 @@ try { try { initShellComm(); } catch (e) { - const errorMessage = { - event: "app-error", - reason: "shellComm" - }; + const errorMessage = { + type: 6, + object: "transport", + method: "handleInboundJSON", + id: 888, + args: [ + "app-error", + [ "shellComm" ] + ] + }; window.chrome.webview.postMessage(JSON.stringify(errorMessage)); } };