@@ -127,37 +127,18 @@ export class WindowController extends ControllerInterface {
127127 * @return Resolves if the permission was granted, otherwise rejects
128128 */
129129 async requestPermission ( ) : Promise < void > {
130- if (
131- // TODO: Remove the cast when this issue is fixed:
132- // https://github.com/Microsoft/TypeScript/issues/14701
133- // tslint:disable-next-line no-any
134- ( ( Notification as any ) . permission as NotificationPermission ) === 'granted'
135- ) {
130+ if ( this . getNotificationPermission_ ( ) === 'granted' ) {
136131 return ;
137132 }
138133
139- return new Promise < void > ( ( resolve , reject ) => {
140- const managePermissionResult = ( result : NotificationPermission ) => {
141- if ( result === 'granted' ) {
142- return resolve ( ) ;
143- } else if ( result === 'denied' ) {
144- return reject ( errorFactory . create ( ERROR_CODES . PERMISSION_BLOCKED ) ) ;
145- } else {
146- return reject ( errorFactory . create ( ERROR_CODES . PERMISSION_DEFAULT ) ) ;
147- }
148- } ;
149-
150- // The Notification.requestPermission API was changed to
151- // return a promise so now have to handle both in case
152- // browsers stop support callbacks for promised version
153- const permissionPromise = Notification . requestPermission (
154- managePermissionResult
155- ) ;
156- if ( permissionPromise ) {
157- // Prefer the promise version as it's the future API.
158- permissionPromise . then ( managePermissionResult ) ;
159- }
160- } ) ;
134+ const permissionResult = await Notification . requestPermission ( ) ;
135+ if ( permissionResult === 'granted' ) {
136+ return ;
137+ } else if ( permissionResult === 'denied' ) {
138+ throw errorFactory . create ( ERROR_CODES . PERMISSION_BLOCKED ) ;
139+ } else {
140+ throw errorFactory . create ( ERROR_CODES . PERMISSION_DEFAULT ) ;
141+ }
161142 }
162143
163144 /**
0 commit comments