- update channels and controllables when window is opened

master
Simon G 5 years ago
parent 029099ca23
commit 66398ad4a4
  1. 18
      Mystify/App.axaml.cs
  2. 6
      Mystify/ViewModels/MainWindowViewModel.cs

@ -20,6 +20,7 @@ namespace Mystify
private IIocContainer? _kernel; private IIocContainer? _kernel;
private INotifyIcon? _notifyIcon; private INotifyIcon? _notifyIcon;
private MainWindow? _mainWindow; private MainWindow? _mainWindow;
private MainWindowViewModel? _mainWindowViewModel;
public override void Initialize() => AvaloniaXamlLoader.Load(this); public override void Initialize() => AvaloniaXamlLoader.Load(this);
public override void OnFrameworkInitializationCompleted() public override void OnFrameworkInitializationCompleted()
@ -31,10 +32,9 @@ namespace Mystify
_kernel = bootstrapper.BootstrapKernel(); _kernel = bootstrapper.BootstrapKernel();
MainModel mainModel = _kernel.Resolve<MainModel>(); MainModel mainModel = _kernel.Resolve<MainModel>();
_mainWindow = new MainWindow(); _mainWindow = new();
_mainWindowViewModel = new (mainModel, _mainWindow);
MainWindowViewModel mainWindowViewModel = new (mainModel, _mainWindow); _mainWindow.DataContext = _mainWindowViewModel;
_mainWindow.DataContext = mainWindowViewModel;
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktopStyleApplicationLifetime) if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktopStyleApplicationLifetime)
{ {
@ -48,20 +48,26 @@ namespace Mystify
{ {
Items = new List<object> Items = new List<object>
{ {
new MenuItem {Header = "Open Mystify", Command = ReactiveCommand.Create(() => _mainWindow?.Show())}, new MenuItem {Header = "Open Mystify", Command = ReactiveCommand.Create(OpenMainWindow)},
new Separator(), new Separator(),
new MenuItem {Header = "Close", Command = ReactiveCommand.Create(() => desktopStyleApplicationLifetime.Shutdown())} new MenuItem {Header = "Close", Command = ReactiveCommand.Create(() => desktopStyleApplicationLifetime.Shutdown())}
} }
}; };
_notifyIcon.ContextMenu = notifyIconContextMenu; _notifyIcon.ContextMenu = notifyIconContextMenu;
_notifyIcon.DoubleClick += (_, _) => _mainWindow?.Show(); _notifyIcon.DoubleClick += (_, _) => OpenMainWindow();
_notifyIcon.Visible = true; _notifyIcon.Visible = true;
} }
base.OnFrameworkInitializationCompleted(); base.OnFrameworkInitializationCompleted();
} }
private void OpenMainWindow()
{
_mainWindowViewModel?.UpdateChannelsAndControllables();
_mainWindow?.Show();
}
private void OnExit(object? sender, ControlledApplicationLifetimeExitEventArgs args) private void OnExit(object? sender, ControlledApplicationLifetimeExitEventArgs args)
{ {
_mainWindow?.Close(); _mainWindow?.Close();

@ -60,5 +60,11 @@ namespace Mystify.ViewModels
if (SelectedControllable != null) if (SelectedControllable != null)
SelectedChannel?.AllocateControllable(SelectedControllable); SelectedChannel?.AllocateControllable(SelectedControllable);
}); });
public void UpdateChannelsAndControllables()
{
RaisePropertyChanged(() => Channels);
RaisePropertyChanged(() => Controllables);
}
} }
} }

Loading…
Cancel
Save