(e: React.MouseEvent)
| 47 | }); |
| 48 | |
| 49 | const onClick = (e: React.MouseEvent) => { |
| 50 | if (!e.currentTarget.getAttribute("href")) { |
| 51 | return; |
| 52 | } |
| 53 | |
| 54 | // External apps with custom protocols (non-HTTP) need special handling |
| 55 | // for error detection when the app isn't installed. |
| 56 | const isExternalProtocolApp = |
| 57 | app.external && app.url && !app.url.startsWith("http"); |
| 58 | |
| 59 | if (isExternalProtocolApp) { |
| 60 | // When browser recognizes the protocol and is able to navigate to the app, |
| 61 | // it will blur away, and will stop the timer. Otherwise, |
| 62 | // an error message will be displayed. |
| 63 | const openAppExternallyFailedTimeout = 1500; |
| 64 | const openAppExternallyFailed = setTimeout(() => { |
| 65 | // Check if this is a JetBrains IDE app |
| 66 | // starts with "jetbrains-gateway://connect#type=coder" (from https://registry.coder.com/modules/coder/jetbrains-gateway) |
| 67 | const isJetBrainsGateway = app.url?.startsWith("jetbrains-gateway:"); |
| 68 | // starts with "jetbrains://gateway/coder" (from https://registry.coder.com/modules/coder/jetbrains) |
| 69 | const isJetBrainsToolbox = app.url?.startsWith("jetbrains:"); |
| 70 | |
| 71 | // Check if this is a coder:// URL |
| 72 | const isCoderApp = app.url?.startsWith("coder:"); |
| 73 | |
| 74 | if (isJetBrainsGateway) { |
| 75 | toast.error(`Failed to open "${label}".`, { |
| 76 | description: "JetBrains Gateway must be installed.", |
| 77 | }); |
| 78 | } else if (isJetBrainsToolbox) { |
| 79 | toast.error(`Failed to open "${label}".`, { |
| 80 | description: "JetBrains Toolbox must be installed.", |
| 81 | }); |
| 82 | } else if (isCoderApp) { |
| 83 | toast.error(`Failed to open "${label}".`, { |
| 84 | description: "Coder Desktop must be installed.", |
| 85 | }); |
| 86 | } else { |
| 87 | toast.error(`Failed to open "${label}".`, { |
| 88 | description: "The app must be installed first.", |
| 89 | }); |
| 90 | } |
| 91 | }, openAppExternallyFailedTimeout); |
| 92 | window.addEventListener("blur", () => { |
| 93 | clearTimeout(openAppExternallyFailed); |
| 94 | }); |
| 95 | |
| 96 | // Custom protocol external apps don't support open_in since they |
| 97 | // rely on the browser's protocol handling. |
| 98 | return; |
| 99 | } |
| 100 | |
| 101 | switch (app.open_in) { |
| 102 | case "slim-window": { |
| 103 | e.preventDefault(); |
| 104 | openAppInNewWindow(href); |
| 105 | return; |
| 106 | } |
no test coverage detected