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