# Programmatic Close API

msger now supports programmatically closing dialogs from the parent process.

## API Options

### 1. Handle-Based API (Recommended)

```javascript
import { showMessageBoxEx } from '@bobfrankston/msger';

const handle = showMessageBoxEx({
    message: 'Please wait...',
    buttons: ['Cancel']
});

console.log('Dialog PID:', handle.pid);

// Close later
setTimeout(() => {
    handle.close();
}, 5000);

// Wait for result
const result = await handle.result;
console.log('Result:', result); // {button: 'closed', closed: true}
```

### 2. Standalone Function

```javascript
import { showMessageBoxEx, closeMessageBox } from '@bobfrankston/msger';

const handle = showMessageBoxEx({
    message: 'Processing...'
});

const pid = handle.pid;

// Close by PID from anywhere
closeMessageBox(pid);
```

### 3. Legacy Promise API (Backward Compatible)

```javascript
import { showMessageBox } from '@bobfrankston/msger';

// Still works - returns promise directly
const result = await showMessageBox({
    message: 'Hello'
});
```

## Return Values

When closed programmatically:
```json
{
  "button": "closed",
  "closed": true
}
```

When user clicks button:
```json
{
  "button": "OK"
}
```

When user presses Escape:
```json
{
  "button": "dismissed",
  "dismissed": true
}
```

## Use Cases

- Progress dialogs that auto-close when task completes
- Timeout-based notifications
- Multi-dialog management
- Detached dialogs (launched then closed remotely)

## Compatibility

- Windows: ✅ Tested
- Linux: ✅ Should work (process.kill)
- macOS: ✅ Should work (process.kill)
