Skip to content
This repository has been archived by the owner on Oct 9, 2023. It is now read-only.

Commit

Permalink
Add compatibility with Messenger 274.1, refactor code
Browse files Browse the repository at this point in the history
  • Loading branch information
haoict committed Jul 26, 2020
1 parent 66079af commit 607a2cd
Show file tree
Hide file tree
Showing 13 changed files with 73 additions and 141 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ Thank you to my friends all around the world who helped me on translation:
- Michael Basquill
- BenCoro
- TC@BE
- jaildeejung007

Contributions of any kind welcome!

Expand Down
8 changes: 6 additions & 2 deletions Tweak.h
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
#import <Foundation/Foundation.h>
#import "settingsview/MNAUtil.h"
#import <libhdev/HUtilities/HCommon.h>
#import "settingsview/MNASettingsViewController.h"
#import "settingsview/MNAIntroViewController.h"

@interface LSAppDelegate : NSObject
- (id)getCurrentLoggedInUserId;
+ (id)sharedInstance; // new methods
- (id)getCurrentLoggedInUserId;
- (void)presentViewController:(id)arg1 animated:(BOOL)arg2 completion:(id)arg3;
@end

@interface MSGSplitViewController : UIViewController
Expand Down Expand Up @@ -48,3 +49,6 @@
@interface LSComposerComponentStackView : UIView
@end

@interface MSGListBinder : NSObject <UITableViewDelegate, UITableViewDataSource, UICollectionViewDelegateFlowLayout, UICollectionViewDataSource>
@property (nonatomic, assign) BOOL didAddMNACellHeaderView;
@end
58 changes: 36 additions & 22 deletions Tweak.xm
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,6 @@ static void reloadPrefs() {
showTheEyeButton = [[settings objectForKey:@"showTheEyeButton"] ?: @(YES) boolValue];
extendStoryVideoUploadLength = [[settings objectForKey:@"extendStoryVideoUploadLength"] ?: @(YES) boolValue];
}
static void PreferencesChangedCallback(CFNotificationCenterRef center, void *observer, CFStringRef name, const void *object, CFDictionaryRef userInfo) {
reloadPrefs();
}


