From 6d26c254a8cf4bb50f503d6d53eca31fa076911e Mon Sep 17 00:00:00 2001 From: Scott Perry Date: Mon, 14 Oct 2013 21:46:44 -0700 Subject: [PATCH] Basic menu bar item. Fixes #37. --- Switch.xcodeproj/project.pbxproj | 12 ++++++++++++ Switch/NNAppDelegate.m | 14 ++++++++++---- Switch/Resources/weave.png | Bin 0 -> 4498 bytes 3 files changed, 22 insertions(+), 4 deletions(-) create mode 100644 Switch/Resources/weave.png diff --git a/Switch.xcodeproj/project.pbxproj b/Switch.xcodeproj/project.pbxproj index ced4fd25..2fa329c0 100644 --- a/Switch.xcodeproj/project.pbxproj +++ b/Switch.xcodeproj/project.pbxproj @@ -17,6 +17,7 @@ BC6B6D13178DDBDA001D691D /* NNCoreWindowController.m in Sources */ = {isa = PBXBuildFile; fileRef = BC6B6D12178DDBDA001D691D /* NNCoreWindowController.m */; }; BC6B6D1C178DE8E5001D691D /* NNAPIEnabledWorker.m in Sources */ = {isa = PBXBuildFile; fileRef = BC6B6D1B178DE8E5001D691D /* NNAPIEnabledWorker.m */; }; BC8D8DA1177BA53100B7A135 /* NNHUDCollectionViewTests.m in Sources */ = {isa = PBXBuildFile; fileRef = BC8D8DA0177BA53100B7A135 /* NNHUDCollectionViewTests.m */; }; + BC948E2E180CFAA6008ED28A /* weave.png in Resources */ = {isa = PBXBuildFile; fileRef = BC948E2D180CFAA6008ED28A /* weave.png */; }; BCA734E116DAC53F00CD4C74 /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = BCA734E016DAC53F00CD4C74 /* Cocoa.framework */; }; BCA734EB16DAC53F00CD4C74 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = BCA734E916DAC53F00CD4C74 /* InfoPlist.strings */; }; BCA734ED16DAC53F00CD4C74 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = BCA734EC16DAC53F00CD4C74 /* main.m */; }; @@ -210,6 +211,7 @@ BC6B6D1A178DE8E5001D691D /* NNAPIEnabledWorker.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NNAPIEnabledWorker.h; sourceTree = ""; }; BC6B6D1B178DE8E5001D691D /* NNAPIEnabledWorker.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NNAPIEnabledWorker.m; sourceTree = ""; }; BC8D8DA0177BA53100B7A135 /* NNHUDCollectionViewTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NNHUDCollectionViewTests.m; sourceTree = ""; }; + BC948E2D180CFAA6008ED28A /* weave.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = weave.png; path = Resources/weave.png; sourceTree = ""; }; BCA734DD16DAC53F00CD4C74 /* Switch.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Switch.app; sourceTree = BUILT_PRODUCTS_DIR; }; BCA734E016DAC53F00CD4C74 /* Cocoa.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Cocoa.framework; path = System/Library/Frameworks/Cocoa.framework; sourceTree = SDKROOT; }; BCA734E316DAC53F00CD4C74 /* AppKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AppKit.framework; path = System/Library/Frameworks/AppKit.framework; sourceTree = SDKROOT; }; @@ -372,6 +374,14 @@ name = Debug; sourceTree = ""; }; + BC948E24180CFA97008ED28A /* Resources */ = { + isa = PBXGroup; + children = ( + BC948E2D180CFAA6008ED28A /* weave.png */, + ); + name = Resources; + sourceTree = ""; + }; BCA734D416DAC53F00CD4C74 = { isa = PBXGroup; children = ( @@ -432,6 +442,7 @@ BCA734E716DAC53F00CD4C74 /* Supporting Files */ = { isa = PBXGroup; children = ( + BC948E24180CFA97008ED28A /* Resources */, BCA7354116E1621400CD4C74 /* constants.h */, BCA7354216E1621400CD4C74 /* constants.m */, BCA734EF16DAC53F00CD4C74 /* Credits.rtf */, @@ -794,6 +805,7 @@ BCA734EB16DAC53F00CD4C74 /* InfoPlist.strings in Resources */, BCA734F716DAC53F00CD4C74 /* MainMenu.xib in Resources */, BCFF232E177E00FB008759C4 /* NNAXDisabledWindowController.xib in Resources */, + BC948E2E180CFAA6008ED28A /* weave.png in Resources */, BCCA7A641807894A00CE36E5 /* NNPreferencesWindowController.xib in Resources */, BC660D5B1796573200CE8333 /* Sparkle.dsa_pub.pem in Resources */, ); diff --git a/Switch/NNAppDelegate.m b/Switch/NNAppDelegate.m index 357b9c73..af62f5e9 100644 --- a/Switch/NNAppDelegate.m +++ b/Switch/NNAppDelegate.m @@ -29,6 +29,7 @@ @interface NNAppDelegate () @property (nonatomic, strong) NNAXDisabledWindowController *disabledWindowController; @property (nonatomic, strong) NNCoreWindowController *coreWindowController; @property (nonatomic, strong) NNPreferencesWindowController *preferencesWindowController; +@property (nonatomic, strong) NSStatusItem *menu; @property (nonatomic, assign) BOOL launched; @end @@ -83,15 +84,19 @@ - (void)applicationDidFinishLaunching:(NSNotification *)aNotification [defaults setBool:NO forKey:@"firstLaunch"]; } + self.menu = [[NSStatusBar systemStatusBar] statusItemWithLength:NSSquareStatusItemLength]; + self.menu.image = [[NSBundle mainBundle] imageForResource:@"weave"]; + self.menu.target = self; + self.menu.action = @selector(showPreferences:); + [defaults synchronize]; self.launched = YES; } #pragma mark IBActions -- (IBAction)showPreferences:(NSMenuItem *)sender { - NotTested(); - [self showPreferencesWindow]; +- (IBAction)showPreferences:(id)sender { + [self.preferencesWindowController showWindow:self]; } #pragma mark Notifications @@ -145,7 +150,8 @@ - (void)requestAXAPITrust; - (void)showPreferencesWindow; { - [self.preferencesWindowController showWindow:self]; + [self showPreferences:self]; + // HACK: There should be a better way to cancel the interface than committing identity fraud. [[NSNotificationCenter defaultCenter] postNotificationName:NNEventManagerKeyNotificationName object:[NNEventManager sharedManager] userInfo:@{NNEventManagerEventTypeKey : @(NNEventManagerEventTypeCancel)}]; [[NSApplication sharedApplication] activateIgnoringOtherApps:YES]; diff --git a/Switch/Resources/weave.png b/Switch/Resources/weave.png new file mode 100644 index 0000000000000000000000000000000000000000..8596df414d1d8c834a08392431710716f6c2423f GIT binary patch literal 4498 zcmb_eXIK;Kx(yKNAS%*CiIFBq=v8`X5s=W7&=Uv{S`d(?p-GV@(hQ)8R6(lJ!GQF- ziFA-A(xoF(MGm+Kp#t?@ z*EkQ<4TJf^Nkf9TJycGqF`l`4%i7=_iFzp5N|ll3K_F^~YLfxpQm?C`Iy)ZeK($sN z{$(QhuoW>mGG8$?V!MVLss_Nn1p*t~jY#~((u^2am+DQ=p6hJdA!T78p*JFVH)Uf3 zRNqx0?f*uQOG?VoXerrVh4@?7j9#mQbGr>5`Ne=Gp`7FZYSjS=Szm7ES<-m@l4e$s zBVfl?!c~zFVG*V@s`PyDbW@Sz_RBf`n)XCI_e>faqMP-t*z?F5_(U?-R7NB)%`}ng zqix203N*n0mJFEP;qB|&eWnEvVob8=n&(b)3=>ghWL*v0Bn42$H%Y&BrH|N?wtEin z%C?;e2Zq5=*=L3lF|!M8Hv1bT`g^#NeFWUfsy#C13qRxi+5z!wv3b;&Y|Q=ZHzi<$OT`6JVRu`02%x+5|&DsS~;4 z>{Pza8VIm?3Q#)n?8~JPNAuXGPqaKV5zEVtZX~G=5dH*s| z8({PpVoe?7H!$VLBEdt!>YL)gXm{5FfD4v}SHdXTuyO$C6*5j|1s_t}k_m$_bzALQ zyMmY^w`dWc@ALZ{G^XLsQ(8)3{kd)0Xlqxl^lPjclR=L4q-P&fxWAwl3xEibUbCcQ z_ZM{`n*afV{52TJo{&K_NHL1QH%juu$4gLnn8f3Oy$hf}z~?>iW}t)%xhe4WJ31E{ zT7Pv#>X3R(A(Dvz3}xUt!})ZjSC5%8PbVo4GF&jG^oADZb85sov1}QN`>0GYaN+ zqf<93ndIp!8knaptOKqETQtN`Dz;IQ^{5$9Uf57ker&`^a^|u_3^K1Ykbwg+%(JJwl7W15h4TEUFUSJk#;B~eUPriZ& zmBg8+Q36f3ETb(=it(?>hLOwH+38!~v3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