Uploaded image for project: 'Compass '
  1. Compass
  2. COMPASS-5686

Add default link handler to Compass

    • Type: Icon: Task Task
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • No version
    • Affects Version/s: None
    • Component/s: Electron, Tech debt
    • None
    • 3
    • Not Needed

      Currently in Compass we handle links in two main ways:

      1. If the link has `_blank` on it then when it is clicked it is handled by the `new-window` event in electron:
      https://github.com/mongodb-js/compass/blob/main/packages/compass/src/main/window-manager.ts#L139

      2. If the link doesn't have `_blank` on it then we currently do not handle the link handling unless the target of the event is an `a` element. This isn't always the case with links without `_blank` as there might be a `span` or something inside of the `a` tag which means this check isn't very robust. The check happens here in the `onLinkClick` function:
      https://github.com/mongodb-js/compass/blob/main/packages/compass/src/app/index.js#L263

      In this ticket let's add another handler for the `will-navigate` web contents event to handle links that are clicked without `_blank`. Let's remove the handling that has the not fully covering `a` tag check as well (and keep the `new-window` handler) since it will no longer need to be used.

      Something like:
      window.webContents.on('will-navigate', function (event, url)

      { event.preventDefault(); void shell.openExternal(url); }

      );

      `will-navigate` docs: https://www.electronjs.org/docs/latest/api/web-contents#event-will-navigate

            Assignee:
            Unassigned Unassigned
            Reporter:
            rhys.howell@mongodb.com Rhys Howell
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: