Add tweak settings preference panel

This commit is contained in:
Sunnyyoung 2017-08-12 20:29:08 +08:00
parent e4fc52d197
commit 1a6294e9d0
27 changed files with 515 additions and 73 deletions

View File

@ -1,34 +1,38 @@
WECHATPATH=/Applications/WeChat.app/Contents/MacOS
DYLIBFILE=WeChatTweak.dylib
build::
clang -dynamiclib ./WeChatTweak.m -fobjc-link-runtime -current_version 1.0 -compatibility_version 1.0 -o ./${DYLIBFILE}
APP_PATH=/Applications/WeChat.app/Contents/MacOS
APP_NAME=WeChat
BACKUP_NAME=WeChat.bak
FRAMEWORK_PATH=WeChatTweak.framework
FRAMEWORK_NAME=WeChatTweak
DYLIB_NAME=WeChatTweak.dylib
debug::
make clean
make build
DYLD_INSERT_LIBRARIES=./${DYLIBFILE} ${WECHATPATH}/WeChat &
DYLD_INSERT_LIBRARIES=${FRAMEWORK_PATH}/${FRAMEWORK_NAME} ${APP_PATH}/${APP_NAME} &
install::
@if ! [[ $EUID -eq 0 ]]; then\
echo "This script should be run using sudo or as the root user.";\
exit 1;\
fi
@if ! [ -f "${WECHATPATH}/WeChat" ]; then\
@if ! [ -f "${APP_PATH}/${APP_NAME}" ]; then\
echo "Can not find the WeChat.";\
exit 1;\
fi
@if ! [ -f "./${DYLIBFILE}" ]; then\
echo "Can not find the dylib file, please build first.";\
@if ! [ -d "${FRAMEWORK_PATH}" ]; then\
echo "Can not find the framework, please build first.";\
exit 1;\
fi
@if [ -f "${WECHATPATH}/${DYLIBFILE}" ]; then\
cp ./${DYLIBFILE} ${WECHATPATH}/${DYLIBFILE};\
echo "Tweak file found! Replace with new tweak file successed!";\
@if [ -f "${APP_PATH}/${DYLIB_NAME}" ]; then\
echo "You're using old version tweak, please uninstall first.";\
exit 1;\
fi
@if [ -d "${APP_PATH}/${FRAMEWORK_PATH}" ]; then\
rm -rf ${APP_PATH}/${FRAMEWORK_PATH};\
cp -R ${FRAMEWORK_PATH} ${APP_PATH};\
echo "Framework found! Replace with new framework successed!";\
else \
cp ${WECHATPATH}/WeChat ${WECHATPATH}/WeChat.bak;\
cp ./${DYLIBFILE} ${WECHATPATH}/${DYLIBFILE};\
./insert_dylib @executable_path/${DYLIBFILE} ${WECHATPATH}/WeChat ${WECHATPATH}/WeChat --all-yes;\
cp ${APP_PATH}/${APP_NAME} ${APP_PATH}/${BACKUP_NAME};\
cp -R ${FRAMEWORK_PATH} ${APP_PATH};\
./insert_dylib @executable_path/${FRAMEWORK_PATH}/${FRAMEWORK_NAME} ${APP_PATH}/${APP_NAME} ${APP_PATH}/${APP_NAME} --all-yes;\
echo "Install successed!";\
fi
@ -37,18 +41,19 @@ uninstall::
echo "This script should be run using sudo or as the root user.";\
exit 1;\
fi
@if ! [ -f "${WECHATPATH}/WeChat" ]; then\
@if ! [ -f "${APP_PATH}/${APP_NAME}" ]; then\
echo "Can not find the WeChat.";\
exit 1;\
fi
@if ! [ -f "${WECHATPATH}/WeChat.bak" ]; then\
@if ! [ -f "${APP_PATH}/${BACKUP_NAME}" ]; then\
echo "Can not find the WeChat backup file.";\
exit 1;\
fi
@rm -rf ${WECHATPATH}/${DYLIBFILE};
@mv ${WECHATPATH}/WeChat.bak ${WECHATPATH}/WeChat;
@rm -rf ${APP_PATH}/${DYLIB_NAME};
@rm -rf ${APP_PATH}/${FRAMEWORK_PATH};
@mv ${APP_PATH}/${BACKUP_NAME} ${APP_PATH}/${APP_NAME};
@echo "Uninstall successed";
clean::
rm -rf ./${DYLIBFILE}
rm -rf ${FRAMEWORK_PATH}

View File

@ -20,6 +20,7 @@
- 右键 dock icon 登录新的微信账号
- 命令行执行:`open -n /Applications/WeChat.app`
- 重新打开应用无需手机认证
- UI界面设置面板
## 使用
@ -28,12 +29,16 @@
## 开发调试
**Requirement: Command Line Tools**
**Requirement: Xcode**
运行命令:`xcode-select --install` 安装 Command Line Tools
### 编译
- `make build` 编译 dylib 动态库到当前目录下
- `make debug` 编译 dylib 动态库并临时注入微信 macOS 客户端
1. 运行 `pod install`
2. 打开 `WeChatTweak.xcworkspace` 并编译
### 调试
- `make debug` 临时注入微信 macOS 客户端
- `make clean` 清除生成文件
## 依赖

