Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

File based settings #1679

Merged
merged 56 commits into from
Mar 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
feb5afd
Rename GlobalStateContext to SettingsAuthContext
franknoirot Feb 5, 2024
e37e235
Naive initial impl of settings persistence to file system
franknoirot Feb 5, 2024
31b98e3
Merge branch 'main' into file-based-settings
franknoirot Feb 7, 2024
def0071
Update app identifier in tauri config
franknoirot Feb 8, 2024
b47bfba
Add "show in folder" tauri command
franknoirot Feb 8, 2024
772bd47
Load from and save to file system in Tauri app
franknoirot Feb 8, 2024
ced700e
Add documents drive to tauri permission scope
franknoirot Feb 8, 2024
4fc6954
Add recursive prop to default dir selection dialog
franknoirot Feb 8, 2024
a0efbc5
Add success toast to web restore defaults action
franknoirot Feb 8, 2024
b958bb7
Add a way to validate read-in settings
franknoirot Feb 8, 2024
7dca5ee
Update imports to use separate settings lib file
franknoirot Feb 8, 2024
40bc44a
Validate localStorage-loaded settings, combine error message
franknoirot Feb 8, 2024
d405442
Add a e2e test for validation
franknoirot Feb 8, 2024
ba0fb23
Clean up state state bugs
franknoirot Feb 8, 2024
3f751c6
Reverse validation looping so new users don't error
franknoirot Feb 8, 2024
d00a1f1
Merge branch 'main' into file-based-settings
franknoirot Feb 8, 2024
aa97975
Merge branch 'main' into file-based-settings
franknoirot Feb 8, 2024
d2f868b
update settingsMachine typegen to remove conflicts
franknoirot Feb 8, 2024
2f2c973
Merge branch 'main' into file-based-settings
franknoirot Feb 15, 2024
27d9229
Fmt
franknoirot Feb 15, 2024
e409a04
Fix TS errors
franknoirot Feb 15, 2024
4b4d50d
Merge branch 'main' into file-based-settings
franknoirot Mar 9, 2024
0d674e4
Fix import paths, etc post-merge
franknoirot Mar 11, 2024
aebe5f2
Merge branch 'main' into file-based-settings
franknoirot Mar 11, 2024
04bd1ea
Make default length units `mm` and 'metric'
franknoirot Mar 12, 2024
e4be642
Rename to SettingsAuth*
franknoirot Mar 12, 2024
7a12319
Merge main
franknoirot Mar 12, 2024
a45fd8d
cargo fmt
franknoirot Mar 12, 2024
3a22fb1
Merge branch 'main' into file-based-settings
franknoirot Mar 12, 2024
d2ae881
Revert Tauri config identifier change
franknoirot Mar 12, 2024
ff97622
Update clientSideInfra's baseUnits from settings
franknoirot Mar 12, 2024
59ee5fb
Break apart CommandBar and CommandBarProvider
franknoirot Mar 13, 2024
e33d116
Bugfix: don't validate defaultValue when it's not configured
franknoirot Mar 13, 2024
a3669ec
Allow some TauriFS functions to no-op from browser
franknoirot Mar 13, 2024
939ca2f
Sidestep circular deps by loading context and kclManager only from Re…
franknoirot Mar 13, 2024
17b6cae
Update broken import paths
franknoirot Mar 13, 2024
be8f3fa
Separate loaders from Router, load settings on every route
franknoirot Mar 13, 2024
57d7ba8
Break apart settings types, utils, and constants
franknoirot Mar 13, 2024
f679f36
Fix Jest tests by decoupling reliance on useLoaderData from SettingsA…
franknoirot Mar 13, 2024
022bc50
Fix up Router loader data with "layout routes"
franknoirot Mar 13, 2024
bc41d30
Move settings validation and toast to custom hook so the toast renders
franknoirot Mar 13, 2024
42be0f2
fmt
franknoirot Mar 13, 2024
d6f1d2f
Merge branch 'main' into file-based-settings
franknoirot Mar 13, 2024
d9e8d93
Use forks for Vitest
franknoirot Mar 13, 2024
937b627
Merge branch 'main' into file-based-settings
franknoirot Mar 13, 2024
aaf4647
Merge branch 'main' into file-based-settings
franknoirot Mar 14, 2024
c344224
$APPCONFIG !== $APPDATA only on Linux
franknoirot Mar 14, 2024
4cd57cb
Debugging on Linux
franknoirot Mar 14, 2024
1f4408c
Better directory validation, fix reset settings button
franknoirot Mar 14, 2024
515381b
Merge branch 'main' into file-based-settings
franknoirot Mar 14, 2024
a504b31
A snapshot a day keeps the bugs away! 📷🐛 (OS: ubuntu)
github-actions[bot] Mar 14, 2024
ed37fdb
defaultDirectory can be empty in browser
franknoirot Mar 14, 2024
94c338c
Merge branch 'main' into file-based-settings
franknoirot Mar 14, 2024
3f09d60
fmt
franknoirot Mar 14, 2024
0ff3776
A snapshot a day keeps the bugs away! 📷🐛 (OS: ubuntu)
github-actions[bot] Mar 14, 2024
5194011
re-trigger CI
franknoirot Mar 14, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 50 additions & 1 deletion e2e/playwright/flow-tests.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { secrets } from './secrets'
import { getUtils } from './test-utils'
import waitOn from 'wait-on'
import { Themes } from '../../src/lib/theme'
import { initialSettings } from '../../src/lib/settings/initialSettings'
import { roundOff } from 'lib/utils'
import { platform } from 'node:os'

