mirror of
https://github.com/Flow-Launcher/Flow.Launcher.git
synced 2026-03-11 08:54:32 +00:00
Every time I start Flow Launcher since the plugins refactor, the Bookmarks plugin has been throwing an exception. The issue stems from it parsing the Bookmarks file, and assuming that every JsonElement in the "roots" element is a JsonValueKind.Object. My Bookmarks file though has a JsonValueKind.String value off the roots key of `"sync_transaction_version": "20297",` along-side the bookmark_bar, other, and synced keys, which ARE objects. When it hits that sync_transaction_version string, and calls EnumerateFolderBookmark with it, it gets into the method because it IS a JsonElement, but then throws an exception on the folderElement.TryGetProperty("children", ...) call because you can't call TryGetProperty on a String, only Objects.
68 lines
2.6 KiB
C#
68 lines
2.6 KiB
C#
using Flow.Launcher.Plugin.BrowserBookmark.Models;
|
|
using Microsoft.AspNetCore.Authentication;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Text.Json;
|
|
|
|
namespace Flow.Launcher.Plugin.BrowserBookmark
|
|
{
|
|
public abstract class ChromiumBookmarkLoader : IBookmarkLoader
|
|
{
|
|
public abstract List<Bookmark> GetBookmarks();
|
|
protected List<Bookmark> LoadBookmarks(string browserDataPath, string name)
|
|
{
|
|
var bookmarks = new List<Bookmark>();
|
|
if (!Directory.Exists(browserDataPath)) return bookmarks;
|
|
var paths = Directory.GetDirectories(browserDataPath);
|
|
|
|
foreach (var profile in paths)
|
|
{
|
|
var bookmarkPath = Path.Combine(profile, "Bookmarks");
|
|
if (!File.Exists(bookmarkPath))
|
|
continue;
|
|
|
|
var source = name + (Path.GetFileName(profile) == "Default" ? "" : $" ({Path.GetFileName(profile)})");
|
|
bookmarks.AddRange(LoadBookmarksFromFile(bookmarkPath, source));
|
|
}
|
|
return bookmarks;
|
|
}
|
|
|
|
protected List<Bookmark> LoadBookmarksFromFile(string path, string source)
|
|
{
|
|
if (!File.Exists(path))
|
|
return new();
|
|
var bookmarks = new List<Bookmark>();
|
|
using var jsonDocument = JsonDocument.Parse(File.ReadAllText(path));
|
|
if (!jsonDocument.RootElement.TryGetProperty("roots", out var rootElement))
|
|
return new();
|
|
foreach (var folder in rootElement.EnumerateObject())
|
|
{
|
|
if (folder.Value.ValueKind == JsonValueKind.Object)
|
|
EnumerateFolderBookmark(folder.Value, bookmarks, source);
|
|
}
|
|
return bookmarks;
|
|
}
|
|
|
|
private void EnumerateFolderBookmark(JsonElement folderElement, List<Bookmark> bookmarks, string source)
|
|
{
|
|
if (!folderElement.TryGetProperty("children", out var childrenElement))
|
|
return;
|
|
foreach (var subElement in childrenElement.EnumerateArray())
|
|
{
|
|
switch (subElement.GetProperty("type").GetString())
|
|
{
|
|
case "folder":
|
|
EnumerateFolderBookmark(subElement, bookmarks, source);
|
|
break;
|
|
default:
|
|
bookmarks.Add(new Bookmark(
|
|
subElement.GetProperty("name").GetString(),
|
|
subElement.GetProperty("url").GetString(),
|
|
source));
|
|
break;
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|