@bobfrankston/msger 0.1.101 → 0.1.103

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.
Binary file
Binary file
@@ -251,6 +251,7 @@ fn generate_html(options: &MessageBoxOptions) -> String {
251
251
  .replace("{BUTTONS}", &buttons_html)
252
252
  .replace("{AUTO_SIZE}", if options.auto_size { "true" } else { "false" })
253
253
  .replace("{FULLSCREEN}", if options.fullscreen { "true" } else { "false" })
254
+ .replace("{ESCAPE_CLOSES}", if options.escape_closes { "true" } else { "false" })
254
255
  .replace("{ZOOM_PERCENT}", &options.zoom_percent.unwrap_or(100.0).to_string())
255
256
  .replace("{DEFAULT_BUTTON}", options.buttons.first().unwrap_or(&"Cancel".to_string()))
256
257
  .replace("{TIMEOUT_SECONDS}", &options.timeout.map(|t| t.to_string()).unwrap_or_else(|| "0".to_string()));
@@ -108,6 +108,9 @@
108
108
  </div>
109
109
  -->
110
110
  <script>
111
+ // Initialize config from Rust
112
+ window.msgerConfig = { escapeCloses: {ESCAPE_CLOSES} };
113
+
111
114
  // msger JavaScript API with error handling
112
115
  (function() {
113
116
  // Check if IPC is available
@@ -316,16 +319,25 @@
316
319
  document.addEventListener('keydown', function(e) {
317
320
  if (e.key === 'Escape') {
318
321
  e.preventDefault();
319
- // Try to exit fullscreen first
320
- if (document.fullscreenElement) {
321
- document.exitFullscreen();
322
- } else {
323
- // CANNOT use IPC - it crashes!
324
- // The Rust window handler should catch Esc key
325
- console.error('Esc key: Cannot send via IPC (crashes). Close window with X button instead.');
326
- // const result = { button: 'Cancel', dismissed: true };
327
- // window.ipc.postMessage(JSON.stringify(result));
322
+ e.stopImmediatePropagation();
323
+
324
+ // Check config (defaults to true for backwards compatibility)
325
+ const escapeCloses = window.msgerConfig?.escapeCloses !== false;
326
+
327
+ // Send IPC message to Rust handler
328
+ try {
329
+ if (typeof window.ipc !== 'undefined' && window.ipc.postMessage) {
330
+ window.ipc.postMessage(JSON.stringify({
331
+ _action: 'escape',
332
+ canClose: escapeCloses
333
+ }));
334
+ } else {
335
+ console.warn('[MSGER] IPC not available for escape');
336
+ }
337
+ } catch(err) {
338
+ console.error('[MSGER] Failed to handle escape:', err);
328
339
  }
340
+ return;
329
341
  } else if (e.key === 'F11') {
330
342
  // Use IPC to toggle native window fullscreen instead of HTML5 fullscreen
331
343
  e.preventDefault();
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bobfrankston/msger",
3
- "version": "0.1.101",
3
+ "version": "0.1.103",
4
4
  "description": "Fast, lightweight, cross-platform message box - Rust-powered alternative to msgview",
5
5
  "type": "module",
6
6
  "main": "./index.js",