/*
debug helper: unfortunately we do rely on exact coord mouse clicks in a few places
Expand Down Expand Up @@ -516,6 +516,55 @@ test('Auto complete works', async ({ page }) => {
|> xLine(5, %) // lin`)
})

// Stored settings validation test
test('Stored settings are validated and fall back to defaults', async ({
page,
context,
}) => {
// Override beforeEach test setup
// with corrupted settings
await context.addInitScript(async () => {
const storedSettings = JSON.parse(
localStorage.getItem('SETTINGS_PERSIST_KEY') || '{}'
)

// Corrupt the settings
storedSettings.baseUnit = 'invalid'
storedSettings.cameraControls = `() => alert('hack the planet')`
storedSettings.defaultDirectory = 123
storedSettings.defaultProjectName = false

localStorage.setItem('SETTINGS_PERSIST_KEY', JSON.stringify(storedSettings))
})

await page.setViewportSize({ width: 1200, height: 500 })
await page.goto('/', { waitUntil: 'domcontentloaded' })

// Check the toast appeared
await expect(
page.getByText(`Error validating persisted settings:`, {
exact: false,
})
).toBeVisible()

// Check the settings were reset
const storedSettings = JSON.parse(
await page.evaluate(
() => localStorage.getItem('SETTINGS_PERSIST_KEY') || '{}'
)
)
await expect(storedSettings.baseUnit).toBe(initialSettings.baseUnit)
await expect(storedSettings.cameraControls).toBe(
initialSettings.cameraControls
)
await expect(storedSettings.defaultDirectory).toBe(
initialSettings.defaultDirectory
)
await expect(storedSettings.defaultProjectName).toBe(
initialSettings.defaultProjectName
)
})

// Onboarding tests
test('Onboarding redirects and code updating', async ({ page, context }) => {
const u = getUtils(page)
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
23 changes: 22 additions & 1 deletion src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use std::io::Read;

use anyhow::Result;
use oauth2::TokenResponse;
use std::process::Command;
use tauri::{InvokeError, Manager};
const DEFAULT_HOST: &str = "https://api.kittycad.io";

Expand Down Expand Up @@ -142,6 +143,25 @@ async fn get_user(
Ok(user_info)
}

/// Open the selected path in the system file manager.
/// 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.
#[tauri::command]
fn show_in_folder(path: String) {
#[cfg(target_os = "windows")]
{
Command::new("explorer")
.args(["/select,", &path]) // The comma after select is not a typo
.spawn()
.unwrap();
}

#[cfg(target_os = "macos")]
{
Command::new("open").args(["-R", &path]).spawn().unwrap();
}
}

fn main() {
tauri::Builder::default()
.setup(|_app| {
Expand All @@ -158,7 +178,8 @@ fn main() {
get_user,
login,
read_toml,
read_txt_file
read_txt_file,
show_in_folder,
])
.plugin(tauri_plugin_fs_extra::init())
.run(tauri::generate_context!())
Expand Down
7 changes: 5 additions & 2 deletions src-tauri/tauri.conf.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@
"fs": {
"scope": [
"$HOME/**/*",
"$APPDATA/**/*"
"$APPCONFIG",
"$APPCONFIG/**/*",
"$DOCUMENT",
"$DOCUMENT/**/*"
],
"all": true
},
Expand Down Expand Up @@ -60,7 +63,7 @@
"icons/icon.icns",
"icons/icon.ico"
],
"identifier": "io.kittycad.modeling-app",
"identifier": "dev.zoo.modeling-app",
"longDescription": "",
"macOS": {
"entitlements": null,
Expand Down
2 changes: 2 additions & 0 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,10 @@ import { useModelingContext } from 'hooks/useModelingContext'
import { useAbsoluteFilePath } from 'hooks/useAbsoluteFilePath'
import { isTauri } from 'lib/isTauri'
import { useLspContext } from 'components/LspProvider'
import { useValidateSettings } from 'hooks/useValidateSettings'

export function App() {
useValidateSettings()
const { project, file } = useLoaderData() as IndexLoaderData
const navigate = useNavigate()
const filePath = useAbsoluteFilePath()
Expand Down
Loading
Loading