public virtual async Task InitiateAsync() { await Settings.InitiateAsync(); Settings.MonitorCustomizations.AbsoluteCapacity = MaxKnownMonitorsCount; Settings.PropertyChanged += OnSettingsChanged; OnSettingsInitiated(); NotifyIconContainer.ShowIcon("pack://application:,,,/Monitorian.Core;component/Resources/Icons/TrayIcon.ico", ProductInfo.Title); _current.MainWindow = new MainWindow(this); _current.MainWindow.Deactivated += (sender, e) => MonitorsResetByKey(); if (StartupAgent.IsWindowShowExpected()) { _current.MainWindow.Show(); } await ScanAsync(); StartupAgent.HandleRequestAsync = HandleRequestAsync; NotifyIconContainer.MouseLeftButtonClick += OnMainWindowShowRequestedBySelf; NotifyIconContainer.MouseRightButtonClick += OnMenuWindowShowRequested; _displayWatcher.Subscribe(() => OnMonitorsChangeInferred(nameof(DisplayWatcher))); _powerWatcher.Subscribe((e) => OnMonitorsChangeInferred(nameof(PowerWatcher), e.Mode, e.Count), PowerManagement.GetOnPowerSettingChanged()); _brightnessWatcher.Subscribe((instanceName, brightness) => Update(instanceName, brightness)); }
public virtual void End() { MonitorsDispose(); NotifyIconContainer.Dispose(); _displayWatcher.Dispose(); _powerWatcher.Dispose(); _brightnessWatcher.Dispose(); }
public MainController() { Settings = new Settings(); Monitors = new ObservableCollection <MonitorViewModel>(); BindingOperations.EnableCollectionSynchronization(Monitors, _monitorsLock); NotifyIconContainer = new NotifyIconContainer(); NotifyIconContainer.MouseLeftButtonClick += OnMainWindowShowRequested; NotifyIconContainer.MouseRightButtonClick += OnMenuWindowShowRequested; _settingsWatcher = new SettingsWatcher(); _powerWatcher = new PowerWatcher(); _brightnessWatcher = new BrightnessWatcher(); }
public AppControllerCore(AppKeeper keeper, SettingsCore settings) { this._keeper = keeper ?? throw new ArgumentNullException(nameof(keeper)); this.Settings = settings ?? throw new ArgumentNullException(nameof(settings)); LanguageService.SwitchDefault(); Monitors = new ObservableCollection <MonitorViewModel>(); BindingOperations.EnableCollectionSynchronization(Monitors, _monitorsLock); NotifyIconContainer = new NotifyIconContainer(); _displayWatcher = new DisplayWatcher(); _powerWatcher = new PowerWatcher(); _brightnessWatcher = new BrightnessWatcher(); }
public MainController(StartupAgent agent) { Settings = new Settings(); StartupAgent = agent ?? throw new ArgumentNullException(nameof(agent)); Monitors = new ObservableCollection <MonitorViewModel>(); BindingOperations.EnableCollectionSynchronization(Monitors, _monitorsLock); NotifyIconContainer = new NotifyIconContainer(); NotifyIconContainer.MouseLeftButtonClick += OnMainWindowShowRequestedBySelf; NotifyIconContainer.MouseRightButtonClick += OnMenuWindowShowRequested; _settingsWatcher = new SettingsWatcher(); _powerWatcher = new PowerWatcher(); _brightnessWatcher = new BrightnessWatcher(); }
protected override void Dispose(bool disposing) { if (_disposed) { return; } if (disposing) { _worker?.Dispose(); NotifyIconContainer.Dispose(); Settings.Current.Dispose(); } _disposed = true; base.Dispose(disposing); }
public async Task InitiateAsync() { Settings.Current.Initiate(); NotifyIconContainer.ShowIcon("pack://application:,,,/Resources/Icons/TrayIcon.ico", ProductInfo.Title); await LoadProfilesAsync(); _current.MainWindow = new MainWindow(this); if (!StartupAgent.IsStartedOnSignIn()) { _current.MainWindow.Show(); } StartupAgent.ShowRequested += OnMainWindowShowRequested; Observable.FromEventPattern( h => _current.MainWindow.Activated += h, h => _current.MainWindow.Activated -= h) .StartWith(new object()) // This is for initial scan. .Subscribe(async _ => await ScanNetworkAsync()) .AddTo(this.Subscription); }
public MainController(StartupAgent agent, IWlanWorker worker) { StartupAgent = agent ?? throw new ArgumentNullException(nameof(agent)); Profiles = new ObservableCollection <ProfileItem>(); BindingOperations.EnableCollectionSynchronization(Profiles, _profilesLock); NotifyIconContainer = new NotifyIconContainer(); NotifyIconContainer.MouseLeftButtonClick += OnMainWindowShowRequested; NotifyIconContainer.MouseRightButtonClick += OnMenuWindowShowRequested; this._worker = worker; IsUpdating = new BooleanNotifier(); IsWorking = new BooleanNotifier(); ShowUpdatingTime(); // For debug ShowWorkingTime(); // For debug RushesRescan = new ReactiveProperty <bool>() .AddTo(this.Subscription); EngagesPriority = new ReactiveProperty <bool>() .AddTo(this.Subscription); EngagesPriority .Subscribe(_ => SetNotifyIconText()) .AddTo(this.Subscription); #region Update RescanTimer = new ReactiveTimer(TimeSpan.FromSeconds(Settings.Current.RescanInterval)) .AddTo(this.Subscription); RescanCommand = IsUpdating .Inverse() .ObserveOnUIDispatcher() // This is for thread access by ReactiveCommand. .ToReactiveCommand(); RescanCommand .Merge(EngagesPriority.Where(x => x).Select(x => x as object)) .Merge(RescanTimer.Select(x => x as object)) .Subscribe(async _ => await ScanNetworkAsync()) .AddTo(this.Subscription); Settings.Current .ObserveProperty(x => x.RescanInterval) .Subscribe(rescanInterval => RescanTimer.Interval = TimeSpan.FromSeconds(rescanInterval)) .AddTo(this.Subscription); RushesRescan .Subscribe(rushesRescan => { if (rushesRescan) { RescanTimer.Start(); } else { RescanTimer.Stop(); } SetNotifyIconText(); }) .AddTo(this.Subscription); var networkRefreshed = Observable.FromEventPattern( h => _worker.NetworkRefreshed += h, h => _worker.NetworkRefreshed -= h); var availabilityChanged = Observable.FromEventPattern( h => _worker.AvailabilityChanged += h, h => _worker.AvailabilityChanged -= h); var interfaceChanged = Observable.FromEventPattern( h => _worker.InterfaceChanged += h, h => _worker.InterfaceChanged -= h); var connectionChanged = Observable.FromEventPattern( h => _worker.ConnectionChanged += h, h => _worker.ConnectionChanged -= h); var profileChanged = Observable.FromEventPattern( h => _worker.ProfileChanged += h, h => _worker.ProfileChanged -= h); Observable.Merge(networkRefreshed, availabilityChanged, interfaceChanged, connectionChanged, profileChanged) .Throttle(TimeSpan.FromMilliseconds(100)) .Subscribe(async _ => { if (RushesRescan.Value) { RescanTimer.Start(TimeSpan.FromSeconds(Settings.Current.RescanInterval)); // Wait for due time. } await LoadProfilesAsync(); }) .AddTo(this.Subscription); #endregion #region Close CloseCommand = new ReactiveProperty <bool>(true) .ToReactiveCommand(); CloseCommand .Subscribe(_ => _current.Shutdown()) .AddTo(this.Subscription); #endregion }