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