Skip to content
This repository has been archived by the owner on Feb 13, 2024. It is now read-only.

Commit

Permalink
Guard from duplicated app icon update (mac)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
AndrewVebster committed Dec 2, 2020
1 parent ec32942 commit 2320fc5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
15 changes: 13 additions & 2 deletions src/ui/osx/TogglDesktop/App/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ @interface AppDelegate ()
@property (nonatomic, assign) BOOL manualMode;
@property (nonatomic, assign) BOOL onTop;

@property (nonatomic) BOOL isAppIconInRunningState;

@end

@implementation AppDelegate
Expand All @@ -126,6 +128,7 @@ - (void)applicationWillFinishLaunching:(NSNotification *)not
self.showMenuBarTimer = NO;
self.manualMode = NO;
self.onTop = NO;
self.isAppIconInRunningState = YES;
}

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
Expand Down Expand Up @@ -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];
Expand Down Expand Up @@ -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];
Expand Down
3 changes: 0 additions & 3 deletions src/ui/osx/TogglDesktop/Common/Utils/AppIconFactory.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down

0 comments on commit 2320fc5

Please sign in to comment.