From 871cc4df356cd8f64f12933ac44c414ea634478c Mon Sep 17 00:00:00 2001 From: 49lf Date: Wed, 31 Jul 2024 15:08:18 -0400 Subject: [PATCH] Make sure links open externally --- src/components/ActionButton.tsx | 2 ++ src/components/HelpMenu.tsx | 2 ++ src/components/LowerRightControls.tsx | 1 + .../ModelingPanes/KclEditorMenu.tsx | 3 +++ src/lib/coredump.ts | 14 +++++--------- src/lib/electron.ts | 5 +++++ src/lib/openWindow.ts | 12 ++++++++++-- src/main.ts | 6 +++++- 8 files changed, 33 insertions(+), 12 deletions(-) diff --git a/src/components/ActionButton.tsx b/src/components/ActionButton.tsx index 4bf392272..c20c9959a 100644 --- a/src/components/ActionButton.tsx +++ b/src/components/ActionButton.tsx @@ -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} to={to || paths.INDEX} className={classNames} + onClick={openExternalBrowserIfDesktop(to)} {...rest} target="_blank" > diff --git a/src/components/HelpMenu.tsx b/src/components/HelpMenu.tsx index 906c0a7d7..3a5318ed7 100644 --- a/src/components/HelpMenu.tsx +++ b/src/components/HelpMenu.tsx @@ -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 = () => (
@@ -141,6 +142,7 @@ function HelpMenuItem({ {as === 'a' ? ( )} + onClick={openExternalBrowserIfDesktop(props.href)} className={`no-underline text-inherit ${baseClassName} ${className}`} > {children} diff --git a/src/components/LowerRightControls.tsx b/src/components/LowerRightControls.tsx index c271b0b40..33e144100 100644 --- a/src/components/LowerRightControls.tsx +++ b/src/components/LowerRightControls.tsx @@ -28,6 +28,7 @@ export function LowerRightControls({ async function reportbug(event: { preventDefault: () => void }) { event?.preventDefault() + event?.stopPropagation() if (!coreDumpManager) { // open default reporting option diff --git a/src/components/ModelingSidebar/ModelingPanes/KclEditorMenu.tsx b/src/components/ModelingSidebar/ModelingPanes/KclEditorMenu.tsx index 7a2093c4a..fc46f7213 100644 --- a/src/components/ModelingSidebar/ModelingPanes/KclEditorMenu.tsx +++ b/src/components/ModelingSidebar/ModelingPanes/KclEditorMenu.tsx @@ -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()} > Read the KCL docs @@ -78,6 +80,7 @@ export const KclEditorMenu = ({ children }: PropsWithChildren) => { href="https://zoo.dev/docs/kcl-samples" target="_blank" rel="noopener noreferrer" + onClick={openExternalBrowserIfDesktop()} > KCL samples diff --git a/src/lib/coredump.ts b/src/lib/coredump.ts index 76c200308..0ffb0f957 100644 --- a/src/lib/coredump.ts +++ b/src/lib/coredump.ts @@ -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 { 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 } diff --git a/src/lib/electron.ts b/src/lib/electron.ts index 1ac567d7e..80fb09eb6 100644 --- a/src/lib/electron.ts +++ b/src/lib/electron.ts @@ -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. diff --git a/src/lib/openWindow.ts b/src/lib/openWindow.ts index 8dc020a97..47c1ff3ff 100644 --- a/src/lib/openWindow.ts +++ b/src/lib/openWindow.ts @@ -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') } diff --git a/src/main.ts b/src/main.ts index 537673a0d..efe2866cf 100644 --- a/src/main.ts +++ b/src/main.ts @@ -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 })