diff --git a/src/mpv/player.cpp b/src/mpv/player.cpp index 83af65b..02c7bce 100644 --- a/src/mpv/player.cpp +++ b/src/mpv/player.cpp @@ -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: diff --git a/src/ui/mainwindow.cpp b/src/ui/mainwindow.cpp index 73fb743..fb5838a 100644 --- a/src/ui/mainwindow.cpp +++ b/src/ui/mainwindow.cpp @@ -140,12 +140,63 @@ void HandleEvent(const std::string &ev, std::vector &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 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 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 &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; diff --git a/src/webview/webview.cpp b/src/webview/webview.cpp index 4dac9c1..277c31a 100644 --- a/src/webview/webview.cpp +++ b/src/webview/webview.cpp @@ -414,14 +414,15 @@ static void SetupWebMessageHandler() EventRegistrationToken cfeToken; g_webview->add_ContainsFullScreenElementChanged( Microsoft::WRL::Callback( - [](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 ); }