Add alfred json compressed switch

This commit is contained in:
Sunnyyoung 2018-03-21 16:03:56 +08:00
parent ff904cee35
commit ebc7e05fda
8 changed files with 151 additions and 10 deletions

View File

@ -13,6 +13,8 @@
7D9049F61F82A41A004E6370 /* fishhook.h in Headers */ = {isa = PBXBuildFile; fileRef = 7D9049F41F82A415004E6370 /* fishhook.h */; };
7D9049F91F82B6FB004E6370 /* NSString+WeChatTweak.m in Sources */ = {isa = PBXBuildFile; fileRef = 7D9049F81F82B6FB004E6370 /* NSString+WeChatTweak.m */; };
7D9049FA1F82B708004E6370 /* NSString+WeChatTweak.h in Headers */ = {isa = PBXBuildFile; fileRef = 7D9049F71F82B6FB004E6370 /* NSString+WeChatTweak.h */; };
7DB8AFBE206211D900E683AE /* WTConfigManager.h in Headers */ = {isa = PBXBuildFile; fileRef = 7DB8AFBC206211D900E683AE /* WTConfigManager.h */; };
7DB8AFBF206211D900E683AE /* WTConfigManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 7DB8AFBD206211D900E683AE /* WTConfigManager.m */; };
7DF8422C1F40583F00D42D79 /* WeChatTweak.h in Headers */ = {isa = PBXBuildFile; fileRef = 7DF8422A1F40583F00D42D79 /* WeChatTweak.h */; settings = {ATTRIBUTES = (Public, ); }; };
7DF842341F4058AB00D42D79 /* WeChatTweak.m in Sources */ = {isa = PBXBuildFile; fileRef = 7DF842331F4058AB00D42D79 /* WeChatTweak.m */; };
7DF842521F4058C600D42D79 /* TweakPreferecesController.h in Headers */ = {isa = PBXBuildFile; fileRef = 7DF8424F1F4058C600D42D79 /* TweakPreferecesController.h */; };
@ -48,6 +50,8 @@
7D9049F41F82A415004E6370 /* fishhook.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = fishhook.h; sourceTree = "<group>"; };
7D9049F71F82B6FB004E6370 /* NSString+WeChatTweak.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "NSString+WeChatTweak.h"; sourceTree = "<group>"; };
7D9049F81F82B6FB004E6370 /* NSString+WeChatTweak.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "NSString+WeChatTweak.m"; sourceTree = "<group>"; };
7DB8AFBC206211D900E683AE /* WTConfigManager.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WTConfigManager.h; sourceTree = "<group>"; };
7DB8AFBD206211D900E683AE /* WTConfigManager.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = WTConfigManager.m; sourceTree = "<group>"; };
7DF842271F40583F00D42D79 /* WeChatTweak.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = WeChatTweak.framework; sourceTree = BUILT_PRODUCTS_DIR; };
7DF8422A1F40583F00D42D79 /* WeChatTweak.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WeChatTweak.h; sourceTree = "<group>"; };
7DF8422B1F40583F00D42D79 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
@ -88,6 +92,8 @@
children = (
7D14E5A21F6447DB00D75132 /* AlfredManager.h */,
7D14E5A31F6447DB00D75132 /* AlfredManager.m */,
7DB8AFBC206211D900E683AE /* WTConfigManager.h */,
7DB8AFBD206211D900E683AE /* WTConfigManager.m */,
);
name = Manager;
sourceTree = "<group>";
@ -191,6 +197,7 @@
7D9049FA1F82B708004E6370 /* NSString+WeChatTweak.h in Headers */,
7DF8422C1F40583F00D42D79 /* WeChatTweak.h in Headers */,
7DF8425B1F4058DD00D42D79 /* NSBundle+WeChatTweak.h in Headers */,
7DB8AFBE206211D900E683AE /* WTConfigManager.h in Headers */,
7D9049F61F82A41A004E6370 /* fishhook.h in Headers */,
7D14E5A41F6447DB00D75132 /* AlfredManager.h in Headers */,
7DF842601F40590500D42D79 /* WeChatTweakHeaders.h in Headers */,
@ -311,6 +318,7 @@
7DF842531F4058C600D42D79 /* TweakPreferecesController.m in Sources */,
7D9049F91F82B6FB004E6370 /* NSString+WeChatTweak.m in Sources */,
7DF842341F4058AB00D42D79 /* WeChatTweak.m in Sources */,
7DB8AFBF206211D900E683AE /* WTConfigManager.m in Sources */,
7D9049F51F82A41A004E6370 /* fishhook.c in Sources */,
7DF8425C1F4058DD00D42D79 /* NSBundle+WeChatTweak.m in Sources */,
);

View File

