Getting Started

Flutter Device Agent

Test Sulala using the Flutter device agent for cross-platform testing including mobile devices.

Overview

The Flutter device agent is a cross-platform application that connects your device to Sulala.ai. It's a Flutter rewrite of the Electron-based device agent, providing better platform support including mobile devices (Android and iOS).

Features

Cross-platform - Works on Windows, macOS, Linux, Android, and iOS
Simple GUI - No command line needed
One-click start - Just enter API key and click start
System tray - Runs in background (desktop platforms)
Auto-reconnect - Automatically reconnects if connection drops
Status indicator - See connection status at a glance
Local search - Searches files, apps, and system info
File upload - Uploads files to cloud storage

Prerequisites

  • Flutter SDK 3.9.2 or higher
  • Dart SDK (included with Flutter)
  • API Key from Sulala dashboard

Platform-Specific Requirements

For desktop builds:

  • macOS: Xcode
  • Windows: Visual Studio with C++ tools
  • Linux: GTK development libraries

For mobile builds:

  • Android: Android Studio and Android SDK
  • iOS: Xcode (macOS only)

Quick Start

Step 1: Navigate to Flutter Agent Directory

cd sulala_device_agent

Step 2: Install Dependencies

flutter pub get

Step 3: Run the App

# For your current platform
flutter run

# For specific platforms
flutter run -d windows
flutter run -d macos
flutter run -d linux
flutter run -d android
flutter run -d ios

Step 4: Configure and Start

  1. Open the app
  2. Enter your API key (from Dashboard → Devices → Your Device → API Key)
  3. Enter server URL (default: http://localhost:3000, change to your production URL)
  4. Click "Start Agent"
  5. Done! Your device is now connected.

The app runs in the background. On desktop platforms, you can minimize it to the system tray.

Building for Production

Desktop Platforms

# macOS
flutter build macos

# Windows
flutter build windows

# Linux
flutter build linux

Mobile Platforms

# Android
flutter build apk --release
# or for app bundle
flutter build appbundle --release

# iOS
flutter build ios --release

Build with Custom Server URL

You can set the server URL at build time:

flutter build macos --dart-define=SERVER_URL=https://sulala.ai

Or set it at runtime using an environment variable:

# macOS/Linux
export SULALA_SERVER_URL=https://sulala.ai
flutter run

# Windows
set SULALA_SERVER_URL=https://sulala.ai
flutter run

How It Works

The Flutter agent:

  1. User enters API key and server URL
  2. App connects to Sulala.ai cloud
  3. Sends heartbeat every 30 seconds
  4. Polls for search requests from the cloud
  5. Executes searches locally (files, apps, system info)
  6. Sends results back automatically
  7. Handles file upload requests when needed

All automatic - user doesn't need to do anything after starting!

Project Structure

lib/
├── main.dart                 # App entry point
├── screens/
│   ├── home_screen.dart      # Main UI screen
│   └── qr_scanner_screen.dart # QR code scanner
├── services/
│   ├── agent_service.dart    # Core agent logic (heartbeat, polling, uploads)
│   ├── notification_service.dart # Local notifications
│   └── tray_service.dart     # System tray integration
├── platform/
│   └── search_service.dart   # Platform-specific search functions
└── config/
    └── app_config.dart       # App configuration

Key Components

AgentService

Singleton service managing the agent lifecycle:

  • Handles heartbeat, polling, search execution, and file uploads
  • Manages connection status and notifies listeners
  • Auto-reconnects on connection failure

SearchService

Platform-specific implementations for searching:

  • macOS: Searches /Applications and ~/Applications
  • Windows: Searches Program Files directories
  • Linux: Searches /usr/bin, /usr/local/bin, /opt
  • File search: Across user directories
  • System info search: Device information

TrayService

System tray integration for desktop platforms:

  • Shows status in tray menu
  • Allows quick window access
  • Platform-specific implementations

API Endpoints

The agent communicates with the following Sulala.ai endpoints:

  • POST /api/devices/heartbeat - Send device heartbeat
  • GET /api/devices/search/pending - Poll for search requests
  • POST /api/devices/search - Submit search results
  • GET /api/devices/files/upload-requests/pending - Poll for upload requests
  • POST /api/devices/files/upload - Upload file to cloud

Configuration

Settings are stored locally using shared_preferences:

  • API key - Your device API key
  • Server URL - Sulala server URL

These are automatically saved when you start the agent.

Server URL Configuration

The server URL can be configured in three ways (in order of precedence):

  1. Environment variable (runtime): SULALA_SERVER_URL
  2. Build-time constant: --dart-define=SERVER_URL=...
  3. Default value: https://sulala.ai

Troubleshooting

App won't start

  • Make sure Flutter is properly installed: flutter doctor
  • Run flutter pub get to install dependencies
  • Check that you have the required platform tools installed

System tray not working

  • System tray is optional and may not work on all platforms
  • The app will continue to function without tray support
  • You can keep the main window open instead

Connection errors

  • Check your API key is correct
  • Verify the server URL is accessible
  • Check your internet connection
  • Ensure the server is running
  • Check firewall settings

Search not finding files/apps

  • The app searches common directories but may not find everything
  • File search is limited to user directories for performance
  • App search is limited to standard installation locations
  • Check file permissions on your system

Build errors

  • Run flutter doctor to check for issues
  • Ensure you have the required platform SDKs installed
  • For iOS: Make sure you have Xcode and CocoaPods installed
  • For Android: Ensure Android SDK is properly configured

Development

Running in Debug Mode

flutter run --debug

Running Tests

flutter test

Code Formatting

flutter format lib/

Hot Reload

During development, you can use hot reload:

  • Press r in the terminal to hot reload
  • Press R to hot restart
  • Press q to quit

Differences from JavaScript Version

  • Better platform support: Works on mobile devices too
  • Native performance: Flutter's compiled performance
  • Smaller bundle size: More efficient than Electron
  • Better mobile UX: Native mobile UI patterns
  • Cross-platform codebase: Single codebase for all platforms

Platform-Specific Notes

macOS

  • Requires proper entitlements for file access
  • System tray works natively
  • App search includes /Applications and ~/Applications

Windows

  • Requires Visual Studio with C++ tools
  • System tray integration via Windows APIs
  • App search includes Program Files directories

Linux

  • Requires GTK development libraries
  • System tray may vary by desktop environment
  • App search includes standard Linux directories

Android

  • Requires Android SDK and Android Studio
  • File access requires proper permissions
  • App search limited to installed apps

iOS

  • Requires Xcode (macOS only)
  • File access requires proper permissions
  • App search limited to installed apps

Next Steps