@@ -7,6 +7,8 @@ use std::{collections::HashMap, fs, path::PathBuf};
7
7
pub struct Settings {
8
8
pub openai_model : String ,
9
9
pub custom_prompts : HashMap < String , String > ,
10
+ #[ serde( default ) ]
11
+ pub prompt_order : Vec < String > ,
10
12
pub selected_tone : Option < String > ,
11
13
pub first_visit_complete : Option < bool > ,
12
14
pub shortcut_enabled : Option < bool > ,
@@ -24,6 +26,7 @@ impl Default for Settings {
24
26
Self {
25
27
openai_model : "gpt-4o-mini" . to_string ( ) ,
26
28
custom_prompts,
29
+ prompt_order : vec ! [ "Improve Writing" . to_string( ) ] ,
27
30
selected_tone : Some ( "Improve Writing" . to_string ( ) ) ,
28
31
first_visit_complete : Some ( false ) ,
29
32
shortcut_enabled : Some ( true ) ,
@@ -35,10 +38,26 @@ impl Default for Settings {
35
38
36
39
impl Settings {
37
40
pub fn load ( ) -> Self {
38
- fs:: read_to_string ( settings_file_path ( ) )
41
+ let mut settings : Settings = fs:: read_to_string ( settings_file_path ( ) )
39
42
. ok ( )
40
43
. 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
42
61
}
43
62
44
63
pub fn save ( & self ) -> Result < ( ) , String > {
0 commit comments