This page demonstrates how your web frontend interacts with the browser-bridge file picker and file writer on the new Cydog Browser via the injected window.showDirectoryPicker() polyfill and the FileSystemBridge.

1. Action Triggers

Clicking the buttons below invokes the native folder selection flow, directory iteration, and the new write file method.

1. Bridge Injection
2. Workspace Handle
3. Directory Iteration
4. Lazy File Read
5. Write File Method

2. Execution Log

Ready to process folder requests...

3. Implementation Snippet

Your JavaScript implementation uses standard File System Access API syntax alongside the new bridge write method:

async function importFolder() {
    try {
        // Triggers the Flutter native file picker via polyfill
        const dirHandle = await window.showDirectoryPicker();
        logMessage(`Opened directory: ${dirHandle.name}`);

        // Iterate through entries using standard async generator
        for await (const entry of dirHandle.values()) {
            if (entry.kind === 'file') {
                logMessage(`Found file: ${entry.name} (${entry.size} bytes)`);
                
                // Fetch the actual file blob data on demand
                const fileBlob = await entry.getFile();
            } else if (entry.kind === 'directory') {
                logMessage(`Found subdirectory: ${entry.name}`);
            }
        }
    } catch (err) {
        logMessage(`Error or cancellation: ${err.message}`);
    }
}

// New Write File Method Implementation via Bridge (Fallback safe)
if (window.__CydogBridge && typeof window.__CydogBridge.writeFile !== 'function') {
    window.__CydogBridge.writeFile = async function(filePath, textData) {
        const domain = window.location.hostname || window.location.protocol || 'local_app';
        return await window.__CydogBridge.request('writeFile', {
            path: filePath,
            text: textData,
            domain: domain
        });
    };
}