Skip to content

Commit 88cbd19

Browse files
committed
Make pinned pipes actually persistent
1 parent 854e235 commit 88cbd19

3 files changed

Lines changed: 16 additions & 7 deletions

File tree

Services/Settings.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ public Settings()
7676
ColumnWidths.ToObservableChangeSet<ObservableDictionary<string, int>, KeyValuePair<string, int>>()
7777
.CastToObject()
7878
.Concat(this.WhenAnyPropertyChanged().ToObservableChangeSet().CastToObject())
79+
.Concat(PinnedNames.ToObservableChangeSet<ObservableSet<string>, string>().CastToObject())
7980
.Throttle(TimeSpan.FromSeconds(1))
8081
.Subscribe(_ => Save());
8182
}

ViewModels/PipeExplorerViewModel.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ public PipeExplorerViewModel()
163163
.Select(v => (ImageSource)App.Current.FindResource(v ? "AppIconActive" : "AppIcon"))
164164
.Subscribe(v => AppIcon = v);
165165

166-
pipesCache.AddOrUpdate(Native.GetPipes().Select(p => new PipeViewModel(p, false)));
166+
pipesCache.AddOrUpdate(Native.GetPipes().Select(p => new PipeViewModel(p, settings.PinnedNames.Contains(p.Name), false)));
167167
IsRunning = settings.StartImmediately;
168168
}
169169

@@ -173,11 +173,11 @@ private void Pipe_Created(object sender, PipeWatcherEventArgs e)
173173
if (opt.HasValue && opt.Value.BeingRemoved)
174174
{
175175
pipesCache.RemoveKey(e.Pipe.Path);
176-
pipesCache.AddOrUpdate(new PipeViewModel(e.Pipe));
176+
pipesCache.AddOrUpdate(new PipeViewModel(e.Pipe, settings.PinnedNames.Contains(e.Pipe.Name)));
177177
}
178178
else if (!opt.HasValue) // avoid re-creation of view models on startup
179179
{
180-
pipesCache.AddOrUpdate(new PipeViewModel(e.Pipe));
180+
pipesCache.AddOrUpdate(new PipeViewModel(e.Pipe, settings.PinnedNames.Contains(e.Pipe.Name)));
181181
}
182182
}
183183

ViewModels/PipeViewModel.cs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,6 @@ class PipeViewModel : ReactiveObject, IComparable<PipeViewModel>, IComparable
4949
[Reactive] public bool RecentlyAdded { get; private set; }
5050
[Reactive] public bool Pinned { get; set; }
5151

52-
public ICommand SwitchPinnedStateCmd { get; }
53-
5452
private DateTime lastUpdateTimestamp;
5553

5654
public void MarkForRemoval()
@@ -60,13 +58,14 @@ public void MarkForRemoval()
6058
BeingRemoved = true;
6159
}
6260

63-
public PipeViewModel(PipeModel model, bool markAsRecentlyAdded = true)
61+
public PipeViewModel(PipeModel model, bool pinned, bool markAsRecentlyAdded = true)
6462
{
6563
Host = model.Host;
6664
Name = model.Name;
6765
Path = model.Path;
6866

69-
SwitchPinnedStateCmd = ReactiveCommand.Create(() => Pinned = !Pinned);
67+
Pinned = pinned;
68+
this.WhenValueChanged(x => x.Pinned).Subscribe(UpdatePinnedNames);
7069

7170
var nowStr = DateTime.Now.ToString(CultureInfo.CurrentUICulture);
7271
if (markAsRecentlyAdded)
@@ -85,6 +84,15 @@ public PipeViewModel(PipeModel model, bool markAsRecentlyAdded = true)
8584
Task.Delay(Locator.Current.GetService<ISettings>().HighlightDuration).ContinueWith(_ => RecentlyAdded = false);
8685
}
8786

87+
private void UpdatePinnedNames(bool isPinned)
88+
{
89+
var names = Locator.Current.GetService<ISettings>().PinnedNames;
90+
if (isPinned)
91+
names.Add(Name);
92+
else
93+
names.Remove(Name);
94+
}
95+
8896
private void UpdatePlainAcl(AclModel acl)
8997
{
9098
var sb = new StringBuilder();

0 commit comments

Comments
 (0)