Skip to content
This repository was archived by the owner on Feb 2, 2023. It is now read-only.
/ jdk15u-dev Public archive

Commit acf2eea

Browse files
author
Vladimir Kempik
committed
8264786: [macos] All Swing/AWT apps cause Allow Notifications prompt to appear when app is launched
Reviewed-by: yan Backport-of: 020236cb9825bf4fa91a495a179623e3fcdc0149
1 parent 9caa290 commit acf2eea

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
@@ -68,11 +68,14 @@ - (id) initWithPeer:(jobject)thePeer {
6868

6969
view = [[AWTTrayIconView alloc] initWithTrayIcon:self];
7070
[theItem setView:view];
71+
[[NSUserNotificationCenter defaultUserNotificationCenter] setDelegate:self];
7172

7273
return self;
7374
}
7475

7576
-(void) dealloc {
77+
[[NSUserNotificationCenter defaultUserNotificationCenter] setDelegate:nil];
78+
7679
JNIEnv *env = [ThreadUtilities getJNIEnvUncached];
7780
(*env)->DeleteGlobalRef(env, peer);
7881

@@ -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
@@ -26,7 +26,7 @@
2626
#import "JNIUtilities.h"
2727
#import <Cocoa/Cocoa.h>
2828

29-
JNIEXPORT @interface NSApplicationAWT : NSApplication <NSUserNotificationCenterDelegate> {
29+
JNIEXPORT @interface NSApplicationAWT : NSApplication {
3030
NSString *fApplicationName;
3131
NSWindow *eventTransparentWindow;
3232
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, 2019, 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

@@ -158,15 +156,8 @@ - (void)finishLaunching
158156
}
159157

160158
[super finishLaunching];
161-
162-
[[NSUserNotificationCenter defaultUserNotificationCenter] setDelegate:self];
163159
}
164160

165-
- (BOOL)userNotificationCenter:(NSUserNotificationCenter *)center
166-
shouldPresentNotification:(NSUserNotification *)notification
167-
{
168-
return YES; // We always show notifications to the user
169-
}
170161

171162
- (void) registerWithProcessManager
172163
{

0 commit comments

Comments
 (0)