mirror of
https://github.com/Almamu/linux-wallpaperengine.git
synced 2025-07-15 13:52:23 +08:00
chore: delay initialization of browser until it's used once
This commit is contained in:
parent
2c4884f432
commit
6c0a9c12d5
@ -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;
|
||||
|
||||
|
@ -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 ();
|
||||
}
|
||||
|
||||
CefMainArgs args (argc, argv2);
|
||||
void CWebBrowserContext::markAsUsed () {
|
||||
if (!this->m_inUse) {
|
||||
this->delayedInitialization();
|
||||
}
|
||||
|
||||
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
|
||||
@ -47,27 +77,3 @@ CWebBrowserContext::CWebBrowserContext (int argc, char** argv) : m_stopped (fals
|
||||
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 ();
|
||||
}
|
@ -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;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user