@bobfrankston/msgapidefs
v0.1.29
Published
TypeScript definitions for msgapi JavaScript API (msgview/msger)
Downloads
1,536
Maintainers
Readme
@bobfrankston/msgapidefs
TypeScript definitions for the msgapi JavaScript API used in msgview and msger.
Installation
npm install @bobfrankston/msgapidefsUsage
// Import to register global window.msgapi type
import '../node_modules/@bobfrankston/msgapidefs/msgapidefs.js';
// Note: '../node_modules/@bobfrankston/msgapidefs/index.js' may also work via package.json exports
// Or import types explicitly
import type { MsgAPI, MsgResult } from '../node_modules/@bobfrankston/msgapidefs/msgapidefs.js';
// msgapi provides APIs not available in browsers/webviews
if (window.msgapi) {
// Window control beyond browser capabilities
window.msgapi.setFullscreen(true);
window.msgapi.setAlwaysOnTop(true);
// File system access (requires allowFs flag)
const file = await window.msgapi.fs?.selectFile();
}
// For standard browser APIs, use native methods:
document.title = 'My App'; // Instead of msgapi.setTitle()
localStorage.setItem('key', 'value'); // Instead of msgapi.saveData()
window.close(); // Instead of msgapi.close() if not passing resultAPI Reference
Window Control
toggleFullscreen()- Toggle fullscreen modesetFullscreen(enabled: boolean)- Set fullscreen stateminimize()- Minimize windowmaximize()- Toggle maximize/restoresetSize(width, height)- Set window sizesetPosition(x, y)- Set window positionsetAlwaysOnTop(enabled: boolean)- Keep window on topclose(result?)- Close window and return result to parent process
File System
fs.selectFile(options?)- Open file pickerfs.selectFiles(options?)- Open multi-file pickerfs.saveFileAs(content, filename?, options?)- Save file dialogfs.selectFolder(options?)- Folder pickerfs.read(path)- Read file (requires allowFs flag)fs.write(path, content)- Write file (requires allowFs flag)fs.list(path)- List directory (requires allowFs flag)fs.exists(path)- Check if file exists (requires allowFs flag)fs.delete(path)- Delete file (requires allowFs flag)
Examples
See samples.html for interactive examples and demos of all API features!
Test in msgview:
msgview -url "file:///path/to/node_modules/@bobfrankston/msgapidefs/samples.html"Test in msger:
msger -url "file:///path/to/node_modules/@bobfrankston/msgapidefs/samples.html"Test in browser:
# Open samples.html in your browser to test browser compatibilityThe samples demonstrate:
- Window control (fullscreen, minimize, maximize, resize, position)
- Data persistence (save/load user preferences, session data, recent files)
- Presentation mode example
- Session management
- And more!
Related Packages
- @bobfrankston/msgview - Electron-based message box (slower, works on Pi)
- @bobfrankston/msger - Rust/wry-based message box (fast, lightweight)
License
ISC
