More refactor fixes and stremio://detail support

- Fixed wrong errorMessage format being send
- Fixed when stremio:// protocol is used and the app is starting because of that not working
- Fixed node server paths sometimes being wrong
- Added support for stremio://detail as protocol
This commit is contained in:
Zarg 2025-01-25 03:43:35 +01:00
parent 5080a6cbcd
commit 51df3c1956
7 changed files with 37 additions and 12 deletions

View file

@ -66,8 +66,8 @@ int g_pulseDirection = -1;
ULONG_PTR g_gdiplusToken = 0;
// Pending messages
std::vector<nlohmann::json> g_inboundMessages;
std::vector<nlohmann::json> g_outboundMessages;
std::wstring g_launchProtocol;
std::atomic<bool> g_isAppReady = false;
std::atomic<bool> g_waitStarted(false);

View file

@ -119,8 +119,8 @@ extern ULONG_PTR g_gdiplusToken;
// App Ready and Event Queue
#define WM_NOTIFY_FLUSH (WM_USER + 101)
extern std::vector<nlohmann::json> g_inboundMessages;
extern std::vector<nlohmann::json> g_outboundMessages;
extern std::wstring g_launchProtocol;
extern std::atomic<bool> g_isAppReady;
extern std::atomic<bool> g_waitStarted;

View file

@ -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<std::wstring> processesToCheck={L"stremio.exe", L"stremio-runtime.exe"};

View file

@ -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;

View file

@ -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<std::string> &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<DWORD>((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);

View file

@ -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

View file

@ -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));
}
};