diff --git a/src/Router.tsx b/src/Router.tsx index 16bb526d4..56385fa7e 100644 --- a/src/Router.tsx +++ b/src/Router.tsx @@ -44,6 +44,7 @@ import * as Sentry from '@sentry/react' import ModelingMachineProvider from 'components/ModelingMachineProvider' import { KclContextProvider } from 'lang/KclSinglton' import FileMachineProvider from 'components/FileMachineProvider' +import { sep } from '@tauri-apps/api/path' if (VITE_KC_SENTRY_DSN && !TEST) { Sentry.init({ @@ -145,10 +146,10 @@ const router = createBrowserRouter( path: paths.FILE + '/:id', element: ( - + @@ -187,23 +188,23 @@ const router = createBrowserRouter( if (params.id && params.id !== BROWSER_FILE_NAME) { const decodedId = decodeURIComponent(params.id) - const projectAndFile = decodedId.replace(defaultDir + '/', '') - const firstSlashIndex = projectAndFile.indexOf('/') + const projectAndFile = decodedId.replace(defaultDir + sep, '') + const firstSlashIndex = projectAndFile.indexOf(sep) const projectName = projectAndFile.slice(0, firstSlashIndex) - const projectPath = defaultDir + '/' + projectName + const projectPath = defaultDir + sep + projectName const currentFileName = projectAndFile.slice(firstSlashIndex + 1) if (firstSlashIndex === -1 || !currentFileName) return redirect( `${paths.FILE}/${encodeURIComponent( - `${params.id}/${PROJECT_ENTRYPOINT}` + `${params.id}${sep}${PROJECT_ENTRYPOINT}` )}` ) // Note that PROJECT_ENTRYPOINT is hardcoded until we support multiple files const code = await readTextFile(decodedId) const entrypointMetadata = await metadata( - projectPath + '/' + PROJECT_ENTRYPOINT + projectPath + sep + PROJECT_ENTRYPOINT ) const children = await readDir(projectPath, { recursive: true }) @@ -270,9 +271,9 @@ const router = createBrowserRouter( isProjectDirectory ) const projects = await Promise.all( - projectsNoMeta.map(async (p) => ({ + projectsNoMeta.map(async (p: FileEntry) => ({ entrypointMetadata: await metadata( - p.path + '/' + PROJECT_ENTRYPOINT + p.path + sep + PROJECT_ENTRYPOINT ), ...p, })) diff --git a/src/components/AppHeader.tsx b/src/components/AppHeader.tsx index aa8851249..fd98f5a9a 100644 --- a/src/components/AppHeader.tsx +++ b/src/components/AppHeader.tsx @@ -32,13 +32,11 @@ export const AppHeader = ({ className } > - {project && ( - - )} + {/* Toolbar if the context deems it */} {showToolbar && (
@@ -47,7 +45,7 @@ export const AppHeader = ({ )} {/* If there are children, show them, otherwise show User menu */} {children || ( -
+
diff --git a/src/components/FileMachineProvider.tsx b/src/components/FileMachineProvider.tsx index e63fa379a..d391b870a 100644 --- a/src/components/FileMachineProvider.tsx +++ b/src/components/FileMachineProvider.tsx @@ -22,6 +22,7 @@ import { } from '@tauri-apps/api/fs' import { FILE_EXT, readProject } from 'lib/tauriFS' import { isTauri } from 'lib/isTauri' +import { sep } from '@tauri-apps/api/path' type MachineContext = { state: StateFrom @@ -56,7 +57,7 @@ export const FileMachineProvider = ({ setCommandBarOpen(false) navigate( `${paths.FILE}/${encodeURIComponent( - context.selectedDirectory + '/' + event.data.name + context.selectedDirectory + sep + event.data.name )}` ) } @@ -82,11 +83,11 @@ export const FileMachineProvider = ({ let name = event.data.name.trim() || DEFAULT_FILE_NAME if (event.data.makeDir) { - await createDir(context.selectedDirectory.path + '/' + name) + await createDir(context.selectedDirectory.path + sep + name) } else { await writeFile( context.selectedDirectory.path + - '/' + + sep + name + (name.endsWith(FILE_EXT) ? '' : FILE_EXT), '' @@ -103,9 +104,9 @@ export const FileMachineProvider = ({ let name = newName ? newName : DEFAULT_FILE_NAME await renameFile( - context.selectedDirectory.path + '/' + oldName, + context.selectedDirectory.path + sep + oldName, context.selectedDirectory.path + - '/' + + sep + name + (name.endsWith(FILE_EXT) || isDir ? '' : FILE_EXT) ) diff --git a/src/components/ProjectSidebarMenu.tsx b/src/components/ProjectSidebarMenu.tsx index bbfb1cdb6..edfd2db13 100644 --- a/src/components/ProjectSidebarMenu.tsx +++ b/src/components/ProjectSidebarMenu.tsx @@ -7,6 +7,7 @@ import { Link } from 'react-router-dom' import { ExportButton } from './ExportButton' import { Fragment } from 'react' import { FileTree } from './FileTree' +import { sep } from '@tauri-apps/api/path' const ProjectSidebarMenu = ({ project, @@ -26,10 +27,10 @@ const ProjectSidebarMenu = ({ KittyCAD App {project?.name ? project.name : 'KittyCAD Modeling App'} @@ -44,16 +45,16 @@ const ProjectSidebarMenu = ({ KittyCAD App
- + {isTauri() && file?.name - ? file.name.slice(file.name.lastIndexOf('/') + 1) + ? file.name.slice(file.name.lastIndexOf(sep) + 1) : 'KittyCAD Modeling App'} {isTauri() && project?.name && ( - + {project.name} )} @@ -68,7 +69,7 @@ const ProjectSidebarMenu = ({ leaveTo="opacity-0" as={Fragment} > - + {({ close }) => ( @@ -90,7 +91,7 @@ const ProjectSidebarMenu = ({ KittyCAD App
@@ -102,7 +103,7 @@ const ProjectSidebarMenu = ({

{project?.entrypointMetadata && (

Created{' '} @@ -120,7 +121,7 @@ const ProjectSidebarMenu = ({ ) : (

)} -
+
({ - entrypointMetadata: await metadata(p.path + '/' + PROJECT_ENTRYPOINT), + entrypointMetadata: await metadata(p.path + sep + PROJECT_ENTRYPOINT), ...p, })) ) @@ -224,7 +225,7 @@ export async function createNewProject( }) } - await writeTextFile(path + '/' + PROJECT_ENTRYPOINT, '').catch((err) => { + await writeTextFile(path + sep + PROJECT_ENTRYPOINT, bracket).catch((err) => { console.error('Error creating new file:', err) throw err }) @@ -232,13 +233,13 @@ export async function createNewProject( const m = await metadata(path) return { - name: path.slice(path.lastIndexOf('/') + 1), + name: path.slice(path.lastIndexOf(sep) + 1), path: path, entrypointMetadata: m, children: [ { name: PROJECT_ENTRYPOINT, - path: path + '/' + PROJECT_ENTRYPOINT, + path: path + sep + PROJECT_ENTRYPOINT, children: [], }, ], diff --git a/src/routes/Home.tsx b/src/routes/Home.tsx index d59d12eb5..6e7221c94 100644 --- a/src/routes/Home.tsx +++ b/src/routes/Home.tsx @@ -29,6 +29,7 @@ import useStateMachineCommands from '../hooks/useStateMachineCommands' import { useGlobalStateContext } from 'hooks/useGlobalStateContext' import { useCommandsContext } from 'hooks/useCommandsContext' import { DEFAULT_PROJECT_NAME } from 'machines/settingsMachine' +import { sep } from '@tauri-apps/api/path' // This route only opens in the Tauri desktop context for now, // as defined in Router.tsx, so we can use the Tauri APIs and types. @@ -58,7 +59,7 @@ const Home = () => { setCommandBarOpen(false) navigate( `${paths.FILE}/${encodeURIComponent( - context.defaultDirectory + '/' + event.data.name + context.defaultDirectory + sep + event.data.name )}` ) } @@ -91,7 +92,7 @@ const Home = () => { name = interpolateProjectNameWithIndex(name, nextIndex) } - await createNewProject(context.defaultDirectory + '/' + name) + await createNewProject(context.defaultDirectory + sep + name) if (shouldUpdateDefaultProjectName) { sendToSettings({ @@ -114,8 +115,8 @@ const Home = () => { } await renameFile( - context.defaultDirectory + '/' + oldName, - context.defaultDirectory + '/' + name + context.defaultDirectory + sep + oldName, + context.defaultDirectory + sep + name ) return `Successfully renamed "${oldName}" to "${name}"` }, @@ -123,7 +124,7 @@ const Home = () => { context: ContextFrom, event: EventFrom ) => { - await removeDir(context.defaultDirectory + '/' + event.data.name, { + await removeDir(context.defaultDirectory + sep + event.data.name, { recursive: true, }) return `Successfully deleted "${event.data.name}"` @@ -172,9 +173,9 @@ const Home = () => { } return ( -
+
-
+

Your Projects

@@ -235,7 +236,7 @@ const Home = () => { ) : ( <> {projects.length > 0 ? ( -