8264786: [macos] All Swing/AWT apps cause Allow Notifications prompt … · openjdk/jdk@020236c (original) (raw)

File tree

4 files changed

lines changed

4 files changed

lines changed

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
1 1 /*
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.
3 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 4 *
5 5 * This code is free software; you can redistribute it and/or modify it
@@ -42,7 +42,7 @@ extern "C" {
42 42 /*
43 43 * AWTTrayIcon
44 44 */
45 -@interface AWTTrayIcon : NSObject {
45 +@interface AWTTrayIcon : NSObject <NSUserNotificationCenterDelegate>{
46 46 jobject peer;
47 47 AWTTrayIconView *view;
48 48 NSStatusItem *theItem;
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
1 1 /*
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.
3 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 4 *
5 5 * This code is free software; you can redistribute it and/or modify it
@@ -68,11 +68,14 @@ - (id) initWithPeer:(jobject)thePeer {
68 68
69 69 view = [[AWTTrayIconView alloc] initWithTrayIcon:self];
70 70 [theItem setView:view];
71 + [[NSUserNotificationCenter defaultUserNotificationCenter] setDelegate:self];
71 72
72 73 return self;
73 74 }
74 75
75 76 -(void) dealloc {
77 + [[NSUserNotificationCenter defaultUserNotificationCenter] setDelegate:nil];
78 +
76 79 JNIEnv *env = [ThreadUtilities getJNIEnvUncached];
77 80 (*env)->DeleteGlobalRef(env, peer);
78 81
@@ -167,6 +170,12 @@ -(void) deliverJavaMouseEvent: (NSEvent *) event {
167 170 (*env)->DeleteLocalRef(env, jEvent);
168 171 }
169 172
173 +- (BOOL)userNotificationCenter:(NSUserNotificationCenter *)center
174 +shouldPresentNotification:(NSUserNotification *)notification
175 +{
176 +return YES; // We always show notifications to the user
177 +}
178 +
170 179 @end //AWTTrayIcon
171 180 //================================================
172 181
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
1 1 /*
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.
3 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 4 *
5 5 * This code is free software; you can redistribute it and/or modify it
@@ -26,7 +26,7 @@
26 26 #import "JNIUtilities.h"
27 27 #import <Cocoa/Cocoa.h>
28 28
29 -JNIEXPORT @interface NSApplicationAWT : NSApplication <NSUserNotificationCenterDelegate> {
29 +JNIEXPORT @interface NSApplicationAWT : NSApplication {
30 30 NSString *fApplicationName;
31 31 NSWindow *eventTransparentWindow;
32 32 NSTimeInterval dummyEventTimestamp;
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
1 1 /*
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.
3 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 4 *
5 5 * This code is free software; you can redistribute it and/or modify it
@@ -77,8 +77,6 @@ - (id) init
77 77
78 78 - (void)dealloc
79 79 {
80 - [[NSUserNotificationCenter defaultUserNotificationCenter] setDelegate:nil];
81 -
82 80 [fApplicationName release];
83 81 fApplicationName = nil;
84 82
@@ -158,15 +156,8 @@ - (void)finishLaunching
158 156 }
159 157
160 158 [super finishLaunching];
161 -
162 - [[NSUserNotificationCenter defaultUserNotificationCenter] setDelegate:self];
163 159 }
164 160
165 -- (BOOL)userNotificationCenter:(NSUserNotificationCenter *)center
166 -shouldPresentNotification:(NSUserNotification *)notification
167 -{
168 -return YES; // We always show notifications to the user
169 -}
170 161
171 162 - (void) registerWithProcessManager
172 163 {