Skip to content
Permalink
Browse files
8264786: [macos] All Swing/AWT apps cause Allow Notifications prompt …
…to appear when app is launched

Reviewed-by: azvegint, kizune
  • Loading branch information
mrserb committed May 3, 2021
1 parent 45760d4 commit 020236c
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 15 deletions.
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2011, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -42,7 +42,7 @@ extern "C" {
/*
* AWTTrayIcon
*/
@interface AWTTrayIcon : NSObject {
@interface AWTTrayIcon : NSObject <NSUserNotificationCenterDelegate>{
jobject peer;
AWTTrayIconView *view;
NSStatusItem *theItem;
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2011, 2017, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2011, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -68,11 +68,14 @@ - (id) initWithPeer:(jobject)thePeer {

view = [[AWTTrayIconView alloc] initWithTrayIcon:self];
[theItem setView:view];
[[NSUserNotificationCenter defaultUserNotificationCenter] setDelegate:self];

return self;
}

-(void) dealloc {
[[NSUserNotificationCenter defaultUserNotificationCenter] setDelegate:nil];

JNIEnv *env = [ThreadUtilities getJNIEnvUncached];
(*env)->DeleteGlobalRef(env, peer);

@@ -167,6 +170,12 @@ -(void) deliverJavaMouseEvent: (NSEvent *) event {
(*env)->DeleteLocalRef(env, jEvent);
}

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

@end //AWTTrayIcon
//================================================

@@ -1,5 +1,5 @@
/*
* Copyright (c) 2011, 2017, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2011, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -26,7 +26,7 @@
#import "JNIUtilities.h"
#import <Cocoa/Cocoa.h>

JNIEXPORT @interface NSApplicationAWT : NSApplication <NSUserNotificationCenterDelegate> {
JNIEXPORT @interface NSApplicationAWT : NSApplication {
NSString *fApplicationName;
NSWindow *eventTransparentWindow;
NSTimeInterval dummyEventTimestamp;
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2011, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2011, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -77,8 +77,6 @@ - (id) init

- (void)dealloc
{
[[NSUserNotificationCenter defaultUserNotificationCenter] setDelegate:nil];

[fApplicationName release];
fApplicationName = nil;

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

[super finishLaunching];

[[NSUserNotificationCenter defaultUserNotificationCenter] setDelegate:self];
}

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

- (void) registerWithProcessManager
{

4 comments on commit 020236c

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@openjdk
Copy link

@openjdk openjdk bot commented on 020236c May 3, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@VladimirKempik could not automatically backport 020236cb to openjdk/jdk15u-dev due to conflicts in the following files:

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

To manually resolve these conflicts run the following commands in your personal fork of openjdk/jdk15u-dev:

$ git checkout -b VladimirKempik-backport-020236cb
$ git fetch --no-tags https://git.openjdk.java.net/jdk 020236cb9825bf4fa91a495a179623e3fcdc0149
$ git cherry-pick --no-commit 020236cb9825bf4fa91a495a179623e3fcdc0149
$ # Resolve conflicts
$ git add files/with/resolved/conflicts
$ git commit -m 'Backport 020236cb9825bf4fa91a495a179623e3fcdc0149'

Once you have resolved the conflicts as explained above continue with creating a pull request towards the openjdk/jdk15u-dev with the title Backport 020236cb9825bf4fa91a495a179623e3fcdc0149.

@RealCLanger
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/backport jdk16u

@openjdk
Copy link

@openjdk openjdk bot commented on 020236c May 23, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@RealCLanger could not automatically backport 020236cb to openjdk/jdk16u due to conflicts in the following files:

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

To manually resolve these conflicts run the following commands in your personal fork of openjdk/jdk16u:

$ git checkout -b RealCLanger-backport-020236cb
$ git fetch --no-tags https://git.openjdk.java.net/jdk 020236cb9825bf4fa91a495a179623e3fcdc0149
$ git cherry-pick --no-commit 020236cb9825bf4fa91a495a179623e3fcdc0149
$ # Resolve conflicts
$ git add files/with/resolved/conflicts
$ git commit -m 'Backport 020236cb9825bf4fa91a495a179623e3fcdc0149'

Once you have resolved the conflicts as explained above continue with creating a pull request towards the openjdk/jdk16u with the title Backport 020236cb9825bf4fa91a495a179623e3fcdc0149.

Please sign in to comment.