/**
* Tweak's hooking code
Expand Down Expand Up @@ -76,7 +72,7 @@ static void PreferencesChangedCallback(CFNotificationCenterRef center, void *obs

%new
- (void)initEyeButton {
self.sideSwitch = [[UIView alloc] initWithFrame:CGRectMake(self.view.frame.size.width - 50, self.view.frame.size.height / 2, 50, 50)];
self.sideSwitch = [[UIView alloc] initWithFrame:CGRectMake(self.view.frame.size.width - 50, self.view.frame.size.height / 2 - 60, 50, 50)];
self.sideSwitch.backgroundColor = [[UIColor grayColor] colorWithAlphaComponent:0.3];
self.sideSwitch.layer.cornerRadius = 10;
self.imageView = [[UIImageView alloc] initWithFrame:CGRectMake(10, 10, 30, 30)];
Expand All @@ -101,15 +97,15 @@ static void PreferencesChangedCallback(CFNotificationCenterRef center, void *obs
BOOL success = [settings writeToFile:plistPath atomically:YES];

if (!success) {
[MNAUtil showAlertMessage:@"Can't write file" title:@"Error" viewController:nil];
[HCommon showAlertMessage:@"Can't write file" withTitle:@"Error" viewController:nil];
} else {
self.imageView.image = [UIImage imageWithContentsOfFile:[NSString stringWithFormat:@"%@/%@", @PREF_BUNDLE_PATH, !disablereadreceipt ? @"no-see.png" : @"see.png"]];
notify_post(PREF_CHANGED_NOTIF);
}
}

%new
-(void)move:(UIPanGestureRecognizer*)sender {
- (void)move:(UIPanGestureRecognizer*)sender {
// Thanks for this post: https://stackoverflow.com/questions/6672677/how-to-use-uipangesturerecognizer-to-move-object-iphone-ipad
[self.view bringSubviewToFront:sender.view];
CGPoint translatedPoint = [sender translationInView:sender.view.superview];
Expand Down Expand Up @@ -156,19 +152,37 @@ static void PreferencesChangedCallback(CFNotificationCenterRef center, void *obs
}
%end

%hook LSTabBarDataSource
- (void)openAppSettingsFromInboxViewController:(UIViewController *)arg1 {
UIAlertController* alert = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:[MNAUtil isiPad] ? UIAlertControllerStyleAlert : UIAlertControllerStyleActionSheet];
[alert addAction:[UIAlertAction actionWithTitle:@"Messenger No Ads Settings ⭐️" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
MNASettingsViewController *settingsVC = [[MNASettingsViewController alloc] init];
UINavigationController *navVC = [[UINavigationController alloc] initWithRootViewController:settingsVC];
[arg1 presentViewController:navVC animated:YES completion:nil];
}]];
[alert addAction:[UIAlertAction actionWithTitle:@"Messenger Settings" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
%orig;
}]];
[alert addAction:[UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:nil]];
[arg1 presentViewController:alert animated:YES completion:nil];
%hook MSGListBinder
%property (nonatomic, assign) BOOL didAddMNACellHeaderView;

- (id)tableView:(UITableView *)arg1 cellForRowAtIndexPath:(id)arg2 {
if (!self.didAddMNACellHeaderView) {
NSMutableSet *_registeredReuseIdentifiers = MSHookIvar<NSMutableSet *>(self, "_registeredReuseIdentifiers");
if ([_registeredReuseIdentifiers containsObject:@"me_setting_avatar_header"]) {
UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 60)];
UITableViewCell *mnaCell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"MNASettings"];
mnaCell.textLabel.text = @"Messenger No Ads Settings";
mnaCell.textLabel.textColor = [HCommon colorFromHex:@KTINT_COLOR];
mnaCell.imageView.image = [UIImage imageNamed:@"/Library/Application Support/MessengerNoAds.bundle/icon.png"];
mnaCell.imageView.layer.cornerRadius = mnaCell.imageView.frame.size.width?:30 / 2.0;
mnaCell.imageView.layer.masksToBounds = TRUE;
mnaCell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
mnaCell.frame = CGRectMake(3, 0, arg1.frame.size.width - 13, mnaCell.frame.size.height);
[mnaCell addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleMNACellTap:)]];
[headerView addSubview:mnaCell];

arg1.tableHeaderView = headerView;
self.didAddMNACellHeaderView = TRUE;
}
}
return %orig;
}

%new
- (void)handleMNACellTap:(UITapGestureRecognizer *)recognizer {
MNASettingsViewController *settingsVC = [[MNASettingsViewController alloc] init];
UINavigationController *navVC = [[UINavigationController alloc] initWithRootViewController:settingsVC];
[[%c(LSAppDelegate) sharedInstance] presentViewController:navVC animated:true completion:nil];
}
%end
%end
Expand Down Expand Up @@ -275,7 +289,7 @@ static void PreferencesChangedCallback(CFNotificationCenterRef center, void *obs
[alert addAction:otherOptionsAction];
[alert addAction:cancelAction];

if ([MNAUtil isiPad]) {
if (IS_iPAD) {
[alert setModalPresentationStyle:UIModalPresentationPopover];
UIPopoverPresentationController *popPresenter = [alert popoverPresentationController];
popPresenter.sourceView = arg1;
Expand Down Expand Up @@ -324,7 +338,7 @@ static void PreferencesChangedCallback(CFNotificationCenterRef center, void *obs
* Constructor
*/
%ctor {
CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(), NULL, (CFNotificationCallback) PreferencesChangedCallback, CFSTR(PREF_CHANGED_NOTIF), NULL, CFNotificationSuspensionBehaviorDeliverImmediately);
CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(), NULL, (CFNotificationCallback) reloadPrefs, CFSTR(PREF_CHANGED_NOTIF), NULL, CFNotificationSuspensionBehaviorDeliverImmediately);
reloadPrefs();

dlopen([[[NSBundle mainBundle].bundlePath stringByAppendingPathComponent:@"Frameworks/NotInCore.framework/NotInCore"] UTF8String], RTLD_NOW);
Expand Down
5 changes: 2 additions & 3 deletions control
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
Package: com.haoict.messengernoads
Name: Messenger No Ads
Depends: mobilesubstrate, com.haoict.libhdev (>= 4.1.0), firmware (>= 10)
Conflicts: com.haoict.messengernoads
Version: 3.6.0
Depends: mobilesubstrate, com.haoict.libhdev (>= 4.5.0), firmware (>= 10)
Version: 3.7.0
Architecture: iphoneos-arm
Description: The best tweak for Messenger app.
The best tweak for Messenger app.
Expand Down
21 changes: 3 additions & 18 deletions pref/Resources/Root.plist
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,6 @@
<string>/Library/PreferenceBundles/MNAPref.bundle/Banner.jpg</string>
</dict>

