22using System . Collections . Generic ;
33using System . IO ;
44using System . Text . Json ;
5+ using Flow . Launcher . Infrastructure . Logger ;
56
67namespace Flow . Launcher . Plugin . BrowserBookmark
78{
89 public abstract class ChromiumBookmarkLoader : IBookmarkLoader
910 {
1011 public abstract List < Bookmark > GetBookmarks ( ) ;
12+
1113 protected List < Bookmark > LoadBookmarks ( string browserDataPath , string name )
1214 {
1315 var bookmarks = new List < Bookmark > ( ) ;
@@ -19,53 +21,63 @@ protected List<Bookmark> LoadBookmarks(string browserDataPath, string name)
1921 var bookmarkPath = Path . Combine ( profile , "Bookmarks" ) ;
2022 if ( ! File . Exists ( bookmarkPath ) )
2123 continue ;
22-
24+
2325 Main . RegisterBookmarkFile ( bookmarkPath ) ;
2426
2527 var source = name + ( Path . GetFileName ( profile ) == "Default" ? "" : $ " ({ Path . GetFileName ( profile ) } )") ;
2628 bookmarks . AddRange ( LoadBookmarksFromFile ( bookmarkPath , source ) ) ;
2729 }
30+
2831 return bookmarks ;
2932 }
3033
3134 protected List < Bookmark > LoadBookmarksFromFile ( string path , string source )
3235 {
3336 if ( ! File . Exists ( path ) )
34- return new ( ) ;
37+ return new List < Bookmark > ( ) ;
3538
3639 var bookmarks = new List < Bookmark > ( ) ;
3740 using var jsonDocument = JsonDocument . Parse ( File . ReadAllText ( path ) ) ;
3841 if ( ! jsonDocument . RootElement . TryGetProperty ( "roots" , out var rootElement ) )
39- return new ( ) ;
42+ return new List < Bookmark > ( ) ;
4043 foreach ( var folder in rootElement . EnumerateObject ( ) )
4144 {
4245 if ( folder . Value . ValueKind == JsonValueKind . Object )
4346 EnumerateFolderBookmark ( folder . Value , bookmarks , source ) ;
4447 }
48+
4549 return bookmarks ;
4650 }
4751
48- private void EnumerateFolderBookmark ( JsonElement folderElement , List < Bookmark > bookmarks , string source )
52+ private void EnumerateFolderBookmark ( JsonElement folderElement , ICollection < Bookmark > bookmarks ,
53+ string source )
4954 {
5055 if ( ! folderElement . TryGetProperty ( "children" , out var childrenElement ) )
5156 return ;
5257 foreach ( var subElement in childrenElement . EnumerateArray ( ) )
5358 {
54- switch ( subElement . GetProperty ( "type" ) . GetString ( ) )
59+ if ( subElement . TryGetProperty ( "type" , out var type ) )
5560 {
56- case "folder" :
57- case "workspace" : // Edge Workspace
58- EnumerateFolderBookmark ( subElement , bookmarks , source ) ;
59- break ;
60- default :
61- bookmarks . Add ( new Bookmark (
62- subElement . GetProperty ( "name" ) . GetString ( ) ,
63- subElement . GetProperty ( "url" ) . GetString ( ) ,
64- source ) ) ;
65- break ;
61+ switch ( type . GetString ( ) )
62+ {
63+ case "folder" :
64+ case "workspace" : // Edge Workspace
65+ EnumerateFolderBookmark ( subElement , bookmarks , source ) ;
66+ break ;
67+ default :
68+ bookmarks . Add ( new Bookmark (
69+ subElement . GetProperty ( "name" ) . GetString ( ) ,
70+ subElement . GetProperty ( "url" ) . GetString ( ) ,
71+ source ) ) ;
72+ break ;
73+ }
74+ }
75+ else
76+ {
77+ Log . Error (
78+ $ "ChromiumBookmarkLoader: EnumerateFolderBookmark: type property not found for { subElement . GetString ( ) } ") ;
6679 }
6780 }
68-
6981 }
7082 }
7183}
0 commit comments