protected override void OnStartup(StartupEventArgs e) { // temporarily take control Current.ShutdownMode = ShutdownMode.OnExplicitShutdown; // prompt user for handle var(OK, handle) = PromptUserForHandle(); // if user declined to enter a handle if (!OK) { Current.Shutdown(); return; /* early exit */ } // else we have a valid handle, so... // relinquish control Current.ShutdownMode = ShutdownMode.OnMainWindowClose; // configure main window and view model var control = string.Format($"{Default.HostAddress}:{Default.ControlPort}"); var config = new Proxy.Config(control, (int)Default.IdleMilliseconds, handle); Current.MainWindow = new MainWindow() { DataContext = new MainWindowViewModel(config, cts.Token) }; // run application Current.MainWindow.Show(); }
public MainWindowViewModel(Proxy.Config proxyConfig, CancellationToken token) { this.handle_ = proxyConfig.Handle; this.filter_ = Lobby.UserHandle; this.input_ = string.Empty; this.chatItems.CollectionChanged += (sender, e) => { Notify(nameof(ChatUpdate)); }; this.userItems.CollectionChanged += (sender, e) => { Notify(nameof(ActiveUser)); }; ChatMessages.SortDescriptions.Add(new SortDescription("UserHandle", ListSortDirection.Ascending)); ChatMessages.Filter = (item) => (item is ChatUpdate msg) && (msg.IsPrivate && Filter == msg.Sender || msg.IsPublic && Filter == GroupSender); Proxy.Start(proxyConfig, token); }
public MainWindowViewModel(Proxy.Config proxyConfig, CancellationToken token) { this.handle_ = proxyConfig.Handle; this.filter_ = Lobby.UserHandle; this.input_ = string.Empty; this.chatItems.CollectionChanged += (sender, e) => { Notify(nameof(ChatUpdate)); }; this.userItems.CollectionChanged += (sender, e) => { Notify(nameof(ActiveUser)); }; ChatMessages.SortDescriptions.Add(new SortDescription("UserHandle", ListSortDirection.Ascending)); ChatMessages.Filter = (item) => (item is ChatUpdate msg) && (msg.IsPrivate && Filter == msg.Sender || msg.IsPublic && Filter == GroupSender); Proxy.UserStream.ObserveOnDispatcher().Subscribe(UpdateActiveUsers); Proxy.NewsStream.ObserveOnDispatcher().Subscribe(UpdateChatHistory); // Add subscription to property, pass updates to a callback Proxy.Start(proxyConfig, token); }