fix: saving off work

This commit is contained in:
Kevin
2025-06-23 14:02:39 -05:00
parent d8ed24f463
commit 6abc35e2fc
10 changed files with 63 additions and 8 deletions

View File

@ -9,6 +9,7 @@ import {
TEST_COLORS,
commonPoints,
getUtils,
enableConsoleLogEverything,
} from '@e2e/playwright/test-utils'
import { expect, test } from '@e2e/playwright/zoo-test'
@ -178,7 +179,19 @@ test.describe('Basic sketch', () => {
cmdBar,
scene,
editor,
tronApp,
}) => {
// await tronApp.cleanProjectDir({
// app: {
// appearance: {
// theme: 'light',
// },
// },
// })
enableConsoleLogEverything({
page,
tronApp,
})
await doBasicSketch(page, ['code'], { cmdBar, scene, homePage, editor })
})
@ -188,6 +201,7 @@ test.describe('Basic sketch', () => {
cmdBar,
scene,
editor,
tronApp,
}) => {
// Load the app with the code panes
await page.addInitScript(async (persistModelingContext) => {

View File

@ -8,10 +8,14 @@ export const TEST_SETTINGS_KEY = '/settings.toml'
export const TEST_SETTINGS: DeepPartial<Settings> = {
app: {
appearance: {
theme: Themes.Dark,
theme: Themes.Light,
},
onboarding_status: 'dismissed',
show_debug_panel: true,
// Tests were written before this setting existed.
// It's true by default because it's a good user experience, but
// these tests require it to be false.
fixed_size_grid: false,
},
modeling: {
enable_ssao: false,

View File

@ -880,10 +880,6 @@ export async function setup(
},
...TEST_SETTINGS.project,
onboarding_status: 'dismissed',
// Tests were written before this setting existed.
// It's true by default because it's a good user experience, but
// these tests require it to be false.
fixed_size_grid: false,
},
project: {
...TEST_SETTINGS.project,

View File

@ -67,6 +67,7 @@ pub struct Settings {
#[derive(Debug, Default, Clone, Deserialize, Serialize, JsonSchema, ts_rs::TS, PartialEq, Validate)]
#[ts(export)]
#[serde(rename_all = "snake_case")]
#[serde(deny_unknown_fields)]
pub struct AppSettings {
/// The settings for the appearance of the app.
#[serde(default, skip_serializing_if = "is_default")]
@ -96,7 +97,6 @@ pub struct AppSettings {
pub show_debug_panel: bool,
/// If true, the grid cells will be fixed-size, where the width is the user's default length unit.
/// If false, the grid's size will scale as the user zooms in and out.
#[serde(default = "make_it_so", skip_serializing_if = "is_default")]
pub fixed_size_grid: bool,
}

View File

@ -69,7 +69,10 @@ export async function executeAst({
path?: string
}): Promise<ExecutionResult> {
try {
console.log('YOLO')
const settings = await jsAppSettings()
console.log('LANG HELPERS', JSON.stringify(settings, null, 4))
const execState = await rustContext.execute(ast, settings, path)
await rustContext.waitForAllEngineCommands()

View File

@ -626,6 +626,7 @@ export const readAppSettingsFile = async () => {
const configToml = await window.electron.readFile(settingsPath, {
encoding: 'utf-8',
})
console.log('config toml', JSON.stringify(configToml, null, 4))
const parsedAppConfig = parseAppSettings(configToml)
if (err(parsedAppConfig)) {
return Promise.reject(parsedAppConfig)
@ -635,6 +636,7 @@ export const readAppSettingsFile = async () => {
parsedAppConfig.settings?.project?.directory
if (hasProjectDirectorySetting) {
console.log('parsed app config', JSON.stringify(parsedAppConfig, null, 4))
return parsedAppConfig
} else {
// inject the default project directory setting
@ -671,6 +673,7 @@ export const readAppSettingsFile = async () => {
),
},
}
console.log('MERGED', JSON.stringify(mergedDefaultConfig, null, 4))
return mergedDefaultConfig
}

View File

@ -51,6 +51,8 @@ export async function getProjectMetaByRouteId(
: readLocalStorageAppSettingsFile()
}
console.log('TEST SETTINGS UTILS', JSON.stringify(configuration, null, 4))
if (err(configuration)) return Promise.reject(configuration)
// Should not be possible but I guess logically it could be

View File

@ -257,6 +257,18 @@ export function createSettings() {
description: 'Toggle free camera while in sketch mode',
validate: (v) => typeof v === 'boolean',
}),
/**
* Fixed size grid
*/
fixedSizeGrid: new Setting<boolean>({
defaultValue: true,
hideOnLevel:'project',
description: 'If true, grid will be a 10x10 grid where each cell is the size of your default length unit. If false, the grid will get bigger as you zoom out and smaller as you zoom in.',
validate: (v) => typeof v === 'boolean',
commandConfig: {
inputType: 'boolean',
},
}),
onboardingStatus: new Setting<OnboardingStatus>({
defaultValue: '',
// TODO: this could be better but we don't have a TS side real enum

View File

@ -51,6 +51,7 @@ const toUndefinedIfNull = (a: any): OmitNull<any> =>
export function configurationToSettingsPayload(
configuration: DeepPartial<Configuration>
): DeepPartial<SaveSettingsPayload> {
console.log('configuration', configuration)
return {
app: {
theme: appThemeToTheme(configuration?.settings?.app?.appearance?.theme),
@ -66,6 +67,7 @@ export function configurationToSettingsPayload(
configuration?.settings?.app?.allow_orbit_in_sketch_mode,
projectDirectory: configuration?.settings?.project?.directory,
showDebugPanel: configuration?.settings?.app?.show_debug_panel,
fixedSizeGrid: configuration.settings?.app?.fixed_size_grid
},
modeling: {
defaultUnit: configuration?.settings?.modeling?.base_unit,
@ -109,6 +111,7 @@ export function settingsPayloadToConfiguration(
stream_idle_mode: configuration?.app?.streamIdleMode,
allow_orbit_in_sketch_mode: configuration?.app?.allowOrbitInSketchMode,
show_debug_panel: configuration?.app?.showDebugPanel,
fixed_size_grid: configuration?.app?.fixedSizeGrid
},
modeling: {
base_unit: configuration?.modeling?.defaultUnit,
@ -327,11 +330,13 @@ export async function loadAndValidateSettings(
settingsNext.app.projectDirectory.default = await getInitialDefaultDir()
}
console.log("FUCK", appSettingsPayload)
settingsNext = setSettingsAtLevel(
settingsNext,
'user',
configurationToSettingsPayload(appSettingsPayload)
)
console.log("FUCK2", settingsNext)
// Load the project settings if they exist
if (projectPath) {
@ -365,10 +370,14 @@ export async function saveSettings(
await initPromise
const onDesktop = isDesktop()
console.log('all settings', allSettings)
// Get the user settings.
const jsAppSettings = getChangedSettingsAtLevel(allSettings, 'user')
const DOG = settingsPayloadToConfiguration(jsAppSettings)
console.log('CAT',jsAppSettings)
console.log("DOG", DOG)
const appTomlString = serializeConfiguration(
settingsPayloadToConfiguration(jsAppSettings)
DOG
)
if (err(appTomlString)) return
@ -542,15 +551,26 @@ export function getSettingInputType(setting: Setting) {
}
export const jsAppSettings = async (): Promise<DeepPartial<Configuration>> => {
console.log("HERE!!!")
let jsAppSettings = default_app_settings()
console.log('old', JSON.stringify(jsAppSettings, null, 4))
console.log("NOT HERE!!!")
if (!TEST) {
// TODO: https://github.com/KittyCAD/modeling-app/issues/6445
const settings = await import('@src/lib/singletons').then((module) =>
module.getSettings()
)
)
console.log('here1', settings)
if (settings) {
console.log('here2', settings)
jsAppSettings = getAllCurrentSettings(settings)
console.log('here3')
console.log('JS APP SETTINGS', jsAppSettings)
console.log('JS APP SETTINGS', settings)
}
}
console.log('here4')
return settingsPayloadToConfiguration(jsAppSettings)
}

View File

@ -98,6 +98,7 @@ export const settingsMachine = setup({
input.rootContext.codeManager.writeCausedByAppCheckedInFileTreeFileSystemWatcher = true
const { currentProject, ...settings } = input.context
console.log('huh', settings)
const val = await saveSettings(settings, currentProject?.path)
if (input.toastCallback) {