Skip to content

Commit

Permalink
add subview to stickyBackgroundView
Browse files Browse the repository at this point in the history
  • Loading branch information
Mengoreo committed Apr 28, 2020
1 parent 89c875c commit 53e98a4
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
6 changes: 4 additions & 2 deletions WeChatExtension/WeChatExtension.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
objects = {

/* Begin PBXBuildFile section */
08294044245812FB0056E0C6 /* pin.png in Resources */ = {isa = PBXBuildFile; fileRef = 08294043245812FA0056E0C6 /* pin.png */; };
1828B9AA23BA319E008EC8E9 /* TKAboutWindowController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 1828B9A923BA319E008EC8E9 /* TKAboutWindowController.xib */; };
1853B3C422C6133C00A5C4FA /* YMIMContactsManager.h in Headers */ = {isa = PBXBuildFile; fileRef = 1853B3C222C6133C00A5C4FA /* YMIMContactsManager.h */; };
1853B3C522C6133C00A5C4FA /* YMIMContactsManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 1853B3C322C6133C00A5C4FA /* YMIMContactsManager.m */; };
Expand Down Expand Up @@ -169,6 +170,7 @@
/* End PBXContainerItemProxy section */

/* Begin PBXFileReference section */
08294043245812FA0056E0C6 /* pin.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = pin.png; sourceTree = "<group>"; };
1802C087239826CB0061823C /* en-GB */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "en-GB"; path = "en-GB.lproj/TKRemoteControlWindowController.strings"; sourceTree = "<group>"; };
1802C088239826CB0061823C /* en-GB */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; name = "en-GB"; path = "en-GB.lproj/Info.plist"; sourceTree = "<group>"; };
1802C089239826CB0061823C /* en-GB */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "en-GB"; path = "en-GB.lproj/Localizable.strings"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -383,6 +385,7 @@
isa = PBXGroup;
children = (
18ECDCF42405194800090014 /* aliPayCode.png */,
08294043245812FA0056E0C6 /* pin.png */,
18B606DD23979FC6000A41DC /* order_avatar.png */,
96B578B62360A92500F3F66C /* Info.plist */,
18A7A12D2272ACE300361A98 /* main.mm */,
Expand Down Expand Up @@ -635,8 +638,6 @@
18D4C34A24236180006A20E2 /* NSObject+ThemeHook.m */,
18B37AB7245536ED00037B58 /* NSObject+Safe.h */,
18B37AB8245536ED00037B58 /* NSObject+Safe.m */,
188A65ED2272ACBA0096663E /* YMMessageModel.h */,
188A65E82272ACBA0096663E /* YMMessageModel.m */,
188A65EB2272ACBA0096663E /* YMMessageTool.h */,
188A65EA2272ACBA0096663E /* YMMessageTool.m */,
);
Expand Down Expand Up @@ -911,6 +912,7 @@
1828B9AA23BA319E008EC8E9 /* TKAboutWindowController.xib in Resources */,
18ECDCF52405194800090014 /* aliPayCode.png in Resources */,
188A65FB2272ACBA0096663E /* TKAutoReplyWindowController.xib in Resources */,
08294044245812FB0056E0C6 /* pin.png in Resources */,
3632293F22A6ADB300F62EAB /* LockPlist.plist in Resources */,
18B606DE23979FC6000A41DC /* order_avatar.png in Resources */,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,31 @@ - (void)hook_setSessionInfo:(MMSessionInfo *)sessionInfo
NSFont *attributesFont = [attributes valueForKey:@"NSFont"];
NSMutableAttributedString *returnValue = [[NSMutableAttributedString alloc] initWithString:str.string attributes:@{NSForegroundColorAttributeName :changeColor, NSFontAttributeName : attributesFont}];
cellView.nickName.attributedStringValue = returnValue;
// MARK: - Add pined image in dark mode
NSBundle *bundle = [NSBundle bundleWithIdentifier:@"MustangYM.WeChatExtension"];
NSString *imgPath= [bundle pathForImageResource:@"pin.png"];

NSImage *pined = [[NSImage alloc] initWithContentsOfFile:imgPath];
NSImageView *pinedView = [[NSImageView alloc] initWithFrame:NSMakeRect(0, 0, 20, 20)];
[pinedView setImage:pined];

pinedView.tag = 9999999;
[cellView.stickyBackgroundView addSubview:pinedView];
pinedView.translatesAutoresizingMaskIntoConstraints = NO;
NSMutableArray<NSLayoutConstraint*> *contraints = [NSMutableArray array];
if (@available(macOS 10.11, *)) {
[contraints addObject:[pinedView.topAnchor constraintEqualToAnchor:cellView.stickyBackgroundView.topAnchor constant:0]];

[contraints addObject:[pinedView.widthAnchor constraintEqualToConstant:10]];

[contraints addObject:[pinedView.heightAnchor constraintEqualToConstant:10]];

[contraints addObject:[pinedView.leadingAnchor constraintEqualToAnchor:cellView.stickyBackgroundView.leadingAnchor constant:0]];
[cellView.stickyBackgroundView addConstraints:contraints];
} else {
// Fallback on earlier versions
}

});
} else {
if (isIgnore) {
Expand Down
Binary file added WeChatExtension/WeChatExtension/pin.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 53e98a4

Please sign in to comment.