Files
modeling-app/src/lib/openWindow.ts
Jonathan Tran 25443eba31 internal: Add lints for promises (#3733)
* Add lints for floating and misued promises

* Add logging async errors in main

* Add async error catch in test-utils

* Change any to unknown

* Trap promise errors and ignore more await warnings

* Add more ignores and toSync helper

* Fix more lint warnings

* Add more ignores and fixes

* Add more reject reporting

* Add accepting arbitrary parameters to toSync()

* Fix more lints

* Revert unintentional change to non-arrow function

* Revert unintentional change to use arrow function

* Fix new warnings in main with auto updater

* Fix formatting

* Change lints to error

This is what the recommended type checked rules do.

* Fix to properly report promise rejections

* Fix formatting

* Fix formatting

* Remove unused import

* Remove unused convenience function

* Move type helpers

* Fix to not return promise when caller doesn't expect it

* Add ignores to lsp code
2024-09-10 08:17:45 +10:00

27 lines
775 B
TypeScript

import { MouseEventHandler } from 'react'
import { isDesktop } from 'lib/isDesktop'
import { reportRejection } from './trap'
export const openExternalBrowserIfDesktop = (to?: string) =>
function (e) {
if (isDesktop()) {
// Ignoring because currentTarget could be a few different things
// @ts-ignore
window.electron
.openExternal(to || e.currentTarget?.href)
.catch(reportRejection)
e.preventDefault()
e.stopPropagation()
return false
}
} as MouseEventHandler<HTMLAnchorElement>
// Open a new browser window desktop style or browser style.
export default async function openWindow(url: string) {
if (isDesktop()) {
await window.electron.openExternal(url)
} else {
window.open(url, '_blank')
}
}