mirror of
https://github.com/Almamu/linux-wallpaperengine.git
synced 2025-07-15 22:02:29 +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]));
|
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 time_t seconds;
|
||||||
static struct tm* timeinfo;
|
static struct tm* timeinfo;
|
||||||
|
|
||||||
|
@ -6,16 +6,46 @@
|
|||||||
|
|
||||||
using namespace WallpaperEngine::WebBrowser;
|
using namespace WallpaperEngine::WebBrowser;
|
||||||
|
|
||||||
CWebBrowserContext::CWebBrowserContext (int argc, char** argv) : m_stopped (false) {
|
CWebBrowserContext::CWebBrowserContext (int argc, char** argv) : m_stopped (false), m_inUse (false), m_argc (argc), m_argv (argv) {}
|
||||||
// clone original argc/argv as they'll be modified by cef
|
|
||||||
char** argv2 = new char*[argc];
|
|
||||||
|
|
||||||
for (int i = 0; i < argc; i++) {
|
CWebBrowserContext::~CWebBrowserContext () {
|
||||||
argv2 [i] = new char [strlen (argv [i]) + 1];
|
this->stop ();
|
||||||
strcpy (argv2 [i], argv [i]);
|
}
|
||||||
|
|
||||||
|
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 (
|
int exit_code = CefExecuteProcess (
|
||||||
args, nullptr, nullptr); // Spawned processes will terminate here(see CefIninitilize below). Maybe implementing
|
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) {
|
if (!result) {
|
||||||
sLog.exception ("CefInitialize: failed");
|
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();
|
~CWebBrowserContext();
|
||||||
|
|
||||||
void markAsUsed();
|
void markAsUsed();
|
||||||
bool isUsed();
|
[[nodiscard]] bool isUsed() const;
|
||||||
void stop();
|
void stop();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
/**
|
||||||
|
* Handles the actual initialization logic
|
||||||
|
*/
|
||||||
|
void delayedInitialization();
|
||||||
|
|
||||||
|
int m_argc;
|
||||||
|
char** m_argv;
|
||||||
bool m_stopped;
|
bool m_stopped;
|
||||||
bool m_inUse;
|
bool m_inUse;
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user