Make sure links open externally
This commit is contained in:
@ -1,4 +1,5 @@
|
||||
import { ActionIcon, ActionIconProps } from './ActionIcon'
|
||||
import { openExternalBrowserIfDesktop } from 'lib/openWindow'
|
||||
import React, { ForwardedRef, forwardRef } from 'react'
|
||||
import { paths } from 'lib/paths'
|
||||
import { Link } from 'react-router-dom'
|
||||
@ -107,6 +108,7 @@ export const ActionButton = forwardRef((props: ActionButtonProps, ref) => {
|
||||
ref={ref as ForwardedRef<HTMLAnchorElement>}
|
||||
to={to || paths.INDEX}
|
||||
className={classNames}
|
||||
onClick={openExternalBrowserIfDesktop(to)}
|
||||
{...rest}
|
||||
target="_blank"
|
||||
>
|
||||
|
@ -7,6 +7,7 @@ import { createAndOpenNewProject } from 'lib/desktopFS'
|
||||
import { paths } from 'lib/paths'
|
||||
import { useAbsoluteFilePath } from 'hooks/useAbsoluteFilePath'
|
||||
import { useLspContext } from './LspProvider'
|
||||
import { openExternalBrowserIfDesktop } from 'lib/openWindow'
|
||||
|
||||
const HelpMenuDivider = () => (
|
||||
<div className="h-[1px] bg-chalkboard-110 dark:bg-chalkboard-80" />
|
||||
@ -141,6 +142,7 @@ function HelpMenuItem({
|
||||
{as === 'a' ? (
|
||||
<a
|
||||
{...(props as React.ComponentProps<'a'>)}
|
||||
onClick={openExternalBrowserIfDesktop(props.href)}
|
||||
className={`no-underline text-inherit ${baseClassName} ${className}`}
|
||||
>
|
||||
{children}
|
||||
|
@ -28,6 +28,7 @@ export function LowerRightControls({
|
||||
|
||||
async function reportbug(event: { preventDefault: () => void }) {
|
||||
event?.preventDefault()
|
||||
event?.stopPropagation()
|
||||
|
||||
if (!coreDumpManager) {
|
||||
// open default reporting option
|
||||
|
@ -7,6 +7,7 @@ import { useConvertToVariable } from 'hooks/useToolbarGuards'
|
||||
import { editorShortcutMeta } from './KclEditorPane'
|
||||
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
|
||||
import { kclManager } from 'lib/singletons'
|
||||
import { openExternalBrowserIfDesktop } from 'lib/openWindow'
|
||||
|
||||
export const KclEditorMenu = ({ children }: PropsWithChildren) => {
|
||||
const { enable: convertToVarEnabled, handleClick: handleConvertToVarClick } =
|
||||
@ -60,6 +61,7 @@ export const KclEditorMenu = ({ children }: PropsWithChildren) => {
|
||||
href="https://zoo.dev/docs/kcl"
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
onClick={openExternalBrowserIfDesktop()}
|
||||
>
|
||||
<span>Read the KCL docs</span>
|
||||
<small>
|
||||
@ -78,6 +80,7 @@ export const KclEditorMenu = ({ children }: PropsWithChildren) => {
|
||||
href="https://zoo.dev/docs/kcl-samples"
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
onClick={openExternalBrowserIfDesktop()}
|
||||
>
|
||||
<span>KCL samples</span>
|
||||
<small>
|
||||
|
@ -2,11 +2,6 @@ import { CommandLog, EngineCommandManager } from 'lang/std/engineConnection'
|
||||
import { WebrtcStats } from 'wasm-lib/kcl/bindings/WebrtcStats'
|
||||
import { OsInfo } from 'wasm-lib/kcl/bindings/OsInfo'
|
||||
import { isDesktop } from 'lib/isDesktop'
|
||||
import {
|
||||
platform as tauriPlatform,
|
||||
arch as tauriArch,
|
||||
version as tauriKernelVersion,
|
||||
} from '@tauri-apps/plugin-os'
|
||||
import { APP_VERSION } from 'routes/Settings'
|
||||
import { UAParser } from 'ua-parser-js'
|
||||
import screenshot from 'lib/screenshot'
|
||||
@ -70,12 +65,13 @@ export class CoreDumpManager {
|
||||
getOsInfo(): Promise<string> {
|
||||
if (this.isDesktop()) {
|
||||
const osinfo: OsInfo = {
|
||||
platform: tauriPlatform(),
|
||||
arch: tauriArch(),
|
||||
browser: 'tauri',
|
||||
version: tauriKernelVersion(),
|
||||
platform: window.electron.platform,
|
||||
arch: window.electron.arch,
|
||||
browser: 'desktop',
|
||||
version: window.electron.version,
|
||||
}
|
||||
return new Promise((resolve) => resolve(JSON.stringify(osinfo)))
|
||||
// (lf94) I'm not sure if this comment is specific to tauri or just desktop...
|
||||
// TODO: get rid of promises now that the tauri api doesn't require them anymore
|
||||
}
|
||||
|
||||
|
@ -4,6 +4,7 @@ import fs from 'node:fs/promises'
|
||||
import packageJson from '../../package.json'
|
||||
|
||||
const open = (args: any) => ipcRenderer.invoke('dialog', args)
|
||||
const openExternal = (url: any) => ipcRenderer.invoke('shell.openExternal', url)
|
||||
const showInFolder = (path: string) => ipcRenderer.invoke('shell.showItemInFolder', path)
|
||||
const login = (host: string) => ipcRenderer.invoke('login', host)
|
||||
|
||||
@ -47,10 +48,14 @@ import('@kittycad/lib').then((kittycad) => {
|
||||
mkdir: fs.mkdir,
|
||||
// opens a dialog
|
||||
open,
|
||||
// opens the URL
|
||||
openExternal,
|
||||
showInFolder,
|
||||
getPath,
|
||||
packageJson,
|
||||
arch: process.arch,
|
||||
platform: process.platform,
|
||||
version: process.version,
|
||||
process: {
|
||||
// Setter/getter has to be created because
|
||||
// these are read-only over the boundary.
|
||||
|
@ -1,10 +1,18 @@
|
||||
import { isDesktop } from 'lib/isDesktop'
|
||||
import { open as tauriOpen } from '@tauri-apps/plugin-shell'
|
||||
|
||||
export const openExternalBrowserIfDesktop = (to) => function(e) {
|
||||
if (isDesktop()) {
|
||||
window.electron.openExternal(to || e.currentTarget.href)
|
||||
e.preventDefault()
|
||||
e.stopPropagation()
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
// Open a new browser window tauri style or browser style.
|
||||
export default async function openWindow(url: string) {
|
||||
if (isDesktop()) {
|
||||
await tauriOpen(url)
|
||||
await window.electron.openExternal(url)
|
||||
} else {
|
||||
window.open(url, '_blank')
|
||||
}
|
||||
|
@ -63,6 +63,10 @@ ipcMain.handle('shell.showItemInFolder', (event, data) => {
|
||||
return shell.showItemInFolder(data)
|
||||
})
|
||||
|
||||
ipcMain.handle('shell.openExternal', (event, data) => {
|
||||
return shell.openExternal(data)
|
||||
})
|
||||
|
||||
ipcMain.handle('login', async (event, host) => {
|
||||
console.log('Logging in...')
|
||||
// Do an OAuth 2.0 Device Authorization Grant dance to get a token.
|
||||
@ -104,5 +108,5 @@ ipcMain.handle('login', async (event, host) => {
|
||||
// Wait for the user to login.
|
||||
const tokenSet = await handle.poll()
|
||||
|
||||
return tokenSet
|
||||
return tokenSet.access_token
|
||||
})
|
||||
|
Reference in New Issue
Block a user