How xlrpa/workbot works
Project type and purpose
• This is a multi‐module Android client application (the “APP” side of WorkBot) that implements an RPA (Robotic Process Automation) framework based on Android’s official SDK and the WeChat/Enterprise WeChat SDK.
• Key features: runs JavaScript “scripts” (via Rhino) to drive AccessibilityService and shell commands, orchestrates UI automation (via automator), exposes a DevPlugin WebSocket for remote control, and bundles dozens of JS utility modules for scripts (axios, bluebird, paddleOCR, etc.).
• There is no separate server in this repo; the “task scheduling platform” is external.
High‐level modules (from file tree)
• app – the Android UI and entry point (Activities, Fragments, Compose UI, ViewModels, user settings, script editor, build tools).
• autojs – the core script engine service: Rhino‐based JS engine, script execution manager, runtime APIs (Console, UI, Shell, Events, Files, Floaty, HTTP), code generator, encryption, preprocessor.
• automator – UI automation DSL: global action automator, UiObject/UiSelector, filters/search algorithms.
• common – shared utilities and compatibility layers (I/O, concurrency, events, app‐permission helpers).
• inrt – an integration variant (“in‐real‐time” or plugin client) that embeds a DevPluginService and WebSocket client to receive remote script commands.
Key runtime components
• UI layer (app module): Activities/Fragments invoke and control scripts, display logs, code editor, script list.
• ScriptEngineService (autojs): bound service that runs JS scripts on an event loop, provides native→JS bridges.
• AccessibilityService (autojs core & automator): listens to UI events, performs click/swipe/drag.
• DevPlugin WebSocket (autojs.devplugin & inrt): runs a Ktor WebSocket server inside the app to accept remote commands, dispatches to the script engine.
• ForegroundService: keeps app alive, handles background script execution.
• Storage: custom file storage (TmpScriptFiles), SQLite databases for timed tasks, intent tasks.
• Networking: update checks (GitHub APIs, Apifox), NodeBB forum integration, downloading scripts/assets.
• Assets: dozens of JS modules under autojs/src/main/assets/modules plus sample scripts under app/src/main/assets/sample.
Relationships and interactions
• The app’s UI binds to ScriptEngineService to start/stop scripts.
• Scripts execute in Rhino (autojs) → call into runtime API classes → use automator to drive AccessibilityService or shell.
• The DevPlugin WebSocket receives JSON commands → routes through Router → invokes ScriptExecutionTask in the engine.
• The engine writes logs to the Console view; UI observes ScriptExecutionObserver.
• Database/storage layers persist timed tasks and script metadata; UI reads via ViewModels.
• Networking modules fetch updates or forum posts; results routed into UI or script environment.
Architectural patterns and principles
• Multi‐module Gradle separation for core engine (autojs), UI (app), automation DSL (automator), common utilities.
• Service‐oriented design: ScriptEngineService, AccessibilityService, ForegroundService decouple background work.
• MVVM in app UI: Activities/Fragments + ViewModels + LiveData/Observers.
• Event‐driven script runtime: EventEmitter, Continuation support in Rhino.
• Plugin architecture: DevPlugin WebSocket and Router for extensibility.
• Asset‐based scripting: bundles JS modules and sample scripts in APK assets.