### Get Cordova Launch Context - JavaScript Source: https://context7.com/open-condo-software/condo-web-cordova-wrapper/llms.txt Retrieves the context data used to launch the application, such as deep link parameters or notification payloads. This function returns null in a web environment and is typically called after the deviceready event. ```javascript window.cordova.plugins.condo.getLaunchContext( (context) => { if (context && context.deepLink) { console.log('Launched via deep link:', context.deepLink); // context structure (when available in native): // { // deepLink: "/tickets/ticket-id-123", // notificationId: "notif-456", // source: "push-notification" // } window.location.href = context.deepLink; } else { console.log('Normal launch - no context available'); // Continue with default app flow } }, (error) => { console.error('Failed to get launch context:', error); } ); ``` -------------------------------- ### JavaScript: sendPostMessage Internal Function & Parent Message Handler Source: https://context7.com/open-condo-software/condo-web-cordova-wrapper/llms.txt Demonstrates the internal `sendPostMessage` function for sending messages and awaiting responses from a parent window, and a parent window's message event listener for handling requests and sending back results or errors. Includes examples for custom events and authorization requests. ```javascript // Internal usage example (called by plugin methods) async function customPluginMethod() { try { const result = await sendPostMessage( 'customEvent', { param1: 'value1', param2: 42 }, 5000 // 5 second timeout ); console.log('Response received:', result); return result; } catch (error) { console.error('Communication error:', error); // Error types: // - "PostMessage timeout after 5000ms for event: customEvent" // - "No parent window available" // - Custom error from parent window response throw error; } } // Parent window message handler implementation example window.addEventListener('message', (event) => { const { eventId, eventName, eventData } = event.data; if (eventName === 'getCurrentResident') { // Process the request const resident = getCurrentUserResident(); // Send response back event.source.postMessage({ eventId: eventId, result: resident }, '*'); } else if (eventName === 'requestServerAuthorizationByUrl') { handleAuthorization(eventData.url) .then((authData) => { event.source.postMessage({ eventId: eventId, result: authData }, '*'); }) .catch((err) => { event.source.postMessage({ eventId: eventId, error: err.message }, '*'); }); } }); ``` -------------------------------- ### Get Current Resident Information - JavaScript Source: https://context7.com/open-condo-software/condo-web-cordova-wrapper/llms.txt Retrieves the current resident's details from the parent application context. This function is crucial for user identification within the application. It accepts a success callback with resident data and an error callback. ```javascript // Get current resident data window.cordova.plugins.condo.getCurrentResident( (resident) => { if (resident) { console.log('Current resident:', resident); // resident object structure: // { // id: "uuid-v4-string", // name: "John Doe", // unitName: "Apt 123", // organizationId: "org-uuid" // } document.getElementById('welcomeMessage').textContent = `Welcome, ${resident.name} (${resident.unitName})`; } else { console.log('No resident currently logged in'); window.location.href = '/login'; } }, (error) => { console.error('Failed to get resident:', error); // Handle error - possibly show offline mode or retry } ); ``` -------------------------------- ### Request Server Authorization by URL - JavaScript Source: https://context7.com/open-condo-software/condo-web-cordova-wrapper/llms.txt Initiates server authorization via a URL. It communicates with the parent window to handle the authentication flow, returning authorization data upon success or an error upon failure. Expects a URL string and options object as input. ```javascript // Request authorization from a Condo server const authUrl = 'https://condo.example.com/auth/callback?token=abc123'; window.cordova.plugins.condo.requestServerAuthorizationByUrl( authUrl, { timeout: 10000 }, (result) => { console.log('Authorization successful:', result); // result contains authorization data from the server // {accessToken: '...', refreshToken: '...', userId: '...'} }, (error) => { console.error('Authorization failed:', error); // Handle timeout or authentication failure } ); // The parent window receives: // { // eventId: "1696800000000_abc1234", // eventName: "requestServerAuthorizationByUrl", // eventData: { url: "https://condo.example.com/auth/callback?token=abc123" } // } // Parent window should respond with: // window.postMessage({ // eventId: "1696800000000_abc1234", // result: {accessToken: "...", refreshToken: "...", userId: "..."} // }, '*'); ``` -------------------------------- ### Handle Cordova deviceready Event - JavaScript Source: https://context7.com/open-condo-software/condo-web-cordova-wrapper/llms.txt Cordova lifecycle event that fires when the Cordova environment is fully initialized and all plugins are ready for use. This ensures that Cordova APIs and plugins are safely accessible. ```javascript // Wait for Cordova to be ready before accessing plugins document.addEventListener('deviceready', onDeviceReady, false); function onDeviceReady() { console.log('Cordova is ready'); console.log('Platform:', window.cordova.platformId); // "web" // Now safe to use all Cordova plugins window.cordova.plugins.condo.getCurrentResident( (resident) => { if (resident) { initializeApplication(resident); } }, (error) => console.error('Error:', error) ); } // Alternative: Promise-based approach function waitForCordova() { return new Promise((resolve) => { if (window.cordova) { document.addEventListener('deviceready', resolve, false); } else { // Fallback if cordova-web.js not loaded resolve(); } }); } // Usage waitForCordova().then(() => { console.log('Cordova ready, starting app'); startApplication(); }); ``` -------------------------------- ### Cordova History Navigation API - JavaScript Source: https://context7.com/open-condo-software/condo-web-cordova-wrapper/llms.txt Provides browser history manipulation compatible with the Cordova navigation model, allowing controlled navigation within the application. It includes methods for pushing, replacing, and navigating history states. ```javascript // Push new state to history window.cordova.plugins.condo.history.pushState( { page: 'profile', userId: '123' }, 'User Profile' ); // Replace current state without adding to history window.cordova.plugins.condo.history.replaceState( { page: 'profile', userId: '123', tab: 'details' }, 'User Profile - Details' ); // Navigate back one step document.getElementById('backButton').addEventListener('click', () => { window.cordova.plugins.condo.history.back(); }); // Navigate forward or backward by amount window.cordova.plugins.condo.history.go(-2); // Go back 2 pages window.cordova.plugins.condo.history.go(1); // Go forward 1 page // Listen to state changes window.addEventListener('popstate', (event) => { console.log('Navigation state:', event.state); // Handle state restoration if (event.state && event.state.page === 'profile') { loadProfilePage(event.state.userId); } }); ``` -------------------------------- ### Close Application - JavaScript Source: https://context7.com/open-condo-software/condo-web-cordova-wrapper/llms.txt Signals the parent window to terminate the embedded web view, providing a controlled exit from the application. It includes success and error callbacks for managing the closure request. ```javascript // Close application on user logout or exit document.getElementById('logoutButton').addEventListener('click', () => { // Perform cleanup localStorage.clear(); sessionStorage.clear(); // Request application closure window.cordova.plugins.condo.closeApplication( () => { console.log('Application close requested'); // Success callback - parent will handle closing }, (error) => { console.error('Failed to close application:', error); // Fallback: navigate to a goodbye page window.location.href = '/goodbye.html'; } ); }); // Parent window receives: // { // eventId: "1696800000000_xyz9876", // eventName: "closeApplication", // eventData: {} // } ``` -------------------------------- ### Control Cordova Input States - JavaScript Source: https://context7.com/open-condo-software/condo-web-cordova-wrapper/llms.txt Enables or disables form inputs to prevent user interaction during loading states or background operations. This is useful for managing UI responsiveness during asynchronous tasks. ```javascript async function performDataSync() { // Disable all inputs window.cordova.plugins.condo.setInputsEnabled( false, (value) => { console.log('Inputs disabled:', value); // false document.body.classList.add('processing'); }, (error) => console.error('Failed to disable inputs:', error) ); try { // Perform sync operation await fetch('/api/sync', { method: 'POST' }); console.log('Sync completed'); } finally { // Re-enable inputs window.cordova.plugins.condo.setInputsEnabled( true, (value) => { console.log('Inputs enabled:', value); // true document.body.classList.remove('processing'); }, (error) => console.error('Failed to enable inputs:', error) ); } } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.