Skip to content

Commit

Permalink
Styled UI
Browse files Browse the repository at this point in the history
  • Loading branch information
apparition47 committed Jul 30, 2020
1 parent 55f1d6d commit 871fc7e
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 17 deletions.
8 changes: 8 additions & 0 deletions MailTrackerBlocker.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
1BED92F81079529C00D22B4C /* MTBMailBundle.m in Sources */ = {isa = PBXBuildFile; fileRef = 559A806E0838E9B10052F47C /* MTBMailBundle.m */; };
1BF51A70108FCD1900AC8268 /* ExceptionHandling.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1BF51A6F108FCD1900AC8268 /* ExceptionHandling.framework */; };
559A81330838EEFD0052F47C /* Security.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 559A812E0838EEFD0052F47C /* Security.framework */; };
7312BAAF24D2F3B800037A14 /* active.pdf in Resources */ = {isa = PBXBuildFile; fileRef = 7312BAAE24D2F3B800037A14 /* active.pdf */; };
7312BAB124D2F3BE00037A14 /* inactive.pdf in Resources */ = {isa = PBXBuildFile; fileRef = 7312BAB024D2F3BE00037A14 /* inactive.pdf */; };
73BB027E24BACA08009BBD68 /* MTBBlockedMessage.m in Sources */ = {isa = PBXBuildFile; fileRef = 73BB027D24BACA08009BBD68 /* MTBBlockedMessage.m */; };
73BB028024BAD368009BBD68 /* NSObject+LPDynamicIvars.m in Sources */ = {isa = PBXBuildFile; fileRef = 73BB027F24BAD368009BBD68 /* NSObject+LPDynamicIvars.m */; };
73F7651A24B9F0B0000DD869 /* HeaderViewController+MailTrackerBlocker.m in Sources */ = {isa = PBXBuildFile; fileRef = 73F7651924B9F0B0000DD869 /* HeaderViewController+MailTrackerBlocker.m */; };
Expand Down Expand Up @@ -91,6 +93,8 @@
559A806E0838E9B10052F47C /* MTBMailBundle.m */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 4; lastKnownFileType = sourcecode.c.objc; path = MTBMailBundle.m; sourceTree = "<group>"; tabWidth = 4; usesTabs = 0; };
559A812E0838EEFD0052F47C /* Security.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Security.framework; path = /System/Library/Frameworks/Security.framework; sourceTree = "<absolute>"; };
559A81860838F3C30052F47C /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
7312BAAE24D2F3B800037A14 /* active.pdf */ = {isa = PBXFileReference; lastKnownFileType = image.pdf; path = active.pdf; sourceTree = "<group>"; };
7312BAB024D2F3BE00037A14 /* inactive.pdf */ = {isa = PBXFileReference; lastKnownFileType = image.pdf; path = inactive.pdf; sourceTree = "<group>"; };
73BB027C24BACA08009BBD68 /* MTBBlockedMessage.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MTBBlockedMessage.h; sourceTree = "<group>"; };
73BB027D24BACA08009BBD68 /* MTBBlockedMessage.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MTBBlockedMessage.m; sourceTree = "<group>"; };
73BB027F24BAD368009BBD68 /* NSObject+LPDynamicIvars.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSObject+LPDynamicIvars.m"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1626,6 +1630,8 @@
089C167CFE841241C02AAC07 /* Resources */ = {
isa = PBXGroup;
children = (
7312BAB024D2F3BE00037A14 /* inactive.pdf */,
7312BAAE24D2F3B800037A14 /* active.pdf */,
559A81860838F3C30052F47C /* Info.plist */,
);
path = Resources;
Expand Down Expand Up @@ -3381,6 +3387,8 @@
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
7312BAAF24D2F3B800037A14 /* active.pdf in Resources */,
7312BAB124D2F3BE00037A14 /* inactive.pdf in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
18 changes: 12 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,15 @@ Only tested on Apple Mail 13.4 on macOS 10.15 Catalina.

## Setup

1. Goto https://github.com/apparition47/MailTrackerBlocker/releases
2. Download then open the `.pkg` to install.
3. In Xcode, open `Preferences > General > Manage Plug-ins... > check "MailTrackerBlocker.mailbundle" > Apply and Restart Mail`
4. Tap on the `🛑 #` button to find out what was blocked.
1. Download and install the latest `.pkg` from the [releases page](https://github.com/apparition47/MailTrackerBlocker/releases).
2. Open Mail, goto `Preferences > General > Manage Plug-ins... > check "MailTrackerBlocker.mailbundle" > Apply and Restart Mail`.
3. Tap on the `ⓧ #` button to find out what was blocked.

You can now reenable "load remote content in messages" if you had it disabled before using MailTrackerBlocker.

### Uninstall

Delete `/Library/Mail/Bundles/MailTrackerBlocker.mailbundle`.

## Building from source

Expand All @@ -42,5 +47,6 @@ make

## Credits

* Mail.app hooking from [GPGMail](https://github.com/GPGTools/GPGMail)
* [Tracker blocking list from @dhh](https://gist.github.com/dhh/360f4dc7ddbce786f8e82b97cdad9d20)
* [GPGMail](https://github.com/GPGTools/GPGMail) team for their work on Mail.app plugins
* [@dhh](https://github.com/dhh) for the [spy pixel tracker blocking list used in HEY](https://gist.github.com/dhh/360f4dc7ddbce786f8e82b97cdad9d20)
* [@bitmanic](https://github.com/bitmanic) for the UI design
Binary file added Resources/active.pdf
Binary file not shown.
Binary file added Resources/inactive.pdf
Binary file not shown.
34 changes: 24 additions & 10 deletions Source/HeaderViewController+MailTrackerBlocker.m
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,18 @@ - (void)MTBDealloc {

- (void)MTBViewDidLoad {
[self MTBViewDidLoad];
NSButton *blockingBtn = [[NSButton alloc] init];
NSButton *blockingBtn = [NSButton buttonWithTitle:[NSString stringWithFormat: @"%d", 0] image:[NSImage imageNamed:@"inactive"] target:self action:@selector(didPressBlockingBtn)];

[mailself setIvar:kBlockingBtn value:blockingBtn];

[blockingBtn setTitle: [NSString stringWithFormat: @"🛑 %d", 0]];
[blockingBtn setImagePosition: NSImageLeft];
[blockingBtn setEnabled:NO];
[blockingBtn setAction:@selector(didPressBlockingBtn)];
[blockingBtn setTarget:self];
blockingBtn.bezelStyle = mailself.detailsLink.bezelStyle;
blockingBtn.bezelColor = mailself.detailsLink.bezelColor;
blockingBtn.bordered = NO;

[[mailself view] addSubview:blockingBtn];

blockingBtn.translatesAutoresizingMaskIntoConstraints = NO;
[blockingBtn.topAnchor constraintEqualToAnchor:mailself.detailsLink.bottomAnchor].active = YES;
[blockingBtn.topAnchor constraintEqualToAnchor:mailself.detailsLink.bottomAnchor constant:8].active = YES;
[blockingBtn.rightAnchor constraintEqualToAnchor:mailself.detailsLink.rightAnchor].active = YES;

[mailself _registerKVOForRepresentedObject:self];
Expand All @@ -47,11 +45,19 @@ - (void)MTBViewDidLoad {

#pragma mark - Buttons

-(void) setButton:(NSButton *)button fontColor:(NSColor *)color {
NSMutableAttributedString *colorTitle = [[NSMutableAttributedString alloc] initWithAttributedString:[button attributedTitle]];
NSRange range = NSMakeRange(0, button.attributedTitle.length);
[colorTitle addAttribute:NSForegroundColorAttributeName value:color range:range];
[colorTitle fixAttributesInRange:range];
[button setAttributedTitle:colorTitle];
}

- (void)didPressBlockingBtn {
MTBBlockedMessage *blkMsg = [[mailself representedObject] getIvar:@"MTBBlockedMessage"];
NSAlert *alert = [[NSAlert alloc] init];
[alert addButtonWithTitle:@"Ok"];
[alert setMessageText: [NSString stringWithFormat: @"MailBlockerTracker blocked %ld trackers", blkMsg.blockedCount]];
[alert setMessageText: [NSString stringWithFormat: @"MailBlockerTracker blocked %ld tracker(s)", blkMsg.blockedCount]];
[alert setInformativeText: blkMsg.description];
[alert setAlertStyle: NSAlertStyleWarning];
[alert beginSheetModalForWindow:[[mailself view] window] completionHandler:nil];
Expand All @@ -62,8 +68,16 @@ - (void)MTBObserveValueForKeyPath:(NSString *)keyPath ofObject:(id)object change
[self MTBObserveValueForKeyPath:keyPath ofObject:object change:change context:context];
MTBBlockedMessage *blkMsg = [[mailself representedObject] getIvar:@"MTBBlockedMessage"];
NSButton *blockingBtn = [mailself getIvar:kBlockingBtn];
[blockingBtn setEnabled: blkMsg.blockedCount > 0];
[blockingBtn setTitle:[NSString stringWithFormat: @"🛑 %ld", [blkMsg blockedCount]]];
[blockingBtn setTitle:[NSString stringWithFormat: @"%ld", [blkMsg blockedCount]]];
if (blkMsg.blockedCount > 0) {
[blockingBtn setEnabled: YES];
[blockingBtn setImage: [NSImage imageNamed:@"active"]];
[self setButton: blockingBtn fontColor: [NSColor systemBlueColor]];
} else {
[blockingBtn setEnabled: NO];
[blockingBtn setImage: [NSImage imageNamed:@"inactive"]];
[self setButton: blockingBtn fontColor: [NSColor systemGrayColor]];
}
}
@end
#undef mailself
32 changes: 32 additions & 0 deletions Source/MTBMailBundle.m
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,10 @@ + (void)initialize {
- (id)init {
if (self = [super init]) {
NSLog(@"Loaded MailTrackerBlocker %@", [self version]);

NSBundle *myBundle = [MTBMailBundle bundle];
[self _loadImages];

[GMCodeInjector injectUsingMethodPrefix:MTBMailSwizzledMethodPrefix];
}

Expand All @@ -140,6 +144,34 @@ - (void)dealloc {

}

- (void)_loadImages {
/**
* Loads all images which are used in the MTB User interface.
*/
// We need to load images and name them, because all images are searched by their name; as they are not located in the main bundle,
// +[NSImage imageNamed:] does not find them.
NSBundle *myBundle = [MTBMailBundle bundle];

NSArray *bundleImageNames = @[@"inactive",
@"active"];
NSMutableArray *bundleImages = [[NSMutableArray alloc] initWithCapacity:[bundleImageNames count]];

for (NSString *name in bundleImageNames) {
NSImage *image = [[NSImage alloc] initByReferencingFile:[myBundle pathForImageResource:name]];

// Shoud an image not exist, log a warning, but don't crash because of inserting
// nil!
if(!image) {
NSLog(@"MTB: Image %@ not found in bundle resources.", name);
continue;
}
[image setName:name];
[bundleImages addObject:image];
}

_bundleImages = bundleImages;

}

#pragma mark Localization Helper

Expand Down
2 changes: 1 addition & 1 deletion Version.config
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
TOOL=MailTrackerBlocker_#MACOS_VERSION#
MAJOR=0
MINOR=2
REVISION=2
REVISION=3
unset PRERELEASE

VERSION="${MAJOR}.${MINOR}${REVISION:+.$REVISION}${PRERELEASE}"

0 comments on commit 871fc7e

Please sign in to comment.