How sunnyyoung/wechattweak-macos works
This project is a macOS tweak for the WeChat client—essentially a dynamic library that enhances and modifies the behavior of the official WeChat macOS application. The primary purpose is to add features such as blocking message revocation, allowing multiple instances of WeChat to be launched, and enhancing message handling (for example, exporting any emoji, QR code recognition, and direct link copying). It also provides a user interface for settings and integrates with other productivity tools like Alfred, Raycast, and Launchbar.
Main components
• Tweak Core & Injection Mechanism: The core is built as a dynamic library that hooks into WeChat. Components like “WeChatTweak.m”, “AntiRevoke.m”, and “MultipleInstances.m” represent the business logic that modifies WeChat behavior.
• UI Preferences & Controller Module: This includes the user interface elements provided by the tweak (for example, “TweakPreferencesController” in various language-specific resources) for configuration of the tweaks.
• Category Extensions: Modules in the “Category” directory (e.g., NSBundle+WeChatTweak.m) enhance or override existing classes using Objective-C categories.
• Integration Modules: Separate integration projects such as the Alfred workflow (WeChat.alfredworkflow), Launchbar action (WeChatTweak.lbaction), and potentially integration with Raycast. These ensure that the tweak communicates smoothly with external applications and services.
• Build & Configuration Artifacts: The project has an Xcode project structure (WeChatTweak.xcodeproj and WeChatTweak.xcworkspace), a Podfile for CocoaPods dependency management, and additional build scripts or configuration files (like the Makefile). These support the build and installation process.
• Injection/Linking Helpers: Files such as “insert_dylib” and “fishhook.podspec” indicate that the project might use dynamic library injection techniques (possibly using tools like fishhook) to hook into WeChat’s runtime.
Relationships and interactions
• The dynamic library (“WeChatTweak”) is injected into the WeChat application at runtime. It intercepts specific function calls (for message retraction, multi-instance management, etc.) and modifies behavior accordingly.
• The UI Preferences component interacts with the core tweak module, letting users enable, disable, or configure features.
• The integration modules operate as adjuncts: for instance, when triggered via Alfred or Launchbar, they might call into the tweak’s API or trigger actions within the WeChat client.
• The build system (Xcode, CocoaPods configuration, and Makefile) coordinates the compilation, linking, and packaging of the dynamic library, ensuring that the injection and integration components are properly included.
Architectural patterns and design principles
• Modularity: The project is cleanly separated into modules – core functionality, UI handling, and external integrations are individually managed.
• Hooking & Injection: The primary pattern is method hooking (using techniques like those provided by fishhook) to intercept and modify behaviors in WeChat.
• Extension & Localization: With multiple language folders and resource bundles (for example, localized strings in en.lproj, zh-Hans.lproj, zh-Hant.lproj), the design emphasizes internationalization alongside extensibility.
• Integration with external tools is treated as first-class citizens – their workflows (Alfred, Launchbar, Raycast) are designed to work seamlessly with the tweak.
Relevant technologies, frameworks, or libraries
• Objective-C and Xcode are the main development environments.
• Cocoa and macOS frameworks form the basis of the UI and system integrations.
• CocoaPods (as indicated by the Podfile and fishhook.podspec) manage third-party dependencies, likely including libraries for hooking and runtime modifications.
• Integration with third-party tools such as Alfred, Raycast, and Launchbar is handled via separate workflow and action packages.
Elements
• Clear labels for each module/component (Core Tweak, UI Preferences, Category Extensions, Integration Modules, Build Tools).
• Optionally, include the injection mechanism showing how the tweak library is injected into the running WeChat client.