Compare commits
23 Commits
Author | SHA1 | Date | |
---|---|---|---|
e123a00d4b | |||
b950cc0583 | |||
c89780a489 | |||
1afed68dd7 | |||
dcbed4f06f | |||
379f154a5c | |||
60c4969322 | |||
cc6dee8ad4 | |||
2fc7c0d5fd | |||
bf2dcd808f | |||
ee21e486d4 | |||
b5a3eb9e9c | |||
c85645c9f2 | |||
cfa4dd2e33 | |||
c620f7269c | |||
2d8d29b345 | |||
00da062586 | |||
aafbaf6c50 | |||
2894c84a4e | |||
c01084feb0 | |||
c461db5f54 | |||
03fcb73aca | |||
8065e7e51a |
35
.github/workflows/build-and-store-wasm.yml
vendored
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
name: Build and Store WASM
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- main
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build-and-upload:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
- uses: actions/setup-node@v4
|
||||||
|
with:
|
||||||
|
node-version-file: '.nvmrc'
|
||||||
|
cache: 'yarn'
|
||||||
|
- name: Install dependencies
|
||||||
|
run: yarn
|
||||||
|
- name: Install Playwright Browsers
|
||||||
|
run: yarn playwright install --with-deps
|
||||||
|
- name: Setup Rust
|
||||||
|
uses: dtolnay/rust-toolchain@stable
|
||||||
|
- name: Cache wasm
|
||||||
|
uses: Swatinem/rust-cache@v2
|
||||||
|
with:
|
||||||
|
workspaces: './src/wasm-lib'
|
||||||
|
- name: build wasm
|
||||||
|
run: yarn build:wasm
|
||||||
|
|
||||||
|
|
||||||
|
# Upload the WASM bundle as an artifact
|
||||||
|
- uses: actions/upload-artifact@v2
|
||||||
|
with:
|
||||||
|
name: wasm-bundle
|
||||||
|
path: src/wasm-lib/pkg
|
17
.github/workflows/cargo-clippy.yml
vendored
@ -19,7 +19,7 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
dir: ['src/wasm-lib']
|
dir: ['src/wasm-lib', 'src-tauri']
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
- name: Install latest rust
|
- name: Install latest rust
|
||||||
@ -31,9 +31,22 @@ jobs:
|
|||||||
|
|
||||||
- name: install dependencies
|
- name: install dependencies
|
||||||
if: matrix.dir == 'src-tauri'
|
if: matrix.dir == 'src-tauri'
|
||||||
|
shell: bash
|
||||||
run: |
|
run: |
|
||||||
sudo apt-get update
|
sudo apt-get update
|
||||||
sudo apt-get install -y libgtk-3-dev libwebkit2gtk-4.0-dev libappindicator3-dev librsvg2-dev patchelf
|
sudo apt-get install -y \
|
||||||
|
libgtk-3-dev \
|
||||||
|
libayatana-appindicator3-dev \
|
||||||
|
webkit2gtk-driver \
|
||||||
|
libsoup-3.0-dev \
|
||||||
|
libjavascriptcoregtk-4.1-dev \
|
||||||
|
libwebkit2gtk-4.1-dev \
|
||||||
|
at-spi2-core \
|
||||||
|
xvfb
|
||||||
|
yarn install
|
||||||
|
yarn build:wasm
|
||||||
|
yarn build:local
|
||||||
|
|
||||||
- name: Rust Cache
|
- name: Rust Cache
|
||||||
uses: Swatinem/rust-cache@v2.6.1
|
uses: Swatinem/rust-cache@v2.6.1
|
||||||
|
|
||||||
|
57
.github/workflows/cargo-test-tauri.yml
vendored
Normal file
@ -0,0 +1,57 @@
|
|||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- main
|
||||||
|
paths:
|
||||||
|
- 'src-tauri/**.rs'
|
||||||
|
- '**/Cargo.toml'
|
||||||
|
- '**/Cargo.lock'
|
||||||
|
- '**/rust-toolchain.toml'
|
||||||
|
- .github/workflows/cargo-test-tauri.yml
|
||||||
|
pull_request:
|
||||||
|
paths:
|
||||||
|
- 'src-tauri/**.rs'
|
||||||
|
- '**/Cargo.toml'
|
||||||
|
- '**/Cargo.lock'
|
||||||
|
- '**/rust-toolchain.toml'
|
||||||
|
- .github/workflows/cargo-test-tauri.yml
|
||||||
|
workflow_dispatch:
|
||||||
|
permissions: read-all
|
||||||
|
concurrency:
|
||||||
|
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
|
||||||
|
cancel-in-progress: true
|
||||||
|
name: cargo test of tauri
|
||||||
|
jobs:
|
||||||
|
cargotest:
|
||||||
|
name: cargo test
|
||||||
|
runs-on: ubuntu-latest-8-cores
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
dir: ['src-tauri']
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
- name: Install latest rust
|
||||||
|
uses: actions-rs/toolchain@v1
|
||||||
|
with:
|
||||||
|
toolchain: stable
|
||||||
|
override: true
|
||||||
|
- name: install dependencies
|
||||||
|
if: matrix.dir == 'src-tauri'
|
||||||
|
run: |
|
||||||
|
sudo apt-get update
|
||||||
|
sudo apt-get install -y \
|
||||||
|
libgtk-3-dev \
|
||||||
|
libayatana-appindicator3-dev \
|
||||||
|
webkit2gtk-driver \
|
||||||
|
libsoup-3.0-dev \
|
||||||
|
libjavascriptcoregtk-4.1-dev \
|
||||||
|
libwebkit2gtk-4.1-dev \
|
||||||
|
at-spi2-core \
|
||||||
|
xvfb
|
||||||
|
- name: Rust Cache
|
||||||
|
uses: Swatinem/rust-cache@v2.6.1
|
||||||
|
- name: cargo test
|
||||||
|
shell: bash
|
||||||
|
run: |-
|
||||||
|
cd "${{ matrix.dir }}"
|
||||||
|
cargo test --all
|
20
.github/workflows/ci.yml
vendored
@ -147,16 +147,16 @@ jobs:
|
|||||||
|
|
||||||
- name: Install ubuntu system dependencies
|
- name: Install ubuntu system dependencies
|
||||||
if: matrix.os == 'ubuntu-latest'
|
if: matrix.os == 'ubuntu-latest'
|
||||||
run: >
|
run: |
|
||||||
sudo apt-get update &&
|
sudo apt-get update
|
||||||
sudo apt-get install -y
|
sudo apt-get install -y \
|
||||||
libgtk-3-dev
|
libgtk-3-dev \
|
||||||
libayatana-appindicator3-dev
|
libayatana-appindicator3-dev \
|
||||||
webkit2gtk-driver
|
webkit2gtk-driver \
|
||||||
libsoup-3.0-dev
|
libsoup-3.0-dev \
|
||||||
libjavascriptcoregtk-4.1-dev
|
libjavascriptcoregtk-4.1-dev \
|
||||||
libwebkit2gtk-4.1-dev
|
libwebkit2gtk-4.1-dev \
|
||||||
at-spi2-core
|
at-spi2-core \
|
||||||
xvfb
|
xvfb
|
||||||
|
|
||||||
- name: Sync node version and setup cache
|
- name: Sync node version and setup cache
|
||||||
|
5
.github/workflows/playwright.yml
vendored
@ -122,3 +122,8 @@ jobs:
|
|||||||
name: playwright-report
|
name: playwright-report
|
||||||
path: playwright-report/
|
path: playwright-report/
|
||||||
retention-days: 30
|
retention-days: 30
|
||||||
|
- uses: actions/upload-artifact@v2
|
||||||
|
if: github.ref == 'refs/heads/main'
|
||||||
|
with:
|
||||||
|
name: wasm-bundle
|
||||||
|
path: src/wasm-lib/pkg
|
||||||
|
2794
docs/kcl/std.json
@ -565,7 +565,9 @@ test('Auto complete works', async ({ page }) => {
|
|||||||
|
|
||||||
await page.keyboard.press('Tab')
|
await page.keyboard.press('Tab')
|
||||||
await page.keyboard.type('12')
|
await page.keyboard.type('12')
|
||||||
|
await page.waitForTimeout(100)
|
||||||
await page.keyboard.press('Tab')
|
await page.keyboard.press('Tab')
|
||||||
|
await page.waitForTimeout(100)
|
||||||
await page.keyboard.press('Tab')
|
await page.keyboard.press('Tab')
|
||||||
await page.keyboard.press('Tab')
|
await page.keyboard.press('Tab')
|
||||||
await page.keyboard.press('Enter')
|
await page.keyboard.press('Enter')
|
||||||
@ -594,13 +596,12 @@ test('Auto complete works', async ({ page }) => {
|
|||||||
|
|
||||||
test('Stored settings are validated and fall back to defaults', async ({
|
test('Stored settings are validated and fall back to defaults', async ({
|
||||||
page,
|
page,
|
||||||
context,
|
|
||||||
}) => {
|
}) => {
|
||||||
const u = getUtils(page)
|
const u = getUtils(page)
|
||||||
|
|
||||||
// Override beforeEach test setup
|
// Override beforeEach test setup
|
||||||
// with corrupted settings
|
// with corrupted settings
|
||||||
await context.addInitScript(
|
await page.addInitScript(
|
||||||
async ({ settingsKey, settings }) => {
|
async ({ settingsKey, settings }) => {
|
||||||
localStorage.setItem(settingsKey, settings)
|
localStorage.setItem(settingsKey, settings)
|
||||||
},
|
},
|
||||||
@ -617,18 +618,18 @@ test('Stored settings are validated and fall back to defaults', async ({
|
|||||||
// Check the settings were reset
|
// Check the settings were reset
|
||||||
const storedSettings = TOML.parse(
|
const storedSettings = TOML.parse(
|
||||||
await page.evaluate(
|
await page.evaluate(
|
||||||
({ settingsKey }) => localStorage.getItem(settingsKey) || '{}',
|
({ settingsKey }) => localStorage.getItem(settingsKey) || '',
|
||||||
{ settingsKey: TEST_SETTINGS_KEY }
|
{ settingsKey: TEST_SETTINGS_KEY }
|
||||||
)
|
)
|
||||||
) as { settings: SaveSettingsPayload }
|
) as { settings: SaveSettingsPayload }
|
||||||
|
|
||||||
expect(storedSettings.settings.app?.theme).toBe('dark')
|
expect(storedSettings.settings?.app?.theme).toBe(undefined)
|
||||||
|
|
||||||
// Check that the invalid settings were removed
|
// Check that the invalid settings were removed
|
||||||
expect(storedSettings.settings.modeling?.defaultUnit).toBe(undefined)
|
expect(storedSettings.settings?.modeling?.defaultUnit).toBe(undefined)
|
||||||
expect(storedSettings.settings.modeling?.mouseControls).toBe(undefined)
|
expect(storedSettings.settings?.modeling?.mouseControls).toBe(undefined)
|
||||||
expect(storedSettings.settings.app?.projectDirectory).toBe(undefined)
|
expect(storedSettings.settings?.app?.projectDirectory).toBe(undefined)
|
||||||
expect(storedSettings.settings.projects?.defaultProjectName).toBe(undefined)
|
expect(storedSettings.settings?.projects?.defaultProjectName).toBe(undefined)
|
||||||
})
|
})
|
||||||
|
|
||||||
test('Project settings can be set and override user settings', async ({
|
test('Project settings can be set and override user settings', async ({
|
||||||
@ -1033,6 +1034,7 @@ const part001 = startSketchOn('-XZ')
|
|||||||
})
|
})
|
||||||
|
|
||||||
test('Can add multiple sketches', async ({ page }) => {
|
test('Can add multiple sketches', async ({ page }) => {
|
||||||
|
test.skip(process.platform === 'darwin', 'Can add multiple sketches')
|
||||||
const u = getUtils(page)
|
const u = getUtils(page)
|
||||||
await page.setViewportSize({ width: 1200, height: 500 })
|
await page.setViewportSize({ width: 1200, height: 500 })
|
||||||
const PUR = 400 / 37.5 //pixeltoUnitRatio
|
const PUR = 400 / 37.5 //pixeltoUnitRatio
|
||||||
|
Before Width: | Height: | Size: 39 KiB After Width: | Height: | Size: 39 KiB |
Before Width: | Height: | Size: 50 KiB After Width: | Height: | Size: 51 KiB |
Before Width: | Height: | Size: 45 KiB After Width: | Height: | Size: 45 KiB |
Before Width: | Height: | Size: 51 KiB After Width: | Height: | Size: 52 KiB |
Before Width: | Height: | Size: 27 KiB After Width: | Height: | Size: 28 KiB |
Before Width: | Height: | Size: 30 KiB After Width: | Height: | Size: 31 KiB |
Before Width: | Height: | Size: 33 KiB After Width: | Height: | Size: 34 KiB |
Before Width: | Height: | Size: 72 KiB After Width: | Height: | Size: 72 KiB |
Before Width: | Height: | Size: 46 KiB After Width: | Height: | Size: 47 KiB |
Before Width: | Height: | Size: 50 KiB After Width: | Height: | Size: 52 KiB |
Before Width: | Height: | Size: 46 KiB After Width: | Height: | Size: 47 KiB |
Before Width: | Height: | Size: 47 KiB After Width: | Height: | Size: 48 KiB |
Before Width: | Height: | Size: 49 KiB After Width: | Height: | Size: 50 KiB |
Before Width: | Height: | Size: 45 KiB After Width: | Height: | Size: 46 KiB |
@ -1,12 +1,13 @@
|
|||||||
import { SaveSettingsPayload } from 'lib/settings/settingsTypes'
|
import { SaveSettingsPayload } from 'lib/settings/settingsTypes'
|
||||||
import { Themes } from 'lib/theme'
|
import { Themes } from 'lib/theme'
|
||||||
|
|
||||||
export const TEST_SETTINGS_KEY = '/user.toml'
|
export const TEST_SETTINGS_KEY = '/settings.toml'
|
||||||
export const TEST_SETTINGS = {
|
export const TEST_SETTINGS = {
|
||||||
app: {
|
app: {
|
||||||
theme: Themes.Dark,
|
theme: Themes.Dark,
|
||||||
onboardingStatus: 'dismissed',
|
onboardingStatus: 'dismissed',
|
||||||
projectDirectory: '',
|
projectDirectory: '',
|
||||||
|
enableSSAO: false,
|
||||||
},
|
},
|
||||||
modeling: {
|
modeling: {
|
||||||
defaultUnit: 'in',
|
defaultUnit: 'in',
|
||||||
@ -23,7 +24,7 @@ export const TEST_SETTINGS = {
|
|||||||
|
|
||||||
export const TEST_SETTINGS_ONBOARDING = {
|
export const TEST_SETTINGS_ONBOARDING = {
|
||||||
...TEST_SETTINGS,
|
...TEST_SETTINGS,
|
||||||
app: { ...TEST_SETTINGS.app, onboardingStatus: '/export ' },
|
app: { ...TEST_SETTINGS.app, onboardingStatus: '/export' },
|
||||||
} satisfies Partial<SaveSettingsPayload>
|
} satisfies Partial<SaveSettingsPayload>
|
||||||
|
|
||||||
export const TEST_SETTINGS_CORRUPTED = {
|
export const TEST_SETTINGS_CORRUPTED = {
|
||||||
|
@ -6,7 +6,7 @@ import { PNG } from 'pngjs'
|
|||||||
|
|
||||||
async function waitForPageLoad(page: Page) {
|
async function waitForPageLoad(page: Page) {
|
||||||
// wait for 'Loading stream...' spinner
|
// wait for 'Loading stream...' spinner
|
||||||
// await page.getByTestId('loading-stream').waitFor()
|
await page.getByTestId('loading-stream').waitFor()
|
||||||
// wait for all spinners to be gone
|
// wait for all spinners to be gone
|
||||||
await page.getByTestId('loading').waitFor({ state: 'detached' })
|
await page.getByTestId('loading').waitFor({ state: 'detached' })
|
||||||
|
|
||||||
|
@ -71,7 +71,7 @@ describe('ZMA (Tauri, Linux)', () => {
|
|||||||
|
|
||||||
// Now should be signed in
|
// Now should be signed in
|
||||||
const newFileButton = await $('[data-testid="home-new-file"]')
|
const newFileButton = await $('[data-testid="home-new-file"]')
|
||||||
expect(await newFileButton.getText()).toEqual('New file')
|
expect(await newFileButton.getText()).toEqual('New project')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('opens the settings page, checks filesystem settings, and closes the settings page', async () => {
|
it('opens the settings page, checks filesystem settings, and closes the settings page', async () => {
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "untitled-app",
|
"name": "untitled-app",
|
||||||
"version": "0.18.1",
|
"version": "0.19.0",
|
||||||
"private": true,
|
"private": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@codemirror/autocomplete": "^6.16.0",
|
"@codemirror/autocomplete": "^6.16.0",
|
||||||
|
2324
src-tauri/Cargo.lock
generated
@ -8,27 +8,26 @@ repository = "https://github.com/KittyCAD/modeling-app"
|
|||||||
default-run = "app"
|
default-run = "app"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
rust-version = "1.70"
|
rust-version = "1.70"
|
||||||
|
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
[build-dependencies]
|
[build-dependencies]
|
||||||
tauri-build = { version = "2.0.0-beta.12", features = [] }
|
tauri-build = { version = "2.0.0-beta.13", features = [] }
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
anyhow = "1"
|
anyhow = "1"
|
||||||
kittycad = "0.2.67"
|
kcl-lib = { version = "0.1.51", path = "../src/wasm-lib/kcl" }
|
||||||
|
kittycad = "0.3.0"
|
||||||
oauth2 = "4.4.2"
|
oauth2 = "4.4.2"
|
||||||
serde = { version = "1.0", features = ["derive"] }
|
|
||||||
serde_json = "1.0"
|
serde_json = "1.0"
|
||||||
tauri = { version = "2.0.0-beta.15", features = [ "devtools", "unstable"] }
|
tauri = { version = "2.0.0-beta.15", features = [ "devtools", "unstable"] }
|
||||||
tauri-plugin-dialog = { version = "2.0.0-beta.5" }
|
tauri-plugin-dialog = { version = "2.0.0-beta.6" }
|
||||||
tauri-plugin-fs = { version = "2.0.0-beta.5" }
|
tauri-plugin-fs = { version = "2.0.0-beta.6" }
|
||||||
tauri-plugin-http = { version = "2.0.0-beta.5" }
|
tauri-plugin-http = { version = "2.0.0-beta.6" }
|
||||||
tauri-plugin-os = { version = "2.0.0-beta.2" }
|
tauri-plugin-os = { version = "2.0.0-beta.2" }
|
||||||
tauri-plugin-process = { version = "2.0.0-beta.2" }
|
tauri-plugin-process = { version = "2.0.0-beta.2" }
|
||||||
tauri-plugin-shell = { version = "2.0.0-beta.2" }
|
tauri-plugin-shell = { version = "2.0.0-beta.2" }
|
||||||
tauri-plugin-updater = { version = "2.0.0-beta.4" }
|
tauri-plugin-updater = { version = "2.0.0-beta.4" }
|
||||||
tokio = { version = "1.37.0", features = ["time"] }
|
tokio = { version = "1.37.0", features = ["time", "fs"] }
|
||||||
toml = "0.8.2"
|
toml = "0.8.2"
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
|
6
src-tauri/rustfmt.toml
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
max_width = 120
|
||||||
|
edition = "2018"
|
||||||
|
format_code_in_doc_comments = true
|
||||||
|
format_strings = false
|
||||||
|
imports_granularity = "Crate"
|
||||||
|
group_imports = "StdExternalCrate"
|
@ -1,91 +1,189 @@
|
|||||||
// Prevents additional console window on Windows in release, DO NOT REMOVE!!
|
// Prevents additional console window on Windows in release, DO NOT REMOVE!!
|
||||||
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
|
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
|
||||||
|
|
||||||
use std::env;
|
use std::{
|
||||||
use std::fs;
|
env,
|
||||||
use std::io::Read;
|
path::{Path, PathBuf},
|
||||||
use std::path::Path;
|
process::Command,
|
||||||
use std::path::PathBuf;
|
};
|
||||||
|
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
|
use kcl_lib::settings::types::{
|
||||||
|
file::{FileEntry, Project},
|
||||||
|
project::ProjectConfiguration,
|
||||||
|
Configuration,
|
||||||
|
};
|
||||||
use oauth2::TokenResponse;
|
use oauth2::TokenResponse;
|
||||||
use serde::Serialize;
|
use tauri::{ipc::InvokeError, Manager};
|
||||||
use std::process::Command;
|
|
||||||
use tauri::ipc::InvokeError;
|
|
||||||
use tauri_plugin_shell::ShellExt;
|
use tauri_plugin_shell::ShellExt;
|
||||||
const DEFAULT_HOST: &str = "https://api.kittycad.io";
|
|
||||||
|
|
||||||
/// This command returns the a json string parse from a toml file at the path.
|
const DEFAULT_HOST: &str = "https://api.zoo.dev";
|
||||||
|
const SETTINGS_FILE_NAME: &str = "settings.toml";
|
||||||
|
const PROJECT_SETTINGS_FILE_NAME: &str = "project.toml";
|
||||||
|
const PROJECT_FOLDER: &str = "zoo-modeling-app-projects";
|
||||||
|
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
fn read_toml(path: &str) -> Result<String, InvokeError> {
|
fn get_initial_default_dir(app: tauri::AppHandle) -> Result<PathBuf, InvokeError> {
|
||||||
let mut file = std::fs::File::open(path).map_err(|e| InvokeError::from_anyhow(e.into()))?;
|
let dir = match app.path().document_dir() {
|
||||||
let mut contents = String::new();
|
Ok(dir) => dir,
|
||||||
file.read_to_string(&mut contents)
|
Err(_) => {
|
||||||
.map_err(|e| InvokeError::from_anyhow(e.into()))?;
|
// for headless Linux (eg. Github Actions)
|
||||||
let value =
|
let home_dir = app.path().home_dir()?;
|
||||||
toml::from_str::<toml::Value>(&contents).map_err(|e| InvokeError::from_anyhow(e.into()))?;
|
home_dir.join("Documents")
|
||||||
let value = serde_json::to_string(&value).map_err(|e| InvokeError::from_anyhow(e.into()))?;
|
}
|
||||||
Ok(value)
|
};
|
||||||
|
|
||||||
|
Ok(dir.join(PROJECT_FOLDER))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// From https://github.com/tauri-apps/tauri/blob/1.x/core/tauri/src/api/dir.rs#L51
|
fn get_app_settings_file_path(app: &tauri::AppHandle) -> Result<PathBuf, InvokeError> {
|
||||||
/// Removed from tauri v2
|
let app_config_dir = app.path().app_config_dir()?;
|
||||||
#[derive(Debug, Serialize)]
|
Ok(app_config_dir.join(SETTINGS_FILE_NAME))
|
||||||
pub struct DiskEntry {
|
|
||||||
/// The path to the entry.
|
|
||||||
pub path: PathBuf,
|
|
||||||
/// The name of the entry (file name with extension or directory name).
|
|
||||||
pub name: Option<String>,
|
|
||||||
/// The children of this entry if it's a directory.
|
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
|
||||||
pub children: Option<Vec<DiskEntry>>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// From https://github.com/tauri-apps/tauri/blob/1.x/core/tauri/src/api/dir.rs#L51
|
|
||||||
/// Removed from tauri v2
|
|
||||||
fn is_dir<P: AsRef<Path>>(path: P) -> Result<bool> {
|
|
||||||
std::fs::metadata(path)
|
|
||||||
.map(|md| md.is_dir())
|
|
||||||
.map_err(Into::into)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// From https://github.com/tauri-apps/tauri/blob/1.x/core/tauri/src/api/dir.rs#L51
|
|
||||||
/// Removed from tauri v2
|
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
fn read_dir_recursive(path: &str) -> Result<Vec<DiskEntry>, InvokeError> {
|
async fn read_app_settings_file(app: tauri::AppHandle) -> Result<Configuration, InvokeError> {
|
||||||
let mut files_and_dirs: Vec<DiskEntry> = vec![];
|
let mut settings_path = get_app_settings_file_path(&app)?;
|
||||||
// let path = path.as_ref();
|
let mut needs_migration = false;
|
||||||
for entry in fs::read_dir(path).map_err(|e| InvokeError::from_anyhow(e.into()))? {
|
|
||||||
let path = entry
|
|
||||||
.map_err(|e| InvokeError::from_anyhow(e.into()))?
|
|
||||||
.path();
|
|
||||||
|
|
||||||
if let Ok(flag) = is_dir(&path) {
|
// Check if this file exists.
|
||||||
files_and_dirs.push(DiskEntry {
|
if !settings_path.exists() {
|
||||||
path: path.clone(),
|
// Try the backwards compatible path.
|
||||||
children: if flag {
|
// TODO: Remove this after a few releases.
|
||||||
Some(read_dir_recursive(path.to_str().expect("No path"))?)
|
let app_config_dir = app.path().app_config_dir()?;
|
||||||
} else {
|
settings_path = format!(
|
||||||
None
|
"{}user.toml",
|
||||||
},
|
app_config_dir.display().to_string().trim_end_matches('/')
|
||||||
name: path
|
)
|
||||||
.file_name()
|
.into();
|
||||||
.map(|name| name.to_string_lossy())
|
needs_migration = true;
|
||||||
.map(|name| name.to_string()),
|
// Check if this path exists.
|
||||||
});
|
if !settings_path.exists() {
|
||||||
|
let mut default = Configuration::default();
|
||||||
|
default.settings.project.directory = get_initial_default_dir(app.clone())?;
|
||||||
|
// Return the default configuration.
|
||||||
|
return Ok(default);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(files_and_dirs)
|
|
||||||
|
let contents = tokio::fs::read_to_string(&settings_path)
|
||||||
|
.await
|
||||||
|
.map_err(|e| InvokeError::from_anyhow(e.into()))?;
|
||||||
|
let mut parsed = Configuration::backwards_compatible_toml_parse(&contents).map_err(InvokeError::from_anyhow)?;
|
||||||
|
if parsed.settings.project.directory == PathBuf::new() {
|
||||||
|
parsed.settings.project.directory = get_initial_default_dir(app.clone())?;
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: Remove this after a few releases.
|
||||||
|
if needs_migration {
|
||||||
|
write_app_settings_file(app, parsed.clone()).await?;
|
||||||
|
// Delete the old file.
|
||||||
|
tokio::fs::remove_file(settings_path)
|
||||||
|
.await
|
||||||
|
.map_err(|e| InvokeError::from_anyhow(e.into()))?;
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(parsed)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// This command returns a string that is the contents of a file at the path.
|
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
fn read_txt_file(path: &str) -> Result<String, InvokeError> {
|
async fn write_app_settings_file(app: tauri::AppHandle, configuration: Configuration) -> Result<(), InvokeError> {
|
||||||
let mut file = std::fs::File::open(path).map_err(|e| InvokeError::from_anyhow(e.into()))?;
|
let settings_path = get_app_settings_file_path(&app)?;
|
||||||
let mut contents = String::new();
|
let contents = toml::to_string_pretty(&configuration).map_err(|e| InvokeError::from_anyhow(e.into()))?;
|
||||||
file.read_to_string(&mut contents)
|
tokio::fs::write(settings_path, contents.as_bytes())
|
||||||
|
.await
|
||||||
.map_err(|e| InvokeError::from_anyhow(e.into()))?;
|
.map_err(|e| InvokeError::from_anyhow(e.into()))?;
|
||||||
Ok(contents)
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn get_project_settings_file_path(app_settings: Configuration, project_name: &str) -> Result<PathBuf, InvokeError> {
|
||||||
|
Ok(app_settings
|
||||||
|
.settings
|
||||||
|
.project
|
||||||
|
.directory
|
||||||
|
.join(project_name)
|
||||||
|
.join(PROJECT_SETTINGS_FILE_NAME))
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tauri::command]
|
||||||
|
async fn read_project_settings_file(
|
||||||
|
app_settings: Configuration,
|
||||||
|
project_name: &str,
|
||||||
|
) -> Result<ProjectConfiguration, InvokeError> {
|
||||||
|
let settings_path = get_project_settings_file_path(app_settings, project_name)?;
|
||||||
|
|
||||||
|
// Check if this file exists.
|
||||||
|
if !settings_path.exists() {
|
||||||
|
// Return the default configuration.
|
||||||
|
return Ok(ProjectConfiguration::default());
|
||||||
|
}
|
||||||
|
|
||||||
|
let contents = tokio::fs::read_to_string(&settings_path)
|
||||||
|
.await
|
||||||
|
.map_err(|e| InvokeError::from_anyhow(e.into()))?;
|
||||||
|
let parsed = ProjectConfiguration::backwards_compatible_toml_parse(&contents).map_err(InvokeError::from_anyhow)?;
|
||||||
|
|
||||||
|
Ok(parsed)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tauri::command]
|
||||||
|
async fn write_project_settings_file(
|
||||||
|
app_settings: Configuration,
|
||||||
|
project_name: &str,
|
||||||
|
configuration: ProjectConfiguration,
|
||||||
|
) -> Result<(), InvokeError> {
|
||||||
|
let settings_path = get_project_settings_file_path(app_settings, project_name)?;
|
||||||
|
let contents = toml::to_string_pretty(&configuration).map_err(|e| InvokeError::from_anyhow(e.into()))?;
|
||||||
|
tokio::fs::write(settings_path, contents.as_bytes())
|
||||||
|
.await
|
||||||
|
.map_err(|e| InvokeError::from_anyhow(e.into()))?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Initialize the directory that holds all the projects.
|
||||||
|
#[tauri::command]
|
||||||
|
async fn initialize_project_directory(configuration: Configuration) -> Result<PathBuf, InvokeError> {
|
||||||
|
configuration
|
||||||
|
.ensure_project_directory_exists()
|
||||||
|
.await
|
||||||
|
.map_err(InvokeError::from_anyhow)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Create a new project directory.
|
||||||
|
#[tauri::command]
|
||||||
|
async fn create_new_project_directory(
|
||||||
|
configuration: Configuration,
|
||||||
|
project_name: &str,
|
||||||
|
initial_code: Option<&str>,
|
||||||
|
) -> Result<Project, InvokeError> {
|
||||||
|
configuration
|
||||||
|
.create_new_project_directory(project_name, initial_code)
|
||||||
|
.await
|
||||||
|
.map_err(InvokeError::from_anyhow)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// List all the projects in the project directory.
|
||||||
|
#[tauri::command]
|
||||||
|
async fn list_projects(configuration: Configuration) -> Result<Vec<Project>, InvokeError> {
|
||||||
|
configuration.list_projects().await.map_err(InvokeError::from_anyhow)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Get information about a project.
|
||||||
|
#[tauri::command]
|
||||||
|
async fn get_project_info(configuration: Configuration, project_name: &str) -> Result<Project, InvokeError> {
|
||||||
|
configuration
|
||||||
|
.get_project_info(project_name)
|
||||||
|
.await
|
||||||
|
.map_err(InvokeError::from_anyhow)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tauri::command]
|
||||||
|
async fn read_dir_recursive(path: &str) -> Result<FileEntry, InvokeError> {
|
||||||
|
kcl_lib::settings::utils::walk_dir(&Path::new(path).to_path_buf())
|
||||||
|
.await
|
||||||
|
.map_err(InvokeError::from_anyhow)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// This command instantiates a new window with auth.
|
/// This command instantiates a new window with auth.
|
||||||
@ -103,8 +201,7 @@ async fn login(app: tauri::AppHandle, host: &str) -> Result<String, InvokeError>
|
|||||||
let auth_client = oauth2::basic::BasicClient::new(
|
let auth_client = oauth2::basic::BasicClient::new(
|
||||||
oauth2::ClientId::new(client_id),
|
oauth2::ClientId::new(client_id),
|
||||||
None,
|
None,
|
||||||
oauth2::AuthUrl::new(format!("{host}/authorize"))
|
oauth2::AuthUrl::new(format!("{host}/authorize")).map_err(|e| InvokeError::from_anyhow(e.into()))?,
|
||||||
.map_err(|e| InvokeError::from_anyhow(e.into()))?,
|
|
||||||
Some(
|
Some(
|
||||||
oauth2::TokenUrl::new(format!("{host}/oauth2/device/token"))
|
oauth2::TokenUrl::new(format!("{host}/oauth2/device/token"))
|
||||||
.map_err(|e| InvokeError::from_anyhow(e.into()))?,
|
.map_err(|e| InvokeError::from_anyhow(e.into()))?,
|
||||||
@ -132,12 +229,10 @@ async fn login(app: tauri::AppHandle, host: &str) -> Result<String, InvokeError>
|
|||||||
// and bypass the shell::open call as it fails on GitHub Actions.
|
// and bypass the shell::open call as it fails on GitHub Actions.
|
||||||
let e2e_tauri_enabled = env::var("E2E_TAURI_ENABLED").is_ok();
|
let e2e_tauri_enabled = env::var("E2E_TAURI_ENABLED").is_ok();
|
||||||
if e2e_tauri_enabled {
|
if e2e_tauri_enabled {
|
||||||
println!(
|
println!("E2E_TAURI_ENABLED is set, won't open {} externally", auth_uri.secret());
|
||||||
"E2E_TAURI_ENABLED is set, won't open {} externally",
|
tokio::fs::write("/tmp/kittycad_user_code", details.user_code().secret())
|
||||||
auth_uri.secret()
|
.await
|
||||||
);
|
.map_err(|e| InvokeError::from_anyhow(e.into()))?;
|
||||||
fs::write("/tmp/kittycad_user_code", details.user_code().secret())
|
|
||||||
.expect("Unable to write /tmp/kittycad_user_code file");
|
|
||||||
} else {
|
} else {
|
||||||
app.shell()
|
app.shell()
|
||||||
.open(auth_uri.secret(), None)
|
.open(auth_uri.secret(), None)
|
||||||
@ -160,10 +255,7 @@ async fn login(app: tauri::AppHandle, host: &str) -> Result<String, InvokeError>
|
|||||||
///This command returns the KittyCAD user info given a token.
|
///This command returns the KittyCAD user info given a token.
|
||||||
/// The string returned from this method is the user info as a json string.
|
/// The string returned from this method is the user info as a json string.
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
async fn get_user(
|
async fn get_user(token: &str, hostname: &str) -> Result<kittycad::types::User, InvokeError> {
|
||||||
token: Option<String>,
|
|
||||||
hostname: &str,
|
|
||||||
) -> Result<kittycad::types::User, InvokeError> {
|
|
||||||
// Use the host passed in if it's set.
|
// Use the host passed in if it's set.
|
||||||
// Otherwise, use the default host.
|
// Otherwise, use the default host.
|
||||||
let host = if hostname.is_empty() {
|
let host = if hostname.is_empty() {
|
||||||
@ -183,7 +275,7 @@ async fn get_user(
|
|||||||
println!("Getting user info...");
|
println!("Getting user info...");
|
||||||
|
|
||||||
// use kittycad library to fetch the user info from /user/me
|
// use kittycad library to fetch the user info from /user/me
|
||||||
let mut client = kittycad::Client::new(token.unwrap());
|
let mut client = kittycad::Client::new(token);
|
||||||
|
|
||||||
if baseurl != DEFAULT_HOST {
|
if baseurl != DEFAULT_HOST {
|
||||||
client.set_base_url(&baseurl);
|
client.set_base_url(&baseurl);
|
||||||
@ -202,43 +294,53 @@ async fn get_user(
|
|||||||
/// From this GitHub comment: https://github.com/tauri-apps/tauri/issues/4062#issuecomment-1338048169
|
/// From this GitHub comment: https://github.com/tauri-apps/tauri/issues/4062#issuecomment-1338048169
|
||||||
/// But with the Linux support removed since we don't need it for now.
|
/// But with the Linux support removed since we don't need it for now.
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
fn show_in_folder(path: String) {
|
fn show_in_folder(path: &str) -> Result<(), InvokeError> {
|
||||||
#[cfg(target_os = "windows")]
|
#[cfg(not(unix))]
|
||||||
{
|
{
|
||||||
Command::new("explorer")
|
Command::new("explorer")
|
||||||
.args(["/select,", &path]) // The comma after select is not a typo
|
.args(["/select,", &path]) // The comma after select is not a typo
|
||||||
.spawn()
|
.spawn()
|
||||||
.unwrap();
|
.map_err(|e| InvokeError::from_anyhow(e.into()))?;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(target_os = "macos")]
|
#[cfg(unix)]
|
||||||
{
|
{
|
||||||
Command::new("open").args(["-R", &path]).spawn().unwrap();
|
Command::new("open")
|
||||||
|
.args(["-R", &path])
|
||||||
|
.spawn()
|
||||||
|
.map_err(|e| InvokeError::from_anyhow(e.into()))?;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() -> Result<()> {
|
||||||
tauri::Builder::default()
|
tauri::Builder::default()
|
||||||
.setup(|_app| {
|
.setup(|_app| {
|
||||||
#[cfg(debug_assertions)]
|
#[cfg(debug_assertions)]
|
||||||
{
|
{
|
||||||
use tauri::Manager;
|
|
||||||
_app.get_webview("main").unwrap().open_devtools();
|
_app.get_webview("main").unwrap().open_devtools();
|
||||||
}
|
}
|
||||||
#[cfg(not(debug_assertions))]
|
#[cfg(not(debug_assertions))]
|
||||||
{
|
{
|
||||||
_app.handle()
|
_app.handle().plugin(tauri_plugin_updater::Builder::new().build())?;
|
||||||
.plugin(tauri_plugin_updater::Builder::new().build())?;
|
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
})
|
})
|
||||||
.invoke_handler(tauri::generate_handler![
|
.invoke_handler(tauri::generate_handler![
|
||||||
|
get_initial_default_dir,
|
||||||
|
initialize_project_directory,
|
||||||
|
create_new_project_directory,
|
||||||
|
list_projects,
|
||||||
|
get_project_info,
|
||||||
get_user,
|
get_user,
|
||||||
login,
|
login,
|
||||||
read_toml,
|
|
||||||
read_txt_file,
|
|
||||||
read_dir_recursive,
|
read_dir_recursive,
|
||||||
show_in_folder,
|
show_in_folder,
|
||||||
|
read_app_settings_file,
|
||||||
|
write_app_settings_file,
|
||||||
|
read_project_settings_file,
|
||||||
|
write_project_settings_file,
|
||||||
])
|
])
|
||||||
.plugin(tauri_plugin_dialog::init())
|
.plugin(tauri_plugin_dialog::init())
|
||||||
.plugin(tauri_plugin_fs::init())
|
.plugin(tauri_plugin_fs::init())
|
||||||
@ -246,6 +348,7 @@ fn main() {
|
|||||||
.plugin(tauri_plugin_os::init())
|
.plugin(tauri_plugin_os::init())
|
||||||
.plugin(tauri_plugin_process::init())
|
.plugin(tauri_plugin_process::init())
|
||||||
.plugin(tauri_plugin_shell::init())
|
.plugin(tauri_plugin_shell::init())
|
||||||
.run(tauri::generate_context!())
|
.run(tauri::generate_context!())?;
|
||||||
.expect("error while running tauri application");
|
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -55,5 +55,5 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"productName": "Zoo Modeling App",
|
"productName": "Zoo Modeling App",
|
||||||
"version": "0.18.1"
|
"version": "0.19.0"
|
||||||
}
|
}
|
||||||
|
@ -3,13 +3,12 @@ import { useCommandsContext } from 'hooks/useCommandsContext'
|
|||||||
import { useKclContext } from 'lang/KclProvider'
|
import { useKclContext } from 'lang/KclProvider'
|
||||||
import { CommandArgument } from 'lib/commandTypes'
|
import { CommandArgument } from 'lib/commandTypes'
|
||||||
import {
|
import {
|
||||||
ResolvedSelectionType,
|
|
||||||
canSubmitSelectionArg,
|
canSubmitSelectionArg,
|
||||||
getSelectionType,
|
getSelectionType,
|
||||||
getSelectionTypeDisplayText,
|
getSelectionTypeDisplayText,
|
||||||
} from 'lib/selections'
|
} from 'lib/selections'
|
||||||
import { modelingMachine } from 'machines/modelingMachine'
|
import { modelingMachine } from 'machines/modelingMachine'
|
||||||
import { useEffect, useRef, useState } from 'react'
|
import { useCallback, useEffect, useRef, useState } from 'react'
|
||||||
import { useHotkeys } from 'react-hotkeys-hook'
|
import { useHotkeys } from 'react-hotkeys-hook'
|
||||||
import { StateFrom } from 'xstate'
|
import { StateFrom } from 'xstate'
|
||||||
|
|
||||||
@ -30,13 +29,13 @@ function CommandBarSelectionInput({
|
|||||||
const { commandBarState, commandBarSend } = useCommandsContext()
|
const { commandBarState, commandBarSend } = useCommandsContext()
|
||||||
const [hasSubmitted, setHasSubmitted] = useState(false)
|
const [hasSubmitted, setHasSubmitted] = useState(false)
|
||||||
const selection = useSelector(arg.machineActor, selectionSelector)
|
const selection = useSelector(arg.machineActor, selectionSelector)
|
||||||
const [selectionsByType, setSelectionsByType] = useState<
|
const initSelectionsByType = useCallback(() => {
|
||||||
'none' | ResolvedSelectionType[]
|
const selectionRangeEnd = selection.codeBasedSelections[0]?.range[1]
|
||||||
>(
|
return !selectionRangeEnd || selectionRangeEnd === code.length
|
||||||
selection.codeBasedSelections[0]?.range[1] === code.length
|
|
||||||
? 'none'
|
? 'none'
|
||||||
: getSelectionType(selection)
|
: getSelectionType(selection)
|
||||||
)
|
}, [selection, code])
|
||||||
|
const selectionsByType = initSelectionsByType()
|
||||||
const [canSubmitSelection, setCanSubmitSelection] = useState<boolean>(
|
const [canSubmitSelection, setCanSubmitSelection] = useState<boolean>(
|
||||||
canSubmitSelectionArg(selectionsByType, arg)
|
canSubmitSelectionArg(selectionsByType, arg)
|
||||||
)
|
)
|
||||||
@ -51,17 +50,14 @@ function CommandBarSelectionInput({
|
|||||||
inputRef.current?.focus()
|
inputRef.current?.focus()
|
||||||
}, [selection, inputRef])
|
}, [selection, inputRef])
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
setSelectionsByType(
|
|
||||||
selection.codeBasedSelections[0]?.range[1] === code.length
|
|
||||||
? 'none'
|
|
||||||
: getSelectionType(selection)
|
|
||||||
)
|
|
||||||
}, [selection])
|
|
||||||
|
|
||||||
// Fast-forward through this arg if it's marked as skippable
|
// Fast-forward through this arg if it's marked as skippable
|
||||||
// and we have a valid selection already
|
// and we have a valid selection already
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
console.log('selection input effect', {
|
||||||
|
selectionsByType,
|
||||||
|
canSubmitSelection,
|
||||||
|
arg,
|
||||||
|
})
|
||||||
setCanSubmitSelection(canSubmitSelectionArg(selectionsByType, arg))
|
setCanSubmitSelection(canSubmitSelectionArg(selectionsByType, arg))
|
||||||
const argValue = commandBarState.context.argumentsToSubmit[arg.name]
|
const argValue = commandBarState.context.argumentsToSubmit[arg.name]
|
||||||
if (canSubmitSelection && arg.skip && argValue === undefined) {
|
if (canSubmitSelection && arg.skip && argValue === undefined) {
|
||||||
|
@ -15,10 +15,10 @@ import {
|
|||||||
import { useCommandsContext } from 'hooks/useCommandsContext'
|
import { useCommandsContext } from 'hooks/useCommandsContext'
|
||||||
import { fileMachine } from 'machines/fileMachine'
|
import { fileMachine } from 'machines/fileMachine'
|
||||||
import { mkdir, remove, rename, create } from '@tauri-apps/plugin-fs'
|
import { mkdir, remove, rename, create } from '@tauri-apps/plugin-fs'
|
||||||
import { readProject } from 'lib/tauriFS'
|
|
||||||
import { isTauri } from 'lib/isTauri'
|
import { isTauri } from 'lib/isTauri'
|
||||||
import { join, sep } from '@tauri-apps/api/path'
|
import { join, sep } from '@tauri-apps/api/path'
|
||||||
import { DEFAULT_FILE_NAME, FILE_EXT } from 'lib/constants'
|
import { DEFAULT_FILE_NAME, FILE_EXT } from 'lib/constants'
|
||||||
|
import { getProjectInfo } from 'lib/tauri'
|
||||||
|
|
||||||
type MachineContext<T extends AnyStateMachine> = {
|
type MachineContext<T extends AnyStateMachine> = {
|
||||||
state: StateFrom<T>
|
state: StateFrom<T>
|
||||||
@ -62,7 +62,7 @@ export const FileMachineProvider = ({
|
|||||||
services: {
|
services: {
|
||||||
readFiles: async (context: ContextFrom<typeof fileMachine>) => {
|
readFiles: async (context: ContextFrom<typeof fileMachine>) => {
|
||||||
const newFiles = isTauri()
|
const newFiles = isTauri()
|
||||||
? await readProject(context.project.path)
|
? (await getProjectInfo(context.project.name)).children
|
||||||
: []
|
: []
|
||||||
return {
|
return {
|
||||||
...context.project,
|
...context.project,
|
||||||
|
@ -94,10 +94,7 @@ export function HelpMenu(props: React.PropsWithChildren) {
|
|||||||
if (isInProject) {
|
if (isInProject) {
|
||||||
navigate('onboarding')
|
navigate('onboarding')
|
||||||
} else {
|
} else {
|
||||||
createAndOpenNewProject(
|
createAndOpenNewProject(navigate)
|
||||||
settings.context.app.projectDirectory.current,
|
|
||||||
navigate
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
|
@ -77,7 +77,7 @@ export const ModelingMachineProvider = ({
|
|||||||
auth,
|
auth,
|
||||||
settings: {
|
settings: {
|
||||||
context: {
|
context: {
|
||||||
app: { theme },
|
app: { theme, enableSSAO },
|
||||||
modeling: { defaultUnit, highlightEdges },
|
modeling: { defaultUnit, highlightEdges },
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -87,6 +87,7 @@ export const ModelingMachineProvider = ({
|
|||||||
useSetupEngineManager(streamRef, token, {
|
useSetupEngineManager(streamRef, token, {
|
||||||
theme: theme.current,
|
theme: theme.current,
|
||||||
highlightEdges: highlightEdges.current,
|
highlightEdges: highlightEdges.current,
|
||||||
|
enableSSAO: enableSSAO.current,
|
||||||
})
|
})
|
||||||
const { htmlRef } = useStore((s) => ({
|
const { htmlRef } = useStore((s) => ({
|
||||||
htmlRef: s.htmlRef,
|
htmlRef: s.htmlRef,
|
||||||
@ -267,10 +268,12 @@ export const ModelingMachineProvider = ({
|
|||||||
'has valid extrude selection': ({ selectionRanges }) => {
|
'has valid extrude selection': ({ selectionRanges }) => {
|
||||||
// A user can begin extruding if they either have 1+ faces selected or nothing selected
|
// A user can begin extruding if they either have 1+ faces selected or nothing selected
|
||||||
// TODO: I believe this guard only allows for extruding a single face at a time
|
// TODO: I believe this guard only allows for extruding a single face at a time
|
||||||
if (selectionRanges.codeBasedSelections.length < 1) return false
|
|
||||||
const isPipe = isSketchPipe(selectionRanges)
|
const isPipe = isSketchPipe(selectionRanges)
|
||||||
|
|
||||||
if (isSelectionLastLine(selectionRanges, codeManager.code))
|
if (
|
||||||
|
selectionRanges.codeBasedSelections.length === 0 ||
|
||||||
|
isSelectionLastLine(selectionRanges, codeManager.code)
|
||||||
|
)
|
||||||
return true
|
return true
|
||||||
if (!isPipe) return false
|
if (!isPipe) return false
|
||||||
|
|
||||||
|
@ -16,7 +16,6 @@ import {
|
|||||||
EditorView,
|
EditorView,
|
||||||
dropCursor,
|
dropCursor,
|
||||||
drawSelection,
|
drawSelection,
|
||||||
ViewUpdate,
|
|
||||||
} from '@codemirror/view'
|
} from '@codemirror/view'
|
||||||
import {
|
import {
|
||||||
indentWithTab,
|
indentWithTab,
|
||||||
@ -191,9 +190,6 @@ export const KclEditorPane = () => {
|
|||||||
return extensions
|
return extensions
|
||||||
}, [kclLSP, copilotLSP, textWrapping.current, cursorBlinking.current])
|
}, [kclLSP, copilotLSP, textWrapping.current, cursorBlinking.current])
|
||||||
|
|
||||||
let debounceTimer: ReturnType<typeof setTimeout> | null = null
|
|
||||||
const updateDelay = 100
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
id="code-mirror-override"
|
id="code-mirror-override"
|
||||||
@ -206,17 +202,6 @@ export const KclEditorPane = () => {
|
|||||||
onCreateEditor={(_editorView) =>
|
onCreateEditor={(_editorView) =>
|
||||||
editorManager.setEditorView(_editorView)
|
editorManager.setEditorView(_editorView)
|
||||||
}
|
}
|
||||||
onUpdate={(view: ViewUpdate) => {
|
|
||||||
// debounce the view update.
|
|
||||||
// otherwise it is laggy for typing.
|
|
||||||
if (debounceTimer) {
|
|
||||||
clearTimeout(debounceTimer)
|
|
||||||
}
|
|
||||||
|
|
||||||
debounceTimer = setTimeout(() => {
|
|
||||||
editorManager.handleOnViewUpdate(view)
|
|
||||||
}, updateDelay)
|
|
||||||
}}
|
|
||||||
indentWithTab={false}
|
indentWithTab={false}
|
||||||
basicSetup={false}
|
basicSetup={false}
|
||||||
/>
|
/>
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
import { FormEvent, useEffect, useRef, useState } from 'react'
|
import { FormEvent, useEffect, useRef, useState } from 'react'
|
||||||
import { type ProjectWithEntryPointMetadata } from 'lib/types'
|
|
||||||
import { paths } from 'lib/paths'
|
import { paths } from 'lib/paths'
|
||||||
import { Link } from 'react-router-dom'
|
import { Link } from 'react-router-dom'
|
||||||
import { ActionButton } from './ActionButton'
|
import { ActionButton } from './ActionButton'
|
||||||
@ -9,11 +8,11 @@ import {
|
|||||||
faTrashAlt,
|
faTrashAlt,
|
||||||
faX,
|
faX,
|
||||||
} from '@fortawesome/free-solid-svg-icons'
|
} from '@fortawesome/free-solid-svg-icons'
|
||||||
import { getPartsCount, readProject } from '../lib/tauriFS'
|
|
||||||
import { FILE_EXT } from 'lib/constants'
|
import { FILE_EXT } from 'lib/constants'
|
||||||
import { Dialog } from '@headlessui/react'
|
import { Dialog } from '@headlessui/react'
|
||||||
import { useHotkeys } from 'react-hotkeys-hook'
|
import { useHotkeys } from 'react-hotkeys-hook'
|
||||||
import Tooltip from './Tooltip'
|
import Tooltip from './Tooltip'
|
||||||
|
import { Project } from 'wasm-lib/kcl/bindings/Project'
|
||||||
|
|
||||||
function ProjectCard({
|
function ProjectCard({
|
||||||
project,
|
project,
|
||||||
@ -21,17 +20,17 @@ function ProjectCard({
|
|||||||
handleDeleteProject,
|
handleDeleteProject,
|
||||||
...props
|
...props
|
||||||
}: {
|
}: {
|
||||||
project: ProjectWithEntryPointMetadata
|
project: Project
|
||||||
handleRenameProject: (
|
handleRenameProject: (
|
||||||
e: FormEvent<HTMLFormElement>,
|
e: FormEvent<HTMLFormElement>,
|
||||||
f: ProjectWithEntryPointMetadata
|
f: Project
|
||||||
) => Promise<void>
|
) => Promise<void>
|
||||||
handleDeleteProject: (f: ProjectWithEntryPointMetadata) => Promise<void>
|
handleDeleteProject: (f: Project) => Promise<void>
|
||||||
}) {
|
}) {
|
||||||
useHotkeys('esc', () => setIsEditing(false))
|
useHotkeys('esc', () => setIsEditing(false))
|
||||||
const [isEditing, setIsEditing] = useState(false)
|
const [isEditing, setIsEditing] = useState(false)
|
||||||
const [isConfirmingDelete, setIsConfirmingDelete] = useState(false)
|
const [isConfirmingDelete, setIsConfirmingDelete] = useState(false)
|
||||||
const [numberOfParts, setNumberOfParts] = useState(1)
|
const [numberOfFiles, setNumberOfFiles] = useState(1)
|
||||||
const [numberOfFolders, setNumberOfFolders] = useState(0)
|
const [numberOfFolders, setNumberOfFolders] = useState(0)
|
||||||
|
|
||||||
let inputRef = useRef<HTMLInputElement>(null)
|
let inputRef = useRef<HTMLInputElement>(null)
|
||||||
@ -41,7 +40,8 @@ function ProjectCard({
|
|||||||
void handleRenameProject(e, project).then(() => setIsEditing(false))
|
void handleRenameProject(e, project).then(() => setIsEditing(false))
|
||||||
}
|
}
|
||||||
|
|
||||||
function getDisplayedTime(date: Date) {
|
function getDisplayedTime(dateStr: string) {
|
||||||
|
const date = new Date(dateStr)
|
||||||
const startOfToday = new Date()
|
const startOfToday = new Date()
|
||||||
startOfToday.setHours(0, 0, 0, 0)
|
startOfToday.setHours(0, 0, 0, 0)
|
||||||
return date.getTime() < startOfToday.getTime()
|
return date.getTime() < startOfToday.getTime()
|
||||||
@ -50,15 +50,12 @@ function ProjectCard({
|
|||||||
}
|
}
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
async function getNumberOfParts() {
|
async function getNumberOfFiles() {
|
||||||
const { kclFileCount, kclDirCount } = getPartsCount(
|
setNumberOfFiles(project.kcl_file_count)
|
||||||
await readProject(project.path)
|
setNumberOfFolders(project.directory_count)
|
||||||
)
|
|
||||||
setNumberOfParts(kclFileCount)
|
|
||||||
setNumberOfFolders(kclDirCount)
|
|
||||||
}
|
}
|
||||||
void getNumberOfParts()
|
void getNumberOfFiles()
|
||||||
}, [project.path])
|
}, [project.kcl_file_count, project.directory_count])
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (inputRef.current) {
|
if (inputRef.current) {
|
||||||
@ -129,7 +126,7 @@ function ProjectCard({
|
|||||||
{project.name?.replace(FILE_EXT, '')}
|
{project.name?.replace(FILE_EXT, '')}
|
||||||
</Link>
|
</Link>
|
||||||
<span className="text-chalkboard-60 text-xs">
|
<span className="text-chalkboard-60 text-xs">
|
||||||
{numberOfParts} part{numberOfParts === 1 ? '' : 's'}{' '}
|
{numberOfFiles} file{numberOfFiles === 1 ? '' : 's'}{' '}
|
||||||
{numberOfFolders > 0 &&
|
{numberOfFolders > 0 &&
|
||||||
`/ ${numberOfFolders} folder${
|
`/ ${numberOfFolders} folder${
|
||||||
numberOfFolders === 1 ? '' : 's'
|
numberOfFolders === 1 ? '' : 's'
|
||||||
@ -137,8 +134,8 @@ function ProjectCard({
|
|||||||
</span>
|
</span>
|
||||||
<span className="text-chalkboard-60 text-xs">
|
<span className="text-chalkboard-60 text-xs">
|
||||||
Edited{' '}
|
Edited{' '}
|
||||||
{project.entrypointMetadata.mtime
|
{project.metadata && project.metadata?.modified
|
||||||
? getDisplayedTime(project.entrypointMetadata.mtime)
|
? getDisplayedTime(project.metadata.modified)
|
||||||
: 'never'}
|
: 'never'}
|
||||||
</span>
|
</span>
|
||||||
<div className="absolute z-10 bottom-2 right-2 flex gap-1 items-center opacity-0 group-hover:opacity-100 group-focus-within:opacity-100">
|
<div className="absolute z-10 bottom-2 right-2 flex gap-1 items-center opacity-0 group-hover:opacity-100 group-focus-within:opacity-100">
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
import { fireEvent, render, screen } from '@testing-library/react'
|
import { fireEvent, render, screen } from '@testing-library/react'
|
||||||
import { BrowserRouter } from 'react-router-dom'
|
import { BrowserRouter } from 'react-router-dom'
|
||||||
import ProjectSidebarMenu from './ProjectSidebarMenu'
|
import ProjectSidebarMenu from './ProjectSidebarMenu'
|
||||||
import { type ProjectWithEntryPointMetadata } from 'lib/types'
|
|
||||||
import { SettingsAuthProviderJest } from './SettingsAuthProvider'
|
import { SettingsAuthProviderJest } from './SettingsAuthProvider'
|
||||||
import { APP_NAME } from 'lib/constants'
|
import { APP_NAME } from 'lib/constants'
|
||||||
import { CommandBarProvider } from './CommandBar/CommandBarProvider'
|
import { CommandBarProvider } from './CommandBar/CommandBarProvider'
|
||||||
|
import { Project } from 'wasm-lib/kcl/bindings/Project'
|
||||||
|
|
||||||
const now = new Date()
|
const now = new Date()
|
||||||
const projectWellFormed = {
|
const projectWellFormed = {
|
||||||
@ -14,29 +14,17 @@ const projectWellFormed = {
|
|||||||
{
|
{
|
||||||
name: 'main.kcl',
|
name: 'main.kcl',
|
||||||
path: '/some/path/Simple Box/main.kcl',
|
path: '/some/path/Simple Box/main.kcl',
|
||||||
|
children: [],
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
entrypointMetadata: {
|
metadata: {
|
||||||
atime: now,
|
created: now.toISOString(),
|
||||||
blksize: 32,
|
modified: now.toISOString(),
|
||||||
blocks: 32,
|
|
||||||
birthtime: now,
|
|
||||||
dev: 1,
|
|
||||||
gid: 1,
|
|
||||||
ino: 1,
|
|
||||||
isDirectory: false,
|
|
||||||
isFile: true,
|
|
||||||
isSymlink: false,
|
|
||||||
mode: 1,
|
|
||||||
mtime: now,
|
|
||||||
nlink: 1,
|
|
||||||
readonly: false,
|
|
||||||
rdev: 1,
|
|
||||||
size: 32,
|
size: 32,
|
||||||
uid: 1,
|
|
||||||
fileAttributes: null,
|
|
||||||
},
|
},
|
||||||
} satisfies ProjectWithEntryPointMetadata
|
kcl_file_count: 1,
|
||||||
|
directory_count: 0,
|
||||||
|
} satisfies Project
|
||||||
|
|
||||||
describe('ProjectSidebarMenu tests', () => {
|
describe('ProjectSidebarMenu tests', () => {
|
||||||
test('Renders the project name', () => {
|
test('Renders the project name', () => {
|
||||||
|
@ -133,13 +133,13 @@ function ProjectMenuPopover({
|
|||||||
<p className="m-0 text-mono" data-testid="projectName">
|
<p className="m-0 text-mono" data-testid="projectName">
|
||||||
{project?.name ? project.name : APP_NAME}
|
{project?.name ? project.name : APP_NAME}
|
||||||
</p>
|
</p>
|
||||||
{project?.entrypointMetadata && (
|
{project?.metadata && project.metadata.created && (
|
||||||
<p
|
<p
|
||||||
className="m-0 text-xs text-chalkboard-80 dark:text-chalkboard-40"
|
className="m-0 text-xs text-chalkboard-80 dark:text-chalkboard-40"
|
||||||
data-testid="createdAt"
|
data-testid="createdAt"
|
||||||
>
|
>
|
||||||
Created{' '}
|
Created{' '}
|
||||||
{project.entrypointMetadata.birthtime?.toLocaleDateString()}
|
{new Date(project.metadata.created).toLocaleDateString()}
|
||||||
</p>
|
</p>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
@ -7,7 +7,12 @@ import React, { createContext, useEffect } from 'react'
|
|||||||
import useStateMachineCommands from '../hooks/useStateMachineCommands'
|
import useStateMachineCommands from '../hooks/useStateMachineCommands'
|
||||||
import { settingsMachine } from 'machines/settingsMachine'
|
import { settingsMachine } from 'machines/settingsMachine'
|
||||||
import { toast } from 'react-hot-toast'
|
import { toast } from 'react-hot-toast'
|
||||||
import { getThemeColorForEngine, setThemeClass, Themes } from 'lib/theme'
|
import {
|
||||||
|
getThemeColorForEngine,
|
||||||
|
getOppositeTheme,
|
||||||
|
setThemeClass,
|
||||||
|
Themes,
|
||||||
|
} from 'lib/theme'
|
||||||
import decamelize from 'decamelize'
|
import decamelize from 'decamelize'
|
||||||
import {
|
import {
|
||||||
AnyStateMachine,
|
AnyStateMachine,
|
||||||
@ -99,6 +104,9 @@ export const SettingsAuthProviderBase = ({
|
|||||||
{
|
{
|
||||||
context: loadedSettings,
|
context: loadedSettings,
|
||||||
actions: {
|
actions: {
|
||||||
|
//TODO: batch all these and if that's difficult to do from tsx,
|
||||||
|
// make it easy to do
|
||||||
|
|
||||||
setClientSideSceneUnits: (context, event) => {
|
setClientSideSceneUnits: (context, event) => {
|
||||||
const newBaseUnit =
|
const newBaseUnit =
|
||||||
event.type === 'set.modeling.defaultUnit'
|
event.type === 'set.modeling.defaultUnit'
|
||||||
@ -115,6 +123,16 @@ export const SettingsAuthProviderBase = ({
|
|||||||
color: getThemeColorForEngine(context.app.theme.current),
|
color: getThemeColorForEngine(context.app.theme.current),
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const opposingTheme = getOppositeTheme(context.app.theme.current)
|
||||||
|
engineCommandManager.sendSceneCommand({
|
||||||
|
cmd_id: uuidv4(),
|
||||||
|
type: 'modeling_cmd_req',
|
||||||
|
cmd: {
|
||||||
|
type: 'set_default_system_properties',
|
||||||
|
color: getThemeColorForEngine(opposingTheme),
|
||||||
|
},
|
||||||
|
})
|
||||||
},
|
},
|
||||||
setEngineEdges: (context) => {
|
setEngineEdges: (context) => {
|
||||||
engineCommandManager.sendSceneCommand({
|
engineCommandManager.sendSceneCommand({
|
||||||
@ -150,7 +168,7 @@ export const SettingsAuthProviderBase = ({
|
|||||||
},
|
},
|
||||||
'Execute AST': () => kclManager.executeCode(true),
|
'Execute AST': () => kclManager.executeCode(true),
|
||||||
persistSettings: (context) =>
|
persistSettings: (context) =>
|
||||||
saveSettings(context, loadedProject?.project?.path),
|
saveSettings(context, loadedProject?.project?.name),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
@ -39,6 +39,8 @@ const CompletionItemKindMap = Object.fromEntries(
|
|||||||
) as Record<CompletionItemKind, string>
|
) as Record<CompletionItemKind, string>
|
||||||
|
|
||||||
const changesDelay = 600
|
const changesDelay = 600
|
||||||
|
let debounceTimer: ReturnType<typeof setTimeout> | null = null
|
||||||
|
const updateDelay = 100
|
||||||
|
|
||||||
export class LanguageServerPlugin implements PluginValue {
|
export class LanguageServerPlugin implements PluginValue {
|
||||||
public client: LanguageServerClient
|
public client: LanguageServerClient
|
||||||
@ -47,6 +49,7 @@ export class LanguageServerPlugin implements PluginValue {
|
|||||||
public workspaceFolders: LSP.WorkspaceFolder[]
|
public workspaceFolders: LSP.WorkspaceFolder[]
|
||||||
private documentVersion: number
|
private documentVersion: number
|
||||||
private foldingRanges: LSP.FoldingRange[] | null = null
|
private foldingRanges: LSP.FoldingRange[] | null = null
|
||||||
|
private viewUpdate: ViewUpdate | null = null
|
||||||
private _defferer = deferExecution((code: string) => {
|
private _defferer = deferExecution((code: string) => {
|
||||||
try {
|
try {
|
||||||
// Update the state (not the editor) with the new code.
|
// Update the state (not the editor) with the new code.
|
||||||
@ -57,8 +60,9 @@ export class LanguageServerPlugin implements PluginValue {
|
|||||||
},
|
},
|
||||||
contentChanges: [{ text: code }],
|
contentChanges: [{ text: code }],
|
||||||
})
|
})
|
||||||
if (editorManager.editorView) {
|
|
||||||
//editorManager.handleOnViewUpdate(editorManager.editorView)
|
if (this.viewUpdate) {
|
||||||
|
editorManager.handleOnViewUpdate(this.viewUpdate)
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(e)
|
console.error(e)
|
||||||
@ -83,14 +87,27 @@ export class LanguageServerPlugin implements PluginValue {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
update({ docChanged }: ViewUpdate) {
|
update(viewUpdate: ViewUpdate) {
|
||||||
if (!docChanged) return
|
this.viewUpdate = viewUpdate
|
||||||
|
if (!viewUpdate.docChanged) {
|
||||||
|
// debounce the view update.
|
||||||
|
// otherwise it is laggy for typing.
|
||||||
|
if (debounceTimer) {
|
||||||
|
clearTimeout(debounceTimer)
|
||||||
|
}
|
||||||
|
|
||||||
|
debounceTimer = setTimeout(() => {
|
||||||
|
editorManager.handleOnViewUpdate(viewUpdate)
|
||||||
|
}, updateDelay)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
const newCode = this.view.state.doc.toString()
|
const newCode = this.view.state.doc.toString()
|
||||||
|
|
||||||
codeManager.code = newCode
|
codeManager.code = newCode
|
||||||
codeManager.writeToFile()
|
codeManager.writeToFile()
|
||||||
kclManager.executeCode()
|
kclManager.executeCode()
|
||||||
|
|
||||||
this.sendChange({
|
this.sendChange({
|
||||||
documentText: newCode,
|
documentText: newCode,
|
||||||
})
|
})
|
||||||
|
@ -11,9 +11,11 @@ export function useSetupEngineManager(
|
|||||||
settings = {
|
settings = {
|
||||||
theme: Themes.System,
|
theme: Themes.System,
|
||||||
highlightEdges: true,
|
highlightEdges: true,
|
||||||
|
enableSSAO: true,
|
||||||
} as {
|
} as {
|
||||||
theme: Themes
|
theme: Themes
|
||||||
highlightEdges: boolean
|
highlightEdges: boolean
|
||||||
|
enableSSAO: boolean
|
||||||
}
|
}
|
||||||
) {
|
) {
|
||||||
const {
|
const {
|
||||||
|
@ -266,9 +266,9 @@ const mySk1 = startSketchAt([0, 0])
|
|||||||
|
|
||||||
|
|
||||||
|> rx(45, %)
|
|> rx(45, %)
|
||||||
/*
|
/*
|
||||||
one more for good measure
|
one more for good measure
|
||||||
*/
|
*/
|
||||||
`
|
`
|
||||||
const { ast } = code2ast(code)
|
const { ast } = code2ast(code)
|
||||||
const recasted = recast(ast)
|
const recasted = recast(ast)
|
||||||
@ -285,7 +285,7 @@ const mySk1 = startSketchAt([0, 0])
|
|||||||
// and another with just white space between others below
|
// and another with just white space between others below
|
||||||
|> ry(45, %)
|
|> ry(45, %)
|
||||||
|> rx(45, %)
|
|> rx(45, %)
|
||||||
/* one more for good measure */
|
/* one more for good measure */
|
||||||
`)
|
`)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
@ -4,7 +4,7 @@ import { Models } from '@kittycad/lib'
|
|||||||
import { exportSave } from 'lib/exportSave'
|
import { exportSave } from 'lib/exportSave'
|
||||||
import { uuidv4 } from 'lib/utils'
|
import { uuidv4 } from 'lib/utils'
|
||||||
import { getNodePathFromSourceRange } from 'lang/queryAst'
|
import { getNodePathFromSourceRange } from 'lang/queryAst'
|
||||||
import { Themes, getThemeColorForEngine } from 'lib/theme'
|
import { Themes, getThemeColorForEngine, getOppositeTheme } from 'lib/theme'
|
||||||
import { DefaultPlanes } from 'wasm-lib/kcl/bindings/DefaultPlanes'
|
import { DefaultPlanes } from 'wasm-lib/kcl/bindings/DefaultPlanes'
|
||||||
|
|
||||||
let lastMessage = ''
|
let lastMessage = ''
|
||||||
@ -941,6 +941,7 @@ export class EngineCommandManager {
|
|||||||
settings = {
|
settings = {
|
||||||
theme: Themes.Dark,
|
theme: Themes.Dark,
|
||||||
highlightEdges: true,
|
highlightEdges: true,
|
||||||
|
enableSSAO: true,
|
||||||
},
|
},
|
||||||
}: {
|
}: {
|
||||||
setMediaStream: (stream: MediaStream) => void
|
setMediaStream: (stream: MediaStream) => void
|
||||||
@ -953,6 +954,7 @@ export class EngineCommandManager {
|
|||||||
settings?: {
|
settings?: {
|
||||||
theme: Themes
|
theme: Themes
|
||||||
highlightEdges: boolean
|
highlightEdges: boolean
|
||||||
|
enableSSAO: boolean
|
||||||
}
|
}
|
||||||
}) {
|
}) {
|
||||||
this.makeDefaultPlanes = makeDefaultPlanes
|
this.makeDefaultPlanes = makeDefaultPlanes
|
||||||
@ -969,7 +971,8 @@ export class EngineCommandManager {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
const url = `${VITE_KC_API_WS_MODELING_URL}?video_res_width=${width}&video_res_height=${height}`
|
const additionalSettings = settings.enableSSAO ? '&post_effect=ssao' : ''
|
||||||
|
const url = `${VITE_KC_API_WS_MODELING_URL}?video_res_width=${width}&video_res_height=${height}${additionalSettings}`
|
||||||
this.engineConnection = new EngineConnection({
|
this.engineConnection = new EngineConnection({
|
||||||
engineCommandManager: this,
|
engineCommandManager: this,
|
||||||
url,
|
url,
|
||||||
@ -989,6 +992,18 @@ export class EngineCommandManager {
|
|||||||
color: getThemeColorForEngine(settings.theme),
|
color: getThemeColorForEngine(settings.theme),
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// Sets the default line colors
|
||||||
|
const opposingTheme = getOppositeTheme(settings.theme)
|
||||||
|
this.sendSceneCommand({
|
||||||
|
cmd_id: uuidv4(),
|
||||||
|
type: 'modeling_cmd_req',
|
||||||
|
cmd: {
|
||||||
|
type: 'set_default_system_properties',
|
||||||
|
color: getThemeColorForEngine(opposingTheme),
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
// Set the edge lines visibility
|
// Set the edge lines visibility
|
||||||
this.sendSceneCommand({
|
this.sendSceneCommand({
|
||||||
type: 'modeling_cmd_req',
|
type: 'modeling_cmd_req',
|
||||||
@ -1326,6 +1341,17 @@ export class EngineCommandManager {
|
|||||||
this.lastArtifactMap = this.artifactMap
|
this.lastArtifactMap = this.artifactMap
|
||||||
this.artifactMap = {}
|
this.artifactMap = {}
|
||||||
await this.initPlanes()
|
await this.initPlanes()
|
||||||
|
await this.sendSceneCommand({
|
||||||
|
type: 'modeling_cmd_req',
|
||||||
|
cmd_id: uuidv4(),
|
||||||
|
cmd: {
|
||||||
|
type: 'make_axes_gizmo',
|
||||||
|
clobber: false,
|
||||||
|
// If true, axes gizmo will be placed in the corner of the screen.
|
||||||
|
// If false, it will be placed at the origin of the scene.
|
||||||
|
gizmo_mode: true,
|
||||||
|
},
|
||||||
|
})
|
||||||
}
|
}
|
||||||
subscribeTo<T extends ModelTypes>({
|
subscribeTo<T extends ModelTypes>({
|
||||||
event,
|
event,
|
||||||
|
@ -1,8 +1,7 @@
|
|||||||
import { readFile, exists as tauriExists } from '@tauri-apps/plugin-fs'
|
import { readFile, exists as tauriExists } from '@tauri-apps/plugin-fs'
|
||||||
import { isTauri } from 'lib/isTauri'
|
import { isTauri } from 'lib/isTauri'
|
||||||
import { join } from '@tauri-apps/api/path'
|
import { join } from '@tauri-apps/api/path'
|
||||||
import { invoke } from '@tauri-apps/api/core'
|
import { readDirRecursive } from 'lib/tauri'
|
||||||
import { FileEntry } from 'lib/types'
|
|
||||||
|
|
||||||
/// FileSystemManager is a class that provides a way to read files from the local file system.
|
/// FileSystemManager is a class that provides a way to read files from the local file system.
|
||||||
/// It assumes that you are in a project since it is solely used by the std lib
|
/// It assumes that you are in a project since it is solely used by the std lib
|
||||||
@ -69,9 +68,7 @@ class FileSystemManager {
|
|||||||
throw new Error(`Error joining dir: ${error}`)
|
throw new Error(`Error joining dir: ${error}`)
|
||||||
})
|
})
|
||||||
.then((p) => {
|
.then((p) => {
|
||||||
invoke<FileEntry[]>('read_dir_recursive', {
|
readDirRecursive(p)
|
||||||
path: p,
|
|
||||||
})
|
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
throw new Error(`Error reading dir: ${error}`)
|
throw new Error(`Error reading dir: ${error}`)
|
||||||
})
|
})
|
||||||
|
@ -102,7 +102,7 @@ describe('testing changeSketchArguments', () => {
|
|||||||
|> startProfileAt([0, 0], %)
|
|> startProfileAt([0, 0], %)
|
||||||
|> ${line}
|
|> ${line}
|
||||||
|> lineTo([0.46, -5.82], %)
|
|> lineTo([0.46, -5.82], %)
|
||||||
// |> rx(45, %)
|
// |> rx(45, %)
|
||||||
`
|
`
|
||||||
const code = genCode(lineToChange)
|
const code = genCode(lineToChange)
|
||||||
const expectedCode = genCode(lineAfterChange)
|
const expectedCode = genCode(lineAfterChange)
|
||||||
|
@ -10,7 +10,10 @@ import init, {
|
|||||||
make_default_planes,
|
make_default_planes,
|
||||||
coredump,
|
coredump,
|
||||||
toml_stringify,
|
toml_stringify,
|
||||||
toml_parse,
|
default_app_settings,
|
||||||
|
parse_app_settings,
|
||||||
|
parse_project_settings,
|
||||||
|
default_project_settings,
|
||||||
} from '../wasm-lib/pkg/wasm_lib'
|
} from '../wasm-lib/pkg/wasm_lib'
|
||||||
import { KCLError } from './errors'
|
import { KCLError } from './errors'
|
||||||
import { KclError as RustKclError } from '../wasm-lib/kcl/bindings/KclError'
|
import { KclError as RustKclError } from '../wasm-lib/kcl/bindings/KclError'
|
||||||
@ -26,6 +29,8 @@ import { CoreDumpManager } from 'lib/coredump'
|
|||||||
import openWindow from 'lib/openWindow'
|
import openWindow from 'lib/openWindow'
|
||||||
import { DefaultPlanes } from 'wasm-lib/kcl/bindings/DefaultPlanes'
|
import { DefaultPlanes } from 'wasm-lib/kcl/bindings/DefaultPlanes'
|
||||||
import { TEST } from 'env'
|
import { TEST } from 'env'
|
||||||
|
import { Configuration } from 'wasm-lib/kcl/bindings/Configuration'
|
||||||
|
import { ProjectConfiguration } from 'wasm-lib/kcl/bindings/ProjectConfiguration'
|
||||||
|
|
||||||
export type { Program } from '../wasm-lib/kcl/bindings/Program'
|
export type { Program } from '../wasm-lib/kcl/bindings/Program'
|
||||||
export type { Value } from '../wasm-lib/kcl/bindings/Value'
|
export type { Value } from '../wasm-lib/kcl/bindings/Value'
|
||||||
@ -349,11 +354,38 @@ export function tomlStringify(toml: any): string {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function tomlParse(toml: string): any {
|
export function defaultAppSettings(): Configuration {
|
||||||
try {
|
try {
|
||||||
const parsed: any = toml_parse(toml)
|
const settings: Configuration = default_app_settings()
|
||||||
return parsed
|
return settings
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
throw new Error(`Error parsing toml: ${e}`)
|
throw new Error(`Error getting default app settings: ${e}`)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function parseAppSettings(toml: string): Configuration {
|
||||||
|
try {
|
||||||
|
const settings: Configuration = parse_app_settings(toml)
|
||||||
|
return settings
|
||||||
|
} catch (e: any) {
|
||||||
|
throw new Error(`Error parsing app settings: ${e}`)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function defaultProjectSettings(): ProjectConfiguration {
|
||||||
|
try {
|
||||||
|
const settings: ProjectConfiguration = default_project_settings()
|
||||||
|
return settings
|
||||||
|
} catch (e: any) {
|
||||||
|
throw new Error(`Error getting default project settings: ${e}`)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function parseProjectSettings(toml: string): ProjectConfiguration {
|
||||||
|
try {
|
||||||
|
const settings: ProjectConfiguration = parse_project_settings(toml)
|
||||||
|
return settings
|
||||||
|
} catch (e: any) {
|
||||||
|
throw new Error(`Error parsing project settings: ${e}`)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
import { MouseControlType } from 'wasm-lib/kcl/bindings/MouseControlType'
|
||||||
|
|
||||||
const noModifiersPressed = (e: React.MouseEvent) =>
|
const noModifiersPressed = (e: React.MouseEvent) =>
|
||||||
!e.ctrlKey && !e.shiftKey && !e.altKey && !e.metaKey
|
!e.ctrlKey && !e.shiftKey && !e.altKey && !e.metaKey
|
||||||
|
|
||||||
@ -20,6 +22,29 @@ export const cameraSystems: CameraSystem[] = [
|
|||||||
'AutoCAD',
|
'AutoCAD',
|
||||||
]
|
]
|
||||||
|
|
||||||
|
export function mouseControlsToCameraSystem(
|
||||||
|
mouseControl: MouseControlType | undefined
|
||||||
|
): CameraSystem | undefined {
|
||||||
|
switch (mouseControl) {
|
||||||
|
case 'kitty_cad':
|
||||||
|
return 'KittyCAD'
|
||||||
|
case 'on_shape':
|
||||||
|
return 'OnShape'
|
||||||
|
case 'trackpad_friendly':
|
||||||
|
return 'Trackpad Friendly'
|
||||||
|
case 'solidworks':
|
||||||
|
return 'Solidworks'
|
||||||
|
case 'nx':
|
||||||
|
return 'NX'
|
||||||
|
case 'creo':
|
||||||
|
return 'Creo'
|
||||||
|
case 'auto_cad':
|
||||||
|
return 'AutoCAD'
|
||||||
|
default:
|
||||||
|
return undefined
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
interface MouseGuardHandler {
|
interface MouseGuardHandler {
|
||||||
description: string
|
description: string
|
||||||
callback: (e: React.MouseEvent) => boolean
|
callback: (e: React.MouseEvent) => boolean
|
||||||
|
@ -8,8 +8,6 @@ export const MAX_PADDING = 7
|
|||||||
* This is available for users to edit as a setting.
|
* This is available for users to edit as a setting.
|
||||||
*/
|
*/
|
||||||
export const DEFAULT_PROJECT_NAME = 'project-$nnn'
|
export const DEFAULT_PROJECT_NAME = 'project-$nnn'
|
||||||
/** The file name for settings files, both at the user and project level */
|
|
||||||
export const SETTINGS_FILE_EXT = '.toml'
|
|
||||||
/** Name given the temporary "project" in the browser version of the app */
|
/** Name given the temporary "project" in the browser version of the app */
|
||||||
export const BROWSER_PROJECT_NAME = 'browser'
|
export const BROWSER_PROJECT_NAME = 'browser'
|
||||||
/** Name given the temporary file in the browser version of the app */
|
/** Name given the temporary file in the browser version of the app */
|
||||||
|
@ -1,10 +1,5 @@
|
|||||||
import { ActionFunction, LoaderFunction, redirect } from 'react-router-dom'
|
import { ActionFunction, LoaderFunction, redirect } from 'react-router-dom'
|
||||||
import {
|
import { FileLoaderData, HomeLoaderData, IndexLoaderData } from './types'
|
||||||
FileEntry,
|
|
||||||
FileLoaderData,
|
|
||||||
HomeLoaderData,
|
|
||||||
IndexLoaderData,
|
|
||||||
} from './types'
|
|
||||||
import { isTauri } from './isTauri'
|
import { isTauri } from './isTauri'
|
||||||
import { getProjectMetaByRouteId, paths } from './paths'
|
import { getProjectMetaByRouteId, paths } from './paths'
|
||||||
import { BROWSER_PATH } from 'lib/paths'
|
import { BROWSER_PATH } from 'lib/paths'
|
||||||
@ -14,24 +9,24 @@ import {
|
|||||||
PROJECT_ENTRYPOINT,
|
PROJECT_ENTRYPOINT,
|
||||||
} from 'lib/constants'
|
} from 'lib/constants'
|
||||||
import { loadAndValidateSettings } from './settings/settingsUtils'
|
import { loadAndValidateSettings } from './settings/settingsUtils'
|
||||||
import {
|
|
||||||
getInitialDefaultDir,
|
|
||||||
getProjectsInDir,
|
|
||||||
initializeProjectDirectory,
|
|
||||||
} from './tauriFS'
|
|
||||||
import makeUrlPathRelative from './makeUrlPathRelative'
|
import makeUrlPathRelative from './makeUrlPathRelative'
|
||||||
import { join, sep } from '@tauri-apps/api/path'
|
import { sep } from '@tauri-apps/api/path'
|
||||||
import { readTextFile, stat } from '@tauri-apps/plugin-fs'
|
import { readTextFile } from '@tauri-apps/plugin-fs'
|
||||||
import { codeManager, kclManager } from 'lib/singletons'
|
import { codeManager, kclManager } from 'lib/singletons'
|
||||||
import { fileSystemManager } from 'lang/std/fileSystemManager'
|
import { fileSystemManager } from 'lang/std/fileSystemManager'
|
||||||
import { invoke } from '@tauri-apps/api/core'
|
import {
|
||||||
|
getProjectInfo,
|
||||||
|
initializeProjectDirectory,
|
||||||
|
listProjects,
|
||||||
|
} from './tauri'
|
||||||
|
import { createSettings } from './settings/initialSettings'
|
||||||
|
|
||||||
// The root loader simply resolves the settings and any errors that
|
// The root loader simply resolves the settings and any errors that
|
||||||
// occurred during the settings load
|
// occurred during the settings load
|
||||||
export const settingsLoader: LoaderFunction = async ({
|
export const settingsLoader: LoaderFunction = async ({
|
||||||
params,
|
params,
|
||||||
}): ReturnType<typeof loadAndValidateSettings> => {
|
}): Promise<ReturnType<typeof createSettings>> => {
|
||||||
let settings = await loadAndValidateSettings()
|
let { settings } = await loadAndValidateSettings()
|
||||||
|
|
||||||
// I don't love that we have to read the settings again here,
|
// I don't love that we have to read the settings again here,
|
||||||
// but we need to get the project path to load the project settings
|
// but we need to get the project path to load the project settings
|
||||||
@ -39,8 +34,9 @@ export const settingsLoader: LoaderFunction = async ({
|
|||||||
const defaultDir = settings.app.projectDirectory.current || ''
|
const defaultDir = settings.app.projectDirectory.current || ''
|
||||||
const projectPathData = getProjectMetaByRouteId(params.id, defaultDir)
|
const projectPathData = getProjectMetaByRouteId(params.id, defaultDir)
|
||||||
if (projectPathData) {
|
if (projectPathData) {
|
||||||
const { projectPath } = projectPathData
|
const { projectName } = projectPathData
|
||||||
settings = await loadAndValidateSettings(projectPath)
|
const { settings: s } = await loadAndValidateSettings(projectName)
|
||||||
|
settings = s
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -49,7 +45,7 @@ export const settingsLoader: LoaderFunction = async ({
|
|||||||
|
|
||||||
// Redirect users to the appropriate onboarding page if they haven't completed it
|
// Redirect users to the appropriate onboarding page if they haven't completed it
|
||||||
export const onboardingRedirectLoader: ActionFunction = async (args) => {
|
export const onboardingRedirectLoader: ActionFunction = async (args) => {
|
||||||
const settings = await loadAndValidateSettings()
|
const { settings } = await loadAndValidateSettings()
|
||||||
const onboardingStatus = settings.app.onboardingStatus.current || ''
|
const onboardingStatus = settings.app.onboardingStatus.current || ''
|
||||||
const notEnRouteToOnboarding = !args.request.url.includes(
|
const notEnRouteToOnboarding = !args.request.url.includes(
|
||||||
paths.ONBOARDING.INDEX
|
paths.ONBOARDING.INDEX
|
||||||
@ -73,7 +69,7 @@ export const onboardingRedirectLoader: ActionFunction = async (args) => {
|
|||||||
export const fileLoader: LoaderFunction = async ({
|
export const fileLoader: LoaderFunction = async ({
|
||||||
params,
|
params,
|
||||||
}): Promise<FileLoaderData | Response> => {
|
}): Promise<FileLoaderData | Response> => {
|
||||||
let settings = await loadAndValidateSettings()
|
let { settings } = await loadAndValidateSettings()
|
||||||
|
|
||||||
const defaultDir = settings.app.projectDirectory.current || '/'
|
const defaultDir = settings.app.projectDirectory.current || '/'
|
||||||
const projectPathData = getProjectMetaByRouteId(params.id, defaultDir)
|
const projectPathData = getProjectMetaByRouteId(params.id, defaultDir)
|
||||||
@ -94,12 +90,7 @@ export const fileLoader: LoaderFunction = async ({
|
|||||||
// TODO: PROJECT_ENTRYPOINT is hardcoded
|
// TODO: PROJECT_ENTRYPOINT is hardcoded
|
||||||
// until we support setting a project's entrypoint file
|
// until we support setting a project's entrypoint file
|
||||||
const code = await readTextFile(currentFilePath)
|
const code = await readTextFile(currentFilePath)
|
||||||
const entrypointMetadata = await stat(
|
|
||||||
await join(projectPath, PROJECT_ENTRYPOINT)
|
|
||||||
)
|
|
||||||
const children = await invoke<FileEntry[]>('read_dir_recursive', {
|
|
||||||
path: projectPath,
|
|
||||||
})
|
|
||||||
// Update both the state and the editor's code.
|
// Update both the state and the editor's code.
|
||||||
// We explicitly do not write to the file here since we are loading from
|
// We explicitly do not write to the file here since we are loading from
|
||||||
// the file system and not the editor.
|
// the file system and not the editor.
|
||||||
@ -113,15 +104,19 @@ export const fileLoader: LoaderFunction = async ({
|
|||||||
|
|
||||||
const projectData: IndexLoaderData = {
|
const projectData: IndexLoaderData = {
|
||||||
code,
|
code,
|
||||||
project: {
|
project: isTauri()
|
||||||
|
? await getProjectInfo(projectName)
|
||||||
|
: {
|
||||||
name: projectName,
|
name: projectName,
|
||||||
path: projectPath,
|
path: projectPath,
|
||||||
children,
|
children: [],
|
||||||
entrypointMetadata,
|
kcl_file_count: 0,
|
||||||
|
directory_count: 0,
|
||||||
},
|
},
|
||||||
file: {
|
file: {
|
||||||
name: currentFileName,
|
name: currentFileName,
|
||||||
path: currentFilePath,
|
path: currentFilePath,
|
||||||
|
children: [],
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -140,6 +135,7 @@ export const fileLoader: LoaderFunction = async ({
|
|||||||
file: {
|
file: {
|
||||||
name: BROWSER_FILE_NAME,
|
name: BROWSER_FILE_NAME,
|
||||||
path: decodeURIComponent(BROWSER_PATH),
|
path: decodeURIComponent(BROWSER_PATH),
|
||||||
|
children: [],
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -152,14 +148,12 @@ export const homeLoader: LoaderFunction = async (): Promise<
|
|||||||
if (!isTauri()) {
|
if (!isTauri()) {
|
||||||
return redirect(paths.FILE + '/%2F' + BROWSER_PROJECT_NAME)
|
return redirect(paths.FILE + '/%2F' + BROWSER_PROJECT_NAME)
|
||||||
}
|
}
|
||||||
const settings = await loadAndValidateSettings()
|
const { configuration } = await loadAndValidateSettings()
|
||||||
|
|
||||||
const projectDir = await initializeProjectDirectory(
|
const projectDir = await initializeProjectDirectory(configuration)
|
||||||
settings.app.projectDirectory.current || (await getInitialDefaultDir())
|
|
||||||
)
|
|
||||||
|
|
||||||
if (projectDir.path) {
|
if (projectDir) {
|
||||||
const projects = await getProjectsInDir(projectDir.path)
|
const projects = await listProjects(configuration)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
projects,
|
projects,
|
||||||
|
@ -420,7 +420,13 @@ export function getSelectionTypeDisplayText(
|
|||||||
const selectionsByType = getSelectionType(selection)
|
const selectionsByType = getSelectionType(selection)
|
||||||
|
|
||||||
return (selectionsByType as Exclude<typeof selectionsByType, 'none'>)
|
return (selectionsByType as Exclude<typeof selectionsByType, 'none'>)
|
||||||
.map(([type, count]) => `${count} ${type}${count > 1 ? 's' : ''}`)
|
.map(
|
||||||
|
// Hack for showing "face" instead of "extrude-wall" in command bar text
|
||||||
|
([type, count]) =>
|
||||||
|
`${count} ${type.replace('extrude-wall', 'face')}${
|
||||||
|
count > 1 ? 's' : ''
|
||||||
|
}`
|
||||||
|
)
|
||||||
.join(', ')
|
.join(', ')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -156,6 +156,13 @@ export function createSettings() {
|
|||||||
</div>
|
</div>
|
||||||
),
|
),
|
||||||
}),
|
}),
|
||||||
|
enableSSAO: new Setting<boolean>({
|
||||||
|
defaultValue: true,
|
||||||
|
description:
|
||||||
|
'Whether or not Screen Space Ambient Occlusion (SSAO) is enabled',
|
||||||
|
validate: (v) => typeof v === 'boolean',
|
||||||
|
hideOnPlatform: 'both', //for now
|
||||||
|
}),
|
||||||
onboardingStatus: new Setting<string>({
|
onboardingStatus: new Setting<string>({
|
||||||
defaultValue: '',
|
defaultValue: '',
|
||||||
validate: (v) => typeof v === 'string',
|
validate: (v) => typeof v === 'string',
|
||||||
|
@ -1,100 +1,228 @@
|
|||||||
import {
|
|
||||||
getInitialDefaultDir,
|
|
||||||
getSettingsFilePaths,
|
|
||||||
readSettingsFile,
|
|
||||||
} from '../tauriFS'
|
|
||||||
import { Setting, createSettings, settings } from 'lib/settings/initialSettings'
|
import { Setting, createSettings, settings } from 'lib/settings/initialSettings'
|
||||||
import { SaveSettingsPayload, SettingsLevel } from './settingsTypes'
|
import { SaveSettingsPayload, SettingsLevel } from './settingsTypes'
|
||||||
import { isTauri } from 'lib/isTauri'
|
import { isTauri } from 'lib/isTauri'
|
||||||
import { remove, writeTextFile, exists } from '@tauri-apps/plugin-fs'
|
import {
|
||||||
import { initPromise, tomlParse, tomlStringify } from 'lang/wasm'
|
defaultAppSettings,
|
||||||
|
defaultProjectSettings,
|
||||||
|
initPromise,
|
||||||
|
parseAppSettings,
|
||||||
|
parseProjectSettings,
|
||||||
|
tomlStringify,
|
||||||
|
} from 'lang/wasm'
|
||||||
|
import { Configuration } from 'wasm-lib/kcl/bindings/Configuration'
|
||||||
|
import { mouseControlsToCameraSystem } from 'lib/cameraControls'
|
||||||
|
import { appThemeToTheme } from 'lib/theme'
|
||||||
|
import {
|
||||||
|
readAppSettingsFile,
|
||||||
|
readProjectSettingsFile,
|
||||||
|
writeAppSettingsFile,
|
||||||
|
writeProjectSettingsFile,
|
||||||
|
} from 'lib/tauri'
|
||||||
|
import { ProjectConfiguration } from 'wasm-lib/kcl/bindings/ProjectConfiguration'
|
||||||
|
import { BROWSER_PROJECT_NAME } from 'lib/constants'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* We expect the settings to be stored in a TOML file
|
* Convert from a rust settings struct into the JS settings struct.
|
||||||
* or TOML-formatted string in localStorage
|
* We do this because the JS settings type has all the fancy shit
|
||||||
* under a top-level [settings] key.
|
* for hiding and showing settings.
|
||||||
* @param path
|
**/
|
||||||
* @returns
|
function configurationToSettingsPayload(
|
||||||
*/
|
configuration: Configuration
|
||||||
function getSettingsFromStorage(path: string) {
|
): Partial<SaveSettingsPayload> {
|
||||||
return isTauri()
|
return {
|
||||||
? readSettingsFile(path)
|
app: {
|
||||||
: (tomlParse(localStorage.getItem(path) ?? '')
|
theme: appThemeToTheme(configuration?.settings?.app?.appearance?.theme),
|
||||||
.settings as Partial<SaveSettingsPayload>)
|
themeColor: configuration?.settings?.app?.appearance?.color
|
||||||
|
? configuration?.settings?.app?.appearance?.color.toString()
|
||||||
|
: undefined,
|
||||||
|
onboardingStatus: configuration?.settings?.app?.onboarding_status,
|
||||||
|
dismissWebBanner: configuration?.settings?.app?.dismiss_web_banner,
|
||||||
|
projectDirectory: configuration?.settings?.project?.directory,
|
||||||
|
enableSSAO: configuration?.settings?.modeling?.enable_ssao,
|
||||||
|
},
|
||||||
|
modeling: {
|
||||||
|
defaultUnit: configuration?.settings?.modeling?.base_unit,
|
||||||
|
mouseControls: mouseControlsToCameraSystem(
|
||||||
|
configuration?.settings?.modeling?.mouse_controls
|
||||||
|
),
|
||||||
|
highlightEdges: configuration?.settings?.modeling?.highlight_edges,
|
||||||
|
showDebugPanel: configuration?.settings?.modeling?.show_debug_panel,
|
||||||
|
},
|
||||||
|
textEditor: {
|
||||||
|
textWrapping: configuration?.settings?.text_editor?.text_wrapping,
|
||||||
|
blinkingCursor: configuration?.settings?.text_editor?.blinking_cursor,
|
||||||
|
},
|
||||||
|
projects: {
|
||||||
|
defaultProjectName:
|
||||||
|
configuration?.settings?.project?.default_project_name,
|
||||||
|
},
|
||||||
|
commandBar: {
|
||||||
|
includeSettings: configuration?.settings?.command_bar?.include_settings,
|
||||||
|
},
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function loadAndValidateSettings(projectPath?: string) {
|
function projectConfigurationToSettingsPayload(
|
||||||
const settings = createSettings()
|
configuration: ProjectConfiguration
|
||||||
settings.app.projectDirectory.default = await getInitialDefaultDir()
|
): Partial<SaveSettingsPayload> {
|
||||||
// First, get the settings data at the user and project level
|
return {
|
||||||
const settingsFilePaths = await getSettingsFilePaths(projectPath)
|
app: {
|
||||||
|
theme: appThemeToTheme(configuration?.settings?.app?.appearance?.theme),
|
||||||
|
themeColor: configuration?.settings?.app?.appearance?.color
|
||||||
|
? configuration?.settings?.app?.appearance?.color.toString()
|
||||||
|
: undefined,
|
||||||
|
onboardingStatus: configuration?.settings?.app?.onboarding_status,
|
||||||
|
dismissWebBanner: configuration?.settings?.app?.dismiss_web_banner,
|
||||||
|
enableSSAO: configuration?.settings?.modeling?.enable_ssao,
|
||||||
|
},
|
||||||
|
modeling: {
|
||||||
|
defaultUnit: configuration?.settings?.modeling?.base_unit,
|
||||||
|
mouseControls: mouseControlsToCameraSystem(
|
||||||
|
configuration?.settings?.modeling?.mouse_controls
|
||||||
|
),
|
||||||
|
highlightEdges: configuration?.settings?.modeling?.highlight_edges,
|
||||||
|
showDebugPanel: configuration?.settings?.modeling?.show_debug_panel,
|
||||||
|
},
|
||||||
|
textEditor: {
|
||||||
|
textWrapping: configuration?.settings?.text_editor?.text_wrapping,
|
||||||
|
blinkingCursor: configuration?.settings?.text_editor?.blinking_cursor,
|
||||||
|
},
|
||||||
|
commandBar: {
|
||||||
|
includeSettings: configuration?.settings?.command_bar?.include_settings,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Load the settings from the files
|
function localStorageAppSettingsPath() {
|
||||||
if (settingsFilePaths.user) {
|
return '/settings.toml'
|
||||||
|
}
|
||||||
|
|
||||||
|
function localStorageProjectSettingsPath() {
|
||||||
|
return '/' + BROWSER_PROJECT_NAME + '/project.toml'
|
||||||
|
}
|
||||||
|
|
||||||
|
function readLocalStorageAppSettingsFile(): Configuration {
|
||||||
|
// TODO: Remove backwards compatibility after a few releases.
|
||||||
|
let stored =
|
||||||
|
localStorage.getItem(localStorageAppSettingsPath()) ??
|
||||||
|
localStorage.getItem('/user.toml') ??
|
||||||
|
''
|
||||||
|
|
||||||
|
if (stored === '') {
|
||||||
|
return defaultAppSettings()
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
return parseAppSettings(stored)
|
||||||
|
} catch (e) {
|
||||||
|
const settings = defaultAppSettings()
|
||||||
|
localStorage.setItem(localStorageAppSettingsPath(), tomlStringify(settings))
|
||||||
|
return settings
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function readLocalStorageProjectSettingsFile(): ProjectConfiguration {
|
||||||
|
// TODO: Remove backwards compatibility after a few releases.
|
||||||
|
let stored = localStorage.getItem(localStorageProjectSettingsPath()) ?? ''
|
||||||
|
|
||||||
|
if (stored === '') {
|
||||||
|
return defaultProjectSettings()
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
return parseProjectSettings(stored)
|
||||||
|
} catch (e) {
|
||||||
|
const settings = defaultProjectSettings()
|
||||||
|
localStorage.setItem(
|
||||||
|
localStorageProjectSettingsPath(),
|
||||||
|
tomlStringify(settings)
|
||||||
|
)
|
||||||
|
return settings
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface AppSettings {
|
||||||
|
settings: ReturnType<typeof createSettings>
|
||||||
|
configuration: Configuration
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function loadAndValidateSettings(
|
||||||
|
projectName?: string
|
||||||
|
): Promise<AppSettings> {
|
||||||
|
const settings = createSettings()
|
||||||
|
const inTauri = isTauri()
|
||||||
|
|
||||||
|
if (!inTauri) {
|
||||||
|
// Make sure we have wasm initialized.
|
||||||
await initPromise
|
await initPromise
|
||||||
const userSettings = await getSettingsFromStorage(settingsFilePaths.user)
|
|
||||||
if (userSettings) {
|
|
||||||
setSettingsAtLevel(settings, 'user', userSettings)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Load the app settings from the file system or localStorage.
|
||||||
|
const appSettings = inTauri
|
||||||
|
? await readAppSettingsFile()
|
||||||
|
: readLocalStorageAppSettingsFile()
|
||||||
|
// Convert the app settings to the JS settings format.
|
||||||
|
const appSettingsPayload = configurationToSettingsPayload(appSettings)
|
||||||
|
setSettingsAtLevel(settings, 'user', appSettingsPayload)
|
||||||
|
|
||||||
// Load the project settings if they exist
|
// Load the project settings if they exist
|
||||||
if (settingsFilePaths.project) {
|
if (projectName) {
|
||||||
const projectSettings = await getSettingsFromStorage(
|
const projectSettings = inTauri
|
||||||
settingsFilePaths.project
|
? await readProjectSettingsFile(appSettings, projectName)
|
||||||
)
|
: readLocalStorageProjectSettingsFile()
|
||||||
if (projectSettings) {
|
|
||||||
setSettingsAtLevel(settings, 'project', projectSettings)
|
const projectSettingsPayload =
|
||||||
}
|
projectConfigurationToSettingsPayload(projectSettings)
|
||||||
|
setSettingsAtLevel(settings, 'project', projectSettingsPayload)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return the settings object
|
// Return the settings object
|
||||||
return settings
|
return { settings, configuration: appSettings }
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function saveSettings(
|
export async function saveSettings(
|
||||||
allSettings: typeof settings,
|
allSettings: typeof settings,
|
||||||
projectPath?: string
|
projectName?: string
|
||||||
) {
|
|
||||||
const settingsFilePaths = await getSettingsFilePaths(projectPath)
|
|
||||||
|
|
||||||
if (settingsFilePaths.user) {
|
|
||||||
const changedSettings = getChangedSettingsAtLevel(allSettings, 'user')
|
|
||||||
|
|
||||||
await writeOrClearPersistedSettings(settingsFilePaths.user, changedSettings)
|
|
||||||
}
|
|
||||||
|
|
||||||
if (settingsFilePaths.project) {
|
|
||||||
const changedSettings = getChangedSettingsAtLevel(allSettings, 'project')
|
|
||||||
|
|
||||||
await writeOrClearPersistedSettings(
|
|
||||||
settingsFilePaths.project,
|
|
||||||
changedSettings
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async function writeOrClearPersistedSettings(
|
|
||||||
settingsFilePath: string,
|
|
||||||
changedSettings: Partial<SaveSettingsPayload>
|
|
||||||
) {
|
) {
|
||||||
|
// Make sure we have wasm initialized.
|
||||||
await initPromise
|
await initPromise
|
||||||
if (changedSettings && Object.keys(changedSettings).length) {
|
const inTauri = isTauri()
|
||||||
if (isTauri()) {
|
|
||||||
await writeTextFile(
|
// Get the user settings.
|
||||||
settingsFilePath,
|
const jsAppSettings = getChangedSettingsAtLevel(allSettings, 'user')
|
||||||
tomlStringify({ settings: changedSettings })
|
const tomlString = tomlStringify({ settings: jsAppSettings })
|
||||||
)
|
// Parse this as a Configuration.
|
||||||
}
|
const appSettings = parseAppSettings(tomlString)
|
||||||
localStorage.setItem(
|
|
||||||
settingsFilePath,
|
// Write the app settings.
|
||||||
tomlStringify({ settings: changedSettings })
|
if (inTauri) {
|
||||||
)
|
await writeAppSettingsFile(appSettings)
|
||||||
} else {
|
} else {
|
||||||
if (isTauri() && (await exists(settingsFilePath))) {
|
localStorage.setItem(
|
||||||
await remove(settingsFilePath)
|
localStorageAppSettingsPath(),
|
||||||
|
tomlStringify(appSettings)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
localStorage.removeItem(settingsFilePath)
|
|
||||||
|
if (!projectName) {
|
||||||
|
// If we're not saving project settings, we're done.
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get the project settings.
|
||||||
|
const jsProjectSettings = getChangedSettingsAtLevel(allSettings, 'project')
|
||||||
|
const projectTomlString = tomlStringify({ settings: jsProjectSettings })
|
||||||
|
// Parse this as a Configuration.
|
||||||
|
const projectSettings = parseProjectSettings(projectTomlString)
|
||||||
|
|
||||||
|
// Write the project settings.
|
||||||
|
if (inTauri) {
|
||||||
|
await writeProjectSettingsFile(appSettings, projectName, projectSettings)
|
||||||
|
} else {
|
||||||
|
localStorage.setItem(
|
||||||
|
localStorageProjectSettingsPath(),
|
||||||
|
tomlStringify(projectSettings)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,7 +3,7 @@ import {
|
|||||||
faArrowUp,
|
faArrowUp,
|
||||||
faCircle,
|
faCircle,
|
||||||
} from '@fortawesome/free-solid-svg-icons'
|
} from '@fortawesome/free-solid-svg-icons'
|
||||||
import { type ProjectWithEntryPointMetadata } from 'lib/types'
|
import { Project } from 'wasm-lib/kcl/bindings/Project'
|
||||||
|
|
||||||
const DESC = ':desc'
|
const DESC = ':desc'
|
||||||
|
|
||||||
@ -27,10 +27,7 @@ export function getNextSearchParams(currentSort: string, newSort: string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function getSortFunction(sortBy: string) {
|
export function getSortFunction(sortBy: string) {
|
||||||
const sortByName = (
|
const sortByName = (a: Project, b: Project) => {
|
||||||
a: ProjectWithEntryPointMetadata,
|
|
||||||
b: ProjectWithEntryPointMetadata
|
|
||||||
) => {
|
|
||||||
if (a.name && b.name) {
|
if (a.name && b.name) {
|
||||||
return sortBy.includes('desc')
|
return sortBy.includes('desc')
|
||||||
? a.name.localeCompare(b.name)
|
? a.name.localeCompare(b.name)
|
||||||
@ -39,16 +36,13 @@ export function getSortFunction(sortBy: string) {
|
|||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
const sortByModified = (
|
const sortByModified = (a: Project, b: Project) => {
|
||||||
a: ProjectWithEntryPointMetadata,
|
if (a.metadata?.modified && b.metadata?.modified) {
|
||||||
b: ProjectWithEntryPointMetadata
|
const aDate = new Date(a.metadata.modified)
|
||||||
) => {
|
const bDate = new Date(b.metadata.modified)
|
||||||
if (a.entrypointMetadata?.mtime && b.entrypointMetadata?.mtime) {
|
|
||||||
return !sortBy || sortBy.includes('desc')
|
return !sortBy || sortBy.includes('desc')
|
||||||
? b.entrypointMetadata.mtime.getTime() -
|
? bDate.getTime() - aDate.getTime()
|
||||||
a.entrypointMetadata.mtime.getTime()
|
: aDate.getTime() - bDate.getTime()
|
||||||
: a.entrypointMetadata.mtime.getTime() -
|
|
||||||
b.entrypointMetadata.mtime.getTime()
|
|
||||||
}
|
}
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
128
src/lib/tauri.ts
Normal file
@ -0,0 +1,128 @@
|
|||||||
|
// This file contains wrappers around the tauri commands we define in rust code.
|
||||||
|
|
||||||
|
import { Models } from '@kittycad/lib/dist/types/src'
|
||||||
|
import { invoke } from '@tauri-apps/api/core'
|
||||||
|
import { Configuration } from 'wasm-lib/kcl/bindings/Configuration'
|
||||||
|
import { ProjectConfiguration } from 'wasm-lib/kcl/bindings/ProjectConfiguration'
|
||||||
|
import { Project } from 'wasm-lib/kcl/bindings/Project'
|
||||||
|
import { FileEntry } from 'wasm-lib/kcl/bindings/FileEntry'
|
||||||
|
|
||||||
|
// Get the initial default dir for holding all projects.
|
||||||
|
export async function getInitialDefaultDir(): Promise<string> {
|
||||||
|
return invoke<string>('get_initial_default_dir')
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function showInFolder(path: string | undefined): Promise<void> {
|
||||||
|
if (!path) {
|
||||||
|
console.error('path is undefined cannot call tauri showInFolder')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
return await invoke('show_in_folder', { path })
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function initializeProjectDirectory(
|
||||||
|
settings: Configuration
|
||||||
|
): Promise<string> {
|
||||||
|
return await invoke<string>('initialize_project_directory', {
|
||||||
|
configuration: settings,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function createNewProjectDirectory(
|
||||||
|
projectName: string,
|
||||||
|
initialCode?: string,
|
||||||
|
configuration?: Configuration
|
||||||
|
): Promise<Project> {
|
||||||
|
if (!configuration) {
|
||||||
|
configuration = await readAppSettingsFile()
|
||||||
|
}
|
||||||
|
return await invoke<Project>('create_new_project_directory', {
|
||||||
|
configuration,
|
||||||
|
projectName,
|
||||||
|
initialCode,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function listProjects(
|
||||||
|
configuration?: Configuration
|
||||||
|
): Promise<Project[]> {
|
||||||
|
if (!configuration) {
|
||||||
|
configuration = await readAppSettingsFile()
|
||||||
|
}
|
||||||
|
return await invoke<Project[]>('list_projects', { configuration })
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function getProjectInfo(
|
||||||
|
projectName: string,
|
||||||
|
configuration?: Configuration
|
||||||
|
): Promise<Project> {
|
||||||
|
if (!configuration) {
|
||||||
|
configuration = await readAppSettingsFile()
|
||||||
|
}
|
||||||
|
return await invoke<Project>('get_project_info', {
|
||||||
|
configuration,
|
||||||
|
projectName,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function login(host: string): Promise<string> {
|
||||||
|
return await invoke('login', { host })
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function getUser(
|
||||||
|
token: string | undefined,
|
||||||
|
host: string
|
||||||
|
): Promise<Models['User_type'] | Record<'error_code', unknown> | void> {
|
||||||
|
if (!token) {
|
||||||
|
console.error('token is undefined cannot call tauri getUser')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
return await invoke<Models['User_type'] | Record<'error_code', unknown>>(
|
||||||
|
'get_user',
|
||||||
|
{
|
||||||
|
token: token,
|
||||||
|
hostname: host,
|
||||||
|
}
|
||||||
|
).catch((err) => console.error('error from Tauri getUser', err))
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function readDirRecursive(path: string): Promise<FileEntry[]> {
|
||||||
|
return await invoke<FileEntry[]>('read_dir_recursive', { path })
|
||||||
|
}
|
||||||
|
|
||||||
|
// Read the contents of the app settings.
|
||||||
|
export async function readAppSettingsFile(): Promise<Configuration> {
|
||||||
|
return await invoke<Configuration>('read_app_settings_file')
|
||||||
|
}
|
||||||
|
|
||||||
|
// Write the contents of the app settings.
|
||||||
|
export async function writeAppSettingsFile(
|
||||||
|
settings: Configuration
|
||||||
|
): Promise<void> {
|
||||||
|
return await invoke('write_app_settings_file', { configuration: settings })
|
||||||
|
}
|
||||||
|
|
||||||
|
// Read project settings file.
|
||||||
|
export async function readProjectSettingsFile(
|
||||||
|
appSettings: Configuration,
|
||||||
|
projectName: string
|
||||||
|
): Promise<ProjectConfiguration> {
|
||||||
|
return await invoke<ProjectConfiguration>('read_project_settings_file', {
|
||||||
|
appSettings,
|
||||||
|
projectName,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// Write project settings file.
|
||||||
|
export async function writeProjectSettingsFile(
|
||||||
|
appSettings: Configuration,
|
||||||
|
projectName: string,
|
||||||
|
settings: ProjectConfiguration
|
||||||
|
): Promise<void> {
|
||||||
|
return await invoke('write_project_settings_file', {
|
||||||
|
appSettings,
|
||||||
|
projectName,
|
||||||
|
configuration: settings,
|
||||||
|
})
|
||||||
|
}
|
@ -1,11 +1,4 @@
|
|||||||
import {
|
import { getNextProjectIndex, interpolateProjectNameWithIndex } from './tauriFS'
|
||||||
deepFileFilter,
|
|
||||||
getNextProjectIndex,
|
|
||||||
getPartsCount,
|
|
||||||
interpolateProjectNameWithIndex,
|
|
||||||
isRelevantFileOrDir,
|
|
||||||
} from './tauriFS'
|
|
||||||
import type { FileEntry } from './types'
|
|
||||||
import { MAX_PADDING } from './constants'
|
import { MAX_PADDING } from './constants'
|
||||||
|
|
||||||
describe('Test project name utility functions', () => {
|
describe('Test project name utility functions', () => {
|
||||||
@ -31,18 +24,22 @@ describe('Test project name utility functions', () => {
|
|||||||
{
|
{
|
||||||
name: 'new-project-04.kcl',
|
name: 'new-project-04.kcl',
|
||||||
path: '/projects/new-project-04.kcl',
|
path: '/projects/new-project-04.kcl',
|
||||||
|
children: [],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'new-project-007.kcl',
|
name: 'new-project-007.kcl',
|
||||||
path: '/projects/new-project-007.kcl',
|
path: '/projects/new-project-007.kcl',
|
||||||
|
children: [],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'new-project-05.kcl',
|
name: 'new-project-05.kcl',
|
||||||
path: '/projects/new-project-05.kcl',
|
path: '/projects/new-project-05.kcl',
|
||||||
|
children: [],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'new-project-0.kcl',
|
name: 'new-project-0.kcl',
|
||||||
path: '/projects/new-project-0.kcl',
|
path: '/projects/new-project-0.kcl',
|
||||||
|
children: [],
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
|
|
||||||
@ -50,101 +47,3 @@ describe('Test project name utility functions', () => {
|
|||||||
expect(getNextProjectIndex('new-project-$n', testFiles)).toBe(8)
|
expect(getNextProjectIndex('new-project-$n', testFiles)).toBe(8)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('Test file tree utility functions', () => {
|
|
||||||
const baseFiles: FileEntry[] = [
|
|
||||||
{
|
|
||||||
name: 'show-me.kcl',
|
|
||||||
path: '/projects/show-me.kcl',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'hide-me.jpg',
|
|
||||||
path: '/projects/hide-me.jpg',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: '.gitignore',
|
|
||||||
path: '/projects/.gitignore',
|
|
||||||
},
|
|
||||||
]
|
|
||||||
|
|
||||||
const filteredBaseFiles: FileEntry[] = [
|
|
||||||
{
|
|
||||||
name: 'show-me.kcl',
|
|
||||||
path: '/projects/show-me.kcl',
|
|
||||||
},
|
|
||||||
]
|
|
||||||
|
|
||||||
it('Only includes files relevant to the project in a flat directory', () => {
|
|
||||||
expect(deepFileFilter(baseFiles, isRelevantFileOrDir)).toEqual(
|
|
||||||
filteredBaseFiles
|
|
||||||
)
|
|
||||||
})
|
|
||||||
|
|
||||||
const nestedFiles: FileEntry[] = [
|
|
||||||
...baseFiles,
|
|
||||||
{
|
|
||||||
name: 'show-me',
|
|
||||||
path: '/projects/show-me',
|
|
||||||
children: [
|
|
||||||
{
|
|
||||||
name: 'show-me-nested',
|
|
||||||
path: '/projects/show-me/show-me-nested',
|
|
||||||
children: baseFiles,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'hide-me',
|
|
||||||
path: '/projects/show-me/hide-me',
|
|
||||||
children: baseFiles.filter((file) => file.name !== 'show-me.kcl'),
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'hide-me',
|
|
||||||
path: '/projects/hide-me',
|
|
||||||
children: baseFiles.filter((file) => file.name !== 'show-me.kcl'),
|
|
||||||
},
|
|
||||||
]
|
|
||||||
|
|
||||||
const filteredNestedFiles: FileEntry[] = [
|
|
||||||
...filteredBaseFiles,
|
|
||||||
{
|
|
||||||
name: 'show-me',
|
|
||||||
path: '/projects/show-me',
|
|
||||||
children: [
|
|
||||||
{
|
|
||||||
name: 'show-me-nested',
|
|
||||||
path: '/projects/show-me/show-me-nested',
|
|
||||||
children: filteredBaseFiles,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
]
|
|
||||||
|
|
||||||
it('Only includes directories that include files relevant to the project in a nested directory', () => {
|
|
||||||
expect(deepFileFilter(nestedFiles, isRelevantFileOrDir)).toEqual(
|
|
||||||
filteredNestedFiles
|
|
||||||
)
|
|
||||||
})
|
|
||||||
|
|
||||||
const withHiddenDir: FileEntry[] = [
|
|
||||||
...baseFiles,
|
|
||||||
{
|
|
||||||
name: '.hide-me',
|
|
||||||
path: '/projects/.hide-me',
|
|
||||||
children: baseFiles,
|
|
||||||
},
|
|
||||||
]
|
|
||||||
|
|
||||||
it(`Hides folders that begin with a ".", even if they contain relevant files`, () => {
|
|
||||||
expect(deepFileFilter(withHiddenDir, isRelevantFileOrDir)).toEqual(
|
|
||||||
filteredBaseFiles
|
|
||||||
)
|
|
||||||
})
|
|
||||||
|
|
||||||
it(`Properly counts the number of relevant files and directories in a project`, () => {
|
|
||||||
expect(getPartsCount(nestedFiles)).toEqual({
|
|
||||||
kclFileCount: 2,
|
|
||||||
kclDirCount: 2,
|
|
||||||
})
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
@ -1,154 +1,19 @@
|
|||||||
import {
|
import { appConfigDir } from '@tauri-apps/api/path'
|
||||||
mkdir,
|
|
||||||
exists,
|
|
||||||
readTextFile,
|
|
||||||
writeTextFile,
|
|
||||||
stat,
|
|
||||||
} from '@tauri-apps/plugin-fs'
|
|
||||||
import { invoke } from '@tauri-apps/api/core'
|
|
||||||
import {
|
|
||||||
appConfigDir,
|
|
||||||
documentDir,
|
|
||||||
homeDir,
|
|
||||||
join,
|
|
||||||
sep,
|
|
||||||
} from '@tauri-apps/api/path'
|
|
||||||
import { isTauri } from './isTauri'
|
import { isTauri } from './isTauri'
|
||||||
import type { FileEntry, ProjectWithEntryPointMetadata } from 'lib/types'
|
import type { FileEntry } from 'lib/types'
|
||||||
import {
|
import {
|
||||||
FILE_EXT,
|
|
||||||
INDEX_IDENTIFIER,
|
INDEX_IDENTIFIER,
|
||||||
MAX_PADDING,
|
MAX_PADDING,
|
||||||
ONBOARDING_PROJECT_NAME,
|
ONBOARDING_PROJECT_NAME,
|
||||||
PROJECT_ENTRYPOINT,
|
PROJECT_ENTRYPOINT,
|
||||||
PROJECT_FOLDER,
|
|
||||||
RELEVANT_FILE_TYPES,
|
|
||||||
SETTINGS_FILE_EXT,
|
|
||||||
} from 'lib/constants'
|
} from 'lib/constants'
|
||||||
import { SaveSettingsPayload, SettingsLevel } from './settings/settingsTypes'
|
|
||||||
import { initPromise, tomlParse } from 'lang/wasm'
|
|
||||||
import { bracket } from './exampleKcl'
|
import { bracket } from './exampleKcl'
|
||||||
import { paths } from './paths'
|
import { paths } from './paths'
|
||||||
|
import {
|
||||||
type PathWithPossibleError = {
|
createNewProjectDirectory,
|
||||||
path: string | null
|
listProjects,
|
||||||
error: Error | null
|
readAppSettingsFile,
|
||||||
}
|
} from './tauri'
|
||||||
|
|
||||||
export async function getInitialDefaultDir() {
|
|
||||||
if (!isTauri()) return ''
|
|
||||||
let dir
|
|
||||||
try {
|
|
||||||
dir = await documentDir()
|
|
||||||
} catch (e) {
|
|
||||||
dir = await join(await homeDir(), 'Documents') // for headless Linux (eg. Github Actions)
|
|
||||||
}
|
|
||||||
|
|
||||||
return await join(dir, PROJECT_FOLDER)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Initializes the project directory and returns the path
|
|
||||||
// with any Errors that occurred
|
|
||||||
export async function initializeProjectDirectory(
|
|
||||||
directory: string
|
|
||||||
): Promise<PathWithPossibleError> {
|
|
||||||
let returnValue: PathWithPossibleError = {
|
|
||||||
path: null,
|
|
||||||
error: null,
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!isTauri()) return returnValue
|
|
||||||
|
|
||||||
if (directory) {
|
|
||||||
returnValue = await testAndCreateDir(directory, returnValue)
|
|
||||||
}
|
|
||||||
|
|
||||||
// If the directory from settings does not exist or could not be created,
|
|
||||||
// use the default directory
|
|
||||||
if (returnValue.path === null) {
|
|
||||||
const INITIAL_DEFAULT_DIR = await getInitialDefaultDir()
|
|
||||||
const defaultReturnValue = await testAndCreateDir(
|
|
||||||
INITIAL_DEFAULT_DIR,
|
|
||||||
returnValue,
|
|
||||||
{
|
|
||||||
exists: 'Error checking default directory.',
|
|
||||||
create: 'Error creating default directory.',
|
|
||||||
}
|
|
||||||
)
|
|
||||||
returnValue.path = defaultReturnValue.path
|
|
||||||
returnValue.error =
|
|
||||||
returnValue.error === null ? defaultReturnValue.error : returnValue.error
|
|
||||||
}
|
|
||||||
|
|
||||||
return returnValue
|
|
||||||
}
|
|
||||||
|
|
||||||
async function testAndCreateDir(
|
|
||||||
directory: string,
|
|
||||||
returnValue = {
|
|
||||||
path: null,
|
|
||||||
error: null,
|
|
||||||
} as PathWithPossibleError,
|
|
||||||
errorMessages = {
|
|
||||||
exists:
|
|
||||||
'Error checking directory at path from saved settings. Using default.',
|
|
||||||
create:
|
|
||||||
'Error creating directory at path from saved settings. Using default.',
|
|
||||||
}
|
|
||||||
): Promise<PathWithPossibleError> {
|
|
||||||
const dirExists = await exists(directory).catch((e) => {
|
|
||||||
console.error(`Error checking directory ${directory}. Original error:`, e)
|
|
||||||
return new Error(errorMessages.exists)
|
|
||||||
})
|
|
||||||
|
|
||||||
if (dirExists instanceof Error) {
|
|
||||||
returnValue.error = dirExists
|
|
||||||
} else if (dirExists === false) {
|
|
||||||
const newDirCreated = await mkdir(directory, { recursive: true }).catch(
|
|
||||||
(e) => {
|
|
||||||
console.error(
|
|
||||||
`Error creating directory ${directory}. Original error:`,
|
|
||||||
e
|
|
||||||
)
|
|
||||||
return new Error(errorMessages.create)
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
if (newDirCreated instanceof Error) {
|
|
||||||
returnValue.error = newDirCreated
|
|
||||||
} else {
|
|
||||||
returnValue.path = directory
|
|
||||||
}
|
|
||||||
} else if (dirExists === true) {
|
|
||||||
returnValue.path = directory
|
|
||||||
}
|
|
||||||
|
|
||||||
return returnValue
|
|
||||||
}
|
|
||||||
|
|
||||||
export function isProjectDirectory(fileOrDir: Partial<FileEntry>) {
|
|
||||||
return (
|
|
||||||
fileOrDir.children?.length &&
|
|
||||||
fileOrDir.children.some((child) => child.name === PROJECT_ENTRYPOINT)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Read the contents of a directory
|
|
||||||
// and return the valid projects
|
|
||||||
export async function getProjectsInDir(projectDir: string) {
|
|
||||||
const readProjects = (
|
|
||||||
await invoke<FileEntry[]>('read_dir_recursive', { path: projectDir })
|
|
||||||
).filter(isProjectDirectory)
|
|
||||||
|
|
||||||
const projectsWithMetadata = await Promise.all(
|
|
||||||
readProjects.map(async (p) => ({
|
|
||||||
entrypointMetadata: await stat(await join(p.path, PROJECT_ENTRYPOINT)),
|
|
||||||
...p,
|
|
||||||
}))
|
|
||||||
)
|
|
||||||
|
|
||||||
return projectsWithMetadata
|
|
||||||
}
|
|
||||||
|
|
||||||
export const isHidden = (fileOrDir: FileEntry) =>
|
export const isHidden = (fileOrDir: FileEntry) =>
|
||||||
!!fileOrDir.name?.startsWith('.')
|
!!fileOrDir.name?.startsWith('.')
|
||||||
@ -156,97 +21,6 @@ export const isHidden = (fileOrDir: FileEntry) =>
|
|||||||
export const isDir = (fileOrDir: FileEntry) =>
|
export const isDir = (fileOrDir: FileEntry) =>
|
||||||
'children' in fileOrDir && fileOrDir.children !== undefined
|
'children' in fileOrDir && fileOrDir.children !== undefined
|
||||||
|
|
||||||
export function deepFileFilter(
|
|
||||||
entries: FileEntry[],
|
|
||||||
filterFn: (f: FileEntry) => boolean
|
|
||||||
): FileEntry[] {
|
|
||||||
const filteredEntries: FileEntry[] = []
|
|
||||||
for (const fileOrDir of entries) {
|
|
||||||
if ('children' in fileOrDir && fileOrDir.children !== undefined) {
|
|
||||||
const filteredChildren = deepFileFilter(fileOrDir.children, filterFn)
|
|
||||||
if (filterFn(fileOrDir)) {
|
|
||||||
filteredEntries.push({
|
|
||||||
...fileOrDir,
|
|
||||||
children: filteredChildren,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
} else if (filterFn(fileOrDir)) {
|
|
||||||
filteredEntries.push(fileOrDir)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return filteredEntries
|
|
||||||
}
|
|
||||||
|
|
||||||
export function deepFileFilterFlat(
|
|
||||||
entries: FileEntry[],
|
|
||||||
filterFn: (f: FileEntry) => boolean
|
|
||||||
): FileEntry[] {
|
|
||||||
const filteredEntries: FileEntry[] = []
|
|
||||||
for (const fileOrDir of entries) {
|
|
||||||
if ('children' in fileOrDir && fileOrDir.children !== undefined) {
|
|
||||||
const filteredChildren = deepFileFilterFlat(fileOrDir.children, filterFn)
|
|
||||||
if (filterFn(fileOrDir)) {
|
|
||||||
filteredEntries.push({
|
|
||||||
...fileOrDir,
|
|
||||||
children: filteredChildren,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
filteredEntries.push(...filteredChildren)
|
|
||||||
} else if (filterFn(fileOrDir)) {
|
|
||||||
filteredEntries.push(fileOrDir)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return filteredEntries
|
|
||||||
}
|
|
||||||
|
|
||||||
// Read the contents of a project directory
|
|
||||||
// and return all relevant files and sub-directories recursively
|
|
||||||
export async function readProject(projectDir: string) {
|
|
||||||
const readFiles = await invoke<FileEntry[]>('read_dir_recursive', {
|
|
||||||
path: projectDir,
|
|
||||||
})
|
|
||||||
|
|
||||||
return deepFileFilter(readFiles, isRelevantFileOrDir)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Given a read project, return the number of .kcl files,
|
|
||||||
// both in the root directory and in sub-directories,
|
|
||||||
// and folders that contain at least one .kcl file
|
|
||||||
export function getPartsCount(project: FileEntry[]) {
|
|
||||||
const flatProject = deepFileFilterFlat(project, isRelevantFileOrDir)
|
|
||||||
|
|
||||||
const kclFileCount = flatProject.filter((f) =>
|
|
||||||
f.name?.endsWith(FILE_EXT)
|
|
||||||
).length
|
|
||||||
const kclDirCount = flatProject.filter((f) => f.children !== undefined).length
|
|
||||||
|
|
||||||
return {
|
|
||||||
kclFileCount,
|
|
||||||
kclDirCount,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Determines if a file or directory is relevant to the project
|
|
||||||
// i.e. not a hidden file or directory, and is a relevant file type
|
|
||||||
// or contains at least one relevant file (even if it's nested)
|
|
||||||
// or is a completely empty directory
|
|
||||||
export function isRelevantFileOrDir(fileOrDir: FileEntry) {
|
|
||||||
let isRelevantDir = false
|
|
||||||
if ('children' in fileOrDir && fileOrDir.children !== undefined) {
|
|
||||||
isRelevantDir =
|
|
||||||
!isHidden(fileOrDir) &&
|
|
||||||
(fileOrDir.children.some(isRelevantFileOrDir) ||
|
|
||||||
fileOrDir.children.length === 0)
|
|
||||||
}
|
|
||||||
const isRelevantFile =
|
|
||||||
!isHidden(fileOrDir) &&
|
|
||||||
RELEVANT_FILE_TYPES.some((ext) => fileOrDir.name?.endsWith(ext))
|
|
||||||
|
|
||||||
return (
|
|
||||||
(isDir(fileOrDir) && isRelevantDir) || (!isDir(fileOrDir) && isRelevantFile)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Deeply sort the files and directories in a project like VS Code does:
|
// Deeply sort the files and directories in a project like VS Code does:
|
||||||
// The main.kcl file is always first, then files, then directories
|
// The main.kcl file is always first, then files, then directories
|
||||||
// Files and directories are sorted alphabetically
|
// Files and directories are sorted alphabetically
|
||||||
@ -279,47 +53,6 @@ export function sortProject(project: FileEntry[]): FileEntry[] {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// Creates a new file in the default directory with the default project name
|
|
||||||
// Returns the path to the new file
|
|
||||||
export async function createNewProject(
|
|
||||||
path: string,
|
|
||||||
initCode = ''
|
|
||||||
): Promise<ProjectWithEntryPointMetadata> {
|
|
||||||
if (!isTauri) {
|
|
||||||
throw new Error('createNewProject() can only be called from a Tauri app')
|
|
||||||
}
|
|
||||||
|
|
||||||
const dirExists = await exists(path)
|
|
||||||
if (!dirExists) {
|
|
||||||
await mkdir(path, { recursive: true }).catch((err) => {
|
|
||||||
console.error('Error creating new directory:', err)
|
|
||||||
throw err
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
await writeTextFile(await join(path, PROJECT_ENTRYPOINT), initCode).catch(
|
|
||||||
(err) => {
|
|
||||||
console.error('Error creating new file:', err)
|
|
||||||
throw err
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
const m = await stat(path)
|
|
||||||
|
|
||||||
return {
|
|
||||||
name: path.slice(path.lastIndexOf(sep()) + 1),
|
|
||||||
path: path,
|
|
||||||
entrypointMetadata: m,
|
|
||||||
children: [
|
|
||||||
{
|
|
||||||
name: PROJECT_ENTRYPOINT,
|
|
||||||
path: await join(path, PROJECT_ENTRYPOINT),
|
|
||||||
children: [],
|
|
||||||
},
|
|
||||||
],
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// create a regex to match the project name
|
// create a regex to match the project name
|
||||||
// replacing any instances of "$n" with a regex to match any number
|
// replacing any instances of "$n" with a regex to match any number
|
||||||
function interpolateProjectName(projectName: string) {
|
function interpolateProjectName(projectName: string) {
|
||||||
@ -373,55 +106,6 @@ function getPaddedIdentifierRegExp() {
|
|||||||
return new RegExp(`${escapedIdentifier}(${escapedIdentifier.slice(-1)}*)`)
|
return new RegExp(`${escapedIdentifier}(${escapedIdentifier.slice(-1)}*)`)
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getUserSettingsFilePath(
|
|
||||||
filename: string = SETTINGS_FILE_EXT
|
|
||||||
) {
|
|
||||||
const dir = await appConfigDir()
|
|
||||||
return await join(dir, filename)
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function readSettingsFile(
|
|
||||||
path: string
|
|
||||||
): Promise<Partial<SaveSettingsPayload>> {
|
|
||||||
const dir = path.slice(0, path.lastIndexOf(sep()))
|
|
||||||
|
|
||||||
const dirExists = await exists(dir)
|
|
||||||
if (!dirExists) {
|
|
||||||
await mkdir(dir, { recursive: true })
|
|
||||||
}
|
|
||||||
|
|
||||||
const settingsExist = dirExists ? await exists(path) : false
|
|
||||||
|
|
||||||
if (!settingsExist) {
|
|
||||||
console.log(`Settings file does not exist at ${path}`)
|
|
||||||
return {}
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
await initPromise
|
|
||||||
const settings = await readTextFile(path)
|
|
||||||
// We expect the settings to be under a top-level [settings] key
|
|
||||||
return tomlParse(settings).settings as Partial<SaveSettingsPayload>
|
|
||||||
} catch (e) {
|
|
||||||
console.error('Error reading settings file:', e)
|
|
||||||
return {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function getSettingsFilePaths(
|
|
||||||
projectPath?: string
|
|
||||||
): Promise<Partial<Record<SettingsLevel, string>>> {
|
|
||||||
const { user, project } = await getSettingsFolderPaths(projectPath)
|
|
||||||
|
|
||||||
return {
|
|
||||||
user: user + 'user' + SETTINGS_FILE_EXT,
|
|
||||||
project:
|
|
||||||
project !== undefined
|
|
||||||
? project + (isTauri() ? sep() : '/') + 'project' + SETTINGS_FILE_EXT
|
|
||||||
: undefined,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function getSettingsFolderPaths(projectPath?: string) {
|
export async function getSettingsFolderPaths(projectPath?: string) {
|
||||||
const user = isTauri() ? await appConfigDir() : '/'
|
const user = isTauri() ? await appConfigDir() : '/'
|
||||||
const project = projectPath !== undefined ? projectPath : undefined
|
const project = projectPath !== undefined ? projectPath : undefined
|
||||||
@ -433,18 +117,15 @@ export async function getSettingsFolderPaths(projectPath?: string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function createAndOpenNewProject(
|
export async function createAndOpenNewProject(
|
||||||
projectDirectory: string,
|
|
||||||
navigate: (path: string) => void
|
navigate: (path: string) => void
|
||||||
) {
|
) {
|
||||||
const projects = await getProjectsInDir(projectDirectory)
|
const configuration = await readAppSettingsFile()
|
||||||
const nextIndex = await getNextProjectIndex(ONBOARDING_PROJECT_NAME, projects)
|
const projects = await listProjects(configuration)
|
||||||
|
const nextIndex = getNextProjectIndex(ONBOARDING_PROJECT_NAME, projects)
|
||||||
const name = interpolateProjectNameWithIndex(
|
const name = interpolateProjectNameWithIndex(
|
||||||
ONBOARDING_PROJECT_NAME,
|
ONBOARDING_PROJECT_NAME,
|
||||||
nextIndex
|
nextIndex
|
||||||
)
|
)
|
||||||
const newFile = await createNewProject(
|
const newFile = await createNewProjectDirectory(name, bracket, configuration)
|
||||||
await join(projectDirectory, name),
|
|
||||||
bracket
|
|
||||||
)
|
|
||||||
navigate(`${paths.FILE}/${encodeURIComponent(newFile.path)}`)
|
navigate(`${paths.FILE}/${encodeURIComponent(newFile.path)}`)
|
||||||
}
|
}
|
||||||
|
@ -1,9 +1,26 @@
|
|||||||
|
import { AppTheme } from 'wasm-lib/kcl/bindings/AppTheme'
|
||||||
|
|
||||||
export enum Themes {
|
export enum Themes {
|
||||||
Light = 'light',
|
Light = 'light',
|
||||||
Dark = 'dark',
|
Dark = 'dark',
|
||||||
System = 'system',
|
System = 'system',
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function appThemeToTheme(
|
||||||
|
theme: AppTheme | undefined
|
||||||
|
): Themes | undefined {
|
||||||
|
switch (theme) {
|
||||||
|
case 'light':
|
||||||
|
return Themes.Light
|
||||||
|
case 'dark':
|
||||||
|
return Themes.Dark
|
||||||
|
case 'system':
|
||||||
|
return Themes.System
|
||||||
|
default:
|
||||||
|
return undefined
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Get the theme from the system settings manually
|
// Get the theme from the system settings manually
|
||||||
export function getSystemTheme(): Exclude<Themes, 'system'> {
|
export function getSystemTheme(): Exclude<Themes, 'system'> {
|
||||||
return typeof globalThis.window !== 'undefined' &&
|
return typeof globalThis.window !== 'undefined' &&
|
||||||
@ -23,6 +40,17 @@ export function setThemeClass(theme: Themes) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Returns the resolved theme in use (Dark || Light)
|
||||||
|
export function getResolvedTheme(theme: Themes) {
|
||||||
|
return theme === Themes.System ? getSystemTheme() : theme
|
||||||
|
}
|
||||||
|
|
||||||
|
// Returns the opposing theme
|
||||||
|
export function getOppositeTheme(theme: Themes) {
|
||||||
|
const resolvedTheme = getResolvedTheme(theme)
|
||||||
|
return resolvedTheme === Themes.Dark ? Themes.Light : Themes.Dark
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The engine takes RGBA values from 0-1
|
* The engine takes RGBA values from 0-1
|
||||||
* So we convert from the conventional 0-255 found in Figma
|
* So we convert from the conventional 0-255 found in Figma
|
||||||
@ -30,7 +58,7 @@ export function setThemeClass(theme: Themes) {
|
|||||||
* @returns { r: number, g: number, b: number, a: number }
|
* @returns { r: number, g: number, b: number, a: number }
|
||||||
*/
|
*/
|
||||||
export function getThemeColorForEngine(theme: Themes) {
|
export function getThemeColorForEngine(theme: Themes) {
|
||||||
const resolvedTheme = theme === Themes.System ? getSystemTheme() : theme
|
const resolvedTheme = getResolvedTheme(theme)
|
||||||
const dark = 28 / 255
|
const dark = 28 / 255
|
||||||
const light = 249 / 255
|
const light = 249 / 255
|
||||||
return resolvedTheme === Themes.Dark
|
return resolvedTheme === Themes.Dark
|
||||||
|