mirror of
https://github.com/Zaarrg/stremio-community-v5.git
synced 2026-05-21 09:22:08 +00:00
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:
parent
5080a6cbcd
commit
51df3c1956
7 changed files with 37 additions and 12 deletions
|
|
@ -66,8 +66,8 @@ int g_pulseDirection = -1;
|
||||||
ULONG_PTR g_gdiplusToken = 0;
|
ULONG_PTR g_gdiplusToken = 0;
|
||||||
|
|
||||||
// Pending messages
|
// Pending messages
|
||||||
std::vector<nlohmann::json> g_inboundMessages;
|
|
||||||
std::vector<nlohmann::json> g_outboundMessages;
|
std::vector<nlohmann::json> g_outboundMessages;
|
||||||
|
std::wstring g_launchProtocol;
|
||||||
std::atomic<bool> g_isAppReady = false;
|
std::atomic<bool> g_isAppReady = false;
|
||||||
std::atomic<bool> g_waitStarted(false);
|
std::atomic<bool> g_waitStarted(false);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -119,8 +119,8 @@ extern ULONG_PTR g_gdiplusToken;
|
||||||
|
|
||||||
// App Ready and Event Queue
|
// App Ready and Event Queue
|
||||||
#define WM_NOTIFY_FLUSH (WM_USER + 101)
|
#define WM_NOTIFY_FLUSH (WM_USER + 101)
|
||||||
extern std::vector<nlohmann::json> g_inboundMessages;
|
|
||||||
extern std::vector<nlohmann::json> g_outboundMessages;
|
extern std::vector<nlohmann::json> g_outboundMessages;
|
||||||
|
extern std::wstring g_launchProtocol;
|
||||||
extern std::atomic<bool> g_isAppReady;
|
extern std::atomic<bool> g_isAppReady;
|
||||||
extern std::atomic<bool> g_waitStarted;
|
extern std::atomic<bool> g_waitStarted;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -61,9 +61,11 @@ int main(int argc, char* argv[])
|
||||||
}
|
}
|
||||||
|
|
||||||
// single instance
|
// single instance
|
||||||
if(!CheckSingleInstance(argc, argv)){
|
std::wstring launchProtocol;
|
||||||
|
if(!CheckSingleInstance(argc, argv, launchProtocol)){
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
g_launchProtocol = launchProtocol;
|
||||||
|
|
||||||
// check stremio-runtime duplicates
|
// check stremio-runtime duplicates
|
||||||
std::vector<std::wstring> processesToCheck={L"stremio.exe", L"stremio-runtime.exe"};
|
std::vector<std::wstring> processesToCheck={L"stremio.exe", L"stremio-runtime.exe"};
|
||||||
|
|
|
||||||
|
|
@ -24,8 +24,9 @@ static void NodeOutputThreadProc()
|
||||||
|
|
||||||
bool StartNodeServer()
|
bool StartNodeServer()
|
||||||
{
|
{
|
||||||
std::wstring exePath = L"stremio-runtime.exe";
|
std::wstring exeDir = GetExeDirectory();
|
||||||
std::wstring scriptPath = L"server.js";
|
std::wstring exePath = exeDir + L"\\stremio-runtime.exe";
|
||||||
|
std::wstring scriptPath = exeDir + L"\\server.js";
|
||||||
if(!FileExists(exePath)){
|
if(!FileExists(exePath)){
|
||||||
AppendToCrashLog(L"[NODE]: Missing stremio-runtime.exe");
|
AppendToCrashLog(L"[NODE]: Missing stremio-runtime.exe");
|
||||||
return false;
|
return false;
|
||||||
|
|
|
||||||
|
|
@ -40,7 +40,7 @@ bool FocusExistingInstance(const std::wstring &protocolArg)
|
||||||
return false;
|
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");
|
g_hMutex = CreateMutexW(nullptr, FALSE, L"SingleInstanceMtx_StremioWebShell");
|
||||||
if(!g_hMutex){
|
if(!g_hMutex){
|
||||||
|
|
@ -65,6 +65,7 @@ bool CheckSingleInstance(int argc, char* argv[])
|
||||||
FocusExistingInstance(protocolArg);
|
FocusExistingInstance(protocolArg);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
outProtocolArg = protocolArg;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -204,7 +205,7 @@ void HandleEvent(const std::string &ev, std::vector<std::string> &args)
|
||||||
refreshWeb(args.size()>0 && args[0]=="all");
|
refreshWeb(args.size()>0 && args[0]=="all");
|
||||||
} else if(ev=="app-error"){
|
} else if(ev=="app-error"){
|
||||||
if(!args.empty() && args.size()>0 && args[0] == "shellComm"){
|
if(!args.empty() && args.size()>0 && args[0] == "shellComm"){
|
||||||
if(g_hSplash && !g_waitStarted.exchange(true)){
|
if(!g_isAppReady && !g_waitStarted.exchange(true)){
|
||||||
WaitAndRefreshIfNeeded();
|
WaitAndRefreshIfNeeded();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -329,6 +330,15 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
||||||
SendToJS(pendingMsg["type"], pendingMsg);
|
SendToJS(pendingMsg["type"], pendingMsg);
|
||||||
}
|
}
|
||||||
g_outboundMessages.clear();
|
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;
|
break;
|
||||||
}
|
}
|
||||||
|
|
@ -430,6 +440,12 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
||||||
j["path"] = utf8FilePath;
|
j["path"] = utf8FilePath;
|
||||||
SendToJS("OpenFile", j);
|
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) {
|
} else if (receivedUrl.rfind(L"stremio://", 0) == 0) {
|
||||||
// Handle stremio:// protocol
|
// Handle stremio:// protocol
|
||||||
std::string utf8Url = WStringToUtf8(receivedUrl);
|
std::string utf8Url = WStringToUtf8(receivedUrl);
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@
|
||||||
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
|
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
|
||||||
|
|
||||||
// Helper for single-instance
|
// 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);
|
bool FocusExistingInstance(const std::wstring& protocolArg);
|
||||||
|
|
||||||
// Our "ToggleFullScreen" logic
|
// Our "ToggleFullScreen" logic
|
||||||
|
|
|
||||||
|
|
@ -33,10 +33,16 @@ try {
|
||||||
try {
|
try {
|
||||||
initShellComm();
|
initShellComm();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
const errorMessage = {
|
const errorMessage = {
|
||||||
event: "app-error",
|
type: 6,
|
||||||
reason: "shellComm"
|
object: "transport",
|
||||||
};
|
method: "handleInboundJSON",
|
||||||
|
id: 888,
|
||||||
|
args: [
|
||||||
|
"app-error",
|
||||||
|
[ "shellComm" ]
|
||||||
|
]
|
||||||
|
};
|
||||||
window.chrome.webview.postMessage(JSON.stringify(errorMessage));
|
window.chrome.webview.postMessage(JSON.stringify(errorMessage));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue