diff --git a/DynamicLyrics/LyricX.xcodeproj/project.pbxproj b/DynamicLyrics/LyricX.xcodeproj/project.pbxproj
index e31b765..8f51778 100644
--- a/DynamicLyrics/LyricX.xcodeproj/project.pbxproj
+++ b/DynamicLyrics/LyricX.xcodeproj/project.pbxproj
@@ -692,7 +692,7 @@
02710EA9152A839F006D4BFF /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
- CODE_SIGN_IDENTITY = "Developer ID Application: Zhu Zheng (R5RMP6G3GQ)";
+ CODE_SIGN_IDENTITY = "";
COMBINE_HIDPI_IMAGES = YES;
FRAMEWORK_SEARCH_PATHS = (
"$(inherited)",
@@ -703,6 +703,7 @@
GCC_PREFIX_HEADER = "LyricX/LyricX-Prefix.pch";
INFOPLIST_FILE = "LyricX/LyricX-Info.plist";
MACOSX_DEPLOYMENT_TARGET = 10.7;
+ OTHER_CODE_SIGN_FLAGS = "";
OTHER_LDFLAGS = "-licucore";
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE = "";
@@ -714,7 +715,7 @@
02710EAA152A839F006D4BFF /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
- CODE_SIGN_IDENTITY = "Developer ID Application: Zhu Zheng (R5RMP6G3GQ)";
+ CODE_SIGN_IDENTITY = "";
COMBINE_HIDPI_IMAGES = YES;
FRAMEWORK_SEARCH_PATHS = (
"$(inherited)",
@@ -725,6 +726,7 @@
GCC_PREFIX_HEADER = "LyricX/LyricX-Prefix.pch";
INFOPLIST_FILE = "LyricX/LyricX-Info.plist";
MACOSX_DEPLOYMENT_TARGET = 10.7;
+ OTHER_CODE_SIGN_FLAGS = "";
OTHER_LDFLAGS = "-licucore";
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE = "";
diff --git a/DynamicLyrics/LyricX/LyricX-Info.plist b/DynamicLyrics/LyricX/LyricX-Info.plist
index 041f21d..c9e831d 100644
--- a/DynamicLyrics/LyricX/LyricX-Info.plist
+++ b/DynamicLyrics/LyricX/LyricX-Info.plist
@@ -19,7 +19,7 @@
CFBundleShortVersionString
2.1
CFBundleVersion
- 1320
+ 1538
LSApplicationCategoryType
public.app-category.music
LSMinimumSystemVersion
diff --git a/DynamicLyrics/LyricX/LyricsView.m b/DynamicLyrics/LyricX/LyricsView.m
index 292cbf8..4d92765 100644
--- a/DynamicLyrics/LyricX/LyricsView.m
+++ b/DynamicLyrics/LyricX/LyricsView.m
@@ -29,7 +29,7 @@ - (id)initWithFrame:(NSRect)frame
self = [super initWithFrame:frame];
if (self) {
nc = [NSNotificationCenter defaultCenter];
- [nc addObserver:self selector:@selector(iTunesLyricsChanged:) name:@"LyricsChanged" object:nil];
+ [nc addObserver:self selector:@selector(iTunesLyricsChanged:) name:@NC_LyricsChanged object:nil];
rootLayer = [[CALayer layer] retain];
diff --git a/DynamicLyrics/LyricX/MainController.m b/DynamicLyrics/LyricX/MainController.m
index fef65c6..47ed5f9 100644
--- a/DynamicLyrics/LyricX/MainController.m
+++ b/DynamicLyrics/LyricX/MainController.m
@@ -110,22 +110,30 @@ - (void) iTunesPlayerInfo:(NSNotification *)note
iTunesApplication *iTunes = [SBApplication applicationWithBundleIdentifier:@"com.apple.iTunes"];
- if ([[[note userInfo] objectForKey:@"Player State"] isEqualToString:@"Stopped"]) {
+ NSString*state=[[note userInfo] objectForKey:@"Player State"];
+
+ if ([state isEqualToString:@"Stopped"]) {
[nc postNotificationName:@"LyricsChanged" object:self userInfo:[NSDictionary dictionaryWithObject:@"DynamicLyrics!" forKey:@"Lyrics"]];
return;
+ }else if([state isEqualToString:@"Paused"]){
+ NSMutableDictionary *dict = [NSMutableDictionary dictionary];
+ [dict setObject:@"iTunesPause" forKey:@"Type"];
+ [dict setObject:@YES forKey:@"isPausing"];
+ [self performSelectorOnMainThread:@selector(WorkingThread:) withObject:dict waitUntilDone:YES];
+ }else if([state isEqualToString:@"Playing"]){
+ {
+ NSMutableDictionary *dict = [NSMutableDictionary dictionary];
+ [dict setObject:@"iTunesPause" forKey:@"Type"];
+ [dict setObject:@NO forKey:@"isPausing"];
+ [self performSelectorOnMainThread:@selector(WorkingThread:) withObject:dict waitUntilDone:YES];
+ }
+
+ if (self.iTunesCurrentTrack == [iTunes currentTrack])return;
+ self.iTunesCurrentTrack = [iTunes currentTrack];
+ NSMutableDictionary *dict = [NSMutableDictionary dictionary];
+ [dict setObject:@"iTunesSongChanged" forKey:@"Type"];
+ [self WorkingThread:dict];
}
-
-
- if ((note != nil) && (![[[note userInfo] objectForKey:@"Player State"] isEqualToString:@"Playing"])) {
- return;
- }
-
- if (self.iTunesCurrentTrack == [iTunes currentTrack]) return;
- self.iTunesCurrentTrack = [iTunes currentTrack];
-
- NSMutableDictionary *dict = [NSMutableDictionary dictionary];
- [dict setObject:@"iTunesSongChanged" forKey:@"Type"];
- [self WorkingThread:dict];
}
}
@@ -221,7 +229,8 @@ - (void) WorkingThread:(NSMutableDictionary*)tmpDict
//this thread should work in main thread
//iTunesPosition or iTunesSongChanged handler
@autoreleasepool {
- if ([[tmpDict objectForKey:@"Type"] isEqualToString:@"iTunesSongChanged"])
+ NSString*type=[tmpDict objectForKey:@"Type"];
+ if ([type isEqualToString:@"iTunesSongChanged"])
{
//iTunesSongChanged
NSLog(@"%@",[iTunesCurrentTrack name]);
@@ -260,7 +269,7 @@ - (void) WorkingThread:(NSMutableDictionary*)tmpDict
}
- else
+ else if([type isEqualToString:@"iTunesPosition"])
{
//iTunesPosition
NSString *_currentPlayerPosition = [NSString stringWithString:[tmpDict objectForKey:@"currentPlayerPosition"]];
@@ -316,6 +325,9 @@ - (void) WorkingThread:(NSMutableDictionary*)tmpDict
}
+ }else if([type isEqualToString:@"iTunesPause"]){
+ id obj=[tmpDict objectForKey:@"isPausing"];
+ [nc postNotificationName:@"iTunesPaused" object:self userInfo:[NSDictionary dictionaryWithObject:obj forKey:@"isPausing"]];
}
}
}
@@ -407,29 +419,28 @@ - (void)iTunesMonitoringThread
[[NSApplication sharedApplication] terminate:self];
//exit(0); //现在不通过Helper结束DynamicLyrics了,因为SandBox的缘故,我又懒得弄NSConnection,直接自己退出=。=
}
- if ([iTunes isRunning] && [iTunes playerState] == iTunesEPlSPlaying) {
- if (iTunesVersion >= 1103042001000000)
- {
- PlayerPosition = [iTunesNEW playerPosition];
+ if ([iTunes isRunning]) {
+ if([iTunes playerState] == iTunesEPlSPlaying){
- } else
- {
- PlayerPosition = [iTunesOLD playerPosition];
- }
-
- if ((currentPlayerPosition / 1000) != PlayerPosition && currentPlayerPosition % 1000 < 900)
- currentPlayerPosition = PlayerPosition * 1000;
- NSMutableDictionary *dict = [NSMutableDictionary dictionary];
-
-
- [dict setObject:@"iTunesPosition" forKey:@"Type"];
- [dict setObject:[NSString stringWithFormat:@"%lu",currentPlayerPosition] forKey:@"currentPlayerPosition"];
- [self performSelectorOnMainThread:@selector(WorkingThread:) withObject:dict waitUntilDone:YES];
-
- }
- else {
- sleep(1);
- }
+ if (iTunesVersion >= 1103042001000000)
+ {
+ PlayerPosition = [iTunesNEW playerPosition];
+
+ } else
+ {
+ PlayerPosition = [iTunesOLD playerPosition];
+ }
+
+ if ((currentPlayerPosition / 1000) != PlayerPosition && currentPlayerPosition % 1000 < 900)
+ currentPlayerPosition = PlayerPosition * 1000;
+ NSMutableDictionary *dict = [NSMutableDictionary dictionary];
+
+
+ [dict setObject:@"iTunesPosition" forKey:@"Type"];
+ [dict setObject:[NSString stringWithFormat:@"%lu",currentPlayerPosition] forKey:@"currentPlayerPosition"];
+ [self performSelectorOnMainThread:@selector(WorkingThread:) withObject:dict waitUntilDone:YES];
+ }else sleep(1);
+ }else sleep(1);
}
}
}
diff --git a/DynamicLyrics/LyricX/MenuBarLyrics.h b/DynamicLyrics/LyricX/MenuBarLyrics.h
index d562267..302cab5 100644
--- a/DynamicLyrics/LyricX/MenuBarLyrics.h
+++ b/DynamicLyrics/LyricX/MenuBarLyrics.h
@@ -13,10 +13,10 @@
NSNotificationCenter *nc;
NSStatusItem *_statusItem;
NSOperationQueue *_queue;
-
}
@property(nonatomic, retain) NSString *CurrentSongLyrics;
+@property(retain)NSMenu*AppMenu;
-(id) initWithMenu:(NSMenu *)AppMenu;
diff --git a/DynamicLyrics/LyricX/MenuBarLyrics.m b/DynamicLyrics/LyricX/MenuBarLyrics.m
index 45d85b4..a58eb3d 100644
--- a/DynamicLyrics/LyricX/MenuBarLyrics.m
+++ b/DynamicLyrics/LyricX/MenuBarLyrics.m
@@ -7,6 +7,7 @@
//
#import "MenuBarLyrics.h"
+#import "LyricXAppDelegate.h"
#import "Constants.h"
@interface NSStatusBar (NSStatusBar_Private)
@@ -33,16 +34,53 @@ -(id) initWithMenu:(NSMenu *)AppMenu;
[image setTemplate:YES];
[_statusItem setImage:image];
[_statusItem setHighlightMode:YES];
- [_statusItem setMenu:AppMenu];
+ self.AppMenu=AppMenu;
+ [_statusItem setTarget:self];
+ [_statusItem setAction:@selector(toggleDesktopLyrics:)];
+ [_statusItem sendActionOn:NSLeftMouseUpMask|NSRightMouseUpMask];
nc = [NSNotificationCenter defaultCenter];
[nc addObserver:self selector:@selector(iTunesLyricsChanged:) name:@NC_LyricsChanged object:nil];
+ [nc addObserver:self selector:@selector(iTunesPaused:) name:@"iTunesPaused" object:nil];
NSLog(@"%@",@"MenuBarLyrics");
}
return self;
}
-
+-(bool)_toggleDesktopLyrics:(NSMenuItem*)item{
+ CGKeyCode key=kVK_ANSI_X;NSString*kx=@"x";
+ CGEventRef kd=CGEventCreateKeyboardEvent(nil,key,true);
+ CGEventRef ku=CGEventCreateKeyboardEvent(nil,key,false);
+ if(!kd||!ku){
+ [_statusItem performSelectorOnMainThread:@selector(setEnabled:) withObject:true waitUntilDone:false];
+ if(kd)CFRelease(kd);
+ if(ku)CFRelease(ku);
+ return false;
+ }
+ NSString*kv=[item keyEquivalent];
+ NSUInteger km=[item keyEquivalentModifierMask];
+ [item setKeyEquivalent:kx];
+ [item setKeyEquivalentModifierMask:0];
+ [NSThread sleepForTimeInterval:0.1];
+ CGEventTapLocation loc=kCGHIDEventTap;
+ CGEventPost(loc,kd);
+ CGEventPost(loc,ku);
+ [NSThread sleepForTimeInterval:0.1];
+ [item setKeyEquivalent:kv];
+ [item setKeyEquivalentModifierMask:km];
+ CFRelease(kd);CFRelease(ku);
+ [_statusItem performSelectorOnMainThread:@selector(setEnabled:) withObject:true waitUntilDone:false];
+ return true;
+}
+-(void)toggleDesktopLyrics:(id)sender{
+ NSEvent*event=[NSApp currentEvent];
+ if([event type]!=NSRightMouseUp&&!([event modifierFlags]&NSControlKeyMask)){
+ [_statusItem setEnabled:false];
+ NSMenuItem*item=[self.AppMenu itemWithTag:100];
+ [self performSelectorInBackground:@selector(_toggleDesktopLyrics:) withObject:item];
+ [_statusItem popUpStatusItemMenu:self.AppMenu];
+ }else [_statusItem popUpStatusItemMenu:self.AppMenu];
+}
-(void) dealloc
{
self.CurrentSongLyrics = nil;
@@ -50,20 +88,35 @@ -(void) dealloc
[_statusItem release];
[super dealloc];
}
-
+-(bool)isStatusBarWideEnoughToDisplayLyrics{
+ // TODO
+ return true;
+}
-(void) showSmoothTitle:(NSString *)title
{
+ NSString*font=@"Bradley Hand";
+// font=@"Jxixinkai";
+ NSMutableDictionary *d = [NSMutableDictionary dictionary];
+ [d setObject:[NSFont fontWithName: font size: 15] forKey:NSFontAttributeName];
+ [d setObject:[NSNumber numberWithInt: 1] forKey:NSBaselineOffsetAttributeName];
+
+
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSString *style = [[NSUserDefaults standardUserDefaults] stringForKey:@"AppleInterfaceStyle"];
CGFloat white = (style && [style isEqualToString:@"Dark"]) ? 1 : 0;
+ {
+ NSAttributedString *shadowTitle = [[NSAttributedString alloc] initWithString:title attributes:d];
+ [_statusItem setAttributedTitle:shadowTitle];
+ if(![self isStatusBarWideEnoughToDisplayLyrics])
+ title=@"…";
+ }
+
for (float alpha = 0.3; alpha < 1.01; alpha+=0.02)
{
NSColor *color = [NSColor colorWithCalibratedWhite:white alpha:alpha];
- NSMutableDictionary *d = [NSMutableDictionary dictionary];
[d setObject:color forKey:NSForegroundColorAttributeName];
- [d setObject:[NSFont fontWithName: @"Lucida Grande" size: 15] forKey:NSFontAttributeName];
NSAttributedString *shadowTitle = [[NSAttributedString alloc] initWithString:title attributes:d];
@@ -103,8 +156,12 @@ -(void) hideSmoothTitle:(NSDictionary *)dict
[_statusItem setTitle:@""];
[pool release];
}
-
-
+-(void)iTunesPaused:(NSNotification*)notification{
+ bool pausing=[[[notification userInfo]valueForKey:@"isPausing"]boolValue];
+ NSLog(@"%s",pausing?"Paused":"Playing");
+ [_statusItem setAttributedTitle:nil];
+ [_statusItem setImage:[NSImage imageNamed:@"StatusIcon"]];
+}
-(void)iTunesLyricsChanged:(NSNotification *)note
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
@@ -134,7 +191,9 @@ -(void)iTunesLyricsChanged:(NSNotification *)note
[_queue cancelAllOperations];
if ([ud boolForKey:@Pref_Enable_MenuBar_Lyrics] || forceUpdate) {
- if ([self.CurrentSongLyrics isEqualToString:@""]) {
+// NSString*trimmed=[self.CurrentSongLyrics stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
+ NSString*trimmed=self.CurrentSongLyrics;
+ if ([trimmed isEqualToString:@""]){
[_statusItem setAttributedTitle:nil];
[_statusItem setImage:[NSImage imageNamed:@"StatusIcon"]];
}else{
diff --git a/DynamicLyrics/LyricX/en.lproj/MainMenu.xib b/DynamicLyrics/LyricX/en.lproj/MainMenu.xib
index 29baee2..de06eaa 100644
--- a/DynamicLyrics/LyricX/en.lproj/MainMenu.xib
+++ b/DynamicLyrics/LyricX/en.lproj/MainMenu.xib
@@ -1,8 +1,8 @@
-
+
-
-
+
+
@@ -11,7 +11,7 @@
-
+
-
\ No newline at end of file
+
diff --git a/DynamicLyrics/LyricX/zh-Hans.lproj/MainMenu.xib b/DynamicLyrics/LyricX/zh-Hans.lproj/MainMenu.xib
index 4f20e0b..70ea85e 100644
--- a/DynamicLyrics/LyricX/zh-Hans.lproj/MainMenu.xib
+++ b/DynamicLyrics/LyricX/zh-Hans.lproj/MainMenu.xib
@@ -1,8 +1,8 @@
-
+
-
-
+
+
@@ -11,7 +11,7 @@
-
+
-
\ No newline at end of file
+
diff --git a/DynamicLyricsHelper/DynamicLyricsHelper.xcodeproj/project.pbxproj b/DynamicLyricsHelper/DynamicLyricsHelper.xcodeproj/project.pbxproj
index 9001634..589bb70 100644
--- a/DynamicLyricsHelper/DynamicLyricsHelper.xcodeproj/project.pbxproj
+++ b/DynamicLyricsHelper/DynamicLyricsHelper.xcodeproj/project.pbxproj
@@ -252,7 +252,7 @@
isa = XCBuildConfiguration;
buildSettings = {
CODE_SIGN_ENTITLEMENTS = DynamicLyricsHelper/DynamicLyricsHelper.entitlements;
- CODE_SIGN_IDENTITY = "Developer ID Application: Zhu Zheng (R5RMP6G3GQ)";
+ CODE_SIGN_IDENTITY = "";
COMBINE_HIDPI_IMAGES = YES;
GCC_C_LANGUAGE_STANDARD = c89;
GCC_PRECOMPILE_PREFIX_HEADER = YES;
@@ -270,7 +270,7 @@
isa = XCBuildConfiguration;
buildSettings = {
CODE_SIGN_ENTITLEMENTS = DynamicLyricsHelper/DynamicLyricsHelper.entitlements;
- CODE_SIGN_IDENTITY = "Developer ID Application: Zhu Zheng (R5RMP6G3GQ)";
+ CODE_SIGN_IDENTITY = "";
COMBINE_HIDPI_IMAGES = YES;
GCC_C_LANGUAGE_STANDARD = c89;
GCC_PRECOMPILE_PREFIX_HEADER = YES;