<!-- <dict>
<key>cell</key>
<string>PSGroupCell</string>
<key>headerCellClass</key>
<string>HPSHeaderCell</string>
<key>label</key>
<string>Messenger No Ads</string>
<key>subtitle</key>
<array>
<string>By @haoict</string>
<string>Free and Open Source!</string>
<string>Made with love</string>
</array>
</dict> -->

<!-- Support Me -->
<dict>
<key>cell</key>
Expand All @@ -47,7 +32,7 @@
<key>action</key>
<string>openURL:</string>
<key>url</key>
<string>https://messenger.com/haoict</string>
<string>https://twitter.com/haoict</string>
</dict>
<dict>
<key>cell</key>
Expand Down Expand Up @@ -89,7 +74,7 @@
<key>action</key>
<string>openURL:</string>
<key>url</key>
<string>https://github.com/haoict/messengernoads</string>
<string>https://github.com/haoict/messenger-no-ads</string>
</dict>
<dict>
<key>cell</key>
Expand All @@ -103,7 +88,7 @@
<key>action</key>
<string>openURL:</string>
<key>url</key>
<string>https://github.com/haoict/messengernoads/issues/new</string>
<string>https://github.com/haoict/messenger-no-ads/issues/new</string>
</dict>

<dict>
Expand Down
Binary file not shown.
6 changes: 3 additions & 3 deletions settingsview/MNAIntroViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ - (void)viewDidLoad {
[gradient setFrame: [[self view] bounds]];
[gradient setStartPoint:CGPointMake(0.0, -0.5)];
[gradient setEndPoint:CGPointMake(1.0, 1.0)];
[gradient setColors:@[(id)[[MNAUtil colorFromHex:@KTINT_COLOR] CGColor], (id)[[UIColor whiteColor] CGColor]]];
[gradient setColors:@[(id)[[HCommon colorFromHex:@KTINT_COLOR] CGColor], (id)[[UIColor whiteColor] CGColor]]];
[gradient setLocations:@[@0,@1]];

[[[self view] layer] insertSublayer:gradient atIndex:0];
Expand Down Expand Up @@ -58,7 +58,7 @@ - (void)viewDidLoad {
UIButton *continueButton = [[UIButton alloc] initWithFrame:CGRectMake(self.view.center.x - 125, self.view.frame.size.height * 4 / 5 - 50, 250.0f, 50.0f)];
[continueButton addTarget:self action:@selector(dismissIntroductionViewController) forControlEvents:UIControlEventTouchUpInside];
[continueButton setTitle:[MNAUtil localizedItem:@"CONFIRM"] forState:UIControlStateNormal];
continueButton.backgroundColor = [MNAUtil colorFromHex:@"#FE2E54"];
continueButton.backgroundColor = [HCommon colorFromHex:@"#FE2E54"];
continueButton.titleLabel.font = [UIFont systemFontOfSize: 17];
continueButton.layer.cornerRadius = 10;
[continueButton setTintColor: [UIColor blackColor]];
Expand Down Expand Up @@ -87,7 +87,7 @@ - (void)dismissIntroductionViewController {
BOOL success = [settings writeToFile:plistPath atomically:YES];

if (!success) {
[MNAUtil showAlertMessage:@"Can't write file" title:@"Error" viewController:nil];
[HCommon showAlertMessage:@"Can't write file" withTitle:@"Error" viewController:nil];
} else {
notify_post(PREF_CHANGED_NOTIF);
}
Expand Down
1 change: 1 addition & 0 deletions settingsview/MNASettingsViewController.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#import <libhdev/HUtilities/HCommon.h>
#import "MNAUtil.h"
#import "MNACellModel.h"
#import "MNATableViewCell.h"
Expand Down
18 changes: 9 additions & 9 deletions settingsview/MNASettingsViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ - (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
// set switches color
UIWindow *keyWindow = [UIApplication sharedApplication].keyWindow;
self.view.tintColor = [MNAUtil colorFromHex:[MNAUtil isDarkMode] ? @KTINT_COLOR_DARKMODE : @KTINT_COLOR];
keyWindow.tintColor = [MNAUtil colorFromHex:[MNAUtil isDarkMode] ? @KTINT_COLOR_DARKMODE : @KTINT_COLOR];
[UISwitch appearanceWhenContainedInInstancesOfClasses:@[self.class]].onTintColor = [MNAUtil colorFromHex:[MNAUtil isDarkMode] ? @KTINT_COLOR_DARKMODE : @KTINT_COLOR];
self.view.tintColor = [HCommon colorFromHex:[HCommon isDarkMode] ? @KTINT_COLOR_DARKMODE : @KTINT_COLOR];
keyWindow.tintColor = [HCommon colorFromHex:[HCommon isDarkMode] ? @KTINT_COLOR_DARKMODE : @KTINT_COLOR];
[UISwitch appearanceWhenContainedInInstancesOfClasses:@[self.class]].onTintColor = [HCommon colorFromHex:[HCommon isDarkMode] ? @KTINT_COLOR_DARKMODE : @KTINT_COLOR];
// set navigation bar color
self.navigationController.navigationBar.barTintColor = [MNAUtil colorFromHex:[MNAUtil isDarkMode] ? @KTINT_COLOR_DARKMODE : @KTINT_COLOR];
self.navigationController.navigationBar.barTintColor = [HCommon colorFromHex:[HCommon isDarkMode] ? @KTINT_COLOR_DARKMODE : @KTINT_COLOR];
self.navigationController.navigationBar.tintColor = [UIColor whiteColor];
[self.navigationController.navigationBar setShadowImage: [UIImage new]];
self.navigationController.navigationController.navigationBar.translucent = NO;
Expand All @@ -60,7 +60,7 @@ - (void)viewWillAppear:(BOOL)animated {
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
UIWindow *keyWindow = [UIApplication sharedApplication].keyWindow;
keyWindow.tintColor = [MNAUtil isDarkMode] ? [UIColor whiteColor] : [UIColor blackColor]; // should be nil for default, but Messenger uses black/white
keyWindow.tintColor = [HCommon isDarkMode] ? [UIColor whiteColor] : [UIColor blackColor]; // should be nil for default, but Messenger uses black/white
self.navigationController.navigationBar.barTintColor = nil;
self.navigationController.navigationBar.tintColor = nil;
[self.navigationController.navigationBar setShadowImage:nil];
Expand All @@ -76,7 +76,7 @@ - (void)viewDidLoad {
_tableView.dataSource = self;
_tableView.alwaysBounceVertical = NO;
_tableView.translatesAutoresizingMaskIntoConstraints = NO;
_tableView.backgroundColor = [MNAUtil colorFromHex:[MNAUtil isDarkMode] ? @TABLE_BACKGROUND_COLOR_DARKMODE : @TABLE_BACKGROUND_COLOR];
_tableView.backgroundColor = [HCommon colorFromHex:[HCommon isDarkMode] ? @TABLE_BACKGROUND_COLOR_DARKMODE : @TABLE_BACKGROUND_COLOR];
[_tableView setSeparatorStyle:UITableViewCellSeparatorStyleNone];
[self.view addSubview:_tableView];
if (@available(iOS 11, *)) {
Expand All @@ -98,7 +98,7 @@ - (void)viewDidLoad {
// setup table image header
_headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 200, 200)];
_headerImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 200, 200)];
_headerImageView.contentMode = ([MNAUtil isiPad] || self.view.bounds.size.width > self.view.bounds.size.height) ? UIViewContentModeScaleAspectFit : UIViewContentModeScaleAspectFill;
_headerImageView.contentMode = (IS_iPAD || self.view.bounds.size.width > self.view.bounds.size.height) ? UIViewContentModeScaleAspectFit : UIViewContentModeScaleAspectFill;
_headerImageView.image = [UIImage imageWithContentsOfFile:[NSString stringWithFormat:@"%@/%@", @PREF_BUNDLE_PATH, @"Banner.jpg"]];
_headerImageView.translatesAutoresizingMaskIntoConstraints = NO;

Expand Down Expand Up @@ -205,7 +205,7 @@ - (void)initTableData {

- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation {
// [_tableView reloadData];
_headerImageView.contentMode = ([MNAUtil isiPad] || self.view.bounds.size.width > self.view.bounds.size.height) ? UIViewContentModeScaleAspectFit : UIViewContentModeScaleAspectFill;
_headerImageView.contentMode = (IS_iPAD || self.view.bounds.size.width > self.view.bounds.size.height) ? UIViewContentModeScaleAspectFit : UIViewContentModeScaleAspectFill;
}

- (void)close {
Expand Down Expand Up @@ -253,7 +253,7 @@ - (void)resetSettings {
[@{} writeToFile:plistPath atomically:YES];
[_tableView reloadData];
notify_post(PREF_CHANGED_NOTIF);
// [MNAUtil showAlertMessage:nil title:@"Done" viewController:self];
// [HCommon showToastMessage:@"" withTitle:@"Done!" timeout:0.5 viewController:self];
[MNAUtil showRequireRestartAlert:self];
}

Expand Down
1 change: 1 addition & 0 deletions settingsview/MNATableViewCell.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#import <libhdev/HUtilities/HCommon.h>
#import <notify.h>
#import "MNAUtil.h"
#import "MNACellModel.h"
Expand Down
16 changes: 8 additions & 8 deletions settingsview/MNATableViewCell.m
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ - (id)initWithData:(MNACellModel *)cellData reuseIdentifier:(NSString *)reuseIde
_plistPath = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0] stringByAppendingPathComponent:@PLIST_FILENAME];
if (self) {
self.textLabel.text = cellData.label;
self.textLabel.textColor = [MNAUtil colorFromHex:[MNAUtil isDarkMode] ? @LABEL_COLOR_DARKMODE : @LABEL_COLOR];
self.textLabel.textColor = [HCommon colorFromHex:[HCommon isDarkMode] ? @LABEL_COLOR_DARKMODE : @LABEL_COLOR];
self.selectionStyle = UITableViewCellSelectionStyleNone;
self.detailTextLabel.text = cellData.subtitle;
self.detailTextLabel.textColor = [MNAUtil colorFromHex:[MNAUtil isDarkMode] ? @SUBTITLE_COLOR_DARKMODE : @SUBTITLE_COLOR];
self.detailTextLabel.textColor = [HCommon colorFromHex:[HCommon isDarkMode] ? @SUBTITLE_COLOR_DARKMODE : @SUBTITLE_COLOR];
if (cellData.disabled) {
self.userInteractionEnabled = NO;
self.textLabel.enabled = NO;
Expand All @@ -44,7 +44,7 @@ - (id)initWithData:(MNACellModel *)cellData reuseIdentifier:(NSString *)reuseIde

case StaticText: {
self.textLabel.font=[UIFont systemFontOfSize:STATIC_FONT_SIZE];
self.contentView.backgroundColor = [MNAUtil colorFromHex:[MNAUtil isDarkMode] ? @STATIC_BACKGROUND_COLOR_DARKMODE : @STATIC_BACKGROUND_COLOR];
self.contentView.backgroundColor = [HCommon colorFromHex:[HCommon isDarkMode] ? @STATIC_BACKGROUND_COLOR_DARKMODE : @STATIC_BACKGROUND_COLOR];
break;
}

Expand Down Expand Up @@ -72,21 +72,21 @@ - (void)setHighlighted:(BOOL)highlighted animated:(BOOL)animated {
[super setHighlighted:highlighted animated:animated];
if (highlighted) {
if (self.selectionStyle != UITableViewCellSelectionStyleNone) {
self.contentView.superview.backgroundColor = [[MNAUtil colorFromHex:@KTINT_COLOR] colorWithAlphaComponent:0.3];
self.contentView.superview.backgroundColor = [[HCommon colorFromHex:@KTINT_COLOR] colorWithAlphaComponent:0.3];
}
} else {
self.contentView.superview.backgroundColor = [MNAUtil colorFromHex:[MNAUtil isDarkMode] ? @CELL_BACKGROUND_COLOR_DARKMODE : @CELL_BACKGROUND_COLOR];
self.contentView.superview.backgroundColor = [HCommon colorFromHex:[HCommon isDarkMode] ? @CELL_BACKGROUND_COLOR_DARKMODE : @CELL_BACKGROUND_COLOR];
}
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
[super setSelected:selected animated:animated];
if (selected) {
if (self.selectionStyle != UITableViewCellSelectionStyleNone) {
self.contentView.superview.backgroundColor = [[MNAUtil colorFromHex:@KTINT_COLOR] colorWithAlphaComponent:0.3];
self.contentView.superview.backgroundColor = [[HCommon colorFromHex:@KTINT_COLOR] colorWithAlphaComponent:0.3];
}
} else {
self.contentView.superview.backgroundColor = [MNAUtil colorFromHex:[MNAUtil isDarkMode] ? @CELL_BACKGROUND_COLOR_DARKMODE : @CELL_BACKGROUND_COLOR];
self.contentView.superview.backgroundColor = [HCommon colorFromHex:[HCommon isDarkMode] ? @CELL_BACKGROUND_COLOR_DARKMODE : @CELL_BACKGROUND_COLOR];
}
}

Expand All @@ -96,7 +96,7 @@ - (void)setPreferenceValue:(id)value {
BOOL success = [settings writeToFile:_plistPath atomically:YES];

if (!success) {
[MNAUtil showAlertMessage:@"Can't write file: %@" title:@"Error" viewController:_vc];
[HCommon showAlertMessage:@"Can't write file" withTitle:@"Error" viewController:nil];
} else {
notify_post(PREF_CHANGED_NOTIF);

Expand Down

0 comments on commit 607a2cd

Please sign in to comment.