mirror of
https://github.com/transmission/transmission.git
synced 2025-12-20 02:18:42 +00:00
[macOS] Use NSAlert APIs to show alert suppression checkbox (#3360)
* [macOS] Simplify branching for termination prevention * [macOS] Use NSAlert APIs to show alert suppression checkbox
This commit is contained in:
committed by
GitHub
parent
e7627dc209
commit
3e73913a1d
@@ -868,8 +868,11 @@ static void removeKeRangerRansomware()
|
|||||||
|
|
||||||
- (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication*)sender
|
- (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication*)sender
|
||||||
{
|
{
|
||||||
if (!self.fQuitRequested && [self.fDefaults boolForKey:@"CheckQuit"])
|
if (self.fQuitRequested || ![self.fDefaults boolForKey:@"CheckQuit"])
|
||||||
{
|
{
|
||||||
|
return NSTerminateNow;
|
||||||
|
}
|
||||||
|
|
||||||
NSUInteger active = 0, downloading = 0;
|
NSUInteger active = 0, downloading = 0;
|
||||||
for (Torrent* torrent in self.fTorrents)
|
for (Torrent* torrent in self.fTorrents)
|
||||||
{
|
{
|
||||||
@@ -883,8 +886,13 @@ static void removeKeRangerRansomware()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ([self.fDefaults boolForKey:@"CheckQuitDownloading"] ? downloading > 0 : active > 0)
|
BOOL preventedByTransfer = [self.fDefaults boolForKey:@"CheckQuitDownloading"] ? downloading > 0 : active > 0;
|
||||||
|
|
||||||
|
if (!preventedByTransfer)
|
||||||
{
|
{
|
||||||
|
return NSTerminateNow;
|
||||||
|
}
|
||||||
|
|
||||||
NSAlert* alert = [[NSAlert alloc] init];
|
NSAlert* alert = [[NSAlert alloc] init];
|
||||||
alert.alertStyle = NSAlertStyleInformational;
|
alert.alertStyle = NSAlertStyleInformational;
|
||||||
alert.messageText = NSLocalizedString(@"Are you sure you want to quit?", "Confirm Quit panel -> title");
|
alert.messageText = NSLocalizedString(@"Are you sure you want to quit?", "Confirm Quit panel -> title");
|
||||||
@@ -900,15 +908,17 @@ static void removeKeRangerRansomware()
|
|||||||
active];
|
active];
|
||||||
[alert addButtonWithTitle:NSLocalizedString(@"Quit", "Confirm Quit panel -> button")];
|
[alert addButtonWithTitle:NSLocalizedString(@"Quit", "Confirm Quit panel -> button")];
|
||||||
[alert addButtonWithTitle:NSLocalizedString(@"Cancel", "Confirm Quit panel -> button")];
|
[alert addButtonWithTitle:NSLocalizedString(@"Cancel", "Confirm Quit panel -> button")];
|
||||||
|
alert.showsSuppressionButton = YES;
|
||||||
|
|
||||||
[alert beginSheetModalForWindow:self.fWindow completionHandler:^(NSModalResponse returnCode) {
|
[alert beginSheetModalForWindow:self.fWindow completionHandler:^(NSModalResponse returnCode) {
|
||||||
|
if (alert.suppressionButton.state == NSControlStateValueOn)
|
||||||
|
{
|
||||||
|
[self.fDefaults setBool:NO forKey:@"CheckQuit"];
|
||||||
|
}
|
||||||
[NSApp replyToApplicationShouldTerminate:returnCode == NSAlertFirstButtonReturn];
|
[NSApp replyToApplicationShouldTerminate:returnCode == NSAlertFirstButtonReturn];
|
||||||
}];
|
}];
|
||||||
return NSTerminateLater;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return NSTerminateNow;
|
return NSTerminateLater;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)applicationWillTerminate:(NSNotification*)notification
|
- (void)applicationWillTerminate:(NSNotification*)notification
|
||||||
|
|||||||
Reference in New Issue
Block a user