View File

@ -20,20 +20,25 @@ A dynamic library tweak for WeChat macOS.
- Right click on the dock icon to login another WeChat account
- Run command: `open -n /Applications/WeChat.app`
- Auto login without authentication
- UI Interface settings panel
## Usage
- `sudo make install` Install or Updrade the dylib
- `sudo make install` Install or Upgrade the dylib
- `sudo make uninstall` Uninstall the dylib
## Development
**Requirement: Command Line Tools**
**Requirement: Xcode**
Run `xcode-select --install` to install Command Line Tools
### Build
- `make build` Build the dylib file to the same dicrectory
- `make debug` Build the dylib file and run `WeChat` with dynamic injection
1. Run `pod install`
2. Open `WeChatTweak.xcworkspace` and build
### Debug
- `make debug` Run `WeChat` with dynamic injection
- `make clean` Clean output files
## Dependency

Binary file not shown.

Before

Width:  |  Height:  |  Size: 575 KiB

After

Width:  |  Height:  |  Size: 1.6 MiB

View File

@ -0,0 +1 @@
Versions/Current/Headers

View File

@ -0,0 +1 @@
Versions/Current/Modules

View File

@ -0,0 +1 @@
Versions/Current/Resources

View File

@ -0,0 +1,15 @@
//
// WeChatTweak.h
// WeChatTweak
//
// Created by Sunnyyoung on 2017/8/11.
// Copyright © 2017年 Sunnyyoung. All rights reserved.
//
#import <Cocoa/Cocoa.h>
#import <objc/runtime.h>
#import <objc/message.h>
#import <JRSwizzle/JRSwizzle.h>
FOUNDATION_EXPORT double WeChatTweakVersionNumber;
FOUNDATION_EXPORT const unsigned char WeChatTweakVersionString[];

View File

@ -0,0 +1,6 @@
framework module WeChatTweak {
umbrella header "WeChatTweak.h"
export *
module * { export * }
}

Binary file not shown.

View File

@ -0,0 +1,44 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>BuildMachineOSBuild</key>
<string>16G29</string>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleExecutable</key>
<string>WeChatTweak</string>
<key>CFBundleIdentifier</key>
<string>net.sunnyyoung.WeChatTweak</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>WeChatTweak</string>
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleSupportedPlatforms</key>
<array>
<string>MacOSX</string>
</array>
<key>CFBundleVersion</key>
<string>1</string>
<key>DTCompiler</key>
<string>com.apple.compilers.llvm.clang.1_0</string>
<key>DTPlatformBuild</key>
<string>8E3004b</string>
<key>DTPlatformVersion</key>
<string>GM</string>
<key>DTSDKBuild</key>
<string>16E185</string>
<key>DTSDKName</key>
<string>macosx10.12</string>
<key>DTXcode</key>
<string>0833</string>
<key>DTXcodeBuild</key>
<string>8E3004b</string>
<key>NSHumanReadableCopyright</key>
<string>Copyright © 2017年 Sunnyyoung. All rights reserved.</string>
</dict>
</plist>

Binary file not shown.

View File

@ -0,0 +1 @@
A

View File

@ -0,0 +1 @@
Versions/Current/WeChatTweak

View File

