Skip to content

Commit

Permalink
NUKE tauri shit post merge with main
Browse files Browse the repository at this point in the history
  • Loading branch information
Irev-Dev committed Aug 15, 2024
1 parent fc4866f commit 160abea
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 34 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/playwright.yml
Original file line number Diff line number Diff line change
Expand Up @@ -453,8 +453,8 @@ jobs:
- name: OR Build Wasm (because wasm cache failed)
if: steps.download-wasm.outcome == 'failure'
run: yarn build:wasm
- name: build web
run: yarn build:local
- name: build electron
run: yarn electron:package
- uses: actions/download-artifact@v4
if: always()
continue-on-error: true
Expand Down
2 changes: 2 additions & 0 deletions interface.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ export interface IElectronAPI {
statIsDirectory: (path: string) => Promise<boolean>
path: typeof path
mkdir: typeof fs.mkdir
join: typeof path.join
sep: typeof path.sep
rename: (prev: string, next: string) => typeof fs.rename
packageJson: {
name: string
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"@fortawesome/react-fontawesome": "^0.2.0",
"@headlessui/react": "^1.7.19",
"@headlessui/tailwindcss": "^0.2.0",
"@kittycad/lib": "^0.0.76",
"@kittycad/lib": "^2.0.0",
"@lezer/highlight": "^1.2.0",
"@lezer/lr": "^1.4.1",
"@react-hook/resize-observer": "^2.0.1",
Expand All @@ -41,6 +41,7 @@
"electron-squirrel-startup": "^1.0.1",
"fuse.js": "^7.0.0",
"html2canvas-pro": "^1.5.8",
"isomorphic-fetch": "^3.0.0",
"json-rpc-2.0": "^1.6.0",
"jszip": "^3.10.1",
"openid-client": "^5.6.5",
Expand Down Expand Up @@ -132,6 +133,7 @@
"@testing-library/react": "^15.0.2",
"@types/d3-force": "^3.0.10",
"@types/electron": "^1.6.10",
"@types/isomorphic-fetch": "^0.0.39",
"@types/mocha": "^10.0.6",
"@types/node": "^18.19.31",
"@types/pixelmatch": "^5.2.6",
Expand Down
23 changes: 9 additions & 14 deletions src/components/FileMachineProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,6 @@ import {
import { useCommandsContext } from 'hooks/useCommandsContext'
import { fileMachine } from 'machines/fileMachine'
import { isDesktop } from 'lib/isDesktop'
import {
mkdir,
remove,
rename,
create,
writeTextFile,
} from '@tauri-apps/plugin-fs'
import { join, sep } from '@tauri-apps/api/path'
import { DEFAULT_FILE_NAME, FILE_EXT } from 'lib/constants'
import { getProjectInfo } from 'lib/desktop'

Expand Down Expand Up @@ -107,17 +99,20 @@ export const FileMachineProvider = ({
let createdPath: string

if (event.data.makeDir) {
createdPath = await join(context.selectedDirectory.path, createdName)
await mkdir(createdPath)
createdPath = await window.electron.join(
context.selectedDirectory.path,
createdName
)
await window.electron.mkdir(createdPath)
} else {
createdPath =
context.selectedDirectory.path +
sep() +
window.electron.sep +
createdName +
(createdName.endsWith(FILE_EXT) ? '' : FILE_EXT)
await create(createdPath)
await window.electron.mkdir(createdPath)
if (event.data.content) {
await writeTextFile(createdPath, event.data.content)
await window.electron.writeFile(createdPath, event.data.content)
}
}

Expand All @@ -142,7 +137,7 @@ export const FileMachineProvider = ({
window.electron.path.sep +
createdName +
(createdName.endsWith(FILE_EXT) ? '' : FILE_EXT)
await create(createdPath)
await window.electron.mkdir(createdPath)
if (event.data.content) {
await window.electron.writeFile(createdPath, '')
}
Expand Down
11 changes: 5 additions & 6 deletions src/components/ToastTextToCad.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { GLTFLoader } from 'three/examples/jsm/loaders/GLTFLoader'
import { OrbitControls } from 'three/examples/jsm/controls/OrbitControls'
import { useFileContext } from 'hooks/useFileContext'
import { isTauri } from 'lib/isTauri'
import { isDesktop } from 'lib/isDesktop'
import { PATHS } from 'lib/paths'
import toast from 'react-hot-toast'
import { sep } from '@tauri-apps/api/path'
import { TextToCad_type } from '@kittycad/lib/dist/types/src/models'
import { useEffect, useRef, useState } from 'react'
import {
Expand Down Expand Up @@ -257,13 +256,13 @@ export function ToastTextToCadSuccess({
if (!hasCopied) {
sendTelemetry(modelId, 'rejected', token)
}
if (isTauri()) {
if (isDesktop()) {
// Delete the file from the project
fileMachineSend({
type: 'Delete file',
data: {
name: data.fileName,
path: `${context.project.path}${sep()}${data.fileName}`,
path: `${context.project.path}${window.electron.sep}${data.fileName}`,
children: null,
},
})
Expand All @@ -273,7 +272,7 @@ export function ToastTextToCadSuccess({
>
{hasCopied ? 'Close' : 'Reject'}
</ActionButton>
{isTauri() ? (
{isDesktop() ? (
<ActionButton
Element="button"
iconStart={{
Expand All @@ -284,7 +283,7 @@ export function ToastTextToCadSuccess({
sendTelemetry(modelId, 'accepted', token)
navigate(
`${PATHS.FILE}/${encodeURIComponent(
`${context.project.path}${sep()}${data.fileName}`
`${context.project.path}${window.electron.sep}${data.fileName}`
)}`
)
toast.dismiss(toastId)
Expand Down
10 changes: 6 additions & 4 deletions src/lib/crossPlatformFetch.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { DEV } from 'env'
import { isTauri } from './isTauri'
import { fetch as tauriFetch } from '@tauri-apps/plugin-http'
import { isDesktop } from 'lib/isDesktop'
import isomorphicFetch from 'isomorphic-fetch'

// TODO I not sure this file should exist

const headers = (token?: string): HeadersInit => ({
'Content-Type': 'application/json',
Expand All @@ -14,14 +16,14 @@ export default async function crossPlatformFetch<T>(
): Promise<T | Error> {
let response = null
let opts = options || {}
if (isTauri()) {
if (isDesktop()) {
if (!token) {
return new Error('No token provided')
}

opts.headers = headers(token)

response = await tauriFetch(url, opts)
response = await isomorphicFetch(url, opts)
} else {
// Add credentials: 'include' to options
// We send the token with the headers only in development mode, DO NOT
Expand Down
4 changes: 2 additions & 2 deletions src/lib/textToCad.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { ContextFrom, EventData, EventFrom } from 'xstate'
import { fileMachine } from 'machines/fileMachine'
import { NavigateFunction } from 'react-router-dom'
import crossPlatformFetch from './crossPlatformFetch'
import { isTauri } from './isTauri'
import { isDesktop } from 'lib/isDesktop'
import { Themes } from './theme'
import { commandBarMachine } from 'machines/commandBarMachine'

Expand Down Expand Up @@ -186,7 +186,7 @@ export async function submitAndAwaitTextToKcl({
.replace(/\W/gi, '-')
.toLowerCase()}`

if (isTauri()) {
if (isDesktop()) {
fileMachineSend({
type: 'Create file',
data: {
Expand Down
2 changes: 2 additions & 0 deletions src/preload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ contextBridge.exposeInMainWorld('electron', {
arch: process.arch,
platform: process.platform,
version: process.version,
join: path.join,
sep: path.sep,
process: {
// Setter/getter has to be created because
// these are read-only over the boundary.
Expand Down
14 changes: 9 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1971,12 +1971,11 @@
"@jridgewell/resolve-uri" "^3.1.0"
"@jridgewell/sourcemap-codec" "^1.4.14"

"@kittycad/lib@^0.0.76":
version "0.0.76"
resolved "https://registry.yarnpkg.com/@kittycad/lib/-/lib-0.0.76.tgz#d544a50c54547139d6dfa15730354313a51d0e49"
integrity sha512-14zzP7JS7J8xiwKltJqiszOCF9LdQeJK2nN58Xjiep+LOEVWtiLSGuILTameU2ryjA3aeQzPtNc1WJZ2JYRg2A==
"@kittycad/lib@^2.0.0":
version "2.0.0"
resolved "https://registry.yarnpkg.com/@kittycad/lib/-/lib-2.0.0.tgz#c7808f47546f5b85371899b0b82989a4049d258d"
integrity sha512-iJCifdt7C+gHCH7xomNhynUmhy4rvM+J3Skxm3vxJR+zMWludm1bSCd+LgUpgk6kZOvkHJ755Y0gfMDYz1IVxw==
dependencies:
node-fetch "3.3.2"
openapi-types "^12.0.0"
ts-node "^10.9.1"
tslib "~2.4"
Expand Down Expand Up @@ -2420,6 +2419,11 @@
resolved "https://registry.yarnpkg.com/@types/http-cache-semantics/-/http-cache-semantics-4.0.4.tgz#b979ebad3919799c979b17c72621c0bc0a31c6c4"
integrity sha512-1m0bIFVc7eJWyve9S0RnuRgcQqF/Xd5QsUZAZeQFr1Q3/p9JWoQQEqmVy+DPTNpGXwhgIetAoYF8JSc33q29QA==

"@types/isomorphic-fetch@^0.0.39":
version "0.0.39"
resolved "https://registry.yarnpkg.com/@types/isomorphic-fetch/-/isomorphic-fetch-0.0.39.tgz#889573a72ca637bc1a665910a41ff1cb3b52011f"
integrity sha512-I0gou/ZdA1vMG7t7gMzL7VYu2xAKU78rW9U1l10MI0nn77pEHq3tQqHQ8hMmXdMpBlkxZOorjI4sO594Z3kKJw==

"@types/istanbul-lib-coverage@*", "@types/istanbul-lib-coverage@^2.0.0":
version "2.0.6"
resolved "https://registry.yarnpkg.com/@types/istanbul-lib-coverage/-/istanbul-lib-coverage-2.0.6.tgz#7739c232a1fee9b4d3ce8985f314c0c6d33549d7"
Expand Down

0 comments on commit 160abea

Please sign in to comment.