@@ -5,73 +5,6 @@ pub struct BookmarksPlugin {
55 entries : Vec < crate :: model:: Entry > ,
66}
77
8- #[ derive( serde:: Deserialize , Debug ) ]
9- #[ serde( untagged) ]
10- #[ allow( dead_code) ]
11- enum Section {
12- #[ serde( rename_all = "PascalCase" ) ]
13- Profile {
14- name : String ,
15- is_relative : String ,
16- path : String ,
17- default : Option < String > ,
18- } ,
19- #[ serde( rename_all = "PascalCase" ) ]
20- General {
21- start_with_last_profile : String ,
22- version : Option < String > ,
23- } ,
24-
25- #[ serde( rename_all = "PascalCase" ) ]
26- Install { default : String , locked : String } ,
27- }
28-
29- fn profile_path ( ) -> anyhow:: Result < String > {
30- let home_directory = std:: env:: var ( "HOME" ) ?;
31-
32- let profiles_file_path = format ! ( "{home_directory}/.mozilla/firefox/profiles.ini" ) ;
33- let profiles_file = std:: fs:: File :: open ( profiles_file_path) ?;
34- let profiles_file_contents: std:: collections:: HashMap < String , Section > =
35- serde_ini:: from_read ( profiles_file) ?;
36-
37- let mut default_profile = profiles_file_contents
38- . values ( )
39- . find ( |section| match section {
40- Section :: Profile { default, .. } => {
41- default. clone ( ) . unwrap_or ( String :: from ( "" ) ) == String :: from ( "1" )
42- }
43- _ => false ,
44- } ) ;
45-
46- if default_profile. is_none ( ) {
47- default_profile = profiles_file_contents
48- . values ( )
49- . find ( |section| match section {
50- Section :: Profile { .. } => true ,
51- _ => false ,
52- } ) ;
53- }
54-
55- if default_profile. is_none ( ) {
56- return Err ( anyhow:: anyhow!( "Could not find a firefox profile." ) ) ;
57- }
58-
59- match default_profile. unwrap ( ) {
60- Section :: Profile {
61- is_relative, path, ..
62- } => {
63- if is_relative. eq ( & String :: from ( "1" ) ) {
64- Ok ( format ! ( "{home_directory}/.mozilla/firefox/{path}" ) )
65- } else {
66- Ok ( path. clone ( ) )
67- }
68- }
69- _ => {
70- unreachable ! ( "A non-profile section should be parsed as a profile." ) ;
71- }
72- }
73- }
74-
758impl Plugin for BookmarksPlugin {
769 fn id ( ) -> & ' static str {
7710 "firefox_bookmarks"
@@ -99,8 +32,7 @@ impl Plugin for BookmarksPlugin {
9932
10033 fn update_entries ( & mut self ) -> anyhow:: Result < ( ) > {
10134 self . entries . clear ( ) ;
102- let profile_path = profile_path ( ) ?;
103-
35+ let profile_path = crate :: plugin:: firefox:: utils:: profile_path ( ) ?;
10436 let bookmarks_file_path = format ! ( "{profile_path}/places.sqlite" ) ;
10537 let cache_directory = crate :: plugin:: utils:: centerpiece_cache_directory ( ) ?;
10638 let bookmarks_cache_file_path = format ! ( "{cache_directory}/firefox-bookmarks.sqlite" ) ;
0 commit comments