PageBridge.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #pragma once
  2. #include <chrono>
  3. #include <cstdint>
  4. #include <filesystem>
  5. #include <map>
  6. #include <set>
  7. #include <string>
  8. #include <vector>
  9. #include "WallpaperEngine/Data/Model/Property.h"
  10. #include "WallpaperEngine/WebBrowser/IPC/WebHostSharedMemory.h"
  11. #include "include/cef_browser.h"
  12. namespace WallpaperEngine::WebBrowser::CEF {
  13. class BrowserClient;
  14. /**
  15. * Runs in the web host process and feeds the page the audio spectrum, media player state and directory property
  16. * contents it gets from the main process through shared memory. The page side is the script SubprocessApp injects.
  17. */
  18. class PageBridge {
  19. public:
  20. PageBridge (
  21. CefRefPtr<CefBrowser> browser, const IPC::WebHostSharedMemory& shm,
  22. const WallpaperEngine::Data::Model::Properties& properties, const BrowserClient& client
  23. );
  24. /** Call regularly from the host loop, does nothing until the page finished loading */
  25. void update ();
  26. private:
  27. using FileTimes = std::map<std::string, std::filesystem::file_time_type>;
  28. void forwardAudio (CefRefPtr<CefFrame> frame);
  29. void forwardMedia (CefRefPtr<CefFrame> frame);
  30. void scanDirectories (CefRefPtr<CefFrame> frame);
  31. CefRefPtr<CefBrowser> m_browser;
  32. const IPC::WebHostSharedMemory& m_shm;
  33. const WallpaperEngine::Data::Model::Properties& m_properties;
  34. const BrowserClient& m_client;
  35. bool m_started = false;
  36. uint32_t m_lastAudioSeq = 0;
  37. bool m_lastAudioSilent = true;
  38. uint32_t m_lastMediaSeq = 0;
  39. uint32_t m_lastCoverVersion = 0;
  40. std::chrono::steady_clock::time_point m_lastDirectoryScan;
  41. std::map<std::string, FileTimes> m_directories;
  42. std::set<std::string> m_reportedMissing;
  43. };
  44. } // namespace WallpaperEngine::WebBrowser::CEF