-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathBrowserComponent.h
40 lines (32 loc) · 1.31 KB
/
BrowserComponent.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
/**
A BrowserComponent wraps the default juce WebBrowserComponent, adding
functionality to communicate with the browser instance using a custom
URL scheme to pass data.
*/
#pragma once
namespace tomduncalf
{
namespace BrowserIntegration
{
class BrowserComponent : public juce::WindowsWebView2WebBrowserComponent
{
public:
/** Create a browser component with the default URL (in debug mode, loading
from the React dev server, and in release mode, loading from the built
application bundle in the Resources directory)
*/
BrowserComponent();
/** Create a browser component with a specific URL */
BrowserComponent (const juce::String initialUrl);
void sendMessage (const juce::var message, bool suppressLog = false);
bool pageAboutToLoad (const juce::String& newURL) override;
void setOnMessageCallback (std::function<void (juce::var)> cb);
void loadUI();
protected:
std::function<void (juce::var)> onMessageCallback;
const juce::String urlSchema = "juce://";
const juce::String jsCallbackName = "receiveMessageFromJuce";
void scriptMessageReceived (const juce::var messageBody) override;
};
}// namespace BrowserIntegration
}// namespace tomduncalf