Command Palette

Search for a command to run...

UnylyUnyly
Назад к скиллам

juce-webview-windows

БесплатноБез исполняемых скриптовНе проверен

Quick-start guide for building JUCE 9 audio plugins with WebView2 UIs on Windows. Covers essential setup, critical member ordering, and step-by-step…

Noizefieldот Noizefield★ 379 звёзд на GitHub

Об этом скилле

JUCE 9 WebView Plugin - Quick Start Guide

Platform: Windows 11 | JUCE 9 | WebView2 | CMake


🎯 Quick Overview

Build audio plugin UIs using modern web technologies (HTML/CSS/JavaScript) instead of C++ JUCE components.

Benefits:

  • Fast iteration with hot reloading
  • Use familiar web frameworks (React, Vue, or vanilla JS)
  • Modern UI capabilities (CSS animations, flexbox, gradients)
  • Team-friendly (frontend devs can work without C++ knowledge)
  • GPU acceleration via WebGL

Trade-offs:

  • ~100MB additional memory footprint
  • Windows 11 WebView2 dependency
  • Different performance characteristics than native C++

📐 UI Layout & Scaling (read before any layout work)

Canonical rules live in .agents/rules/ui-layout-system.md. In short:

  • Geometry is authored on a grid in rem (1 rem = 1 cell); scaling is pure CSS via html { font-size: min(100vw/cols, 100vh/rows) } — never CSS zoom, transform: scale wrappers, or JS-computed scale factors.
  • Design/ui-map.json is the contract; index.html must match it 1:1 (id="ctl-<param>"). Vendor templates/webview/apc-ui/ → Source/ui/public/apc-ui/, don't hand-roll components.
  • Resizable plugins use an in-page .apc-grip (the JUCE ResizableCornerComponent cannot paint over a heavyweight webview), wired to the resizeGrip native function; aspect is locked via setFixedAspectRatio and re-asserted in resized().
  • Set WinWebView2{}.withBackgroundColour(<plate colour>) to kill drag-flash.
  • Gate: node bin/apc.js validate ui --plugin <Name> must pass before build.

🔴 CRITICAL: Member Declaration Order (PREVENTS DAW CRASHES)

⚠️ #1 CAUSE OF WEBVIEW PLUGIN CRASHES - MUST FOLLOW

The Rule

C++ destroys members in REVERSE order of declaration. WebView references relays, so relays must be declared FIRST to be destroyed LAST.

Correct Pattern (PluginEditor.h)

private:
    YourAudioProcessor& audioProcessor;

    // ═══════════════════════════════════════════════════════════════
    // CRITICAL: Destruction Order = Reverse of Declaration
    // Order: Relays → WebView → Attachments
    // ═══════════════════════════════════════════════════════════════

    // 1. RELAYS FIRST (destroyed last)
    juce::WebSliderRelay gainRelay { "GAIN" };
    juce::WebSliderRelay frequencyRelay { "FREQUENCY" };

    // 2. WEBVIEW SECOND (destroyed middle)
    std::unique_ptr<juce::WebBrowserComponent> webView;

    // 3. ATTACHMENTS LAST (destroyed first)
    std::unique_ptr<juce::WebSliderParameterAttachment> gainAttachment;
    std::unique_ptr<juce::WebSliderParameterAttachment> frequencyAttachment;

Wrong Order → DAW Crash on Unload

See: .agents/troubleshooting/resolutions/webview-member-order-crash.md


📋 Step-by-Step Implementation

Step 1: Create Web UI Files

plugins/YourPlugin/
└── Source/
    └── ui/
        └── public/
            ├── index.html
            └── js/
                └── index.js

CRITICAL (webview-008): ES6 modules fail in JUCE WebView - there must be NO separate .js files and no external scripts. Everything goes inline into ONE