Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 25 additions & 3 deletions src/Files.Uwp/Controllers/SidebarPinnedController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ public class SidebarPinnedController : IJson

private bool suppressChangeEvent;

private string configContent;

public string JsonFileName { get; } = "PinnedItems.json";

private string folderPath => Path.Combine(ApplicationData.Current.LocalFolder.Path, "settings");
Expand Down Expand Up @@ -90,7 +92,8 @@ private async Task LoadAsync()

try
{
Model = JsonConvert.DeserializeObject<SidebarPinnedModel>(await FileIO.ReadTextAsync(JsonFile.Result));
configContent = await FileIO.ReadTextAsync(JsonFile.Result);
Model = JsonConvert.DeserializeObject<SidebarPinnedModel>(configContent);
if (Model == null)
{
throw new ArgumentException($"{JsonFileName} is empty, regenerating...");
Expand Down Expand Up @@ -127,8 +130,27 @@ private async void Query_ContentsChanged(IStorageQueryResultBase sender, object
return;
}

// Watched file changed externally, reload the sidebar items
await ReloadAsync();
try
{
var configFile = await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appdata:///local/settings/PinnedItems.json"));
var content = await FileIO.ReadTextAsync(configFile);

if (configContent != content)
{
configContent = content;
}
else
{
return;
}

// Watched file changed externally, reload the sidebar items
await ReloadAsync();
}
catch
{
// ignored
}
}

public void SaveModel()
Expand Down
13 changes: 7 additions & 6 deletions src/Files.Uwp/Controllers/TerminalController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,8 @@ private async Task LoadAsync()

try
{
var content = await FileIO.ReadTextAsync(JsonFile.Result);
configContent = content;
Model = JsonConvert.DeserializeObject<TerminalFileModel>(content);
configContent = await FileIO.ReadTextAsync(JsonFile.Result);
Model = JsonConvert.DeserializeObject<TerminalFileModel>(configContent);
if (Model == null)
{
throw new ArgumentException($"{JsonFileName} is empty, regenerating...");
Expand All @@ -93,9 +92,11 @@ private async Task LoadAsync()

private async Task StartWatchConfigChangeAsync()
{
var configFile = await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appdata:///local/settings/terminal.json"));
var folder = await configFile.GetParentAsync();
query = folder.CreateFileQuery();
var queryOptions = new QueryOptions();
queryOptions.ApplicationSearchFilter = "System.FileName:" + JsonFileName;

var settingsFolder = await ApplicationData.Current.LocalFolder.GetFolderAsync("settings");
query = settingsFolder.CreateFileQueryWithOptions(queryOptions);
query.ContentsChanged += Query_ContentsChanged;
await query.GetFilesAsync();
}
Expand Down