From 8dbfee654cb9222436dbb209f3a338bf4b72b930 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20Brandsta=CC=88tter?= Date: Sun, 25 Feb 2018 17:29:27 +0100 Subject: [PATCH 1/2] Add grayscale icon option to settings window. --- FreenetTray/Base.lproj/FNSettingsWindow.xib | 32 +++++++++++++++++---- FreenetTray/FNSettingsWindowController.h | 2 ++ FreenetTray/FNSettingsWindowController.m | 3 ++ FreenetTray/defaults.plist | 2 ++ 4 files changed, 33 insertions(+), 6 deletions(-) diff --git a/FreenetTray/Base.lproj/FNSettingsWindow.xib b/FreenetTray/Base.lproj/FNSettingsWindow.xib index 98c7104..1cd406e 100644 --- a/FreenetTray/Base.lproj/FNSettingsWindow.xib +++ b/FreenetTray/Base.lproj/FNSettingsWindow.xib @@ -20,14 +20,14 @@ - - + + - + + diff --git a/FreenetTray/FNSettingsWindowController.h b/FreenetTray/FNSettingsWindowController.h index 6ece36a..38cb4b5 100644 --- a/FreenetTray/FNSettingsWindowController.h +++ b/FreenetTray/FNSettingsWindowController.h @@ -32,4 +32,6 @@ -(IBAction)uninstallFreenet:(id)sender; +-(IBAction)changeTrayIconColor:(id)sender; + @end diff --git a/FreenetTray/FNSettingsWindowController.m b/FreenetTray/FNSettingsWindowController.m index 403ce41..609835d 100644 --- a/FreenetTray/FNSettingsWindowController.m +++ b/FreenetTray/FNSettingsWindowController.m @@ -96,6 +96,9 @@ -(IBAction)selectNodeLocation:(id)sender { } +-(IBAction)changeTrayIconColor:(id)sender { +} + -(IBAction)uninstallFreenet:(id)sender { [FNHelpers displayUninstallAlert]; } diff --git a/FreenetTray/defaults.plist b/FreenetTray/defaults.plist index 939a3d3..39d2b36 100644 --- a/FreenetTray/defaults.plist +++ b/FreenetTray/defaults.plist @@ -12,5 +12,7 @@ firstlaunch + grayscaleIcon + From e8dd5b31e77177ffe44652ba47710323a7ee2843 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20Brandsta=CC=88tter?= Date: Sun, 25 Feb 2018 17:48:42 +0100 Subject: [PATCH 2/2] Draw the menu icon according to the userDefaults --- FreenetTray/FNSettingsWindowController.m | 3 ++ FreenetTray/TrayIcon.h | 1 + FreenetTray/TrayIcon.m | 58 ++++++++++++++++++++++-- 3 files changed, 59 insertions(+), 3 deletions(-) diff --git a/FreenetTray/FNSettingsWindowController.m b/FreenetTray/FNSettingsWindowController.m index 609835d..60622a2 100644 --- a/FreenetTray/FNSettingsWindowController.m +++ b/FreenetTray/FNSettingsWindowController.m @@ -18,6 +18,8 @@ #import "FNNodeController.h" +#import "TrayIcon.h" + @interface FNSettingsWindowController () @end @@ -97,6 +99,7 @@ -(IBAction)selectNodeLocation:(id)sender { } -(IBAction)changeTrayIconColor:(id)sender { + [TrayIcon refreshColors]; } -(IBAction)uninstallFreenet:(id)sender { diff --git a/FreenetTray/TrayIcon.h b/FreenetTray/TrayIcon.h index ffb6b5e..406a417 100644 --- a/FreenetTray/TrayIcon.h +++ b/FreenetTray/TrayIcon.h @@ -19,6 +19,7 @@ + (void)drawRunningIcon; + (void)drawNotRunningIcon; + (void)drawHighlightedIcon; ++ (void)refreshColors; // Generated Images + (NSImage*)imageOfRunningIcon; diff --git a/FreenetTray/TrayIcon.m b/FreenetTray/TrayIcon.m index 4503a23..6b984eb 100644 --- a/FreenetTray/TrayIcon.m +++ b/FreenetTray/TrayIcon.m @@ -13,6 +13,17 @@ #import "TrayIcon.h" +@interface TrayIcon () + +// color getter ++ (NSColor *)runningIconColor; ++ (NSColor *)notRunningIconColor; ++ (NSColor *)highlightedIconColor; + +@end + + + @implementation TrayIcon #pragma mark Cache @@ -21,16 +32,57 @@ @implementation TrayIcon static NSImage* _imageOfNotRunningIcon = nil; static NSImage* _imageOfHighlightedIcon = nil; +static NSColor* _runningColor = nil; +static NSColor* _notRunningColor = nil; +static NSColor* _highlightedColor = nil; + + #pragma mark Initialization + (void)initialize { + [TrayIcon refreshColors]; +} + +#pragma mark Tray colors + ++ (void)refreshColors { + + _imageOfRunningIcon = nil; + _imageOfNotRunningIcon = nil; + _imageOfHighlightedIcon = nil; + + NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; + + _runningColor = [defaults boolForKey:@"grayscaleIcon"] + ? [NSColor colorWithCalibratedRed: 1. green:1. blue: 1. alpha: 1.] + : [NSColor colorWithCalibratedRed: 0.161 green: 0.322 blue: 0.765 alpha: 1.]; + + _notRunningColor = [defaults boolForKey:@"grayscaleIcon"] + ? [NSColor colorWithCalibratedRed: 0.337 green: 0.337 blue: 0.337 alpha: 1] + : [NSColor colorWithCalibratedRed: 1. green: 0. blue: 0. alpha: 1.]; + + _highlightedColor = [defaults boolForKey:@"grayscaleIcon"] + ? [NSColor colorWithCalibratedRed: 0.663 green: 0.663 blue: 0.663 alpha: 1] + : [NSColor colorWithCalibratedRed: 1 green: 1 blue: 1 alpha: 1]; +} + ++ (NSColor *)runningIconColor { + return _runningColor; +} + ++ (NSColor *)notRunningIconColor { + return _notRunningColor; +} + ++ (NSColor *)highlightedIconColor { + return _highlightedColor; } #pragma mark Drawing Methods + (void)drawRunningIcon { //// Color Declarations - NSColor* run = [NSColor colorWithCalibratedRed: 0.161 green: 0.322 blue: 0.765 alpha: 1]; + NSColor* run = [TrayIcon runningIconColor]; //// Group { @@ -64,7 +116,7 @@ + (void)drawRunningIcon { + (void)drawNotRunningIcon { //// Color Declarations - NSColor* stop = [NSColor colorWithCalibratedRed: 1 green: 0 blue: 0 alpha: 1]; + NSColor* stop = [TrayIcon notRunningIconColor]; //// Group { @@ -98,7 +150,7 @@ + (void)drawNotRunningIcon { + (void)drawHighlightedIcon { //// Color Declarations - NSColor* highlight = [NSColor colorWithCalibratedRed: 1 green: 1 blue: 1 alpha: 1]; + NSColor* highlight = [TrayIcon highlightedIconColor]; //// Group {