Skip to content

Commit f4ef9ee

Browse files
committed
add WebView2 Rainmeter plugin implementation with core functionality and package dependencies.
1 parent a45e45c commit f4ef9ee

File tree

3 files changed

+114
-26
lines changed

3 files changed

+114
-26
lines changed

README.md

Lines changed: 17 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,22 @@ LeftMouseUpAction=[!CommandMeasure MeasureWebView "ExecuteScript alert('Hello!')
8585

8686
;Open DevTools
8787
LeftMouseUpAction=[!CommandMeasure MeasureWebView "OpenDevTools"]
88+
89+
; SetWidth
90+
LeftMouseUpAction=[!CommandMeasure MeasureWebView "SetWidth 500"]
91+
; Dynamically sets the width of the WebView2 control in pixels.
92+
93+
; SetHeight
94+
LeftMouseUpAction=[!CommandMeasure MeasureWebView "SetHeight 400"]
95+
; Dynamically sets the height of the WebView2 control in pixels.
96+
97+
; SetX
98+
LeftMouseUpAction=[!CommandMeasure MeasureWebView "SetX 100"]
99+
; Dynamically sets the X position of the WebView2 control relative to the skin window.
100+
101+
;SetY
102+
LeftMouseUpAction=[!CommandMeasure MeasureWebView "SetY 50"]
103+
;Dynamically sets the Y position of the WebView2 control relative to the skin window.
88104
```
89105

90106
## 💡 Examples
@@ -331,29 +347,6 @@ This creates:
331347
- Plugin DLLs in `dist\` folder
332348
- Complete `.rmskin` package for distribution
333349

334-
## 🐛 Troubleshooting
335-
336-
### WebView2 doesn't appear
337-
- Ensure WebView2 Runtime is installed
338-
- Check Rainmeter log for error messages
339-
- Verify skin window has appropriate dimensions
340-
341-
### Mouse/Keyboard events not working
342-
- **Fixed in v0.0.3**: Added JavaScript settings (`put_IsScriptEnabled`, `put_AreDefaultScriptDialogsEnabled`, `put_IsWebMessageEnabled`)
343-
- Ensure you're using the latest version
344-
345-
### File paths not loading
346-
- Use `#@#` for @Resources folder: `URL=#@#mypage.html`
347-
- Or use absolute paths: `URL=C:\MyFolder\page.html`
348-
349-
## 📝 Technical Details
350-
351-
- **WebView2 SDK**: Microsoft.Web.WebView2 (v1.0.2792.45)
352-
- **Runtime**: Uses Windows Implementation Library (WIL)
353-
- **Architecture**: Supports both x86 and x64
354-
- **Language**: C++17
355-
- **User Data**: Stored in `%TEMP%\RainmeterWebView2`
356-
357350
## 🤝 Contributing
358351

359352
Contributions are welcome! Please feel free to submit a Pull Request.
@@ -380,4 +373,4 @@ This project is licensed under the MIT License.
380373

381374
---
382375

383-
**Made with ❤️ for the Rainmeter community**
376+
**Made with ❤️ by nstechbytes**

WebView2/Plugin.cpp

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,10 +229,105 @@ PLUGIN_EXPORT void ExecuteBang(void* data, LPCWSTR args)
229229
);
230230
}
231231
}
232+
else if (_wcsicmp(action.c_str(), L"SetWidth") == 0)
233+
{
234+
if (!param.empty())
235+
{
236+
measure->width = _wtoi(param.c_str());
237+
238+
// Update WebView2 bounds
239+
if (measure->webViewController)
240+
{
241+
RECT bounds;
242+
GetClientRect(measure->skinWindow, &bounds);
243+
bounds.left = measure->x;
244+
bounds.top = measure->y;
245+
bounds.right = measure->x + measure->width;
246+
if (measure->height > 0)
247+
{
248+
bounds.bottom = measure->y + measure->height;
249+
}
250+
measure->webViewController->put_Bounds(bounds);
251+
}
252+
}
253+
}
254+
else if (_wcsicmp(action.c_str(), L"SetHeight") == 0)
255+
{
256+
if (!param.empty())
257+
{
258+
measure->height = _wtoi(param.c_str());
259+
260+
// Update WebView2 bounds
261+
if (measure->webViewController)
262+
{
263+
RECT bounds;
264+
GetClientRect(measure->skinWindow, &bounds);
265+
bounds.left = measure->x;
266+
bounds.top = measure->y;
267+
if (measure->width > 0)
268+
{
269+
bounds.right = measure->x + measure->width;
270+
}
271+
bounds.bottom = measure->y + measure->height;
272+
measure->webViewController->put_Bounds(bounds);
273+
}
274+
}
275+
}
276+
else if (_wcsicmp(action.c_str(), L"SetX") == 0)
277+
{
278+
if (!param.empty())
279+
{
280+
measure->x = _wtoi(param.c_str());
281+
282+
// Update WebView2 bounds
283+
if (measure->webViewController)
284+
{
285+
RECT bounds;
286+
GetClientRect(measure->skinWindow, &bounds);
287+
bounds.left = measure->x;
288+
bounds.top = measure->y;
289+
if (measure->width > 0)
290+
{
291+
bounds.right = measure->x + measure->width;
292+
}
293+
if (measure->height > 0)
294+
{
295+
bounds.bottom = measure->y + measure->height;
296+
}
297+
measure->webViewController->put_Bounds(bounds);
298+
}
299+
}
300+
}
301+
else if (_wcsicmp(action.c_str(), L"SetY") == 0)
302+
{
303+
if (!param.empty())
304+
{
305+
measure->y = _wtoi(param.c_str());
306+
307+
// Update WebView2 bounds
308+
if (measure->webViewController)
309+
{
310+
RECT bounds;
311+
GetClientRect(measure->skinWindow, &bounds);
312+
bounds.left = measure->x;
313+
bounds.top = measure->y;
314+
if (measure->width > 0)
315+
{
316+
bounds.right = measure->x + measure->width;
317+
}
318+
if (measure->height > 0)
319+
{
320+
bounds.bottom = measure->y + measure->height;
321+
}
322+
measure->webViewController->put_Bounds(bounds);
323+
}
324+
}
325+
}
232326
else if (_wcsicmp(action.c_str(), L"OpenDevTools") == 0)
233327
{
234328
measure->webView->OpenDevToolsWindow();
235329
}
330+
236331
}
237332

238333
PLUGIN_EXPORT void Finalize(void* data)

WebView2/packages.config

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<packages>
3-
<package id="Microsoft.Web.WebView2" version="1.0.2792.45" targetFramework="native" />
4-
<package id="Microsoft.Windows.ImplementationLibrary" version="1.0.240803.1" targetFramework="native" />
3+
<package id="Microsoft.Web.WebView2" version="1.0.1054.31" targetFramework="native" />
4+
<package id="Microsoft.Windows.ImplementationLibrary" version="1.0.211019.2" targetFramework="native" />
55
</packages>

0 commit comments

Comments
 (0)