2024-08-16 07:15:42 -04:00
|
|
|
import { isDesktop } from './isDesktop'
|
2025-03-01 13:59:01 -08:00
|
|
|
import { deserialize_files } from '@rust/kcl-wasm-lib/pkg/kcl_wasm_lib'
|
2023-08-02 16:23:17 -07:00
|
|
|
import { browserSaveFile } from './browserSaveFile'
|
|
|
|
|
2024-03-14 11:50:46 -04:00
|
|
|
import JSZip from 'jszip'
|
2024-08-04 00:51:30 -04:00
|
|
|
import ModelingAppFile from './modelingAppFile'
|
2024-09-17 19:06:06 -04:00
|
|
|
import toast from 'react-hot-toast'
|
|
|
|
import { EXPORT_TOAST_MESSAGES } from './constants'
|
2024-03-14 11:50:46 -04:00
|
|
|
|
2024-09-17 19:06:06 -04:00
|
|
|
const save_ = async (file: ModelingAppFile, toastId: string) => {
|
2023-08-02 16:23:17 -07:00
|
|
|
try {
|
2024-08-16 07:15:42 -04:00
|
|
|
if (isDesktop()) {
|
2024-05-06 13:07:35 -07:00
|
|
|
const extension = file.name.split('.').pop() || null
|
|
|
|
let extensions: string[] = []
|
|
|
|
if (extension !== null) {
|
|
|
|
extensions.push(extension)
|
|
|
|
}
|
|
|
|
|
2024-09-04 13:12:16 -07:00
|
|
|
if (window.electron.process.env.IS_PLAYWRIGHT) {
|
Move all tests over to electron (#4484)
* Move all tests over to electron
* Pass the correct param to playwright-electron.sh
* Add shebang to script and add macos-14-large as a target
* Get sketch-tests.spec.ts passing in electron
* Try out 4 workers
* Got testing-segment-overlays passing
* Pass testing-selections.spec.ts
* Go back to fix up sketch-tests test
* Pass various.spec.ts, by far the hardest one
* Pass can-sketch-on-all-planes... with ease
* Pass command bar tests
* fmt
* Completely fix code mirror text navigating for tests
* Pass debug pane tests
* Pass desktop export tests
* Pass editor tests
* Pass file tree tests
* Pass onboarding tests
* Corrected a fixme in file-tree.spec!
* Painfully fix hardcoded coordinates in point-click.spec
* Pass machine.spec tests
* Pass projects, fought hard with filechooser
* Pass regresion-tests.spec tests
* Pass network and connection tests
* Pass camera-movement.spec tests
* Extreme time eaten by gizmo test fixes. All passing now.
* Merge main (tests changed x_x) and pass all constraints.spec tests (pain)
* Pass another painful spec suite: testing-settings
* Pass perspective-toggle, interesting note
* Pass samples loading tests
* Pass app header tests
* Pass text-to-cad tests
* Pass segment-overlays (minor ache) and ability to switch to web if needed :)
* Fix a ton of syntax changes and deflake 2 more tests (pain)
* Correct all tsc errors
* Remove to-electron script
* Add an f-ton of shit because playwright doesnt want S P R E A D
* Try CI again
* Stop snapshots of exports (already test in e2e)
* Fix flake in double click editor
* Hopefully help CI flake
* Fixmes, fixmes everywhere
* One more fixme to settings
* Skip another code pane flake
* Port jess's projects.spec tests
* fixup
* Reuse electron window; difficult task
* Rebased and refixed
* Remove duplicate cases
* A snapshot a day keeps the bugs away! 📷🐛 (OS: ubuntu-latest-8-cores)
* Reduce the workers to something CI can handle
* Lower it further, we need to think about the others
* Update package.json
Co-authored-by: Pierre Jacquier <pierrejacquier39@gmail.com>
* Update package.json
Co-authored-by: Pierre Jacquier <pierrejacquier39@gmail.com>
* Fix the last tests and tsc errors
* Timeout to 120 and windows-2022-16core
* Fix windows runner detection, enable concurrency temporarily
* Hopefully this time fix windows runner detection
* Comment out Vector, add back removed camera test code
* A snapshot a day keeps the bugs away! 📷🐛 (OS: ubuntu-latest-8-cores)
* A snapshot a day keeps the bugs away! 📷🐛 (OS: macos-14-large)
* A snapshot a day keeps the bugs away! 📷🐛 (OS: macos-14-large)
* Fix camera tests again
* Massively deflake a whole class of tests
* A snapshot a day keeps the bugs away! 📷🐛 (OS: macos-14-large)
* A snapshot a day keeps the bugs away! 📷🐛 (OS: macos-14-large)
* A snapshot a day keeps the bugs away! 📷🐛 (OS: ubuntu-latest-8-cores)
* Try new CI and fix small onboarding test
* Derp
* No github tuning
* Try mac
* Add back all the OS
* Lord, hallow be thy name
* A snapshot a day keeps the bugs away! 📷🐛 (OS: namespace-profile-ubuntu-8-cores)
* A snapshot a day keeps the bugs away! 📷🐛 (OS: windows-latest-8-cores)
* One last try with window-16-cores
* Trigger CI
* Try AWS Windows runner
* Passing on windows locally with a few skips
* Skip more win tests, add back all three oses
* A snapshot a day keeps the bugs away! 📷🐛 (OS: windows-16-cores)
* Add two more fixmes
* 2 more fixmes
* skip segment overlays on win32
* Another fixme
* Trigger CI
* Trigger CI
* Quick clean up
* Move all tests over to electron
* Pass the correct param to playwright-electron.sh
* Add shebang to script and add macos-14-large as a target
* Get sketch-tests.spec.ts passing in electron
* Try out 4 workers
* Got testing-segment-overlays passing
* Pass testing-selections.spec.ts
* Go back to fix up sketch-tests test
* Pass various.spec.ts, by far the hardest one
* Pass can-sketch-on-all-planes... with ease
* Pass command bar tests
* fmt
* Completely fix code mirror text navigating for tests
* Pass debug pane tests
* Pass desktop export tests
* Pass editor tests
* Pass file tree tests
* Pass onboarding tests
* Corrected a fixme in file-tree.spec!
* Painfully fix hardcoded coordinates in point-click.spec
* Pass machine.spec tests
* Pass projects, fought hard with filechooser
* Pass regresion-tests.spec tests
* Pass network and connection tests
* Pass camera-movement.spec tests
* Extreme time eaten by gizmo test fixes. All passing now.
* Merge main (tests changed x_x) and pass all constraints.spec tests (pain)
* Pass another painful spec suite: testing-settings
* Pass perspective-toggle, interesting note
* Pass samples loading tests
* Pass app header tests
* Pass text-to-cad tests
* Pass segment-overlays (minor ache) and ability to switch to web if needed :)
* Fix a ton of syntax changes and deflake 2 more tests (pain)
* Correct all tsc errors
* Remove to-electron script
* Add an f-ton of shit because playwright doesnt want S P R E A D
* Try CI again
* Stop snapshots of exports (already test in e2e)
* Fix flake in double click editor
* Hopefully help CI flake
* Fixmes, fixmes everywhere
* One more fixme to settings
* Skip another code pane flake
* Port jess's projects.spec tests
* fixup
* Reuse electron window; difficult task
* Rebased and refixed
* Remove duplicate cases
* A snapshot a day keeps the bugs away! 📷🐛 (OS: ubuntu-latest-8-cores)
* Reduce the workers to something CI can handle
* Lower it further, we need to think about the others
* Update package.json
Co-authored-by: Pierre Jacquier <pierrejacquier39@gmail.com>
* Update package.json
Co-authored-by: Pierre Jacquier <pierrejacquier39@gmail.com>
* Fix the last tests and tsc errors
* Timeout to 120 and windows-2022-16core
* Fix windows runner detection, enable concurrency temporarily
* Hopefully this time fix windows runner detection
* Comment out Vector, add back removed camera test code
* A snapshot a day keeps the bugs away! 📷🐛 (OS: ubuntu-latest-8-cores)
* A snapshot a day keeps the bugs away! 📷🐛 (OS: macos-14-large)
* A snapshot a day keeps the bugs away! 📷🐛 (OS: macos-14-large)
* Fix camera tests again
* Massively deflake a whole class of tests
* A snapshot a day keeps the bugs away! 📷🐛 (OS: macos-14-large)
* A snapshot a day keeps the bugs away! 📷🐛 (OS: macos-14-large)
* Try new CI and fix small onboarding test
* Derp
* No github tuning
* Try mac
* Add back all the OS
* Lord, hallow be thy name
* A snapshot a day keeps the bugs away! 📷🐛 (OS: namespace-profile-ubuntu-8-cores)
* A snapshot a day keeps the bugs away! 📷🐛 (OS: windows-latest-8-cores)
* Try AWS Windows runner
* Passing on windows locally with a few skips
* Trigger CI
* A snapshot a day keeps the bugs away! 📷🐛 (OS: namespace-profile-ubuntu-8-cores)
* fmt, tsc, lint
* Enable two fixmes again
* Fix lint, codespell, fmt
* Fix lint
* Don't run e2e on draft, add back concurrency, clean up
* One last windows skip
---------
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Pierre Jacquier <pierrejacquier39@gmail.com>
Co-authored-by: Pierre Jacquier <pierre@zoo.dev>
2024-12-18 17:58:03 -05:00
|
|
|
// Skip file picker, save to the test dir downloads directory
|
|
|
|
const testSettingsPath = await window.electron.getAppTestProperty(
|
|
|
|
'TEST_SETTINGS_FILE_KEY'
|
|
|
|
)
|
|
|
|
const downloadDir = window.electron.join(
|
|
|
|
testSettingsPath,
|
|
|
|
'downloads-during-playwright'
|
|
|
|
)
|
|
|
|
await window.electron.mkdir(downloadDir, { recursive: true })
|
2024-08-19 16:29:44 +10:00
|
|
|
await window.electron.writeFile(
|
Move all tests over to electron (#4484)
* Move all tests over to electron
* Pass the correct param to playwright-electron.sh
* Add shebang to script and add macos-14-large as a target
* Get sketch-tests.spec.ts passing in electron
* Try out 4 workers
* Got testing-segment-overlays passing
* Pass testing-selections.spec.ts
* Go back to fix up sketch-tests test
* Pass various.spec.ts, by far the hardest one
* Pass can-sketch-on-all-planes... with ease
* Pass command bar tests
* fmt
* Completely fix code mirror text navigating for tests
* Pass debug pane tests
* Pass desktop export tests
* Pass editor tests
* Pass file tree tests
* Pass onboarding tests
* Corrected a fixme in file-tree.spec!
* Painfully fix hardcoded coordinates in point-click.spec
* Pass machine.spec tests
* Pass projects, fought hard with filechooser
* Pass regresion-tests.spec tests
* Pass network and connection tests
* Pass camera-movement.spec tests
* Extreme time eaten by gizmo test fixes. All passing now.
* Merge main (tests changed x_x) and pass all constraints.spec tests (pain)
* Pass another painful spec suite: testing-settings
* Pass perspective-toggle, interesting note
* Pass samples loading tests
* Pass app header tests
* Pass text-to-cad tests
* Pass segment-overlays (minor ache) and ability to switch to web if needed :)
* Fix a ton of syntax changes and deflake 2 more tests (pain)
* Correct all tsc errors
* Remove to-electron script
* Add an f-ton of shit because playwright doesnt want S P R E A D
* Try CI again
* Stop snapshots of exports (already test in e2e)
* Fix flake in double click editor
* Hopefully help CI flake
* Fixmes, fixmes everywhere
* One more fixme to settings
* Skip another code pane flake
* Port jess's projects.spec tests
* fixup
* Reuse electron window; difficult task
* Rebased and refixed
* Remove duplicate cases
* A snapshot a day keeps the bugs away! 📷🐛 (OS: ubuntu-latest-8-cores)
* Reduce the workers to something CI can handle
* Lower it further, we need to think about the others
* Update package.json
Co-authored-by: Pierre Jacquier <pierrejacquier39@gmail.com>
* Update package.json
Co-authored-by: Pierre Jacquier <pierrejacquier39@gmail.com>
* Fix the last tests and tsc errors
* Timeout to 120 and windows-2022-16core
* Fix windows runner detection, enable concurrency temporarily
* Hopefully this time fix windows runner detection
* Comment out Vector, add back removed camera test code
* A snapshot a day keeps the bugs away! 📷🐛 (OS: ubuntu-latest-8-cores)
* A snapshot a day keeps the bugs away! 📷🐛 (OS: macos-14-large)
* A snapshot a day keeps the bugs away! 📷🐛 (OS: macos-14-large)
* Fix camera tests again
* Massively deflake a whole class of tests
* A snapshot a day keeps the bugs away! 📷🐛 (OS: macos-14-large)
* A snapshot a day keeps the bugs away! 📷🐛 (OS: macos-14-large)
* A snapshot a day keeps the bugs away! 📷🐛 (OS: ubuntu-latest-8-cores)
* Try new CI and fix small onboarding test
* Derp
* No github tuning
* Try mac
* Add back all the OS
* Lord, hallow be thy name
* A snapshot a day keeps the bugs away! 📷🐛 (OS: namespace-profile-ubuntu-8-cores)
* A snapshot a day keeps the bugs away! 📷🐛 (OS: windows-latest-8-cores)
* One last try with window-16-cores
* Trigger CI
* Try AWS Windows runner
* Passing on windows locally with a few skips
* Skip more win tests, add back all three oses
* A snapshot a day keeps the bugs away! 📷🐛 (OS: windows-16-cores)
* Add two more fixmes
* 2 more fixmes
* skip segment overlays on win32
* Another fixme
* Trigger CI
* Trigger CI
* Quick clean up
* Move all tests over to electron
* Pass the correct param to playwright-electron.sh
* Add shebang to script and add macos-14-large as a target
* Get sketch-tests.spec.ts passing in electron
* Try out 4 workers
* Got testing-segment-overlays passing
* Pass testing-selections.spec.ts
* Go back to fix up sketch-tests test
* Pass various.spec.ts, by far the hardest one
* Pass can-sketch-on-all-planes... with ease
* Pass command bar tests
* fmt
* Completely fix code mirror text navigating for tests
* Pass debug pane tests
* Pass desktop export tests
* Pass editor tests
* Pass file tree tests
* Pass onboarding tests
* Corrected a fixme in file-tree.spec!
* Painfully fix hardcoded coordinates in point-click.spec
* Pass machine.spec tests
* Pass projects, fought hard with filechooser
* Pass regresion-tests.spec tests
* Pass network and connection tests
* Pass camera-movement.spec tests
* Extreme time eaten by gizmo test fixes. All passing now.
* Merge main (tests changed x_x) and pass all constraints.spec tests (pain)
* Pass another painful spec suite: testing-settings
* Pass perspective-toggle, interesting note
* Pass samples loading tests
* Pass app header tests
* Pass text-to-cad tests
* Pass segment-overlays (minor ache) and ability to switch to web if needed :)
* Fix a ton of syntax changes and deflake 2 more tests (pain)
* Correct all tsc errors
* Remove to-electron script
* Add an f-ton of shit because playwright doesnt want S P R E A D
* Try CI again
* Stop snapshots of exports (already test in e2e)
* Fix flake in double click editor
* Hopefully help CI flake
* Fixmes, fixmes everywhere
* One more fixme to settings
* Skip another code pane flake
* Port jess's projects.spec tests
* fixup
* Reuse electron window; difficult task
* Rebased and refixed
* Remove duplicate cases
* A snapshot a day keeps the bugs away! 📷🐛 (OS: ubuntu-latest-8-cores)
* Reduce the workers to something CI can handle
* Lower it further, we need to think about the others
* Update package.json
Co-authored-by: Pierre Jacquier <pierrejacquier39@gmail.com>
* Update package.json
Co-authored-by: Pierre Jacquier <pierrejacquier39@gmail.com>
* Fix the last tests and tsc errors
* Timeout to 120 and windows-2022-16core
* Fix windows runner detection, enable concurrency temporarily
* Hopefully this time fix windows runner detection
* Comment out Vector, add back removed camera test code
* A snapshot a day keeps the bugs away! 📷🐛 (OS: ubuntu-latest-8-cores)
* A snapshot a day keeps the bugs away! 📷🐛 (OS: macos-14-large)
* A snapshot a day keeps the bugs away! 📷🐛 (OS: macos-14-large)
* Fix camera tests again
* Massively deflake a whole class of tests
* A snapshot a day keeps the bugs away! 📷🐛 (OS: macos-14-large)
* A snapshot a day keeps the bugs away! 📷🐛 (OS: macos-14-large)
* Try new CI and fix small onboarding test
* Derp
* No github tuning
* Try mac
* Add back all the OS
* Lord, hallow be thy name
* A snapshot a day keeps the bugs away! 📷🐛 (OS: namespace-profile-ubuntu-8-cores)
* A snapshot a day keeps the bugs away! 📷🐛 (OS: windows-latest-8-cores)
* Try AWS Windows runner
* Passing on windows locally with a few skips
* Trigger CI
* A snapshot a day keeps the bugs away! 📷🐛 (OS: namespace-profile-ubuntu-8-cores)
* fmt, tsc, lint
* Enable two fixmes again
* Fix lint, codespell, fmt
* Fix lint
* Don't run e2e on draft, add back concurrency, clean up
* One last windows skip
---------
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Pierre Jacquier <pierrejacquier39@gmail.com>
Co-authored-by: Pierre Jacquier <pierre@zoo.dev>
2024-12-18 17:58:03 -05:00
|
|
|
window.electron.join(downloadDir, file.name),
|
2024-08-19 16:29:44 +10:00
|
|
|
new Uint8Array(file.contents)
|
|
|
|
)
|
2024-09-17 19:06:06 -04:00
|
|
|
toast.success(EXPORT_TOAST_MESSAGES.SUCCESS, { id: toastId })
|
2024-08-19 16:29:44 +10:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2024-03-14 11:50:46 -04:00
|
|
|
// Open a dialog to save the file.
|
2024-08-16 07:15:42 -04:00
|
|
|
const filePathMeta = await window.electron.save({
|
2024-03-14 11:50:46 -04:00
|
|
|
defaultPath: file.name,
|
2024-05-06 13:07:35 -07:00
|
|
|
filters: [
|
|
|
|
{
|
|
|
|
name: 'model',
|
|
|
|
extensions: extensions,
|
|
|
|
},
|
|
|
|
],
|
2024-03-14 11:50:46 -04:00
|
|
|
})
|
|
|
|
|
2024-08-16 07:15:42 -04:00
|
|
|
// The user canceled the save.
|
|
|
|
// Return early.
|
2024-09-17 19:06:06 -04:00
|
|
|
if (filePathMeta.canceled) {
|
|
|
|
toast.dismiss(toastId)
|
|
|
|
return
|
|
|
|
}
|
2024-03-14 11:50:46 -04:00
|
|
|
|
|
|
|
// Write the file.
|
2024-08-16 07:15:42 -04:00
|
|
|
await window.electron.writeFile(
|
|
|
|
filePathMeta.filePath,
|
|
|
|
new Uint8Array(file.contents)
|
|
|
|
)
|
2024-09-17 19:06:06 -04:00
|
|
|
toast.success(EXPORT_TOAST_MESSAGES.SUCCESS, { id: toastId })
|
2024-03-14 11:50:46 -04:00
|
|
|
} else {
|
|
|
|
// Download the file to the user's computer.
|
|
|
|
// Now we need to download the files to the user's downloads folder.
|
|
|
|
// Or the destination they choose.
|
|
|
|
// Iterate over the files.
|
|
|
|
// Create a new blob.
|
|
|
|
const blob = new Blob([new Uint8Array(file.contents)])
|
|
|
|
// Save the file.
|
2024-09-17 19:06:06 -04:00
|
|
|
await browserSaveFile(blob, file.name, toastId)
|
2023-08-02 16:23:17 -07:00
|
|
|
}
|
|
|
|
} catch (e) {
|
|
|
|
// TODO: do something real with the error.
|
2024-08-04 00:51:30 -04:00
|
|
|
console.error('export error', e)
|
2024-09-17 19:06:06 -04:00
|
|
|
toast.error(EXPORT_TOAST_MESSAGES.FAILED, { id: toastId })
|
2023-08-02 16:23:17 -07:00
|
|
|
}
|
|
|
|
}
|
2024-03-14 11:50:46 -04:00
|
|
|
|
|
|
|
// Saves files locally from an export call.
|
2024-11-19 11:30:23 -05:00
|
|
|
// We override the file's name with one passed in from the client side.
|
|
|
|
export async function exportSave({
|
|
|
|
data,
|
|
|
|
fileName,
|
|
|
|
toastId,
|
|
|
|
}: {
|
|
|
|
data: ArrayBuffer
|
|
|
|
fileName: string
|
|
|
|
toastId: string
|
|
|
|
}) {
|
2024-03-14 11:50:46 -04:00
|
|
|
// This converts the ArrayBuffer to a Rust equivalent Vec<u8>.
|
|
|
|
let uintArray = new Uint8Array(data)
|
|
|
|
|
2024-05-06 13:07:35 -07:00
|
|
|
let files: ModelingAppFile[] = deserialize_files(uintArray)
|
2024-03-14 11:50:46 -04:00
|
|
|
|
|
|
|
if (files.length > 1) {
|
|
|
|
let zip = new JSZip()
|
|
|
|
for (const file of files) {
|
|
|
|
zip.file(file.name, new Uint8Array(file.contents), { binary: true })
|
|
|
|
}
|
|
|
|
return zip.generateAsync({ type: 'array' }).then((contents) => {
|
2024-11-19 11:30:23 -05:00
|
|
|
return save_({ name: `${fileName || 'output'}.zip`, contents }, toastId)
|
2024-03-14 11:50:46 -04:00
|
|
|
})
|
|
|
|
} else {
|
2024-11-19 11:30:23 -05:00
|
|
|
files[0].name = fileName || files[0].name
|
2024-09-17 19:06:06 -04:00
|
|
|
return save_(files[0], toastId)
|
2024-03-14 11:50:46 -04:00
|
|
|
}
|
|
|
|
}
|