@ -8,11 +8,13 @@
#import "TweakPreferecesController.h"
#import "NSBundle+WeChatTweak.h"
#import "WTConfigManager.h"
@interface TweakPreferecesController () <MASPreferencesViewController>
@property (weak) IBOutlet NSPopUpButton *autoAuthButton;
@property (weak) IBOutlet NSPopUpButton *notificationTypeButton;
@property (weak) IBOutlet NSPopUpButton *compressedJSONEnabledButton;
@end
@ -28,11 +30,13 @@
}
- (void)reloadData {
WTConfigManager *configManager = WTConfigManager.sharedInstance;
NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
BOOL enabledAutoAuth = [userDefaults boolForKey:WeChatTweakPreferenceAutoAuthKey];
RevokeNotificationType notificationType = [userDefaults integerForKey:WeChatTweakPreferenceRevokeNotificationTypeKey];
[self.autoAuthButton selectItemAtIndex:enabledAutoAuth ? 1 : 0];
[self.notificationTypeButton selectItemAtIndex:notificationType];
[self.compressedJSONEnabledButton selectItemAtIndex:configManager.compressedJSONEnabled ? 0 : 1];
}
#pragma mark - Event method
@ -48,6 +52,11 @@
[[NSUserDefaults standardUserDefaults] setInteger:type forKey:WeChatTweakPreferenceRevokeNotificationTypeKey];
}
- (IBAction)switchCompressedJSONEnabledAction:(NSPopUpButton *)sender {
BOOL enabled = sender.indexOfSelectedItem == 0;
WTConfigManager.sharedInstance.compressedJSONEnabled = enabled;
}
#pragma mark - MASPreferencesViewController
- (NSString *)identifier {

View File

@ -1,14 +1,15 @@
<?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">
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="13771" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
<dependencies>
<deployment identifier="macosx"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="12121"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="13771"/>
<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="compressedJSONEnabledButton" destination="ylY-lF-oFq" id="yqW-Bl-hNf"/>
<outlet property="notificationTypeButton" destination="6x2-KV-p8w" id="Kfn-2a-Yup"/>
<outlet property="view" destination="Hz6-mo-xeY" id="0bl-1N-x8E"/>
</connections>
@ -16,19 +17,19 @@
<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"/>
<rect key="frame" x="0.0" y="0.0" width="430" height="123"/>
<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"/>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="RFE-oR-GRm">
<rect key="frame" x="58" y="86" 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"/>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="B87-eD-uhI">
<rect key="frame" x="72" y="53" 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"/>
@ -36,7 +37,7 @@
</textFieldCell>
</textField>
<popUpButton verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="5by-EJ-3f2">
<rect key="frame" x="173" y="50" width="64" height="26"/>
<rect key="frame" x="173" y="81" 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"/>
@ -56,7 +57,7 @@
</connections>
</popUpButton>
<popUpButton verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="6x2-KV-p8w">
<rect key="frame" x="173" y="17" width="144" height="26"/>
<rect key="frame" x="173" y="48" width="144" height="26"/>
<popUpButtonCell key="cell" type="push" title="跟随聊天通知设置" bezelStyle="rounded" alignment="left" lineBreakMode="truncatingTail" state="on" 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"/>
@ -78,18 +79,60 @@
<action selector="switchNotificationTypeAction:" target="-2" id="xjO-Ck-wem"/>
</connections>
</popUpButton>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="zsd-Bb-6l4">
<rect key="frame" x="43" y="20" width="126" height="17"/>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" title="Alfred JSON 压缩:" id="jHw-2a-B2t">
<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="ylY-lF-oFq">
<rect key="frame" x="173" y="15" 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="10G-t9-s4T" id="taL-8q-Quu">
<behavior key="behavior" lightByBackground="YES" lightByGray="YES"/>
<font key="font" metaFont="menu"/>
<menu key="menu" id="2qr-A3-Yo5">
<items>
<menuItem title="开启" state="on" id="10G-t9-s4T">
<modifierMask key="keyEquivalentModifierMask"/>
</menuItem>
<menuItem title="关闭" id="MEN-Kg-wfj">
<modifierMask key="keyEquivalentModifierMask"/>
</menuItem>
</items>
</menu>
</popUpButtonCell>
<connections>
<action selector="switchCompressedJSONEnabledAction:" target="-2" id="HLt-oc-7An"/>
</connections>
</popUpButton>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="kNm-y0-HmG">
<rect key="frame" x="242" y="20" width="84" height="17"/>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" title="需重启客户端" id="2vl-mc-m3L">
<font key="font" size="13" name=".PingFangSC-Regular"/>
<color key="textColor" name="disabledControlTextColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
</subviews>
<constraints>
<constraint firstItem="B87-eD-uhI" firstAttribute="trailing" secondItem="RFE-oR-GRm" secondAttribute="trailing" id="3p1-WF-TYr"/>
<constraint firstItem="zsd-Bb-6l4" firstAttribute="top" secondItem="B87-eD-uhI" secondAttribute="bottom" constant="16" id="62W-9V-E2u"/>
<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="zsd-Bb-6l4" firstAttribute="trailing" secondItem="RFE-oR-GRm" secondAttribute="trailing" id="Wlh-6X-UJN"/>
<constraint firstItem="kNm-y0-HmG" firstAttribute="centerY" secondItem="ylY-lF-oFq" secondAttribute="centerY" id="eMk-RJ-Mbw"/>
<constraint firstItem="6x2-KV-p8w" firstAttribute="centerY" secondItem="B87-eD-uhI" secondAttribute="centerY" id="gqp-om-e0O"/>
<constraint firstItem="ylY-lF-oFq" firstAttribute="centerY" secondItem="zsd-Bb-6l4" secondAttribute="centerY" id="h7g-u6-ZwV"/>
<constraint firstItem="B87-eD-uhI" firstAttribute="top" secondItem="RFE-oR-GRm" secondAttribute="bottom" constant="16" id="lG1-vw-epo"/>
<constraint firstItem="kNm-y0-HmG" firstAttribute="leading" secondItem="ylY-lF-oFq" secondAttribute="trailing" constant="10" id="urr-9v-Okd"/>
<constraint firstItem="5by-EJ-3f2" firstAttribute="leading" secondItem="RFE-oR-GRm" secondAttribute="trailing" constant="8" id="v9V-TW-Voc"/>
<constraint firstItem="ylY-lF-oFq" firstAttribute="leading" secondItem="5by-EJ-3f2" secondAttribute="leading" id="wQB-cU-fmf"/>
</constraints>
<point key="canvasLocation" x="139" y="164"/>
<point key="canvasLocation" x="139" y="179.5"/>
</customView>
</objects>
</document>

View File

@ -0,0 +1,19 @@
//
// WTConfigManager.h
// WeChatTweak
//
// Created by Sunny Young on 21/03/2018.
// Copyright © 2018 Sunnyyoung. All rights reserved.
//
#import <Cocoa/Cocoa.h>
#import <objc/runtime.h>
#import <objc/message.h>
@interface WTConfigManager : NSObject
@property (nonatomic, assign) BOOL compressedJSONEnabled;
+ (instancetype)sharedInstance;
@end

View File

@ -0,0 +1,49 @@
//
// WTConfigManager.m
// WeChatTweak
//
// Created by Sunny Young on 21/03/2018.
// Copyright © 2018 Sunnyyoung. All rights reserved.
//
#import "WTConfigManager.h"
static NSString * const WeChatTweakCompressedJSONEnabledKey = @"WeChatTweakCompressedJSONEnabledKey";
@interface WTConfigManager()
@end
@implementation WTConfigManager
+ (instancetype)sharedInstance {
static dispatch_once_t onceToken;
static WTConfigManager *shared;
dispatch_once(&onceToken, ^{
shared = [[WTConfigManager alloc] init];
});
return shared;
}
- (instancetype)init {
self = [super init];
if (self) {
NSUserDefaults *userDefaults = NSUserDefaults.standardUserDefaults;
if ([userDefaults objectForKey:WeChatTweakCompressedJSONEnabledKey]) {
_compressedJSONEnabled = [userDefaults boolForKey:WeChatTweakCompressedJSONEnabledKey];
} else {
_compressedJSONEnabled = YES;
}
}
return self;
}
#pragma mark - Property method
- (void)setCompressedJSONEnabled:(BOOL)compressedJSONEnabled {
_compressedJSONEnabled = compressedJSONEnabled;
[NSUserDefaults.standardUserDefaults setBool:compressedJSONEnabled forKey:WeChatTweakCompressedJSONEnabledKey];
[NSUserDefaults.standardUserDefaults synchronize];
}
@end

View File

@ -13,6 +13,7 @@
#import "NSString+WeChatTweak.h"
#import "TweakPreferecesController.h"
#import "AlfredManager.h"
#import "WTConfigManager.h"
// Global Function
static NSArray<NSString *> *(*original_NSSearchPathForDirectoriesInDomains)(NSSearchPathDirectory directory, NSSearchPathDomainMask domainMask, BOOL expandTilde);
@ -60,6 +61,7 @@ static void __attribute__((constructor)) tweak(void) {
class_addProperty(objc_getClass("WCContactData"), "wt_avatarPath", attrs, 4);
class_addMethod(objc_getClass("WCContactData"), @selector(wt_avatarPath), method_getImplementation(class_getInstanceMethod(objc_getClass("WCContactData"), @selector(wt_avatarPath))), "@@:");
class_addMethod(objc_getClass("WCContactData"), @selector(setWt_avatarPath:), method_getImplementation(class_getInstanceMethod(objc_getClass("WCContactData"), @selector(setWt_avatarPath:))), "v@:@");
class_addMethod(objc_getClass("WCContactData"), @selector(modelPropertyWhitelist), method_getImplementation(class_getClassMethod(objc_getClass("WCContactData"), @selector(modelPropertyWhitelist))), "v@:");
}
#pragma mark - No Revoke Message
@ -198,4 +200,15 @@ static void __attribute__((constructor)) tweak(void) {
return;
}
+ (NSArray *)modelPropertyWhitelist {
if (WTConfigManager.sharedInstance.compressedJSONEnabled) {
return @[@"wt_avatarPath",
@"m_nsRemark",
@"m_nsNickName",
@"m_nsUsrName"];
} else {
return nil;
}
}
@end