How bandarhl/bhtwitter works
File-Structure Analysis
• Top-level:
• Tweak build files: Tweak.x, control, build.sh, Makefile
• Feature modules: AppIcon/, CustomTabBar/, BHDownload/, ThemeColor/, etc.
• Core manager: BHTManager.h/.m
• Packaging outputs: packages/, layout/ (resource bundle structure)
• Pattern: Modular Objective-C classes grouped by feature. A single dynamic library (the tweak) loads into the host app, then instantiates controllers and services.
README Insights
• Build flow: build.sh driving Theos to produce .deb (rootful/rootless) or .ipa (sideload/TrollStore)
Main Components
a. Host Environment
– Twitter app process (com.atebits.Tweetie2)
– MobileSubstrate/insert library loader
b. Tweak Core
– BHTwitter.dylib (built via Theos)
– BHTManager: orchestrates feature modules
c. Feature Modules (all dynamic-loaded classes within the dylib)
– AppIcon module (BHAppIconViewController + cells/items)
– CustomTabBar module (BHCustomTabBarViewController + items/sections)
– BHDownload service (inline button triggers FFmpegKit sessions for video download)
– ThemeColor module (BHColorThemeViewController + cells/items)
– SettingsViewController (aggregates per-feature toggles)
– SimpleAlert (common confirmation alerts)
d. Third-Party Libraries (static libs linked into the dylib)
– FFmpegKit (libffmpegkit.a + ffmpeg/ headers) – media processing
– SAMKeychain – secure credential storage
– JGProgressHUD – UI progress indicators
e. Resource Bundle
– BHTwitter.bundle under layout/ containing localized strings, Info.plist, assets
f. Build & Packaging Pipeline
– build.sh → Theos (compiles tweak, links static libraries) → dpkg control → produces .deb or wraps .ipa
– GitHub Actions workflow invoking same script with parameters
Interactions & Data Flow
• At runtime:
1. MobileSubstrate injects BHTwitter.dylib into Twitter.
2. BHTManager initializes modules on app launch or when relevant screens appear.
3. User taps “Download” button in tweet UI → BHDownloadInlineButton calls BHDownload service → FFmpegKitSession API invoked → progress updates via JGProgressHUD → saved file in sandbox or shared container.
4. User opens settings UI → SettingsViewController instantiates each feature’s controller → toggles persisted in BHTwitter.plist via BHTBundle and/or NSUserDefaults.
6. CustomTabBar hooks Twitter’s tab controller class, replaces it with BHCustomTabBarViewController.
Architectural Patterns & Principles
• Modular feature grouping: each tweak aspect in its own folder, exposing a view controller or service.
• Singleton manager (BHTManager) for lifecycle orchestration.
• Method swizzling / runtime hooking for injecting UI and behavior.
• Static linking of third‐party C libraries (FFmpeg, OpenSSL) into the dylib for self-containment.
• Theos build system employing Makefiles and dpkg control.