Skip to content

Commit 7fc2cd1

Browse files
committed
feat: drag the tones
1 parent 190e8d3 commit 7fc2cd1

File tree

4 files changed

+353
-85
lines changed

4 files changed

+353
-85
lines changed

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
"tauri": "tauri"
1111
},
1212
"dependencies": {
13+
"@dnd-kit/core": "^6.3.1",
14+
"@dnd-kit/sortable": "^10.0.0",
15+
"@dnd-kit/utilities": "^3.2.2",
1316
"@tauri-apps/api": "^2.2.0",
1417
"@tauri-apps/plugin-dialog": "^2.2.2",
1518
"@tauri-apps/plugin-notification": "~2",

pnpm-lock.yaml

Lines changed: 61 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src-tauri/src/settings.rs

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ use std::{collections::HashMap, fs, path::PathBuf};
77
pub struct Settings {
88
pub openai_model: String,
99
pub custom_prompts: HashMap<String, String>,
10+
#[serde(default)]
11+
pub prompt_order: Vec<String>,
1012
pub selected_tone: Option<String>,
1113
pub first_visit_complete: Option<bool>,
1214
pub shortcut_enabled: Option<bool>,
@@ -24,6 +26,7 @@ impl Default for Settings {
2426
Self {
2527
openai_model: "gpt-4o-mini".to_string(),
2628
custom_prompts,
29+
prompt_order: vec!["Improve Writing".to_string()],
2730
selected_tone: Some("Improve Writing".to_string()),
2831
first_visit_complete: Some(false),
2932
shortcut_enabled: Some(true),
@@ -35,10 +38,26 @@ impl Default for Settings {
3538

3639
impl Settings {
3740
pub fn load() -> Self {
38-
fs::read_to_string(settings_file_path())
41+
let mut settings: Settings = fs::read_to_string(settings_file_path())
3942
.ok()
4043
.and_then(|contents| serde_json::from_str(&contents).ok())
41-
.unwrap_or_default()
44+
.unwrap_or_default();
45+
46+
// Ensure backward compatibility: populate prompt_order if missing or empty
47+
if settings.prompt_order.is_empty() && !settings.custom_prompts.is_empty() {
48+
let mut prompt_names: Vec<String> = settings.custom_prompts.keys().cloned().collect();
49+
// Ensure "Improve Writing" comes first if it exists
50+
if let Some(pos) = prompt_names.iter().position(|x| x == "Improve Writing") {
51+
let improve_writing = prompt_names.remove(pos);
52+
prompt_names.insert(0, improve_writing);
53+
}
54+
settings.prompt_order = prompt_names;
55+
56+
// Save the updated settings immediately to persist the migration
57+
let _ = settings.save();
58+
}
59+
60+
settings
4261
}
4362

4463
pub fn save(&self) -> Result<(), String> {

0 commit comments

Comments
 (0)