From 2607a2b892ce3c4f4da0b09c88ed1d6a4951020c Mon Sep 17 00:00:00 2001 From: der richter Date: Thu, 30 Jan 2020 14:32:31 +0100 Subject: mac: activate logging when started from the bundle this creates a default log for the last mpv run when started from the bundle. that way one can get a log of what happened even after an issue occurred. also add a menu entry under Help to show the current log, but only when the bundle is used. Fixes #7396 Fixes #2547 --- osdep/macosx_menubar.m | 45 +++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 41 insertions(+), 4 deletions(-) (limited to 'osdep') diff --git a/osdep/macosx_menubar.m b/osdep/macosx_menubar.m index 349dd85aff..11fdda5e53 100644 --- a/osdep/macosx_menubar.m +++ b/osdep/macosx_menubar.m @@ -594,6 +594,15 @@ @"key" : @"", @"target" : self, @"url" : @"https://github.com/mpv-player/mpv/issues/new/choose" + }], + [NSMutableDictionary dictionaryWithDictionary:@{ + @"name" : @"Show log File…", + @"action" : @"showFile:", + @"key" : @"", + @"target" : self, + @"file" : @"~/Library/Logs/mpv.log", + @"alertTitle" : @"No log File found.", + @"alertText" : @"You deactivated logging for the Bundle." }] ] } @@ -609,6 +618,7 @@ { NSMenu *mainMenu = [[NSMenu alloc] initWithTitle:@"MainMenu"]; [NSApp setServicesMenu:[[NSMenu alloc] init]]; + NSString* bundle = [[[NSProcessInfo processInfo] environment] objectForKey:@"MPVBUNDLE"]; for(id mMenu in menuTree) { NSMenu *menu = [[NSMenu alloc] initWithTitle:mMenu[@"name"]]; @@ -618,17 +628,25 @@ [mainMenu setSubmenu:menu forItem:mItem]; for(id subMenu in mMenu[@"menu"]) { + NSString *name = subMenu[@"name"]; + NSString *action = subMenu[@"action"]; + #if HAVE_MACOS_TOUCHBAR - if ([subMenu[@"action"] isEqual:@"toggleTouchBarCustomizationPalette:"]) { + if ([action isEqual:@"toggleTouchBarCustomizationPalette:"]) { if (![NSApp respondsToSelector:@selector(touchBar)]) continue; } #endif - if ([subMenu[@"name"] isEqual:@"separator"]) { + + if ([name isEqual:@"Show log File…"] && ![bundle isEqual:@"true"]) { + continue; + } + + if ([name isEqual:@"separator"]) { [menu addItem:[NSMenuItem separatorItem]]; } else { - NSMenuItem *iItem = [menu addItemWithTitle:subMenu[@"name"] - action:NSSelectorFromString(subMenu[@"action"]) + NSMenuItem *iItem = [menu addItemWithTitle:name + action:NSSelectorFromString(action) keyEquivalent:subMenu[@"key"]]; [iItem setTarget:subMenu[@"target"]]; [subMenu setObject:iItem forKey:@"menuItem"]; @@ -754,6 +772,25 @@ [[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:url]]; } +- (void)showFile:(NSMenuItem *)menuItem +{ + NSWorkspace *workspace = [NSWorkspace sharedWorkspace]; + NSFileManager *fileManager = [NSFileManager defaultManager]; + NSMutableDictionary *mItemDict = [self getDictFromMenuItem:menuItem]; + NSString *file = [mItemDict[@"file"] stringByExpandingTildeInPath]; + + if ([fileManager fileExistsAtPath:file]){ + NSURL *url = [NSURL fileURLWithPath:file]; + NSArray *urlArray = [NSArray arrayWithObjects:url, nil]; + + [workspace activateFileViewerSelectingURLs:urlArray]; + return; + } + + [self alertWithTitle:mItemDict[@"alertTitle"] + andText:mItemDict[@"alertText"]]; +} + - (void)alertWithTitle:(NSString *)title andText:(NSString *)text { NSAlert *alert = [[NSAlert alloc] init]; -- cgit v1.2.3