WebExeBuilder Documentation

close

Category: Application Control

Namespace: web.app.close

Description

Close the application immediately and exit the program. This method terminates the application gracefully, allowing any cleanup operations to complete before the window closes.

Syntax

await web.app.close();

Parameters

None

Returns

Promise<void> - Resolves when the application begins closing

Example

Simple example

await web.app.close();

Practical example

const confirmClose = confirm('Are you sure you want to exit?');

if (confirmClose) {
    await web.app.close();
}

Advanced example

async function exitApplication() {
    // Save user data
    const saved = await saveUserData();
    
    if (saved) {
        console.log('Data saved successfully');
        await web.app.close();
    } else {
        const forceClose = confirm('Failed to save data. Exit anyway?');
        if (forceClose) {
            await web.app.close();
        }
    }
}

Use Cases

  • Add an Exit button to your application menu
  • Close the app after completing a task
  • Implement keyboard shortcuts (Alt+F4, Ctrl+Q)
  • Exit after user confirmation dialog
  • Close after saving user data
  • Implement auto-close after inactivity
  • Exit when critical error occurs
  • Close from system tray menu

Error Handling

This method does not throw errors. The application will close regardless of the current state.

Performance Tips

  • Always save important data before calling close()
  • Consider showing a confirmation dialog for unsaved changes
  • Use async/await to ensure cleanup operations complete
  • Don't rely on code after close() - it may not execute
  • web.app.windowMinimize() - Minimize instead of closing
  • web.window.hide() - Hide window without closing

Notes

  • The application closes immediately after this call
  • Any unsaved data will be lost unless saved first
  • Consider implementing a "Are you sure?" confirmation
  • This is equivalent to clicking the X button on the window