Skip to content
This repository was archived by the owner on Sep 2, 2022. It is now read-only.
/ jdk16u Public archive

Commit 375be17

Browse files
committed
8264786: [macos] All Swing/AWT apps cause Allow Notifications prompt to appear when app is launched
Reviewed-by: vkempik, mdoerr, mbaesken Backport-of: 020236cb9825bf4fa91a495a179623e3fcdc0149
1 parent 6f948a7 commit 375be17

File tree

4 files changed

+15
-15
lines changed

4 files changed

+15
-15
lines changed

src/java.desktop/macosx/native/libawt_lwawt/awt/CTrayIcon.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2011, 2021, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -42,7 +42,7 @@ extern "C" {
4242
/*
4343
* AWTTrayIcon
4444
*/
45-
@interface AWTTrayIcon : NSObject {
45+
@interface AWTTrayIcon : NSObject <NSUserNotificationCenterDelegate>{
4646
jobject peer;
4747
AWTTrayIconView *view;
4848
NSStatusItem *theItem;

src/java.desktop/macosx/native/libawt_lwawt/awt/CTrayIcon.m

+10-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2011, 2017, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2011, 2021, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -69,11 +69,14 @@ - (id) initWithPeer:(jobject)thePeer {
6969

7070
view = [[AWTTrayIconView alloc] initWithTrayIcon:self];
7171
[theItem setView:view];
72+
[[NSUserNotificationCenter defaultUserNotificationCenter] setDelegate:self];
7273

7374
return self;
7475
}
7576

7677
-(void) dealloc {
78+
[[NSUserNotificationCenter defaultUserNotificationCenter] setDelegate:nil];
79+
7780
JNIEnv *env = [ThreadUtilities getJNIEnvUncached];
7881
JNFDeleteGlobalRef(env, peer);
7982

@@ -166,6 +169,12 @@ -(void) deliverJavaMouseEvent: (NSEvent *) event {
166169
(*env)->DeleteLocalRef(env, jEvent);
167170
}
168171

172+
- (BOOL)userNotificationCenter:(NSUserNotificationCenter *)center
173+
shouldPresentNotification:(NSUserNotification *)notification
174+
{
175+
return YES; // We always show notifications to the user
176+
}
177+
169178
@end //AWTTrayIcon
170179
//================================================
171180

src/java.desktop/macosx/native/libosxapp/NSApplicationAWT.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2011, 2017, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2011, 2021, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -32,7 +32,7 @@
3232
#import <Cocoa/Cocoa.h>
3333
#import <JavaNativeFoundation/JavaNativeFoundation.h>
3434

35-
JNIEXPORT @interface NSApplicationAWT : NSApplication <NSUserNotificationCenterDelegate> {
35+
JNIEXPORT @interface NSApplicationAWT : NSApplication {
3636
NSString *fApplicationName;
3737
NSWindow *eventTransparentWindow;
3838
NSTimeInterval dummyEventTimestamp;

src/java.desktop/macosx/native/libosxapp/NSApplicationAWT.m

+1-10
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2011, 2020, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2011, 2021, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -77,8 +77,6 @@ - (id) init
7777

7878
- (void)dealloc
7979
{
80-
[[NSUserNotificationCenter defaultUserNotificationCenter] setDelegate:nil];
81-
8280
[fApplicationName release];
8381
fApplicationName = nil;
8482

@@ -159,17 +157,10 @@ - (void)finishLaunching
159157

160158
[super finishLaunching];
161159

162-
[[NSUserNotificationCenter defaultUserNotificationCenter] setDelegate:self];
163-
164160
// inform any interested parties that the AWT has arrived and is pumping
165161
[[NSNotificationCenter defaultCenter] postNotificationName:JNFRunLoopDidStartNotification object:self];
166162
}
167163

168-
- (BOOL)userNotificationCenter:(NSUserNotificationCenter *)center
169-
shouldPresentNotification:(NSUserNotification *)notification
170-
{
171-
return YES; // We always show notifications to the user
172-
}
173164

174165
- (void) registerWithProcessManager
175166
{

0 commit comments

Comments
 (0)