From 2320fc53982c7e8ee202d8fa46ef24ad59df3bac Mon Sep 17 00:00:00 2001 From: Andrii Nester Date: Mon, 30 Nov 2020 17:03:30 +0200 Subject: [PATCH] Guard from duplicated app icon update (mac) Setting app icon allocates additional memory that's not released till app is killed. This commit ensures that icon is updated only when state has changed. --- src/ui/osx/TogglDesktop/App/AppDelegate.m | 15 +++++++++++++-- .../TogglDesktop/Common/Utils/AppIconFactory.m | 3 --- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/ui/osx/TogglDesktop/App/AppDelegate.m b/src/ui/osx/TogglDesktop/App/AppDelegate.m index 57235cefdc..ad73cfe02d 100644 --- a/src/ui/osx/TogglDesktop/App/AppDelegate.m +++ b/src/ui/osx/TogglDesktop/App/AppDelegate.m @@ -111,6 +111,8 @@ @interface AppDelegate () @property (nonatomic, assign) BOOL manualMode; @property (nonatomic, assign) BOOL onTop; +@property (nonatomic) BOOL isAppIconInRunningState; + @end @implementation AppDelegate @@ -126,6 +128,7 @@ - (void)applicationWillFinishLaunching:(NSNotification *)not self.showMenuBarTimer = NO; self.manualMode = NO; self.onTop = NO; + self.isAppIconInRunningState = YES; } - (void)applicationDidFinishLaunching:(NSNotification *)aNotification @@ -888,7 +891,11 @@ - (void)displayTimerState:(TimeEntryViewItem *)timeEntry { if (!self.willTerminate) { - [NSApp setApplicationIconImage:[AppIconFactory appIconWithType:AppIconTypeActive]]; + if (!self.isAppIconInRunningState) + { + [NSApp setApplicationIconImage:[AppIconFactory appIconWithType:AppIconTypeActive]]; + self.isAppIconInRunningState = YES; + } } [self updateStatusItem]; @@ -918,7 +925,11 @@ - (void)indicateStoppedTimer { // Change app dock icon to default // See https://developer.apple.com/library/mac/documentation/Carbon/Conceptual/customizing_docktile/dockconcepts.pdf - [NSApp setApplicationIconImage:[AppIconFactory appIconWithType:AppIconTypeDefault]]; + if (self.isAppIconInRunningState) + { + [NSApp setApplicationIconImage:[AppIconFactory appIconWithType:AppIconTypeDefault]]; + self.isAppIconInRunningState = NO; + } } [self updateStatusItem]; diff --git a/src/ui/osx/TogglDesktop/Common/Utils/AppIconFactory.m b/src/ui/osx/TogglDesktop/Common/Utils/AppIconFactory.m index f5280e70b1..a2d2ee852f 100644 --- a/src/ui/osx/TogglDesktop/Common/Utils/AppIconFactory.m +++ b/src/ui/osx/TogglDesktop/Common/Utils/AppIconFactory.m @@ -28,9 +28,6 @@ + (NSImage *)appIconWithType:(AppIconType)type icon = [NSImage imageNamed:@"AppIconNotRunning"]; break; } - - // Adapt well with black/white macOS appearance - icon.template = YES; return icon; }