Skip to content

Commit fde9cce

Browse files
committed
Add option to refresh page when the source becomes active
1 parent ad115e7 commit fde9cce

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

obs-browser/main-source.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ static void browser_source_get_defaults(obs_data_t *settings)
2929
obs_data_set_default_int(settings, "height", 600);
3030
obs_data_set_default_int(settings, "fps", 30);
3131
obs_data_set_default_bool(settings, "shutdown", false);
32+
obs_data_set_default_bool(settings, "restart_when_active", false);
3233
obs_data_set_default_string(settings, "css", "body { background-color: rgba(0, 0, 0, 0); margin: 0px auto; overflow: hidden; }");
3334
}
3435

@@ -107,6 +108,8 @@ static obs_properties_t *browser_source_get_properties(void *data)
107108
obs_module_text("CSS"), OBS_TEXT_MULTILINE);
108109
obs_properties_add_bool(props, "shutdown",
109110
obs_module_text("Shutdown when not active"));
111+
obs_properties_add_bool(props, "restart_when_active",
112+
obs_module_text("Refresh browser when scene becomes active"));
110113

111114
obs_properties_add_button(props, "refreshnocache",
112115
obs_module_text("Refresh cache of current page"), refreshnocache_button_clicked);
@@ -143,6 +146,21 @@ static const char *browser_source_get_name(void *)
143146
return obs_module_text("BrowserSource");
144147
}
145148

149+
static void browser_source_activate(void *data)
150+
{
151+
BrowserSource *bs = static_cast<BrowserSource *>(data);
152+
obs_data_t *settings = obs_source_get_settings(bs->GetSource());
153+
bool restart = obs_data_get_bool(settings, "restart_when_active");
154+
155+
if (restart)
156+
BrowserManager::Instance()->RefreshPageNoCache(bs->GetBrowserIdentifier());
157+
}
158+
159+
static void browser_source_deactivate(void *data)
160+
{
161+
162+
}
163+
146164
// Called when the source is visible
147165
static void browser_source_show(void *data)
148166
{
@@ -267,6 +285,9 @@ create_browser_source_info()
267285
browser_source_info.video_render = browser_source_render;
268286
browser_source_info.show = browser_source_show;
269287
browser_source_info.hide = browser_source_hide;
288+
browser_source_info.activate = browser_source_activate;
289+
browser_source_info.deactivate = browser_source_deactivate;
290+
270291

271292
return browser_source_info;
272293
}

shared/browser-source.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ class BrowserSource {
8282
uint32_t height;
8383
uint32_t fps;
8484
bool shutdown;
85+
bool restart_when_active;
8586

8687
int browserIdentifier;
8788

0 commit comments

Comments
 (0)