Lf94/tauri to electron (#3315)
* Get electron building something at all * Merge Frank test setup work (#3418) * Working window.electron.getPath * Loading project-specific settings in electron tests * Simplify test until we can get snapshots/traces working in electron tests * test tweaks --------- Co-authored-by: Frank Noirot <frank@kittycad.io> * add test #3375 and #3420 * put kcl files together * move files * can sort projects #3362 * File in the file pane should open with a single click #3385 * pressing delete on home screen should do nothing #3387 * add aria labels to icons * Rename and delete projects, also spam arrow keys when renaming #3364 #3365 #3259 * Fix up paths * Update flake.nix to support Electron * Remove a layer of indirection * Work without a web server * Fix settings#projectDir link on home * Fix login (requires new @kittycad/lib WHICH IS NOT INCLUDED HERE) * Lee: Tests are broken because auth skip needs to happen * get setting override envs passed through * tweak eletron CI * yml tweak * fmt * NUKE tauri shit post merge with main * another test auth tweak * Revert "another test auth tweak" This reverts commitb2254b10af
. * try CI again * CI tweaks * SKIP_AUTH true now on playwright * Skipping auth when NODE_ENV=development now * fmt Signed-off-by: Jess Frazelle <github@jessfraz.com> * Use BASE_URL() * fix exists Signed-off-by: Jess Frazelle <github@jessfraz.com> * fix foldername for macos Signed-off-by: Jess Frazelle <github@jessfraz.com> * update for windows Signed-off-by: Jess Frazelle <github@jessfraz.com> * fix version in lower right Signed-off-by: Jess Frazelle <github@jessfraz.com> * cleanup unused imports Signed-off-by: Jess Frazelle <github@jessfraz.com> * progress on is playwright Signed-off-by: Jess Frazelle <github@jessfraz.com> * fix test folders Signed-off-by: Jess Frazelle <github@jessfraz.com> * fix fmt Signed-off-by: Jess Frazelle <github@jessfraz.com> * remove tauri from actions bullshit Signed-off-by: Jess Frazelle <github@jessfraz.com> * remove tauri dir Signed-off-by: Jess Frazelle <github@jessfraz.com> * fixups the coredump async shit Signed-off-by: Jess Frazelle <github@jessfraz.com> * updates Signed-off-by: Jess Frazelle <github@jessfraz.com> * node env dev Signed-off-by: Jess Frazelle <github@jessfraz.com> * fix cancellable Signed-off-by: Jess Frazelle <github@jessfraz.com> * cleanup unnessary things Signed-off-by: Jess Frazelle <github@jessfraz.com> * fix Signed-off-by: Jess Frazelle <github@jessfraz.com> * env vars Signed-off-by: Jess Frazelle <github@jessfraz.com> * Bring back fix for NOT using hardcoded main.kcl * env Signed-off-by: Jess Frazelle <github@jessfraz.com> * fmt Signed-off-by: Jess Frazelle <github@jessfraz.com> * updates Signed-off-by: Jess Frazelle <github@jessfraz.com> * Revert "updates" This reverts commit da5d9f1043eb94404e8b3f8044088e990e34a4ef. * updates Signed-off-by: Jess Frazelle <github@jessfraz.com> * remove tauri clippuy Signed-off-by: Jess Frazelle <github@jessfraz.com> * less retries for now, no debug Signed-off-by: Jess Frazelle <github@jessfraz.com> * updates Signed-off-by: Jess Frazelle <github@jessfraz.com> * tsconfig Signed-off-by: Jess Frazelle <github@jessfraz.com> * small tsc fix * update some tsc Signed-off-by: Jess Frazelle <github@jessfraz.com> * tsc env Signed-off-by: Jess Frazelle <github@jessfraz.com> * fix other tsc Signed-off-by: Jess Frazelle <github@jessfraz.com> * small change for routeLoaders * rm old screenshot Signed-off-by: Jess Frazelle <github@jessfraz.com> * fix auth Signed-off-by: Jess Frazelle <github@jessfraz.com> * fix last onew Signed-off-by: Jess Frazelle <github@jessfraz.com> * auth clean up * fix package.json Signed-off-by: Jess Frazelle <github@jessfraz.com> * fix Signed-off-by: Jess Frazelle <github@jessfraz.com> * dissmissed screen on tests * add waits between files being written * put back retried Signed-off-by: Jess Frazelle <github@jessfraz.com> * fix weird programMemory Map issue * put private back * Revert "put private back" This reverts commitd311b978ca
. * Revert "fix weird programMemory Map issue" This reverts commit6c387bdf62
. * remove serde-wasm-bindgen Signed-off-by: Jess Frazelle <github@jessfraz.com> * add env Signed-off-by: Jess Frazelle <github@jessfraz.com> * A snapshot a day keeps the bugs away! 📷🐛 (OS: ubuntu) * A snapshot a day keeps the bugs away! 📷🐛 (OS: ubuntu) * fix tests * more test tweaks * A snapshot a day keeps the bugs away! 📷🐛 (OS: ubuntu) * another tweak * A snapshot a day keeps the bugs away! 📷🐛 (OS: ubuntu) * more test tweaks * more tweaks * increase macos timeout * try fix macos * disable macos playwright tests --------- Signed-off-by: Jess Frazelle <github@jessfraz.com> Co-authored-by: Kurt Hutten <k.hutten@protonmail.ch> Co-authored-by: Frank Noirot <frank@kittycad.io> Co-authored-by: Adam Sunderland <iterion@gmail.com> Co-authored-by: Jess Frazelle <github@jessfraz.com> Co-authored-by: Jess Frazelle <jessfraz@users.noreply.github.com> Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
This commit is contained in:
@ -1,7 +1,7 @@
|
||||
import { ActionFunction, LoaderFunction, redirect } from 'react-router-dom'
|
||||
import { FileLoaderData, HomeLoaderData, IndexLoaderData } from './types'
|
||||
import { isTauri } from './isTauri'
|
||||
import { getProjectMetaByRouteId, PATHS } from './paths'
|
||||
import { isDesktop } from './isDesktop'
|
||||
import { BROWSER_PATH } from 'lib/paths'
|
||||
import {
|
||||
BROWSER_FILE_NAME,
|
||||
@ -10,15 +10,13 @@ import {
|
||||
} from 'lib/constants'
|
||||
import { loadAndValidateSettings } from './settings/settingsUtils'
|
||||
import makeUrlPathRelative from './makeUrlPathRelative'
|
||||
import { sep } from '@tauri-apps/api/path'
|
||||
import { readTextFile } from '@tauri-apps/plugin-fs'
|
||||
import { codeManager } from 'lib/singletons'
|
||||
import { codeManager, kclManager } from 'lib/singletons'
|
||||
import { fileSystemManager } from 'lang/std/fileSystemManager'
|
||||
import {
|
||||
getProjectInfo,
|
||||
initializeProjectDirectory,
|
||||
ensureProjectDirectoryExists,
|
||||
listProjects,
|
||||
} from './tauri'
|
||||
} from './desktop'
|
||||
import { createSettings } from './settings/initialSettings'
|
||||
|
||||
// The root loader simply resolves the settings and any errors that
|
||||
@ -42,7 +40,7 @@ export const settingsLoader: LoaderFunction = async ({
|
||||
const { settings: s } = await loadAndValidateSettings(
|
||||
project_path || undefined
|
||||
)
|
||||
settings = s
|
||||
return s
|
||||
}
|
||||
}
|
||||
|
||||
@ -72,9 +70,10 @@ export const onboardingRedirectLoader: ActionFunction = async (args) => {
|
||||
return settingsLoader(args)
|
||||
}
|
||||
|
||||
export const fileLoader: LoaderFunction = async ({
|
||||
params,
|
||||
}): Promise<FileLoaderData | Response> => {
|
||||
export const fileLoader: LoaderFunction = async (
|
||||
routerData
|
||||
): Promise<FileLoaderData | Response> => {
|
||||
const { params } = routerData
|
||||
let { configuration } = await loadAndValidateSettings()
|
||||
|
||||
const projectPathData = await getProjectMetaByRouteId(
|
||||
@ -87,44 +86,53 @@ export const fileLoader: LoaderFunction = async ({
|
||||
const { project_name, project_path, current_file_name, current_file_path } =
|
||||
projectPathData
|
||||
|
||||
if (!current_file_name || !current_file_path || !project_name) {
|
||||
return redirect(
|
||||
`${PATHS.FILE}/${encodeURIComponent(
|
||||
`${params.id}${isTauri() ? sep() : '/'}${PROJECT_ENTRYPOINT}`
|
||||
)}`
|
||||
)
|
||||
const urlObj = new URL(routerData.request.url)
|
||||
let code = ''
|
||||
|
||||
if (!urlObj.pathname.endsWith('/settings')) {
|
||||
if (!current_file_name || !current_file_path || !project_name) {
|
||||
return redirect(
|
||||
`${PATHS.FILE}/${encodeURIComponent(
|
||||
isDesktop()
|
||||
? (await getProjectInfo(project_path)).default_file
|
||||
: params.id + '/' + PROJECT_ENTRYPOINT
|
||||
)}`
|
||||
)
|
||||
}
|
||||
|
||||
code = await window.electron.readFile(current_file_path)
|
||||
|
||||
// Update both the state and the editor's code.
|
||||
// We explicitly do not write to the file here since we are loading from
|
||||
// the file system and not the editor.
|
||||
codeManager.updateCurrentFilePath(current_file_path)
|
||||
codeManager.updateCodeStateEditor(code)
|
||||
// We don't want to call await on execute code since we don't want to block the UI
|
||||
kclManager.executeCode(true)
|
||||
}
|
||||
|
||||
// TODO: PROJECT_ENTRYPOINT is hardcoded
|
||||
// until we support setting a project's entrypoint file
|
||||
const code = await readTextFile(current_file_path)
|
||||
|
||||
// Update both the state and the editor's code.
|
||||
// We explicitly do not write to the file here since we are loading from
|
||||
// the file system and not the editor.
|
||||
codeManager.updateCurrentFilePath(current_file_path)
|
||||
codeManager.updateCodeStateEditor(code)
|
||||
|
||||
// Set the file system manager to the project path
|
||||
// So that WASM gets an updated path for operations
|
||||
fileSystemManager.dir = project_path
|
||||
|
||||
const defaultProjectData = {
|
||||
name: project_name || 'unnamed',
|
||||
path: project_path,
|
||||
children: [],
|
||||
kcl_file_count: 0,
|
||||
directory_count: 0,
|
||||
metadata: null,
|
||||
default_file: project_path,
|
||||
}
|
||||
|
||||
const projectData: IndexLoaderData = {
|
||||
code,
|
||||
project: isTauri()
|
||||
? await getProjectInfo(project_path, configuration)
|
||||
: {
|
||||
name: project_name,
|
||||
path: project_path,
|
||||
children: [],
|
||||
kcl_file_count: 0,
|
||||
directory_count: 0,
|
||||
metadata: null,
|
||||
default_file: project_path,
|
||||
},
|
||||
project: isDesktop()
|
||||
? (await getProjectInfo(project_path)) ?? defaultProjectData
|
||||
: defaultProjectData,
|
||||
file: {
|
||||
name: current_file_name,
|
||||
path: current_file_path,
|
||||
name: current_file_name || '',
|
||||
path: current_file_path?.split('/').slice(0, -1).join('/') ?? '',
|
||||
children: [],
|
||||
},
|
||||
}
|
||||
@ -154,12 +162,12 @@ export const fileLoader: LoaderFunction = async ({
|
||||
export const homeLoader: LoaderFunction = async (): Promise<
|
||||
HomeLoaderData | Response
|
||||
> => {
|
||||
if (!isTauri()) {
|
||||
if (!isDesktop()) {
|
||||
return redirect(PATHS.FILE + '/%2F' + BROWSER_PROJECT_NAME)
|
||||
}
|
||||
const { configuration } = await loadAndValidateSettings()
|
||||
|
||||
const projectDir = await initializeProjectDirectory(configuration)
|
||||
const projectDir = await ensureProjectDirectoryExists(configuration)
|
||||
|
||||
if (projectDir) {
|
||||
const projects = await listProjects(configuration)
|
||||
|
Reference in New Issue
Block a user