MCPcopy Index your code
hub / github.com/angular/angular / handleClick

Method handleClick

packages/service-worker/worker/src/driver.ts:426–477  ·  view source on GitHub ↗
(notification: Notification, action?: string)

Source from the content-addressed store, hash-verified

424 }
425
426 private async handleClick(notification: Notification, action?: string): Promise<void> {
427 notification.close();
428
429 const options: {-readonly [K in keyof Notification]?: Notification[K]} = {};
430 // The filter uses `name in notification` because the properties are on the prototype so
431 // hasOwnProperty does not work here
432 NOTIFICATION_OPTION_NAMES.filter((name) => name in notification).forEach(
433 (name) => (options[name] = notification[name]),
434 );
435
436 const notificationAction = action === '' || action === undefined ? 'default' : action;
437
438 const onActionClick = notification?.data?.onActionClick?.[notificationAction];
439
440 const urlToOpen = new URL(onActionClick?.url ?? '', this.scope.registration.scope).href;
441
442 switch (onActionClick?.operation) {
443 case 'openWindow':
444 await this.scope.clients.openWindow(urlToOpen);
445 break;
446 case 'focusLastFocusedOrOpen': {
447 let matchingClient = await this.getLastFocusedMatchingClient(this.scope);
448 if (matchingClient) {
449 await matchingClient?.focus();
450 } else {
451 await this.scope.clients.openWindow(urlToOpen);
452 }
453 break;
454 }
455 case 'navigateLastFocusedOrOpen': {
456 let matchingClient = await this.getLastFocusedMatchingClient(this.scope);
457 if (matchingClient) {
458 matchingClient = await matchingClient.navigate(urlToOpen);
459 await matchingClient?.focus();
460 } else {
461 await this.scope.clients.openWindow(urlToOpen);
462 }
463 break;
464 }
465 case 'sendRequest': {
466 await this.scope.fetch(urlToOpen);
467 break;
468 }
469 default:
470 break;
471 }
472
473 await this.broadcast({
474 type: 'NOTIFICATION_CLICK',
475 data: {action, notification: options},
476 });
477 }
478
479 /**
480 * Handles the closing of a notification by extracting its options and

Callers 2

onClickMethod · 0.95

Calls 9

broadcastMethod · 0.95
openWindowMethod · 0.80
focusMethod · 0.65
closeMethod · 0.45
forEachMethod · 0.45
filterMethod · 0.45
navigateMethod · 0.45
fetchMethod · 0.45

Tested by

no test coverage detected