Browse Source

allow web-ui late init

Signed-off-by: falkTX <falktx@falktx.com>
web-ui
falkTX 1 year ago
parent
commit
0fe900dfd2
Signed by: falkTX <falktx@falktx.com> GPG Key ID: CDBAA37ABC74FBA0
4 changed files with 43 additions and 12 deletions
  1. +4
    -2
      dgl/Web.hpp
  2. +26
    -8
      dgl/src/Web.cpp
  3. +7
    -0
      distrho/extra/WebViewImpl.hpp
  4. +6
    -2
      distrho/src/DistrhoUI.cpp

+ 4
- 2
dgl/Web.hpp View File

@@ -43,7 +43,7 @@ public:
/** /**
Constructor for a WebViewWidget. Constructor for a WebViewWidget.
*/ */
explicit WebViewWidget(Window& windowToMapTo);
explicit WebViewWidget(Window& windowToMapTo, bool initLater = false);


/** /**
Destructor. Destructor.
@@ -55,11 +55,13 @@ public:
void reload(); void reload();


protected: protected:
void init(const char* initialJS);

virtual void onMessage(char* message); virtual void onMessage(char* message);
void onResize(const ResizeEvent& ev) override; void onResize(const ResizeEvent& ev) override;


private: private:
const DISTRHO_NAMESPACE::WebViewHandle webview;
DISTRHO_NAMESPACE::WebViewHandle webview;
void idleCallback() override; void idleCallback() override;
void onDisplay() override {} void onDisplay() override {}




+ 26
- 8
dgl/src/Web.cpp View File

@@ -26,15 +26,15 @@


START_NAMESPACE_DGL START_NAMESPACE_DGL


// -----------------------------------------------------------------------
// --------------------------------------------------------------------------------------------------------------------


WebViewWidget::WebViewWidget(Window& windowToMapTo)
WebViewWidget::WebViewWidget(Window& windowToMapTo, bool initLater)
: TopLevelWidget(windowToMapTo), : TopLevelWidget(windowToMapTo),
webview(webViewCreate(windowToMapTo.getNativeWindowHandle(),
windowToMapTo.getWidth(),
windowToMapTo.getHeight(),
windowToMapTo.getScaleFactor(),
WebViewOptions(_on_msg, this)))
webview(initLater ? nullptr : webViewCreate(windowToMapTo.getNativeWindowHandle(),
windowToMapTo.getWidth(),
windowToMapTo.getHeight(),
windowToMapTo.getScaleFactor(),
WebViewOptions(_on_msg, this)))
{ {
#if !(defined(DISTRHO_OS_MAC) || defined(DISTRHO_OS_WINDOWS)) #if !(defined(DISTRHO_OS_MAC) || defined(DISTRHO_OS_WINDOWS))
if (webview != nullptr) if (webview != nullptr)
@@ -53,6 +53,24 @@ WebViewWidget::~WebViewWidget()
} }
} }


void WebViewWidget::init(const char* const initialJS)
{
DISTRHO_SAFE_ASSERT_RETURN(webview == nullptr,);

WebViewOptions options(_on_msg, this);
options.initialJS = initialJS;
webview = webViewCreate(getWindow().getNativeWindowHandle(), getWidth(), getHeight(), getScaleFactor(), options);

// FIXME implement initialJS
if (webview != nullptr)
webViewEvaluateJS(webview, initialJS);

#if !(defined(DISTRHO_OS_MAC) || defined(DISTRHO_OS_WINDOWS))
if (webview != nullptr)
addIdleCallback(this, 1000 / 60);
#endif
}

void WebViewWidget::evaluateJS(const char* const js) void WebViewWidget::evaluateJS(const char* const js)
{ {
if (webview != nullptr) if (webview != nullptr)
@@ -87,7 +105,7 @@ void WebViewWidget::idleCallback()
webViewIdle(webview); webViewIdle(webview);
} }


// -----------------------------------------------------------------------
// --------------------------------------------------------------------------------------------------------------------


static void notImplemented(const char* const name) static void notImplemented(const char* const name)
{ {


+ 7
- 0
distrho/extra/WebViewImpl.hpp View File

@@ -45,6 +45,11 @@ struct WebViewOptions {
PositionOffset() : x(0), y(0) {} PositionOffset() : x(0), y(0) {}
} offset; } offset;


/**
Set some JavaScript to evalute on every new page load.
*/
const char* initialJS;

/** /**
Message callback triggered from JavaScript code inside the WebView. Message callback triggered from JavaScript code inside the WebView.
*/ */
@@ -54,12 +59,14 @@ struct WebViewOptions {
/** Constructor for default values */ /** Constructor for default values */
WebViewOptions() WebViewOptions()
: offset(), : offset(),
initialJS(nullptr),
callback(nullptr), callback(nullptr),
callbackPtr(nullptr) {} callbackPtr(nullptr) {}


/** Constructor providing a callback */ /** Constructor providing a callback */
WebViewOptions(const WebViewMessageCallback cb, void* const ptr) WebViewOptions(const WebViewMessageCallback cb, void* const ptr)
: offset(), : offset(),
initialJS(nullptr),
callback(cb), callback(cb),
callbackPtr(ptr) {} callbackPtr(ptr) {}
}; };


+ 6
- 2
distrho/src/DistrhoUI.cpp View File

@@ -246,7 +246,11 @@ UI::UI(const uint width, const uint height, const bool automaticallyScaleAndSetA
#else #else
false false
#endif #endif
)),
)
#if DISTRHO_UI_WEB_VIEW
, true
#endif
),
uiData(UI::PrivateData::s_nextPrivateData) uiData(UI::PrivateData::s_nextPrivateData)
{ {
#if !DISTRHO_PLUGIN_HAS_EXTERNAL_UI #if !DISTRHO_PLUGIN_HAS_EXTERNAL_UI
@@ -269,7 +273,7 @@ UI::UI(const uint width, const uint height, const bool automaticallyScaleAndSetA
#endif #endif


#if DISTRHO_UI_WEB_VIEW #if DISTRHO_UI_WEB_VIEW
evaluateJS(
init(
"editParameter=function(index,started){window.webkit.messageHandlers.external.postMessage('editparam '+index+' '+(started ? 1 : 0))};" "editParameter=function(index,started){window.webkit.messageHandlers.external.postMessage('editparam '+index+' '+(started ? 1 : 0))};"
"setParameterValue=function(index,value){window.webkit.messageHandlers.external.postMessage('setparam '+index+' '+value)};" "setParameterValue=function(index,value){window.webkit.messageHandlers.external.postMessage('setparam '+index+' '+value)};"
#if DISTRHO_PLUGIN_WANT_STATE #if DISTRHO_PLUGIN_WANT_STATE


Loading…
Cancel
Save