@bobfrankston/msgapidefs 0.1.2 → 0.1.4
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/.claude/settings.local.json +5 -1
- package/README.md +19 -55
- package/msgapidefs.d.ts +2 -64
- package/msgapidefs.js +1 -14
- package/msgapidefs.ts +3 -75
- package/package.json +1 -1
- package/samples.html +30 -10
package/README.md
CHANGED
|
@@ -10,47 +10,28 @@ npm install @bobfrankston/msgapidefs
|
|
|
10
10
|
|
|
11
11
|
## Usage
|
|
12
12
|
|
|
13
|
-
### TypeScript
|
|
14
|
-
|
|
15
13
|
```typescript
|
|
16
|
-
|
|
17
|
-
import
|
|
18
|
-
|
|
19
|
-
// Option 1: Type the global window.msgapi
|
|
20
|
-
declare global {
|
|
21
|
-
interface Window {
|
|
22
|
-
msgapi?: MsgAPI;
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
// Check if running in msgview/msger
|
|
27
|
-
if (isMsgAPI()) {
|
|
28
|
-
window.msgapi!.setTitle('My Application');
|
|
29
|
-
window.msgapi!.saveData('lastOpened', new Date().toISOString());
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
// Option 2: Use getMsgAPI() for cross-platform compatibility
|
|
33
|
-
const msgapi = getMsgAPI();
|
|
34
|
-
msgapi.saveData('userPrefs', { theme: 'dark' }); // Works in both msgview/msger and browser!
|
|
35
|
-
msgapi.setTitle('My App'); // Only works in msgview/msger, no-op in browser
|
|
36
|
-
```
|
|
37
|
-
|
|
38
|
-
### JavaScript
|
|
14
|
+
// Import to register global window.msgapi type
|
|
15
|
+
import '../node_modules/@bobfrankston/msgapidefs/msgapidefs.js';
|
|
16
|
+
// Note: '../node_modules/@bobfrankston/msgapidefs/index.js' may also work via package.json exports
|
|
39
17
|
|
|
40
|
-
|
|
41
|
-
import {
|
|
18
|
+
// Or import types explicitly
|
|
19
|
+
import type { MsgAPI, MsgResult } from '../node_modules/@bobfrankston/msgapidefs/msgapidefs.js';
|
|
42
20
|
|
|
43
|
-
|
|
21
|
+
// msgapi provides APIs not available in browsers/webviews
|
|
22
|
+
if (window.msgapi) {
|
|
23
|
+
// Window control beyond browser capabilities
|
|
24
|
+
window.msgapi.setFullscreen(true);
|
|
25
|
+
window.msgapi.setAlwaysOnTop(true);
|
|
44
26
|
|
|
45
|
-
//
|
|
46
|
-
|
|
47
|
-
const settings = msgapi.loadData('userSettings', { fontSize: 12 });
|
|
48
|
-
|
|
49
|
-
// Window control (msgview/msger only, gracefully degrades in browser)
|
|
50
|
-
if (isMsgAPI()) {
|
|
51
|
-
msgapi.toggleFullscreen();
|
|
52
|
-
msgapi.setAlwaysOnTop(true);
|
|
27
|
+
// File system access (requires allowFs flag)
|
|
28
|
+
const file = await window.msgapi.fs?.selectFile();
|
|
53
29
|
}
|
|
30
|
+
|
|
31
|
+
// For standard browser APIs, use native methods:
|
|
32
|
+
document.title = 'My App'; // Instead of msgapi.setTitle()
|
|
33
|
+
localStorage.setItem('key', 'value'); // Instead of msgapi.saveData()
|
|
34
|
+
window.close(); // Instead of msgapi.close() if not passing result
|
|
54
35
|
```
|
|
55
36
|
|
|
56
37
|
## API Reference
|
|
@@ -64,17 +45,9 @@ if (isMsgAPI()) {
|
|
|
64
45
|
- `setSize(width, height)` - Set window size
|
|
65
46
|
- `setPosition(x, y)` - Set window position
|
|
66
47
|
- `setAlwaysOnTop(enabled: boolean)` - Keep window on top
|
|
67
|
-
- `
|
|
68
|
-
- `close(result?)` - Close window with optional result
|
|
69
|
-
|
|
70
|
-
### Data Persistence
|
|
71
|
-
|
|
72
|
-
- `saveData(key, value)` - Save data to localStorage
|
|
73
|
-
- `loadData(key, defaultValue?)` - Load data from localStorage
|
|
74
|
-
- `removeData(key)` - Remove data
|
|
75
|
-
- `clearData()` - Clear all msgapi data
|
|
48
|
+
- `close(result?)` - Close window and return result to parent process
|
|
76
49
|
|
|
77
|
-
### File System
|
|
50
|
+
### File System
|
|
78
51
|
|
|
79
52
|
- `fs.selectFile(options?)` - Open file picker
|
|
80
53
|
- `fs.selectFiles(options?)` - Open multi-file picker
|
|
@@ -112,15 +85,6 @@ The samples demonstrate:
|
|
|
112
85
|
- Session management
|
|
113
86
|
- And more!
|
|
114
87
|
|
|
115
|
-
## Browser Compatibility
|
|
116
|
-
|
|
117
|
-
The `getMsgAPI()` function returns a browser-compatible implementation:
|
|
118
|
-
|
|
119
|
-
- **Data persistence**: Uses localStorage in both msgview/msger and browser
|
|
120
|
-
- **Window control**: No-op in browser (except `setTitle` updates document.title)
|
|
121
|
-
- **File system**: Not available in browser (`fs` is undefined)
|
|
122
|
-
|
|
123
|
-
This allows you to write code once that works in both environments!
|
|
124
88
|
|
|
125
89
|
## Related Packages
|
|
126
90
|
|
package/msgapidefs.d.ts
CHANGED
|
@@ -4,20 +4,7 @@
|
|
|
4
4
|
* This module provides type-safe access to msgapi's window control,
|
|
5
5
|
* data persistence, and file system features (used by msgview and msger).
|
|
6
6
|
*
|
|
7
|
-
*
|
|
8
|
-
* ```typescript
|
|
9
|
-
* // Import to register global window.msgapi type (browser direct import)
|
|
10
|
-
* import '../node_modules/@bobfrankston/msgapidefs/msgapidefs.js';
|
|
11
|
-
* // Note: '../node_modules/@bobfrankston/msgapidefs/index.js' may also work via package.json exports
|
|
12
|
-
*
|
|
13
|
-
* // Or import types explicitly
|
|
14
|
-
* import type { MsgAPI, MsgResult } from '../node_modules/@bobfrankston/msgapidefs/msgapidefs.js';
|
|
15
|
-
*
|
|
16
|
-
* // window.msgapi is now typed automatically
|
|
17
|
-
* if (window.msgapi) {
|
|
18
|
-
* window.msgapi.setTitle('My App');
|
|
19
|
-
* }
|
|
20
|
-
* ```
|
|
7
|
+
* See README.md for complete usage documentation and examples.
|
|
21
8
|
*/
|
|
22
9
|
/**
|
|
23
10
|
* Result object returned when the window closes
|
|
@@ -133,14 +120,7 @@ export interface MsgAPI {
|
|
|
133
120
|
*/
|
|
134
121
|
setAlwaysOnTop(enabled: boolean): void;
|
|
135
122
|
/**
|
|
136
|
-
*
|
|
137
|
-
* @param title - New window title
|
|
138
|
-
* @example
|
|
139
|
-
* msgapi.setTitle("My Application");
|
|
140
|
-
*/
|
|
141
|
-
setTitle(title: string): void;
|
|
142
|
-
/**
|
|
143
|
-
* Close the window
|
|
123
|
+
* Close the window and return result to parent process
|
|
144
124
|
* @param result - Optional result to return to parent process
|
|
145
125
|
* @example
|
|
146
126
|
* // Close with default dismissed result
|
|
@@ -150,48 +130,6 @@ export interface MsgAPI {
|
|
|
150
130
|
* msgapi.close({button: 'OK', value: 'user data'});
|
|
151
131
|
*/
|
|
152
132
|
close(result?: Partial<MsgResult>): void;
|
|
153
|
-
/**
|
|
154
|
-
* Send result and close window (legacy compatibility)
|
|
155
|
-
* @param result - Result to return to parent process
|
|
156
|
-
* @example
|
|
157
|
-
* msgapi.sendResult({button: 'Submit', value: 'form data'});
|
|
158
|
-
*/
|
|
159
|
-
sendResult(result: Partial<MsgResult>): void;
|
|
160
|
-
/**
|
|
161
|
-
* Save data to persistent storage
|
|
162
|
-
* Data is stored with 'msgapi_' prefix in localStorage
|
|
163
|
-
* @param key - Storage key
|
|
164
|
-
* @param value - Value to store (will be JSON.stringify'd)
|
|
165
|
-
* @returns true on success, false on failure
|
|
166
|
-
* @example
|
|
167
|
-
* msgapi.saveData('userPrefs', {theme: 'dark', fontSize: 14});
|
|
168
|
-
*/
|
|
169
|
-
saveData(key: string, value: any): boolean;
|
|
170
|
-
/**
|
|
171
|
-
* Load data from persistent storage
|
|
172
|
-
* @param key - Storage key
|
|
173
|
-
* @param defaultValue - Default value if key not found
|
|
174
|
-
* @returns Stored value or defaultValue
|
|
175
|
-
* @example
|
|
176
|
-
* const prefs = msgapi.loadData('userPrefs', {theme: 'light'});
|
|
177
|
-
*/
|
|
178
|
-
loadData<T = any>(key: string, defaultValue?: T): T;
|
|
179
|
-
/**
|
|
180
|
-
* Remove data from persistent storage
|
|
181
|
-
* @param key - Storage key to remove
|
|
182
|
-
* @returns true on success, false on failure
|
|
183
|
-
* @example
|
|
184
|
-
* msgapi.removeData('tempData');
|
|
185
|
-
*/
|
|
186
|
-
removeData(key: string): boolean;
|
|
187
|
-
/**
|
|
188
|
-
* Clear all msgapi data from persistent storage
|
|
189
|
-
* Only removes items with 'msgapi_' prefix
|
|
190
|
-
* @returns true on success, false on failure
|
|
191
|
-
* @example
|
|
192
|
-
* msgapi.clearData();
|
|
193
|
-
*/
|
|
194
|
-
clearData(): boolean;
|
|
195
133
|
/**
|
|
196
134
|
* File system operations namespace
|
|
197
135
|
*/
|
package/msgapidefs.js
CHANGED
|
@@ -4,19 +4,6 @@
|
|
|
4
4
|
* This module provides type-safe access to msgapi's window control,
|
|
5
5
|
* data persistence, and file system features (used by msgview and msger).
|
|
6
6
|
*
|
|
7
|
-
*
|
|
8
|
-
* ```typescript
|
|
9
|
-
* // Import to register global window.msgapi type (browser direct import)
|
|
10
|
-
* import '../node_modules/@bobfrankston/msgapidefs/msgapidefs.js';
|
|
11
|
-
* // Note: '../node_modules/@bobfrankston/msgapidefs/index.js' may also work via package.json exports
|
|
12
|
-
*
|
|
13
|
-
* // Or import types explicitly
|
|
14
|
-
* import type { MsgAPI, MsgResult } from '../node_modules/@bobfrankston/msgapidefs/msgapidefs.js';
|
|
15
|
-
*
|
|
16
|
-
* // window.msgapi is now typed automatically
|
|
17
|
-
* if (window.msgapi) {
|
|
18
|
-
* window.msgapi.setTitle('My App');
|
|
19
|
-
* }
|
|
20
|
-
* ```
|
|
7
|
+
* See README.md for complete usage documentation and examples.
|
|
21
8
|
*/
|
|
22
9
|
export {};
|
package/msgapidefs.ts
CHANGED
|
@@ -4,20 +4,7 @@
|
|
|
4
4
|
* This module provides type-safe access to msgapi's window control,
|
|
5
5
|
* data persistence, and file system features (used by msgview and msger).
|
|
6
6
|
*
|
|
7
|
-
*
|
|
8
|
-
* ```typescript
|
|
9
|
-
* // Import to register global window.msgapi type (browser direct import)
|
|
10
|
-
* import '../node_modules/@bobfrankston/msgapidefs/msgapidefs.js';
|
|
11
|
-
* // Note: '../node_modules/@bobfrankston/msgapidefs/index.js' may also work via package.json exports
|
|
12
|
-
*
|
|
13
|
-
* // Or import types explicitly
|
|
14
|
-
* import type { MsgAPI, MsgResult } from '../node_modules/@bobfrankston/msgapidefs/msgapidefs.js';
|
|
15
|
-
*
|
|
16
|
-
* // window.msgapi is now typed automatically
|
|
17
|
-
* if (window.msgapi) {
|
|
18
|
-
* window.msgapi.setTitle('My App');
|
|
19
|
-
* }
|
|
20
|
-
* ```
|
|
7
|
+
* See README.md for complete usage documentation and examples.
|
|
21
8
|
*/
|
|
22
9
|
|
|
23
10
|
/**
|
|
@@ -146,15 +133,7 @@ export interface MsgAPI {
|
|
|
146
133
|
setAlwaysOnTop(enabled: boolean): void;
|
|
147
134
|
|
|
148
135
|
/**
|
|
149
|
-
*
|
|
150
|
-
* @param title - New window title
|
|
151
|
-
* @example
|
|
152
|
-
* msgapi.setTitle("My Application");
|
|
153
|
-
*/
|
|
154
|
-
setTitle(title: string): void;
|
|
155
|
-
|
|
156
|
-
/**
|
|
157
|
-
* Close the window
|
|
136
|
+
* Close the window and return result to parent process
|
|
158
137
|
* @param result - Optional result to return to parent process
|
|
159
138
|
* @example
|
|
160
139
|
* // Close with default dismissed result
|
|
@@ -165,59 +144,8 @@ export interface MsgAPI {
|
|
|
165
144
|
*/
|
|
166
145
|
close(result?: Partial<MsgResult>): void;
|
|
167
146
|
|
|
168
|
-
/**
|
|
169
|
-
* Send result and close window (legacy compatibility)
|
|
170
|
-
* @param result - Result to return to parent process
|
|
171
|
-
* @example
|
|
172
|
-
* msgapi.sendResult({button: 'Submit', value: 'form data'});
|
|
173
|
-
*/
|
|
174
|
-
sendResult(result: Partial<MsgResult>): void;
|
|
175
|
-
|
|
176
|
-
// ========================================
|
|
177
|
-
// Data Persistence (localStorage wrapper)
|
|
178
|
-
// ========================================
|
|
179
|
-
|
|
180
|
-
/**
|
|
181
|
-
* Save data to persistent storage
|
|
182
|
-
* Data is stored with 'msgapi_' prefix in localStorage
|
|
183
|
-
* @param key - Storage key
|
|
184
|
-
* @param value - Value to store (will be JSON.stringify'd)
|
|
185
|
-
* @returns true on success, false on failure
|
|
186
|
-
* @example
|
|
187
|
-
* msgapi.saveData('userPrefs', {theme: 'dark', fontSize: 14});
|
|
188
|
-
*/
|
|
189
|
-
saveData(key: string, value: any): boolean;
|
|
190
|
-
|
|
191
|
-
/**
|
|
192
|
-
* Load data from persistent storage
|
|
193
|
-
* @param key - Storage key
|
|
194
|
-
* @param defaultValue - Default value if key not found
|
|
195
|
-
* @returns Stored value or defaultValue
|
|
196
|
-
* @example
|
|
197
|
-
* const prefs = msgapi.loadData('userPrefs', {theme: 'light'});
|
|
198
|
-
*/
|
|
199
|
-
loadData<T = any>(key: string, defaultValue?: T): T;
|
|
200
|
-
|
|
201
|
-
/**
|
|
202
|
-
* Remove data from persistent storage
|
|
203
|
-
* @param key - Storage key to remove
|
|
204
|
-
* @returns true on success, false on failure
|
|
205
|
-
* @example
|
|
206
|
-
* msgapi.removeData('tempData');
|
|
207
|
-
*/
|
|
208
|
-
removeData(key: string): boolean;
|
|
209
|
-
|
|
210
|
-
/**
|
|
211
|
-
* Clear all msgapi data from persistent storage
|
|
212
|
-
* Only removes items with 'msgapi_' prefix
|
|
213
|
-
* @returns true on success, false on failure
|
|
214
|
-
* @example
|
|
215
|
-
* msgapi.clearData();
|
|
216
|
-
*/
|
|
217
|
-
clearData(): boolean;
|
|
218
|
-
|
|
219
147
|
// ========================================
|
|
220
|
-
// File System Access
|
|
148
|
+
// File System Access
|
|
221
149
|
// ========================================
|
|
222
150
|
|
|
223
151
|
/**
|
package/package.json
CHANGED
package/samples.html
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
<!DOCTYPE html>
|
|
2
1
|
<html>
|
|
3
2
|
<head>
|
|
4
3
|
<meta charset="UTF-8">
|
|
@@ -72,6 +71,27 @@
|
|
|
72
71
|
border-radius: 3px;
|
|
73
72
|
font-family: 'Courier New', monospace;
|
|
74
73
|
}
|
|
74
|
+
button.danger {
|
|
75
|
+
background: #dc3545;
|
|
76
|
+
}
|
|
77
|
+
button.danger:hover {
|
|
78
|
+
background: #c82333;
|
|
79
|
+
}
|
|
80
|
+
.small-text {
|
|
81
|
+
font-size: 12px;
|
|
82
|
+
color: #666;
|
|
83
|
+
margin-top: 10px;
|
|
84
|
+
}
|
|
85
|
+
.medium-text {
|
|
86
|
+
margin-top: 10px;
|
|
87
|
+
font-size: 13px;
|
|
88
|
+
}
|
|
89
|
+
h3.spaced {
|
|
90
|
+
margin-top: 20px;
|
|
91
|
+
}
|
|
92
|
+
ul.feature-list {
|
|
93
|
+
font-size: 13px;
|
|
94
|
+
}
|
|
75
95
|
</style>
|
|
76
96
|
</head>
|
|
77
97
|
<body>
|
|
@@ -118,11 +138,11 @@
|
|
|
118
138
|
<div class="section">
|
|
119
139
|
<h2>Window Controls (⚠️ Currently Broken)</h2>
|
|
120
140
|
<p>These buttons demonstrate the broken IPC window controls. They will log errors but not crash.</p>
|
|
121
|
-
<button onclick="tryOK()"
|
|
122
|
-
<button onclick="tryCancel()"
|
|
123
|
-
<button onclick="tryClose()"
|
|
141
|
+
<button onclick="tryOK()" class="danger">Try OK (Logs Error)</button>
|
|
142
|
+
<button onclick="tryCancel()" class="danger secondary">Try Cancel (Logs Error)</button>
|
|
143
|
+
<button onclick="tryClose()" class="danger secondary">Try Close (Logs Error)</button>
|
|
124
144
|
<div id="outputControls" class="output">Click any button to see why window controls don't work</div>
|
|
125
|
-
<p
|
|
145
|
+
<p class="small-text">
|
|
126
146
|
<strong>Why broken:</strong> wry 0.47.2 has a bug where window.ipc.postMessage() crashes with "InvalidUri" error.<br>
|
|
127
147
|
<strong>Workarounds:</strong> Use CLI flags (-size, -title), F11 for fullscreen, X button to close, or Alt+F4.
|
|
128
148
|
</p>
|
|
@@ -145,18 +165,18 @@
|
|
|
145
165
|
<h2>Storage Location & PWA Support</h2>
|
|
146
166
|
<p><strong>localStorage is saved to:</strong></p>
|
|
147
167
|
<code>%LOCALAPPDATA%\Microsoft\Edge\User Data\WebView2\Default\Local Storage\leveldb\</code>
|
|
148
|
-
<p
|
|
168
|
+
<p class="medium-text">
|
|
149
169
|
Data persists across sessions and survives app restarts.
|
|
150
170
|
Each URL origin has its own storage partition.
|
|
151
171
|
</p>
|
|
152
172
|
<button onclick="showStorageInfo()">Show Storage Info</button>
|
|
153
173
|
<div id="output5" class="output">Click to see current storage info</div>
|
|
154
174
|
|
|
155
|
-
<h3
|
|
156
|
-
<p
|
|
175
|
+
<h3 class="spaced">PWA Support ✅</h3>
|
|
176
|
+
<p class="medium-text">
|
|
157
177
|
msger supports Progressive Web Apps loaded via <code>-url</code>:
|
|
158
178
|
</p>
|
|
159
|
-
<ul
|
|
179
|
+
<ul class="feature-list">
|
|
160
180
|
<li>✅ <strong>Service Workers</strong> - Background sync, offline support</li>
|
|
161
181
|
<li>✅ <strong>IndexedDB</strong> - Large data storage (GBs)</li>
|
|
162
182
|
<li>✅ <strong>Cache API</strong> - Offline assets</li>
|
|
@@ -165,7 +185,7 @@
|
|
|
165
185
|
<li>❌ <strong>Push Notifications</strong> - Platform dependent</li>
|
|
166
186
|
<li>❌ <strong>"Install" UI</strong> - Already native window</li>
|
|
167
187
|
</ul>
|
|
168
|
-
<p
|
|
188
|
+
<p class="small-text">
|
|
169
189
|
Example: <code>node cli.js -url https://your-pwa.app -detach</code>
|
|
170
190
|
</p>
|
|
171
191
|
</div>
|