Skip to content

Commit f60bac7

Browse files
committed
Merge pull request #14 from OsirisNL/shutdown
Added option to shutdown the browser when it's not active.
2 parents cd27bfe + 5707626 commit f60bac7

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

obs-browser/main-source.cpp

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ static obs_properties_t *browser_source_get_properties(void *)
7676
obs_module_text("FPS"), 1, 60, 1);
7777
obs_properties_add_text(props, "css",
7878
obs_module_text("CSS"), OBS_TEXT_MULTILINE);
79+
obs_properties_add_bool(props, "shutdown",
80+
obs_module_text("Shutdown when not active"));
7981
#ifdef __APPLE__
8082
// osx is the only process-isolated cef impl
8183
obs_properties_add_button(props, "restart",
@@ -108,6 +110,23 @@ static const char *browser_source_get_name(void *)
108110
return obs_module_text("BrowserSource");
109111
}
110112

113+
static void browser_source_activate(void *data)
114+
{
115+
BrowserSource *bs = static_cast<BrowserSource *>(data);
116+
117+
if ( bs->GetShutdown() )
118+
bs->UpdateBrowser();
119+
120+
}
121+
122+
static void browser_source_deactivate(void *data)
123+
{
124+
BrowserSource *bs = static_cast<BrowserSource *>(data);
125+
126+
if (bs->GetShutdown())
127+
BrowserManager::Instance()->DestroyBrowser(bs->GetBrowserIdentifier());
128+
}
129+
111130

112131
static void *browser_source_create(obs_data_t *settings, obs_source_t *source)
113132
{
@@ -187,7 +206,7 @@ create_browser_source_info()
187206
browser_source_info.id = "browser_source";
188207
browser_source_info.type = OBS_SOURCE_TYPE_INPUT;
189208
browser_source_info.output_flags = OBS_SOURCE_VIDEO |
190-
OBS_SOURCE_INTERACTION;
209+
OBS_SOURCE_INTERACTION | OBS_SOURCE_DO_NOT_DUPLICATE;
191210
#ifdef __APPLE__
192211
browser_source_info.output_flags |= OBS_SOURCE_CUSTOM_DRAW;
193212
#endif
@@ -207,6 +226,8 @@ create_browser_source_info()
207226
browser_source_info.get_properties = browser_source_get_properties;
208227
browser_source_info.get_defaults = browser_source_get_defaults;
209228
browser_source_info.video_render = browser_source_render;
229+
browser_source_info.activate = browser_source_activate;
230+
browser_source_info.deactivate = browser_source_deactivate;
210231

211232
return browser_source_info;
212233
}

0 commit comments

Comments
 (0)