macOS: remove quitting badge (#2495)

Co-authored-by: Charles Kerr <charles@charleskerr.com>
This commit is contained in:
FX Coudert 2022-01-25 18:45:06 +01:00 committed by GitHub
parent 020a9e45ae
commit 4fe33496c7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 5 additions and 33 deletions

View File

@ -14,12 +14,10 @@
CGFloat fDownloadRate;
CGFloat fUploadRate;
BOOL fQuitting;
}
- (instancetype)initWithLib:(tr_session*)lib;
- (BOOL)setRatesWithDownload:(CGFloat)downloadRate upload:(CGFloat)uploadRate;
- (void)setQuitting;
@end

View File

@ -9,7 +9,7 @@
@interface BadgeView ()
- (void)badge:(NSImage*)badge string:(NSString*)string atHeight:(CGFloat)height adjustForQuit:(BOOL)quit;
- (void)badge:(NSImage*)badge string:(NSString*)string atHeight:(CGFloat)height;
@end
@ -23,7 +23,6 @@
fDownloadRate = 0.0;
fUploadRate = 0.0;
fQuitting = NO;
}
return self;
}
@ -41,31 +40,17 @@
return YES;
}
- (void)setQuitting
{
fQuitting = YES;
}
- (void)drawRect:(NSRect)rect
{
[NSApp.applicationIconImage drawInRect:rect fromRect:NSZeroRect operation:NSCompositingOperationSourceOver fraction:1.0];
if (fQuitting)
{
NSImage* quitBadge = [NSImage imageNamed:@"QuitBadge"];
[self badge:quitBadge string:NSLocalizedString(@"Quitting", "Dock Badger -> quit")
atHeight:(NSHeight(rect) - quitBadge.size.height) * 0.5
adjustForQuit:YES];
return;
}
BOOL const upload = fUploadRate >= 0.1;
BOOL const download = fDownloadRate >= 0.1;
CGFloat bottom = 0.0;
if (upload)
{
NSImage* uploadBadge = [NSImage imageNamed:@"UploadBadge"];
[self badge:uploadBadge string:[NSString stringForSpeedAbbrev:fUploadRate] atHeight:bottom adjustForQuit:NO];
[self badge:uploadBadge string:[NSString stringForSpeedAbbrev:fUploadRate] atHeight:bottom];
if (download)
{
bottom += uploadBadge.size.height + BETWEEN_PADDING; //download rate above upload rate
@ -73,12 +58,11 @@
}
if (download)
{
[self badge:[NSImage imageNamed:@"DownloadBadge"] string:[NSString stringForSpeedAbbrev:fDownloadRate] atHeight:bottom
adjustForQuit:NO];
[self badge:[NSImage imageNamed:@"DownloadBadge"] string:[NSString stringForSpeedAbbrev:fDownloadRate] atHeight:bottom];
}
}
- (void)badge:(NSImage*)badge string:(NSString*)string atHeight:(CGFloat)height adjustForQuit:(BOOL)quit
- (void)badge:(NSImage*)badge string:(NSString*)string atHeight:(CGFloat)height
{
if (!fAttributes)
{
@ -111,7 +95,7 @@
//string is in center of image
NSRect stringRect;
stringRect.origin.x = NSMidX(badgeRect) - stringSize.width * 0.5;
stringRect.origin.y = NSMidY(badgeRect) - stringSize.height * 0.5 + (quit ? 2.0 : 1.0); //adjust for shadow, extra for quit
stringRect.origin.y = NSMidY(badgeRect) - stringSize.height * 0.5 + 1.0; //adjust for shadow
stringRect.size = stringSize;
[string drawInRect:stringRect withAttributes:fAttributes];

View File

@ -21,6 +21,5 @@
- (void)addCompletedTorrent:(Torrent*)torrent;
- (void)removeTorrent:(Torrent*)torrent;
- (void)clearCompleted;
- (void)setQuitting;
@end

View File

@ -69,11 +69,4 @@
}
}
- (void)setQuitting
{
[self clearCompleted];
[(BadgeView*)NSApp.dockTile.contentView setQuitting];
[NSApp.dockTile display];
}
@end

View File

@ -882,8 +882,6 @@ static void removeKeRangerRansomware()
}
}
[fBadger setQuitting];
//remove all torrent downloads
if (fPendingTorrentDownloads)
{