Skip to content

Commit da89c41

Browse files
committed
Add comprehensive documentation for the JavaScript API Bridge, including API reference tables, usage examples, and notes.
1 parent 23fd588 commit da89c41

File tree

1 file changed

+158
-0
lines changed

1 file changed

+158
-0
lines changed

README.md

Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,164 @@ Create `@Resources\dashboard.html`:
179179
</html>
180180
```
181181

182+
## JavaScript API Bridge
183+
184+
The WebView2 plugin automatically injects a global `rm` object into all loaded web pages, providing seamless access to Rainmeter API functions from JavaScript.
185+
186+
## API Reference Tables
187+
188+
### Reading Options
189+
190+
| Method | Parameters | Returns | Description |
191+
|--------|------------|---------|-------------|
192+
| `rm.ReadString(option, default)` | `option` (string), `default` (string) | Promise<string> | Read a string option from the skin |
193+
| `rm.ReadInt(option, default)` | `option` (string), `default` (number) | Promise<number> | Read an integer option from the skin |
194+
| `rm.ReadDouble(option, default)` | `option` (string), `default` (number) | Promise<number> | Read a double/float option from the skin |
195+
| `rm.ReadFormula(option, default)` | `option` (string), `default` (number) | Promise<number> | Read and evaluate a formula option |
196+
| `rm.ReadPath(option, default)` | `option` (string), `default` (string) | Promise<string> | Read a file path option from the skin |
197+
198+
### Reading from Other Sections
199+
200+
| Method | Parameters | Returns | Description |
201+
|--------|------------|---------|-------------|
202+
| `rm.ReadStringFromSection(section, option, default)` | `section` (string), `option` (string), `default` (string) | Promise<string> | Read a string from another section/measure |
203+
| `rm.ReadIntFromSection(section, option, default)` | `section` (string), `option` (string), `default` (number) | Promise<number> | Read an integer from another section/measure |
204+
| `rm.ReadDoubleFromSection(section, option, default)` | `section` (string), `option` (string), `default` (number) | Promise<number> | Read a double from another section/measure |
205+
| `rm.ReadFormulaFromSection(section, option, default)` | `section` (string), `option` (string), `default` (number) | Promise<number> | Read and evaluate a formula from another section |
206+
207+
### Utility Functions
208+
209+
| Method | Parameters | Returns | Description |
210+
|--------|------------|---------|-------------|
211+
| `rm.ReplaceVariables(text)` | `text` (string) | Promise<string> | Replace Rainmeter variables in text (e.g., `#CURRENTCONFIG#`) |
212+
| `rm.PathToAbsolute(path)` | `path` (string) | Promise<string> | Convert relative path to absolute path |
213+
| `rm.Execute(command)` | `command` (string) | void | Execute a Rainmeter bang command |
214+
| `rm.Log(message, level)` | `message` (string), `level` (string) | void | Log a message to Rainmeter log. Levels: `'Notice'`, `'Warning'`, `'Error'`, `'Debug'` |
215+
216+
### Information Properties
217+
218+
| Property | Returns | Description |
219+
|----------|---------|-------------|
220+
| `rm.MeasureName` | Promise<string> | Get the name of the current measure |
221+
| `rm.SkinName` | Promise<string> | Get the name of the current skin |
222+
| `rm.SkinWindowHandle` | Promise<string> | Get the window handle of the skin |
223+
| `rm.SettingsFile` | Promise<string> | Get the path to Rainmeter settings file |
224+
225+
## Usage Examples
226+
227+
#### Reading Options
228+
229+
```javascript
230+
// Read string option
231+
const url = await rm.ReadString('Url', 'default');
232+
233+
// Read integer option
234+
const width = await rm.ReadInt('Width', 800);
235+
236+
// Read double/float option
237+
const height = await rm.ReadDouble('Height', 600.0);
238+
239+
// Read formula option
240+
const value = await rm.ReadFormula('SomeFormula', 0);
241+
242+
// Read path option
243+
const path = await rm.ReadPath('FilePath', '');
244+
```
245+
246+
#### Reading from Other Sections
247+
248+
```javascript
249+
// Read string from another section
250+
const value = await rm.ReadStringFromSection('MeasureName', 'Option', 'default');
251+
252+
// Read int from another section
253+
const num = await rm.ReadIntFromSection('MeasureName', 'Option', 0);
254+
255+
// Read double from another section
256+
const dbl = await rm.ReadDoubleFromSection('MeasureName', 'Option', 0.0);
257+
258+
// Read formula from another section
259+
const formula = await rm.ReadFormulaFromSection('MeasureName', 'Option', 0.0);
260+
```
261+
262+
#### Utility Functions
263+
264+
```javascript
265+
// Replace Rainmeter variables
266+
const replaced = await rm.ReplaceVariables('#CURRENTCONFIG#');
267+
268+
// Convert relative path to absolute
269+
const absolutePath = await rm.PathToAbsolute('#@#file.txt');
270+
271+
// Execute Rainmeter bang
272+
rm.Execute('[!SetVariable MyVar "Hello"]');
273+
274+
// Log message to Rainmeter log
275+
rm.Log('Message from JavaScript', 'Notice'); // Levels: Notice, Warning, Error, Debug
276+
```
277+
278+
#### Information Properties
279+
280+
```javascript
281+
// Get measure name
282+
const measureName = await rm.MeasureName;
283+
284+
// Get skin name
285+
const skinName = await rm.SkinName;
286+
287+
// Get skin window handle
288+
const handle = await rm.SkinWindowHandle;
289+
290+
// Get settings file path
291+
const settingsFile = await rm.SettingsFile;
292+
```
293+
294+
### Complete Example
295+
296+
```html
297+
<!DOCTYPE html>
298+
<html>
299+
<head>
300+
<title>Rainmeter Integration</title>
301+
</head>
302+
<body>
303+
<h1>Rainmeter API Demo</h1>
304+
<button onclick="updateFromRainmeter()">Get Skin Info</button>
305+
<div id="output"></div>
306+
307+
<script>
308+
async function updateFromRainmeter() {
309+
try {
310+
// Read values from Rainmeter
311+
const width = await rm.ReadInt('Width', 800);
312+
const skinName = await rm.SkinName;
313+
314+
// Display results
315+
document.getElementById('output').innerHTML =
316+
`Skin: ${skinName}<br>Width: ${width}px`;
317+
318+
// Log to Rainmeter
319+
rm.Log('Updated from JavaScript', 'Notice');
320+
321+
// Execute Rainmeter command
322+
rm.Execute('[!UpdateMeter *][!Redraw]');
323+
} catch (error) {
324+
console.error('Error:', error);
325+
}
326+
}
327+
</script>
328+
</body>
329+
</html>
330+
```
331+
332+
### Notes
333+
334+
- All read methods return Promises and should be used with `await` or `.then()`
335+
- Execute and Log methods are fire-and-forget (no return value)
336+
- Property getters (MeasureName, SkinName, etc.) also return Promises
337+
- The `rm` object is automatically available in all pages loaded by the plugin
338+
- No additional setup or imports required
339+
182340
## 🔧 Building from Source
183341

184342
### Prerequisites

0 commit comments

Comments
 (0)