mirror of
https://github.com/Zaarrg/stremio-community-v5.git
synced 2026-05-10 12:10:54 +00:00
Refactor fixes
- Fixed wrong mpv ended logic - Fixed thumbfast logic missing - Fixed fullscreen not working
This commit is contained in:
parent
1976366f44
commit
5080a6cbcd
3 changed files with 77 additions and 26 deletions
|
|
@ -140,27 +140,24 @@ void HandleMpvEvents()
|
|||
nlohmann::json j;
|
||||
j["type"]="mpv-event-ended";
|
||||
switch(ef->reason){
|
||||
case MPV_END_FILE_REASON_EOF:
|
||||
j["reason"]="quit";
|
||||
case MPV_END_FILE_REASON_EOF:
|
||||
j["reason"]="quit";
|
||||
SendToJS("mpv-event-ended", j);
|
||||
break;
|
||||
case MPV_END_FILE_REASON_ERROR:
|
||||
{
|
||||
std::string err = mpv_error_string(ef->error);
|
||||
std::string capitalized = capitalizeFirstLetter(err);
|
||||
j["reason"]="error";
|
||||
if(ef->error<0)
|
||||
j["error"]= capitalized;
|
||||
AppendToCrashLog("[MPV]: " + capitalized);
|
||||
SendToJS("mpv-event-ended", j);
|
||||
case MPV_END_FILE_REASON_ERROR: {
|
||||
std::string errorString = mpv_error_string(ef->error);
|
||||
std::string capitalizedErrorString = capitalizeFirstLetter(errorString);
|
||||
j["reason"]="error";
|
||||
if(ef->error<0)
|
||||
j["error"]= capitalizedErrorString;
|
||||
SendToJS("mpv-event-ended", j);
|
||||
AppendToCrashLog("[MPV]: " + capitalizedErrorString);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
j["reason"]="other";
|
||||
break;
|
||||
}
|
||||
default:
|
||||
j["reason"]="other";
|
||||
SendToJS("mpv-event-ended", j);
|
||||
break;
|
||||
}
|
||||
PostMessage(g_hWnd, WM_NOTIFY_FLUSH, 0, 0);
|
||||
break;
|
||||
}
|
||||
case MPV_EVENT_SHUTDOWN:
|
||||
|
|
|
|||
|
|
@ -140,12 +140,63 @@ void HandleEvent(const std::string &ev, std::vector<std::string> &args)
|
|||
} else if(ev=="mpv-observe-prop"){
|
||||
HandleMpvObserveProp(args);
|
||||
} else if(ev=="app-ready"){
|
||||
std::cout<<"[Native->JS] APP READY"<<"\n" << std::endl;
|
||||
g_isAppReady=true;
|
||||
HideSplash();
|
||||
PostMessage(g_hWnd, WM_NOTIFY_FLUSH, 0, 0);
|
||||
} else if(ev=="update-requested"){
|
||||
RunInstallerAndExit();
|
||||
} else if(ev == "seek-hover") {
|
||||
if (g_thumbFastHeight == 0) return;
|
||||
if(g_ignoreHover) {
|
||||
auto now = std::chrono::steady_clock::now();
|
||||
if(now < g_ignoreUntil) {
|
||||
return;
|
||||
}
|
||||
g_ignoreHover = false;
|
||||
}
|
||||
|
||||
// Expecting arguments: hovered_seconds, x, y
|
||||
if(args.size() < 3) {
|
||||
std::cerr << "seek-hover requires at least 3 arguments.\n";
|
||||
return;
|
||||
}
|
||||
|
||||
// Convert the y-coordinate from string to an integer
|
||||
int yCoord = 0;
|
||||
try {
|
||||
yCoord = std::stoi(args[2]);
|
||||
} catch(const std::exception &e) {
|
||||
std::cerr << "Error converting y coordinate: " << e.what() << "\n";
|
||||
return;
|
||||
}
|
||||
|
||||
// Subtract the thumb fast height from y
|
||||
int adjustedY = yCoord - g_thumbFastHeight;
|
||||
|
||||
// Prepare command for thumbfast with adjusted y-coordinate
|
||||
std::vector<std::string> cmdArgs = {
|
||||
"script-message-to",
|
||||
"thumbfast",
|
||||
"thumb",
|
||||
args[0], // hovered_seconds
|
||||
args[1], // x
|
||||
std::to_string(adjustedY) // y with offset
|
||||
};
|
||||
|
||||
HandleMpvCommand(cmdArgs);
|
||||
}
|
||||
else if(ev == "seek-leave") {
|
||||
if (g_thumbFastHeight == 0) return;
|
||||
// Set ignore flag and calculate ignore-until timestamp
|
||||
g_ignoreHover = true;
|
||||
g_ignoreUntil = std::chrono::steady_clock::now() + IGNORE_DURATION;
|
||||
|
||||
std::vector<std::string> cmdArgs = {
|
||||
"script-message-to",
|
||||
"thumbfast",
|
||||
"clear"
|
||||
};
|
||||
HandleMpvCommand(cmdArgs);
|
||||
} else if(ev=="start-drag"){
|
||||
ReleaseCapture();
|
||||
SendMessageW(g_hWnd, WM_NCLBUTTONDOWN, HTCAPTION, 0);
|
||||
|
|
@ -167,7 +218,9 @@ void HandleEvent(const std::string &ev, std::vector<std::string> &args)
|
|||
void HandleInboundJSON(const std::string &msg)
|
||||
{
|
||||
try {
|
||||
#ifdef DEBUG_BUILD
|
||||
std::cout << "[JS -> NATIVE]: " << msg << std::endl;
|
||||
#endif
|
||||
|
||||
auto j = nlohmann::json::parse(msg);
|
||||
int type = 0;
|
||||
|
|
|
|||
|
|
@ -414,14 +414,15 @@ static void SetupWebMessageHandler()
|
|||
EventRegistrationToken cfeToken;
|
||||
g_webview->add_ContainsFullScreenElementChanged(
|
||||
Microsoft::WRL::Callback<ICoreWebView2ContainsFullScreenElementChangedEventHandler>(
|
||||
[](ICoreWebView2* sender, IUnknown*){
|
||||
BOOL inFull = FALSE;
|
||||
sender->get_ContainsFullScreenElement(&inFull);
|
||||
g_isFullscreen = inFull;
|
||||
// Toggle here or in WndProc
|
||||
PostMessage(g_hWnd, WM_NOTIFY_FLUSH, 0, 0);
|
||||
return S_OK;
|
||||
}).Get(),
|
||||
[](ICoreWebView2* sender, IUnknown* /*args*/) -> HRESULT
|
||||
{
|
||||
// FullScreen Toggle Handle
|
||||
BOOL inFull = FALSE;
|
||||
sender->get_ContainsFullScreenElement(&inFull);
|
||||
ToggleFullScreen(g_hWnd, inFull != FALSE);
|
||||
return S_OK;
|
||||
}
|
||||
).Get(),
|
||||
&cfeToken
|
||||
);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue