diff --git a/src/WallpaperEngine/Application/CWallpaperApplication.cpp b/src/WallpaperEngine/Application/CWallpaperApplication.cpp index 3d6f071..3374f17 100644 --- a/src/WallpaperEngine/Application/CWallpaperApplication.cpp +++ b/src/WallpaperEngine/Application/CWallpaperApplication.cpp @@ -395,11 +395,6 @@ void CWallpaperApplication::show () { this->m_context.settings.general.screenScalings [background])); } - // wallpapers are setup, free browsesr context if possible - if (!this->m_browserContext.isUsed ()) { - this->m_browserContext.stop (); - } - static time_t seconds; static struct tm* timeinfo; diff --git a/src/WallpaperEngine/WebBrowser/CWebBrowserContext.cpp b/src/WallpaperEngine/WebBrowser/CWebBrowserContext.cpp index 61df7be..b8a95ac 100644 --- a/src/WallpaperEngine/WebBrowser/CWebBrowserContext.cpp +++ b/src/WallpaperEngine/WebBrowser/CWebBrowserContext.cpp @@ -6,16 +6,46 @@ using namespace WallpaperEngine::WebBrowser; -CWebBrowserContext::CWebBrowserContext (int argc, char** argv) : m_stopped (false) { - // clone original argc/argv as they'll be modified by cef - char** argv2 = new char*[argc]; +CWebBrowserContext::CWebBrowserContext (int argc, char** argv) : m_stopped (false), m_inUse (false), m_argc (argc), m_argv (argv) {} - for (int i = 0; i < argc; i++) { - argv2 [i] = new char [strlen (argv [i]) + 1]; - strcpy (argv2 [i], argv [i]); +CWebBrowserContext::~CWebBrowserContext () { + this->stop (); +} + +void CWebBrowserContext::markAsUsed () { + if (!this->m_inUse) { + this->delayedInitialization(); } - CefMainArgs args (argc, argv2); + this->m_inUse = true; +} + +bool CWebBrowserContext::isUsed () const { + return this->m_inUse; +} + +void CWebBrowserContext::stop () { + if (this->m_stopped) { + return; + } + + sLog.out ("Shutting down CEF"); + + this->m_stopped = true; + + CefShutdown (); +} + +void CWebBrowserContext::delayedInitialization () { + // clone original argc/argv as they'll be modified by cef + char** argv2 = new char*[this->m_argc]; + + for (int i = 0; i < this->m_argc; i++) { + argv2 [i] = new char [strlen (this->m_argv [i]) + 1]; + strcpy (argv2 [i], this->m_argv [i]); + } + + CefMainArgs args (this->m_argc, argv2); int exit_code = CefExecuteProcess ( args, nullptr, nullptr); // Spawned processes will terminate here(see CefIninitilize below). Maybe implementing @@ -46,28 +76,4 @@ CWebBrowserContext::CWebBrowserContext (int argc, char** argv) : m_stopped (fals if (!result) { sLog.exception ("CefInitialize: failed"); } -} - -CWebBrowserContext::~CWebBrowserContext () { - this->stop (); -} - -void CWebBrowserContext::markAsUsed () { - this->m_inUse = true; -} - -bool CWebBrowserContext::isUsed () { - return this->m_inUse; -} - -void CWebBrowserContext::stop () { - if (this->m_stopped) { - return; - } - - sLog.out ("Shutting down CEF"); - - this->m_stopped = true; - - CefShutdown (); } \ No newline at end of file diff --git a/src/WallpaperEngine/WebBrowser/CWebBrowserContext.h b/src/WallpaperEngine/WebBrowser/CWebBrowserContext.h index d689ff1..4003030 100644 --- a/src/WallpaperEngine/WebBrowser/CWebBrowserContext.h +++ b/src/WallpaperEngine/WebBrowser/CWebBrowserContext.h @@ -7,10 +7,17 @@ namespace WallpaperEngine::WebBrowser { ~CWebBrowserContext(); void markAsUsed(); - bool isUsed(); + [[nodiscard]] bool isUsed() const; void stop(); private: + /** + * Handles the actual initialization logic + */ + void delayedInitialization(); + + int m_argc; + char** m_argv; bool m_stopped; bool m_inUse; };