How xland/horsejs works
Project type and purpose
• This is a native desktop-application framework (HorseJs) written in C++/Win32 that hosts a WebView2 control and exposes a global JavaScript object (horse) to the embedded HTML/JS/CSS UI.
• Purpose: let developers write cross-platform-style desktop UIs purely in web technologies, with access to native OS features (clipboard, dialogs, file system, processes, tray, etc.) via built-in modules or user-supplied DLL plugins.
File structure
• Top-level:
• App/ → C++ host application (WebView2 initialization, binding JS↔C++).
• Processor/ → Native implementations of each horse.* module (Clipboard, Dialog, Fs, Net, Notify, Os, Process, Screen, Tray, Win).
• Lib/ → Third-party libraries (rapidjson) and precompiled headers.
• Script/ → Frontend JS/TS library that runs in the renderer—defines the TypeScript interfaces for horse.*, example pages, assets (css, index.html).
• Res/ → Native resources (.rc).
• TestDll/ → Sample native plugin showing how to extend with user DLL.
• main.cpp → Entry point that ties App/ and Processor/.
• Doc/ → Markdown documentation for each module and quick-start.
• Configuration and build:
• HorseJs.sln / .vcxproj → Visual Studio solution/project.
• Script/tsconfig.json, config.json → TS compilation and runtime behavior.
• packages.config → external NuGet/WebView2 runtime dependency.
README
• Describes HorseJs as “using HTML/JS/CSS to create fast, stable desktop apps.”
• Lists all horse.* modules and links to their docs.
• Emphasizes a tiny single-exe (<1M) without extra DLLs, based on WebView2.
a. Main components
1. Native Host (C++ App)
• Subcomponents:
• WebView2 Controller
• JS►C++ Binding Layer (BrowserWindowConfig, BrowserWindowPage)
• Message Dispatcher (MsgProcessor)
• Module Manager (loads Processor/*)
• JSON Parser/Serializer (rapidjson)
2. Horse Modules (Processor/*)
• One class per feature (Clipboard, Dialog, Fs, Net, etc.)
3. Script Layer (Script/*.ts)
• TypeScript wrappers for horse.*
• UI assets (index.html + css)
4. User UI
• HTML/CSS pages, event handlers call horse APIs
5. Optional Plugin DLL (TestDll)
• Demonstrates extensibility via horse.dll module
b. Relationships & interactions
1. On startup, Native Host reads config.json → configures WebView2.
2. Host injects Script/index.html + bundled TS output into WebView.
3. UI JS calls window.chrome.webview.postMessage({module, method, args}).
4. Message Dispatcher receives JSON → routes to the correct Processor module → executes native code.
5. Processor returns result → serialized via rapidjson → posted back to JS.
6. JS promise resolves, UI updates.
7. For user-supplied feature, horse.dll module loads external DLL via Dll.cpp.
c. Architectural patterns/design principles
• Message-based RPC between renderer and host
• Adapter/facade pattern: each horse.* module is a facade over Win32 API
• Plugin architecture: DLL loading for extensibility
• Single responsibility: one Processor class per feature
• Layered separation: UI layer (HTML/JS), script library (TS), native host, modules, third-party libs
d. Key technologies/frameworks/libraries
• C++17 with Win32/WebView2
• rapidjson for JSON handling
• TypeScript for strong typing in the script layer
• HTML/CSS for UI
• Visual Studio solution/project files
• WebView2 runtime (Edge-based)
Final advice
• Every processor module as a separate node
• Layered nature (UI → Script API → Host → Native modules)
• Do not omit the rapidjson library and TestDll extensibility path