Skip to content
This repository has been archived by the owner on Nov 22, 2022. It is now read-only.

Commit

Permalink
Fix tray menu out of sync issue
Browse files Browse the repository at this point in the history
  • Loading branch information
ExcitedCodes committed Jul 27, 2020
1 parent 2cff683 commit 98ec4c9
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 9 deletions.
5 changes: 3 additions & 2 deletions NaiveWPF/Data/RemoteConfigGroup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@ public string Name
}
}
private string _name = null;

public RemoteConfigGroup(string name)
public RemoteConfigGroup(string name, MainWindow main)
{
Name = name;
CollectionChanged += (s, e) => main.ReloadTrayMenu();
}

public new void Add(RemoteConfig item)
Expand Down
2 changes: 1 addition & 1 deletion NaiveWPF/Data/Subscription.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public bool Update(bool silent)
goto CONTINUE2;
}
}
mainRemotes.Add(new RemoteConfigGroup(group)
mainRemotes.Add(new RemoteConfigGroup(group, Main)
{
new RemoteConfig(name,ProxyType.NaiveProxy)
{
Expand Down
7 changes: 4 additions & 3 deletions NaiveWPF/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ public MainWindow(string config, bool autorun)
{
try
{
var group = new RemoteConfigGroup(g.Key);
var group = new RemoteConfigGroup(g.Key, this);
foreach (KeyValuePair<string, dynamic> r in (Dictionary<string, dynamic>)g.Value)
{
try
Expand Down Expand Up @@ -217,7 +217,7 @@ public MainWindow(string config, bool autorun)

if (Remotes.Count == 0)
{
Remotes.Add(new RemoteConfigGroup("Default"));
Remotes.Add(new RemoteConfigGroup("Default", this));
}
ConfigPath = config;
ResizeMode = AllowWindowResize.Value ? ResizeMode.CanResize : ResizeMode.CanMinimize;
Expand All @@ -234,6 +234,7 @@ public MainWindow(string config, bool autorun)
ResizeMode = AllowWindowResize.Value ? ResizeMode.CanResize : ResizeMode.CanMinimize;
Save();
};
Remotes.CollectionChanged += (s, e) => ReloadTrayMenu();
Listeners.CollectionChanged += (s, e) => ReloadTrayMenu();

Listeners.Add(new FakeListener());
Expand Down Expand Up @@ -384,7 +385,7 @@ private void Window_MouseDown(object sender, MouseButtonEventArgs e)

#region Tray Icon & Menu

private void ReloadTrayMenu()
public void ReloadTrayMenu()
{
// ItemSource Binding will cause severe width issue, so we create menu by code...
var menu = FindResource("TrayMenu") as ContextMenu;
Expand Down
4 changes: 2 additions & 2 deletions NaiveWPF/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,5 @@
// 可以指定所有值,也可以使用以下所示的 "*" 预置版本号和修订号
// 方法是按如下所示使用“*”: :
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("2.0.3.1")]
[assembly: AssemblyFileVersion("2.0.3.1")]
[assembly: AssemblyVersion("2.0.3.2")]
[assembly: AssemblyFileVersion("2.0.3.2")]
2 changes: 1 addition & 1 deletion NaiveWPF/View/ProxyTab.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ private void MenuItemAddGroup_Click(object sender, RoutedEventArgs e)
return;
}
}
Main.Remotes.Add(new RemoteConfigGroup(name));
Main.Remotes.Add(new RemoteConfigGroup(name, Main));
Main.Save();
}

Expand Down

0 comments on commit 98ec4c9

Please sign in to comment.