Skip to content

Commit

Permalink
Delete old webview approach in favour of DPF one
Browse files Browse the repository at this point in the history
Signed-off-by: falkTX <[email protected]>
  • Loading branch information
falkTX committed Sep 25, 2024
1 parent 0051a7f commit d89647e
Show file tree
Hide file tree
Showing 10 changed files with 36 additions and 1,024 deletions.
2 changes: 1 addition & 1 deletion src/plugin/ChildProcess.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#pragma once

#include "extra/Sleep.hpp"
#include "Time.hpp"
#include "extra/Time.hpp"

#ifdef DISTRHO_OS_WINDOWS
# include <string>
Expand Down
48 changes: 29 additions & 19 deletions src/plugin/DesktopUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include "DistrhoPluginUtils.hpp"
#include "NanoButton.hpp"
#include "ResizeHandle.hpp"
#include "WebView.hpp"
#include "extra/WebView.hpp"

#include "utils.hpp"

Expand All @@ -24,7 +24,7 @@ class DesktopUI : public UI,
String errorDetail;
ResizeHandle resizeHandle;
int port = 0;
void* webview = nullptr;
WebViewHandle webview = nullptr;

public:
DesktopUI()
Expand Down Expand Up @@ -76,7 +76,7 @@ class DesktopUI : public UI,
~DesktopUI() override
{
if (webview != nullptr)
destroyWebView(webview);
webViewDestroy(webview);
}

protected:
Expand Down Expand Up @@ -106,7 +106,7 @@ class DesktopUI : public UI,

if (webview != nullptr)
{
destroyWebView(webview);
webViewDestroy(webview);
webview = nullptr;
buttonOpenWebGui.hide();
}
Expand Down Expand Up @@ -154,16 +154,33 @@ class DesktopUI : public UI,

if (webview != nullptr)
{
destroyWebView(webview);
webViewDestroy(webview);
webview = nullptr;

buttonOpenWebGui.hide();
repaint();
}

port = nport;
d_stderr("webview port is %d", kPortNumOffset + port * 3 + 2);
webview = addWebView(getWindow().getNativeWindowHandle(), getScaleFactor(), kPortNumOffset + port * 3 + 2);

const double scaleFactor = getScaleFactor();

uint offset = kVerticalOffset * scaleFactor;
uint width = getWidth();
uint height = getHeight() - offset;

WebViewOptions opts;
opts.offset.y = offset;

char url[32] = {};
std::snprintf(url, 31, "http://127.0.0.1:%u/", kPortNumOffset + port * 3 + 2);

webview = webViewCreate(url,
getWindow().getNativeWindowHandle(),
width,
height,
scaleFactor,
opts);

if (webview == nullptr)
{
Expand Down Expand Up @@ -225,7 +242,7 @@ class DesktopUI : public UI,
{
case 1:
if (webview != nullptr)
reloadWebView(webview, kPortNumOffset + port * 3 + 2);
webViewReload(webview);
break;
case 2:
openUserFilesDir();
Expand All @@ -244,18 +261,11 @@ class DesktopUI : public UI,
return;

const double scaleFactor = getScaleFactor();
const uint offset = kVerticalOffset * scaleFactor;
const uint width = ev.size.getWidth();
const uint height = ev.size.getHeight() - offset;

uint offset = kVerticalOffset * scaleFactor;
uint width = ev.size.getWidth();
uint height = ev.size.getHeight() - offset;

#ifdef DISTRHO_OS_MAC
offset /= scaleFactor;
width /= scaleFactor;
height /= scaleFactor;
#endif

resizeWebView(webview, offset, width, height);
webViewResize(webview, width, height, scaleFactor);
}

// -------------------------------------------------------------------------------------------------------
Expand Down
3 changes: 2 additions & 1 deletion src/plugin/DistrhoPluginInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,12 @@
#define DISTRHO_PLUGIN_WANT_STATE 1
#define DISTRHO_PLUGIN_WANT_FULL_STATE 1
#define DISTRHO_PLUGIN_WANT_WEBVIEW 1
#define DISTRHO_UI_FILE_BROWSER 0
#define DISTRHO_UI_DEFAULT_WIDTH 1170
#define DISTRHO_UI_DEFAULT_HEIGHT 600
#define DISTRHO_UI_FILE_BROWSER 0
#define DISTRHO_UI_USE_NANOVG 1
#define DISTRHO_UI_USER_RESIZABLE 1
#define DISTRHO_UI_WEB_VIEW 1

static const constexpr unsigned int kVerticalOffset = 30;
static const constexpr unsigned int kPortNumOffset = 18190;
Expand Down
21 changes: 2 additions & 19 deletions src/plugin/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

export DISTRHO_NAMESPACE = DesktopDISTRHO
export DGL_NAMESPACE = DesktopDGL
export FILE_BROWSER_DISABLED = true
export NVG_FONT_TEXTURE_FLAGS = NVG_IMAGE_NEAREST
export USE_WEB_VIEW = true

include ../DPF/Makefile.base.mk

Expand All @@ -23,14 +23,6 @@ FILES_DSP = \

FILES_UI = DesktopUI.cpp NanoButton.cpp utils.cpp

ifeq ($(MACOS),true)
FILES_UI += WebViewWK.mm
else ifeq ($(WINDOWS),true)
FILES_UI += WebViewCHOC.cpp
else
FILES_UI += WebViewX11.cpp
endif

# ---------------------------------------------------------------------------------------------------------------------
# Do some magic

Expand All @@ -44,19 +36,10 @@ TARGETS = features au clap lv2_sep vst2 vst3

BUILD_CXX_FLAGS += -DVERSION='"$(shell cat ../../VERSION)"'
BUILD_CXX_FLAGS += -pthread

ifeq ($(MACOS),true)
else ifeq ($(WINDOWS),true)
BUILD_CXX_FLAGS += -I../CHOC
else
BUILD_CXX_FLAGS += $(shell $(PKG_CONFIG) --cflags Qt5Core)
# -std=gnu++14
endif

LINK_FLAGS += -pthread

ifeq ($(MACOS),true)
LINK_FLAGS += -framework CoreFoundation -framework IOKit -framework WebKit
LINK_FLAGS += -framework CoreFoundation -framework IOKit
else ifeq ($(WINDOWS),true)
LINK_FLAGS += -lole32 -luuid -lwinmm
else
Expand Down
127 changes: 0 additions & 127 deletions src/plugin/Time.hpp

This file was deleted.

17 changes: 0 additions & 17 deletions src/plugin/WebView.hpp

This file was deleted.

Loading

0 comments on commit d89647e

Please sign in to comment.