@ -8,9 +8,17 @@
/* Begin PBXBuildFile section */
48F335DC5AE4FE2A0D87FE8A /* libPods-WeChatTweak.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 417879E20C242D6E4E7C74A7 /* libPods-WeChatTweak.a */; };
7D2A39861F3EDF3700F5D4A6 /* NSBundle+WeChatTweak.h in Headers */ = {isa = PBXBuildFile; fileRef = 7D2A39841F3EDF3700F5D4A6 /* NSBundle+WeChatTweak.h */; };
7D2A39871F3EDF3700F5D4A6 /* NSBundle+WeChatTweak.m in Sources */ = {isa = PBXBuildFile; fileRef = 7D2A39851F3EDF3700F5D4A6 /* NSBundle+WeChatTweak.m */; };
7D2A398A1F3EE1A000F5D4A6 /* NSString+WeChatTweak.h in Headers */ = {isa = PBXBuildFile; fileRef = 7D2A39881F3EE1A000F5D4A6 /* NSString+WeChatTweak.h */; };
7D2A398B1F3EE1A000F5D4A6 /* NSString+WeChatTweak.m in Sources */ = {isa = PBXBuildFile; fileRef = 7D2A39891F3EE1A000F5D4A6 /* NSString+WeChatTweak.m */; };
7D2A39931F3F187300F5D4A6 /* Prefs-Tweak.tiff in Resources */ = {isa = PBXBuildFile; fileRef = 7D2A39921F3F187300F5D4A6 /* Prefs-Tweak.tiff */; };
7D3500E91F3EC86A00D59AD0 /* WeChatTweakHeaders.h in Headers */ = {isa = PBXBuildFile; fileRef = 7D3500E81F3EC86A00D59AD0 /* WeChatTweakHeaders.h */; };
7D35ECC61F3E355500D59AD0 /* TweakPreferecesController.h in Headers */ = {isa = PBXBuildFile; fileRef = 7D35ECC31F3E355500D59AD0 /* TweakPreferecesController.h */; };
7D35ECC71F3E355500D59AD0 /* TweakPreferecesController.m in Sources */ = {isa = PBXBuildFile; fileRef = 7D35ECC41F3E355500D59AD0 /* TweakPreferecesController.m */; };
7D35ECC81F3E355500D59AD0 /* TweakPreferecesController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 7D35ECC51F3E355500D59AD0 /* TweakPreferecesController.xib */; };
7DC79EA91F3DA8AA008E04CB /* WeChatTweak.h in Headers */ = {isa = PBXBuildFile; fileRef = 7DC79EA71F3DA8AA008E04CB /* WeChatTweak.h */; settings = {ATTRIBUTES = (Public, ); }; };
7DC79EB11F3DABF9008E04CB /* WeChatTweak.m in Sources */ = {isa = PBXBuildFile; fileRef = 7DC79EB01F3DABF9008E04CB /* WeChatTweak.m */; };
7DC79EB31F3DAC03008E04CB /* WeChatTweakHeaders.h in Headers */ = {isa = PBXBuildFile; fileRef = 7DC79EB21F3DAC03008E04CB /* WeChatTweakHeaders.h */; };
7DC79EB91F3DB678008E04CB /* WeChatTweak.framework in Export Framework */ = {isa = PBXBuildFile; fileRef = 7DC79EA41F3DA8AA008E04CB /* WeChatTweak.framework */; };
/* End PBXBuildFile section */
@ -30,11 +38,19 @@
/* Begin PBXFileReference section */
417879E20C242D6E4E7C74A7 /* libPods-WeChatTweak.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-WeChatTweak.a"; sourceTree = BUILT_PRODUCTS_DIR; };
7D2A39841F3EDF3700F5D4A6 /* NSBundle+WeChatTweak.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSBundle+WeChatTweak.h"; sourceTree = "<group>"; };
7D2A39851F3EDF3700F5D4A6 /* NSBundle+WeChatTweak.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSBundle+WeChatTweak.m"; sourceTree = "<group>"; };
7D2A39881F3EE1A000F5D4A6 /* NSString+WeChatTweak.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSString+WeChatTweak.h"; sourceTree = "<group>"; };
7D2A39891F3EE1A000F5D4A6 /* NSString+WeChatTweak.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSString+WeChatTweak.m"; sourceTree = "<group>"; };
7D2A39921F3F187300F5D4A6 /* Prefs-Tweak.tiff */ = {isa = PBXFileReference; lastKnownFileType = image.tiff; path = "Prefs-Tweak.tiff"; sourceTree = "<group>"; };
7D3500E81F3EC86A00D59AD0 /* WeChatTweakHeaders.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WeChatTweakHeaders.h; sourceTree = "<group>"; };
7D35ECC31F3E355500D59AD0 /* TweakPreferecesController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TweakPreferecesController.h; sourceTree = "<group>"; };
7D35ECC41F3E355500D59AD0 /* TweakPreferecesController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TweakPreferecesController.m; sourceTree = "<group>"; };
7D35ECC51F3E355500D59AD0 /* TweakPreferecesController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = TweakPreferecesController.xib; sourceTree = "<group>"; };
7DC79EA41F3DA8AA008E04CB /* WeChatTweak.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = WeChatTweak.framework; sourceTree = BUILT_PRODUCTS_DIR; };
7DC79EA71F3DA8AA008E04CB /* WeChatTweak.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WeChatTweak.h; sourceTree = "<group>"; };
7DC79EA81F3DA8AA008E04CB /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
7DC79EB01F3DABF9008E04CB /* WeChatTweak.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = WeChatTweak.m; sourceTree = "<group>"; };
7DC79EB21F3DAC03008E04CB /* WeChatTweakHeaders.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WeChatTweakHeaders.h; sourceTree = "<group>"; };
86FF0006D15CDE78239D0DD5 /* Pods-WeChatTweak.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-WeChatTweak.debug.xcconfig"; path = "Pods/Target Support Files/Pods-WeChatTweak/Pods-WeChatTweak.debug.xcconfig"; sourceTree = "<group>"; };
8850EDEE6E6610673CA4D1D2 /* Pods-WeChatTweak.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-WeChatTweak.release.xcconfig"; path = "Pods/Target Support Files/Pods-WeChatTweak/Pods-WeChatTweak.release.xcconfig"; sourceTree = "<group>"; };
/* End PBXFileReference section */
@ -59,6 +75,35 @@
name = Frameworks;
sourceTree = "<group>";
};
7D2A398C1F3EE26E00F5D4A6 /* Category */ = {
isa = PBXGroup;
children = (
7D2A39841F3EDF3700F5D4A6 /* NSBundle+WeChatTweak.h */,
7D2A39851F3EDF3700F5D4A6 /* NSBundle+WeChatTweak.m */,
7D2A39881F3EE1A000F5D4A6 /* NSString+WeChatTweak.h */,
7D2A39891F3EE1A000F5D4A6 /* NSString+WeChatTweak.m */,
);
name = Category;
sourceTree = "<group>";
};
7D2A398D1F3EE27C00F5D4A6 /* Controller */ = {
isa = PBXGroup;
children = (
7D35ECC31F3E355500D59AD0 /* TweakPreferecesController.h */,
7D35ECC41F3E355500D59AD0 /* TweakPreferecesController.m */,
7D35ECC51F3E355500D59AD0 /* TweakPreferecesController.xib */,
);
name = Controller;
sourceTree = "<group>";
};
7D2A398F1F3F143100F5D4A6 /* Resources */ = {
isa = PBXGroup;
children = (
7D2A39921F3F187300F5D4A6 /* Prefs-Tweak.tiff */,
);
path = Resources;
sourceTree = "<group>";
};
7DC79E9A1F3DA8AA008E04CB = {
isa = PBXGroup;
children = (
@ -80,9 +125,11 @@
7DC79EA61F3DA8AA008E04CB /* WeChatTweak */ = {
isa = PBXGroup;
children = (
7DC79EB21F3DAC03008E04CB /* WeChatTweakHeaders.h */,
7DC79EA71F3DA8AA008E04CB /* WeChatTweak.h */,
7DC79EB01F3DABF9008E04CB /* WeChatTweak.m */,
7D2A398D1F3EE27C00F5D4A6 /* Controller */,
7D2A398C1F3EE26E00F5D4A6 /* Category */,
7D2A398F1F3F143100F5D4A6 /* Resources */,
7DC79EAF1F3DA8BE008E04CB /* Supporting Files */,
);
path = WeChatTweak;
@ -92,6 +139,7 @@
isa = PBXGroup;
children = (
7DC79EA81F3DA8AA008E04CB /* Info.plist */,
7D3500E81F3EC86A00D59AD0 /* WeChatTweakHeaders.h */,
);
name = "Supporting Files";
sourceTree = "<group>";
@ -112,8 +160,11 @@
isa = PBXHeadersBuildPhase;
buildActionMask = 2147483647;
files = (
7DC79EB31F3DAC03008E04CB /* WeChatTweakHeaders.h in Headers */,
7DC79EA91F3DA8AA008E04CB /* WeChatTweak.h in Headers */,
7D35ECC61F3E355500D59AD0 /* TweakPreferecesController.h in Headers */,
7D2A398A1F3EE1A000F5D4A6 /* NSString+WeChatTweak.h in Headers */,
7D2A39861F3EDF3700F5D4A6 /* NSBundle+WeChatTweak.h in Headers */,
7D3500E91F3EC86A00D59AD0 /* WeChatTweakHeaders.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@ -178,6 +229,8 @@
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
7D35ECC81F3E355500D59AD0 /* TweakPreferecesController.xib in Resources */,
7D2A39931F3F187300F5D4A6 /* Prefs-Tweak.tiff in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@ -224,7 +277,10 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
7D2A398B1F3EE1A000F5D4A6 /* NSString+WeChatTweak.m in Sources */,
7D35ECC71F3E355500D59AD0 /* TweakPreferecesController.m in Sources */,
7DC79EB11F3DABF9008E04CB /* WeChatTweak.m in Sources */,
7D2A39871F3EDF3700F5D4A6 /* NSBundle+WeChatTweak.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@ -340,6 +396,7 @@
INFOPLIST_FILE = WeChatTweak/Info.plist;
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/Frameworks";
MACOSX_DEPLOYMENT_TARGET = 10.10;
PRODUCT_BUNDLE_IDENTIFIER = net.sunnyyoung.WeChatTweak;
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
@ -360,6 +417,7 @@
INFOPLIST_FILE = WeChatTweak/Info.plist;
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/Frameworks";
MACOSX_DEPLOYMENT_TARGET = 10.10;
PRODUCT_BUNDLE_IDENTIFIER = net.sunnyyoung.WeChatTweak;
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;

View File

@ -0,0 +1,15 @@
//
// NSBundle+WeChatTweak.h
// WeChatTweak
//
// Created by Sunnyyoung on 2017/8/12.
// Copyright © 2017年 Sunnyyoung. All rights reserved.
//
#import <Cocoa/Cocoa.h>
@interface NSBundle (WeChatTweak)
+ (instancetype)tweakBundle;
@end

View File

@ -0,0 +1,17 @@
//
// NSBundle+WeChatTweak.m
// WeChatTweak
//
// Created by Sunnyyoung on 2017/8/12.
// Copyright © 2017 Sunnyyoung. All rights reserved.
//
#import "NSBundle+WeChatTweak.h"
@implementation NSBundle (WeChatTweak)
+ (instancetype)tweakBundle {
return [NSBundle bundleWithIdentifier:@"net.sunnyyoung.WeChatTweak"];
}
@end

View File

@ -0,0 +1,15 @@
//
// NSString+WeChatTweak.h
// WeChatTweak
//
// Created by Sunnyyoung on 2017/8/12.
// Copyright © 2017年 Sunnyyoung. All rights reserved.
//
#import <Foundation/Foundation.h>
@interface NSString (WeChatTweak)
- (NSString *)tweak_subStringFrom:(NSString *)beginString to:(NSString *)endString;
@end

View File

@ -0,0 +1,20 @@
//
// NSString+WeChatTweak.m
// WeChatTweak
//
// Created by Sunnyyoung on 2017/8/12.
// Copyright © 2017 Sunnyyoung. All rights reserved.
//
#import "NSString+WeChatTweak.h"
@implementation NSString (WeChatTweak)
- (NSString *)tweak_subStringFrom:(NSString *)beginString to:(NSString *)endString {
NSRange begin = [self rangeOfString:beginString];
NSRange end = [self rangeOfString:endString];
NSRange range = NSMakeRange(begin.location + begin.length, end.location - begin.location - begin.length);
return [self substringWithRange:range];
}
@end

Binary file not shown.

View File

@ -0,0 +1,22 @@
//
// TweakPreferecesController.h
// WeChatTweak
//
// Created by Sunnyyoung on 2017/8/12.
// Copyright © 2017年 Sunnyyoung. All rights reserved.
//
#import "WeChatTweakHeaders.h"
typedef NS_ENUM(NSUInteger, RevokeNotificationType) {
RevokeNotificationTypeFollow = 0,
RevokeNotificationTypeReceiveAll,
RevokeNotificationTypeDisable,
};
static NSString * const WeChatTweakPreferenceAutoAuthKey = @"WeChatTweakPreferenceAutoAuthKey";
static NSString * const WeChatTweakPreferenceRevokeNotificationTypeKey = @"WeChatTweakPreferenceRevokeNotificationTypeKey";
@interface TweakPreferecesController : NSViewController
@end

View File

@ -0,0 +1,73 @@
//
// TweakPreferecesController.m
// WeChatTweak
//
// Created by Sunnyyoung on 2017/8/12.
// Copyright © 2017 Sunnyyoung. All rights reserved.
//
#import "TweakPreferecesController.h"
#import "NSBundle+WeChatTweak.h"
@interface TweakPreferecesController () <MASPreferencesViewController>
@property (weak) IBOutlet NSPopUpButton *autoAuthButton;
@property (weak) IBOutlet NSPopUpButton *notificationTypeButton;
@end
@implementation TweakPreferecesController
- (void)viewDidLoad {
[super viewDidLoad];
}
- (void)viewWillAppear {
[super viewWillAppear];
[self reloadData];
}
- (void)reloadData {
NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
BOOL enabledAutoAuth = [userDefaults boolForKey:WeChatTweakPreferenceAutoAuthKey];
RevokeNotificationType notificationType = [userDefaults integerForKey:WeChatTweakPreferenceRevokeNotificationTypeKey];
[self.autoAuthButton selectItemAtIndex:enabledAutoAuth ? 1 : 0];
[self.notificationTypeButton selectItemAtIndex:notificationType];
}
#pragma mark - Event method
- (IBAction)switchAutoAuthAction:(NSPopUpButton *)sender {
BOOL enabled = sender.indexOfSelectedItem == 1;
[[NSUserDefaults standardUserDefaults] setBool:enabled forKey:WeChatTweakPreferenceAutoAuthKey];
[[NSUserDefaults standardUserDefaults] synchronize];
}
- (IBAction)switchNotificationTypeAction:(NSPopUpButton *)sender {
RevokeNotificationType type = sender.indexOfSelectedItem;
[[NSUserDefaults standardUserDefaults] setInteger:type forKey:WeChatTweakPreferenceRevokeNotificationTypeKey];
}
#pragma mark - MASPreferencesViewController
- (NSString *)identifier {
return @"tweak";
}
- (NSString *)toolbarItemLabel {
return @"Tweak";
}
- (NSImage *)toolbarItemImage {
return [[NSBundle tweakBundle] imageForResource:@"Prefs-Tweak"];
}
- (BOOL)hasResizableWidth {
return NO;
}
- (BOOL)hasResizableHeight {
return NO;
}
@end

View File

@ -0,0 +1,95 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="12121" systemVersion="16G29" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
<dependencies>
<deployment identifier="macosx"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="12121"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<objects>
<customObject id="-2" userLabel="File's Owner" customClass="TweakPreferecesController">
<connections>
<outlet property="autoAuthButton" destination="5by-EJ-3f2" id="VIV-sZ-ybx"/>
<outlet property="notificationTypeButton" destination="6x2-KV-p8w" id="Kfn-2a-Yup"/>
<outlet property="view" destination="Hz6-mo-xeY" id="0bl-1N-x8E"/>
</connections>
</customObject>
<customObject id="-1" userLabel="First Responder" customClass="FirstResponder"/>
<customObject id="-3" userLabel="Application" customClass="NSObject"/>
<customView id="Hz6-mo-xeY">
<rect key="frame" x="0.0" y="0.0" width="430" height="92"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<subviews>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" allowsCharacterPickerTouchBarItem="NO" translatesAutoresizingMaskIntoConstraints="NO" id="RFE-oR-GRm">
<rect key="frame" x="58" y="55" width="111" height="17"/>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" title="免手机认证登陆:" id="UiV-zj-l6I">
<font key="font" size="13" name=".PingFangSC-Regular"/>
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" allowsCharacterPickerTouchBarItem="NO" translatesAutoresizingMaskIntoConstraints="NO" id="B87-eD-uhI">
<rect key="frame" x="72" y="22" width="97" height="17"/>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" title="消息撤回通知:" id="UKv-CM-nGt">
<font key="font" size="13" name=".PingFangSC-Regular"/>
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
<popUpButton verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="5by-EJ-3f2">
<rect key="frame" x="173" y="50" width="64" height="26"/>
<popUpButtonCell key="cell" type="push" title="关闭" bezelStyle="rounded" alignment="left" lineBreakMode="truncatingTail" state="on" borderStyle="borderAndBezel" imageScaling="proportionallyDown" inset="2" selectedItem="Vcv-eD-OM9" id="8qB-Jj-tlv">
<behavior key="behavior" lightByBackground="YES" lightByGray="YES"/>
<font key="font" metaFont="menu"/>
<menu key="menu" id="sFO-8T-61S">
<items>
<menuItem title="关闭" state="on" id="Vcv-eD-OM9">
<modifierMask key="keyEquivalentModifierMask"/>
</menuItem>
<menuItem title="开启" id="KQg-jN-y9a">
<modifierMask key="keyEquivalentModifierMask"/>
</menuItem>
</items>
</menu>
</popUpButtonCell>
<connections>
<action selector="switchAutoAuthAction:" target="-2" id="P6Q-aT-ADE"/>
</connections>
</popUpButton>
<popUpButton verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="6x2-KV-p8w">
<rect key="frame" x="173" y="17" width="144" height="26"/>
<popUpButtonCell key="cell" type="push" title="跟随消息通知设置" bezelStyle="rounded" alignment="left" lineBreakMode="truncatingTail" borderStyle="borderAndBezel" imageScaling="proportionallyDown" inset="2" selectedItem="gec-CY-E1x" id="wek-GT-N5V">
<behavior key="behavior" lightByBackground="YES" lightByGray="YES"/>
<font key="font" metaFont="menu"/>
<menu key="menu" id="H2J-gJ-aGD">
<items>
<menuItem title="跟随消息通知设置" id="gec-CY-E1x">
<modifierMask key="keyEquivalentModifierMask"/>
</menuItem>
<menuItem title="全部接收" id="da4-aJ-lEy">
<modifierMask key="keyEquivalentModifierMask"/>
</menuItem>
<menuItem title="全部关闭" state="on" id="Uk9-Oc-Jtv">
<modifierMask key="keyEquivalentModifierMask"/>
</menuItem>
</items>
</menu>
</popUpButtonCell>
<connections>
<action selector="switchNotificationTypeAction:" target="-2" id="xjO-Ck-wem"/>
</connections>
</popUpButton>
</subviews>
<constraints>
<constraint firstItem="B87-eD-uhI" firstAttribute="trailing" secondItem="RFE-oR-GRm" secondAttribute="trailing" id="3p1-WF-TYr"/>
<constraint firstItem="RFE-oR-GRm" firstAttribute="top" secondItem="Hz6-mo-xeY" secondAttribute="top" constant="20" id="CWK-cO-DBz"/>
<constraint firstItem="5by-EJ-3f2" firstAttribute="centerY" secondItem="RFE-oR-GRm" secondAttribute="centerY" id="QLN-KI-HUD"/>
<constraint firstItem="RFE-oR-GRm" firstAttribute="leading" secondItem="Hz6-mo-xeY" secondAttribute="leading" constant="60" id="R8y-0p-4Sk"/>
<constraint firstItem="6x2-KV-p8w" firstAttribute="leading" secondItem="5by-EJ-3f2" secondAttribute="leading" id="WSG-53-r8r"/>
<constraint firstItem="6x2-KV-p8w" firstAttribute="centerY" secondItem="B87-eD-uhI" secondAttribute="centerY" id="gqp-om-e0O"/>
<constraint firstItem="B87-eD-uhI" firstAttribute="top" secondItem="RFE-oR-GRm" secondAttribute="bottom" constant="16" id="lG1-vw-epo"/>
<constraint firstItem="5by-EJ-3f2" firstAttribute="leading" secondItem="RFE-oR-GRm" secondAttribute="trailing" constant="8" id="v9V-TW-Voc"/>
</constraints>
<point key="canvasLocation" x="139" y="164"/>
</customView>
</objects>
</document>

View File

@ -8,31 +8,9 @@
#import "WeChatTweak.h"
#import "WeChatTweakHeaders.h"
@implementation NSString (WeChatTweak)
- (NSString *)tweak_sessionFromMessage {
NSRange begin = [self rangeOfString:@"<session>"];
NSRange end = [self rangeOfString:@"</session>"];
NSRange range = NSMakeRange(begin.location + begin.length,end.location - begin.location - begin.length);
return [self substringWithRange:range];
}
- (NSUInteger)tweak_newMessageIDFromMessage {
NSRange begin = [self rangeOfString:@"<newmsgid>"];
NSRange end = [self rangeOfString:@"</newmsgid>"];
NSRange range = NSMakeRange(begin.location + begin.length,end.location - begin.location - begin.length);
return [[self substringWithRange:range] longLongValue];
}
- (NSString *)tweak_replaceMessageFromMessage {
NSRange begin = [self rangeOfString:@"<replacemsg><![CDATA["];
NSRange end = [self rangeOfString:@"]]></replacemsg>"];
NSRange range = NSMakeRange(begin.location + begin.length,end.location - begin.location - begin.length);
return [self substringWithRange:range];
}
@end
#import "NSBundle+WeChatTweak.h"
#import "NSString+WeChatTweak.h"
#import "TweakPreferecesController.h"
@implementation NSObject (WeChatTweak)
@ -44,15 +22,17 @@ static void __attribute__((constructor)) tweak(void) {
[objc_getClass("AppDelegate") jr_swizzleMethod:NSSelectorFromString(@"applicationShouldTerminate:") withMethod:@selector(tweak_applicationShouldTerminate:) error:nil];
[objc_getClass("MessageService") jr_swizzleMethod:NSSelectorFromString(@"onRevokeMsg:") withMethod:@selector(tweak_onRevokeMsg:) error:nil];
[objc_getClass("CUtility") jr_swizzleClassMethod:NSSelectorFromString(@"HasWechatInstance") withClassMethod:@selector(tweak_HasWechatInstance) error:nil];
[objc_getClass("MASPreferencesWindowController") jr_swizzleMethod:NSSelectorFromString(@"initWithViewControllers:") withMethod:@selector(tweak_initWithViewControllers:) error:nil];
[objc_getClass("MASPreferencesWindowController") jr_swizzleMethod:NSSelectorFromString(@"viewControllerForIdentifier:") withMethod:@selector(tweak_viewControllerForIdentifier:) error:nil];
}
#pragma mark - No Revoke Message
- (void)tweak_onRevokeMsg:(NSString *)message {
// Decode message
NSString *session = [message tweak_sessionFromMessage];
NSUInteger newMessageID = [message tweak_newMessageIDFromMessage];
NSString *replaceMessage = [message tweak_replaceMessageFromMessage];
NSString *session = [message tweak_subStringFrom:@"<session>" to:@"</session>"];
NSUInteger newMessageID = [message tweak_subStringFrom:@"<newmsgid>" to:@"</newmsgid>"].longLongValue;
NSString *replaceMessage = [message tweak_subStringFrom:@"<replacemsg><![CDATA[" to:@"]]></replacemsg>"];
// Prepare message data
MessageData *localMessageData = [((MessageService *)self) GetMsgData:session svrId:newMessageID];
@ -74,12 +54,18 @@ static void __attribute__((constructor)) tweak(void) {
});
// Prepare notification information
MMServiceCenter *serviceCenter = [objc_getClass("MMServiceCenter") defaultCenter];
NSUserNotification *userNotification = [[NSUserNotification alloc] init];
BOOL isChatStatusNotifyOpen = YES;
if ([session rangeOfString:@"@chatroom"].location == NSNotFound) {
ContactStorage *contactStorage = [serviceCenter getService:objc_getClass("ContactStorage")];
WCContactData *contact = [contactStorage GetContact:session];
isChatStatusNotifyOpen = [contact isChatStatusNotifyOpen];
userNotification.informativeText = replaceMessage;
} else {
GroupStorage *groupStorage = [[objc_getClass("MMServiceCenter") defaultCenter] getService:objc_getClass("GroupStorage")];
WCContactData *groupContact = [groupStorage GetGroupContact: session];
GroupStorage *groupStorage = [serviceCenter getService:objc_getClass("GroupStorage")];
WCContactData *groupContact = [groupStorage GetGroupContact:session];
isChatStatusNotifyOpen = [groupContact isChatStatusNotifyOpen];
NSString *groupName = groupContact.m_nsNickName.length ? groupContact.m_nsNickName : @"群组";
userNotification.informativeText = [NSString stringWithFormat:@"%@: %@", groupName, replaceMessage];
}
@ -89,11 +75,17 @@ static void __attribute__((constructor)) tweak(void) {
// Delete message if it is revoke from myself
if ([localMessageData isSendFromSelf]) {
[((MessageService *)self) DelMsg:session msgList:@[localMessageData] isDelAll:NO isManual:YES];
[((MessageService *)self) AddRevokePromptMsg:session msgData: promptMessageData];
[((MessageService *)self) AddRevokePromptMsg:session msgData:promptMessageData];
} else {
[[NSUserNotificationCenter defaultUserNotificationCenter] deliverNotification:userNotification];
[((MessageService *)self) AddRevokePromptMsg:session msgData: promptMessageData];
[((MessageService *)self) notifyAddMsgOnMainThread:session msgData: promptMessageData];
[((MessageService *)self) AddRevokePromptMsg:session msgData:promptMessageData];
[((MessageService *)self) notifyAddMsgOnMainThread:session msgData:promptMessageData];
}
// Deliver notification
if (![localMessageData isSendFromSelf]) {
RevokeNotificationType notificationType = [[NSUserDefaults standardUserDefaults] integerForKey:WeChatTweakPreferenceRevokeNotificationTypeKey];
if (notificationType == RevokeNotificationTypeReceiveAll || (notificationType == RevokeNotificationTypeFollow && isChatStatusNotifyOpen)) {
[[NSUserNotificationCenter defaultUserNotificationCenter] deliverNotification:userNotification];
}
}
});
}
@ -119,24 +111,43 @@ static void __attribute__((constructor)) tweak(void) {
[task launch];
}
#pragma mark - Auto auth
#pragma mark - Auto Auth
- (void)tweak_applicationDidFinishLaunching:(NSNotification *)notification {
[self tweak_applicationDidFinishLaunching:notification];
NSString *bundleIdentifier = [[objc_getClass("NSBundle") mainBundle] bundleIdentifier];
NSArray *instances = [objc_getClass("NSRunningApplication") runningApplicationsWithBundleIdentifier:bundleIdentifier];
// Detect multiple instance conflict
if (instances.count == 1) {
BOOL hasInstance = instances.count == 1;
BOOL enabledAutoAuth = [[NSUserDefaults standardUserDefaults] boolForKey:WeChatTweakPreferenceAutoAuthKey];
if (hasInstance && enabledAutoAuth) {
AccountService *accountService = [[objc_getClass("MMServiceCenter") defaultCenter] getService:objc_getClass("AccountService")];
if ([accountService canAutoAuth]) {
[accountService AutoAuth];
}
}
}
- (NSApplicationTerminateReply)tweak_applicationShouldTerminate:(NSApplication *)sender {
return NSTerminateNow;
BOOL enabledAutoAuth = [[NSUserDefaults standardUserDefaults] boolForKey:WeChatTweakPreferenceAutoAuthKey];
if (enabledAutoAuth) {
return NSTerminateNow;
} else {
return [self tweak_applicationShouldTerminate:sender];
}
}
#pragma mark - Preferences Window
- (id)tweak_initWithViewControllers:(NSArray *)arg1 {
NSMutableArray *viewControllers = [NSMutableArray arrayWithArray:arg1];
TweakPreferecesController *controller = [[objc_getClass("TweakPreferecesController") alloc] initWithNibName:nil bundle:[NSBundle tweakBundle]];
[viewControllers addObject:controller];
return [self tweak_initWithViewControllers:viewControllers];
}
- (id)tweak_viewControllerForIdentifier:(NSString *)arg1 {
return [self tweak_viewControllerForIdentifier:arg1];
}
@end

View File

@ -27,6 +27,14 @@
@property(retain, nonatomic) NSString *m_nsNickName;
- (BOOL)isChatStatusNotifyOpen;
@end
@interface ContactStorage : NSObject
- (id)GetContact:(id)arg1;
@end
@interface GroupStorage: NSObject
@ -57,3 +65,26 @@
- (void)AutoAuth;
@end
@protocol MASPreferencesViewController <NSObject>
@property(readonly, nonatomic) NSString *toolbarItemLabel;
@property(readonly, nonatomic) NSImage *toolbarItemImage;
@property(readonly, nonatomic) NSString *identifier;
@optional
@property(readonly, nonatomic) BOOL hasResizableHeight;
@property(readonly, nonatomic) BOOL hasResizableWidth;
- (NSView *)initialKeyView;
- (void)viewDidDisappear;
- (void)viewWillAppear;
@end
@interface MASPreferencesWindowController : NSWindowController
@property(readonly, nonatomic) NSMutableArray *viewControllers;
- (id)initWithViewControllers:(NSArray *)arg1;
@end