@bobfrankston/msger 0.1.377 → 0.1.380
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +34 -2
- package/cli.js +12 -2
- package/msger-native/bin/msgernative.exe +0 -0
- package/package.json +1 -1
- package/shower.d.ts +1 -0
- package/shower.js +2 -1
package/README.md
CHANGED
|
@@ -92,6 +92,32 @@ msger -url "https://example.com" -dev
|
|
|
92
92
|
msger --help
|
|
93
93
|
```
|
|
94
94
|
|
|
95
|
+
### Headless mode (`-noshow`) — use the WebView as a CSS/JS engine
|
|
96
|
+
|
|
97
|
+
`-noshow` doesn't open a visible window, but the WebView still loads HTML, runs `<script>` blocks, and resolves CSS — so an embedded script can query the engine and post a result back via `window.ipc.postMessage`. Combined with `-result <fieldname>` to print just one field, this lets you use msger as a headless rendering engine for things like `contrast-color()`, `getComputedStyle()`, and `CSS.supports()`.
|
|
98
|
+
|
|
99
|
+
```bash
|
|
100
|
+
# Resolve contrast-color() — needs a DOM element + getComputedStyle because
|
|
101
|
+
# CSS functions only resolve through the cascade.
|
|
102
|
+
msger -noshow -html '<div id=x style="color:contrast-color(steelblue)"></div>
|
|
103
|
+
<script>
|
|
104
|
+
requestAnimationFrame(() => requestAnimationFrame(() => {
|
|
105
|
+
window.ipc.postMessage(JSON.stringify({
|
|
106
|
+
button: "r",
|
|
107
|
+
value: getComputedStyle(document.getElementById("x")).color
|
|
108
|
+
}));
|
|
109
|
+
}));
|
|
110
|
+
</script>' -result value
|
|
111
|
+
# → rgb(255, 255, 255)
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
The Node API works the same way — pass `noshow: true` and `html: "..."` to `showMessageBox`, then read `result.value` from the resolved promise.
|
|
115
|
+
|
|
116
|
+
Notes:
|
|
117
|
+
- `-result <fieldname>` prints just that field's value (string as-is, other types JSON-stringified) instead of the full `MessageBoxResult` JSON. Useful for shell consumption.
|
|
118
|
+
- The two `requestAnimationFrame` calls let layout settle before reading computed style — needed for `contrast-color`, gradients, etc.
|
|
119
|
+
- The original `-noshow -save` behavior is unchanged: it still exits after saving without ever creating a WebView.
|
|
120
|
+
|
|
95
121
|
## JSON Configuration Files
|
|
96
122
|
|
|
97
123
|
You can store message box configuration in a JSON file for reuse. JSON files support comments (JSON5 format).
|
|
@@ -118,7 +144,7 @@ msger -title "Test" -message "Saving config..." -save test.json
|
|
|
118
144
|
|
|
119
145
|
**Notes:**
|
|
120
146
|
- The `-save` option saves only the explicitly specified command-line arguments, not derived defaults. This keeps config files minimal and allows defaults to evolve.
|
|
121
|
-
-
|
|
147
|
+
- `-noshow` with `-save` writes the config and exits without ever creating a WebView. Without `-save`, `-noshow` creates the WebView and runs scripts but doesn't open a visible window — useful for headless CSS/JS resolution (see "Headless mode" below).
|
|
122
148
|
- File extensions: If you don't specify `.json`, it will be added automatically (e.g., `myconfig` becomes `myconfig.json`).
|
|
123
149
|
|
|
124
150
|
### Complete JSON Structure
|
|
@@ -264,8 +290,14 @@ Options:
|
|
|
264
290
|
-fullscreen, --fullscreen Start window in fullscreen mode (F11 to toggle, Escape to exit)
|
|
265
291
|
-raw, --raw With -html: load HTML as-is, no msger template/buttons (alias: -full)
|
|
266
292
|
-debug, --debug Return debug info (HTML, size, autoSize) in result
|
|
293
|
+
-noshow, --noshow Don't display the window. With -save, exits after saving.
|
|
294
|
+
Otherwise the WebView still loads + runs scripts so a page
|
|
295
|
+
can post a result via window.ipc.postMessage; only the
|
|
296
|
+
window isn't shown. Useful for headless CSS/JS resolution.
|
|
267
297
|
-noresult, --noresult Suppress JSON result output on stdout (errors still go to stderr)
|
|
268
|
-
-result, --result
|
|
298
|
+
-result, --result [fieldname] Re-enable result output. With <fieldname>, print just that
|
|
299
|
+
field (e.g. -result value → bare string). Strings print as-is,
|
|
300
|
+
other types JSON-stringify. Missing field → exit 2.
|
|
269
301
|
-v, -version, --version Show version number
|
|
270
302
|
-help, -?, --help Show help message
|
|
271
303
|
|
package/cli.js
CHANGED
|
@@ -40,12 +40,19 @@ Options:
|
|
|
40
40
|
-ontop Keep window always on top of other windows
|
|
41
41
|
-load <file> Load options from JSON file (supports comments)
|
|
42
42
|
-save <file> Save current options to JSON file
|
|
43
|
-
-noshow
|
|
43
|
+
-noshow Don't display the window. With -save, also exits after saving.
|
|
44
|
+
Otherwise the WebView still loads and runs scripts (so a page can
|
|
45
|
+
query the DOM/CSS and post a result via window.ipc.postMessage)
|
|
46
|
+
— only the window isn't mapped on screen. Useful for headless
|
|
47
|
+
CSS/JS resolution (e.g. contrast-color, getComputedStyle).
|
|
44
48
|
-pin Create pinnable Start Menu shortcut (requires -load)
|
|
45
49
|
-dev Open DevTools (F12) automatically on startup (for debugging)
|
|
46
50
|
-debug Return debug info (HTML, size) in result
|
|
47
51
|
-noresult Suppress JSON result output on stdout (errors still go to stderr)
|
|
48
|
-
-result
|
|
52
|
+
-result [fieldname] Re-enable result output (overrides -noresult from a config file).
|
|
53
|
+
With <fieldname>, print just that field's value (e.g. -result value
|
|
54
|
+
prints only result.value, no JSON wrapper). Strings print as-is;
|
|
55
|
+
other types JSON-stringify. Missing field → exit 2.
|
|
49
56
|
-v, -version, --version Show version number (alone: print and exit; with options: show in title)
|
|
50
57
|
-help, -?, --help Show this help message
|
|
51
58
|
|
|
@@ -63,6 +70,9 @@ Examples:
|
|
|
63
70
|
echo -e "\\x1b[31mError:\\x1b[0m Something failed" | msger
|
|
64
71
|
echo '{"message":"Test","buttons":["OK"]}' | msger
|
|
65
72
|
|
|
73
|
+
# Headless evaluation — use the WebView as a CSS/JS engine, no UI
|
|
74
|
+
msger -noshow -html "<div id=x style='color:contrast-color(steelblue)'></div><script>requestAnimationFrame(()=>requestAnimationFrame(()=>window.ipc.postMessage(JSON.stringify({button:'x',value:getComputedStyle(document.getElementById('x')).color}))))</script>" -result value
|
|
75
|
+
|
|
66
76
|
Notes:
|
|
67
77
|
- If no options are provided, all non-option arguments are concatenated as the message
|
|
68
78
|
- Message text supports ANSI color codes (automatically converted to HTML)
|
|
Binary file
|
package/package.json
CHANGED
package/shower.d.ts
CHANGED
|
@@ -50,6 +50,7 @@ export interface MessageBoxOptions {
|
|
|
50
50
|
initScriptPath?: string; /** Path to JS file injected into WebView (avoids large JSON) */
|
|
51
51
|
service?: boolean; /** Service mode: bidirectional IPC with parent. Stdin/stdout stay open. */
|
|
52
52
|
contentDir?: string; /** Base directory for custom protocol file serving (avoids file:// URLs) */
|
|
53
|
+
hidden?: boolean; /** Create the window invisible. The WebView still renders so JS / CSS / layout queries (e.g. `getComputedStyle`, `contrast-color()`) resolve; the window just isn't mapped on screen. Set by the CLI's `-noshow` flag. */
|
|
53
54
|
}
|
|
54
55
|
export interface MessageBoxResult {
|
|
55
56
|
button: string;
|
package/shower.js
CHANGED
|
@@ -675,7 +675,8 @@ export function showService(options) {
|
|
|
675
675
|
if (!rustOptions.app_name)
|
|
676
676
|
rustOptions.app_name = _appName;
|
|
677
677
|
const jsonToSend = JSON.stringify(rustOptions);
|
|
678
|
-
|
|
678
|
+
if (process.env.MSGER_DEBUG)
|
|
679
|
+
console.log(`[service] Sending to Rust: ${jsonToSend.slice(0, 200)}`);
|
|
679
680
|
child.stdin?.write(jsonToSend + "\n");
|
|
680
681
|
return new ServiceHandle(child);
|
|
681
682
|
}
|