public override void SetUpReference() { base.SetUpReference(); IStartupManager startupManager = startupManagerAdaptor.GetStartupManager(); thisMainMenuUIElement.SetStartupManager(startupManager); }
static StartupManagerSingletonProvider() { #if MicrosoftStore CurrentStartupManager = new CentennialStartupManager(); #elif STEAM CurrentStartupManager = new SteamStartupManager(); #else CurrentStartupManager = new DesktopStartupManager(); #endif }
public HostingEngine( IServerManager serverManager, IStartupManager startupManager, IApplicationBuilderFactory builderFactory, IHttpContextFactory httpContextFactory) { _serverManager = serverManager; _startupManager = startupManager; _builderFactory = builderFactory; _httpContextFactory = httpContextFactory; }
public void Boot(string[] args, IStartupManager startupManager, IMessengerService messengerService) { _shellVM = _serviceProvider.GetInstance <IShellVM>(); RaiseInitializedEvent(_shellVM); startupManager.Completed += appStartupManager_Completed; startupManager.Failed += appStartupManager_Failed; startupManager.StartupProcedure(); }
public static async Task Initialize(int hostPort) { //MyDocuments这个路径不会虚拟化,方便从Dart端读取 _runningDataFilePath = $"{Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)}\\{AppName}\\runningData.json"; _userSettingFilePath = $"{Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData)}\\{AppName}\\Config\\userSetting.json"; try { //应用程序数据 RunningData = await JsonHelper.JsonDeserializeFromFileAsync <RunningData>(_runningDataFilePath); if (RunningData == null) { //生成默认运行数据 RunningData = new RunningData(); } //更新端口号 RunningData.HostPort = hostPort; await JsonHelper.JsonSerializeAsync(RunningData, _runningDataFilePath); await LoadUserSetting(); //开机启动 DesktopBridge.Helpers helpers = new DesktopBridge.Helpers(); if (helpers.IsRunningAsUwp()) { _startupManager = new DesktopBridgeStartupManager(AppName); } else { string path = Assembly.GetEntryAssembly().Location.Replace(".dll", ".exe"); _startupManager = new DesktopStartupHelper(AppName, path); } await ApplySetting(UserSetting); if (RunningData.CurrentWalpapers != null) { foreach (var item in RunningData.CurrentWalpapers) { await WallpaperApi.ShowWallpaper(item.Value, item.Key); } } } catch (Exception ex) { logger.Error($"WallpaperStore constructor Ex:{ex}"); } finally { Initialized = true; } }
public LoadingViewModel( INavigationService navigationService, IStartupManager startupManager, IEventAggregator eventAggregator) { NavigationService = navigationService; StartupManager = startupManager; CancelDownload = new DelegateCommand(OnCancelDownload); eventAggregator .GetEvent <ContentDownloadProgressUpdated>() .Subscribe(OnProgressUpdated); }
public AppLifetimeHandler( ILogFactory logFactory, IHealthNotifier healthNotifier, IStartupManager startupManager, IShutdownManager shutdownManager, IWebHostEnvironment hostingEnvironment) { _logFactory = logFactory ?? throw new ArgumentNullException(nameof(logFactory)); _healthNotifier = healthNotifier ?? throw new ArgumentNullException(nameof(healthNotifier)); _startupManager = startupManager ?? throw new ArgumentNullException(nameof(startupManager)); _shutdownManager = shutdownManager ?? throw new ArgumentNullException(nameof(shutdownManager)); _hostingEnvironment = hostingEnvironment ?? throw new ArgumentNullException(nameof(hostingEnvironment)); _log = logFactory.CreateLog(this); }
public static async void InitlizeSetting() { if (SettingInitialized) { return; } //开机启动 DesktopBridge.Helpers helpers = new DesktopBridge.Helpers(); if (helpers.IsRunningAsUwp()) { _startupManager = new DesktopBridgeStartupManager("LiveWallpaper"); } else { //string path = Assembly.GetEntryAssembly().Location.Replace(".dll", ".exe"); _startupManager = new DesktopStartupHelper("LiveWallpaper"); } //配置相关 SettingDefaultFile = Path.Combine(AppDomain.CurrentDomain.SetupInformation.ApplicationBase, "Res\\setting.default.json"); SettingDescFile = Path.Combine(AppDomain.CurrentDomain.SetupInformation.ApplicationBase, "Res\\setting.desc.json"); var appData = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData); AppDataDir = $"{appData}\\LiveWallpaper"; SettingPath = $"{AppDataDir}\\Config\\setting.json"; AppDataPath = $"{AppDataDir}\\appData.json"; PurchaseDataPath = $"{AppDataDir}\\purchaseData.json"; await CheckDefaultSetting(); //应用程序数据 AppData = await JsonHelper.JsonDeserializeFromFileAsync <AppData>(AppDataPath); if (AppData == null) { AppData = new AppData(); await ApplyAppDataAsync(); } Setting = await JsonHelper.JsonDeserializeFromFileAsync <SettingObject>(SettingPath); LocalWallpaperDir = Setting.General.WallpaperSaveDir; SettingInitialized = true; }
public AppLifetimeHandler( ILogFactory logFactory, IHealthNotifier healthNotifier, IStartupManager startupManager, IShutdownManager shutdownManager, IWebHostEnvironment hostingEnvironment, IConfigurationRoot configurationRoot, IReloadingManager <MonitoringServiceClientSettings> monitoringServiceClientSettings) { _logFactory = logFactory ?? throw new ArgumentNullException(nameof(logFactory)); _healthNotifier = healthNotifier ?? throw new ArgumentNullException(nameof(healthNotifier)); _startupManager = startupManager ?? throw new ArgumentNullException(nameof(startupManager)); _shutdownManager = shutdownManager ?? throw new ArgumentNullException(nameof(shutdownManager)); _hostingEnvironment = hostingEnvironment ?? throw new ArgumentNullException(nameof(hostingEnvironment)); _configurationRoot = configurationRoot ?? throw new ArgumentNullException(nameof(configurationRoot)); _monitoringServiceClientSettings = monitoringServiceClientSettings ?? throw new ArgumentNullException(nameof(monitoringServiceClientSettings)); _log = logFactory.CreateLog(this); }
public ContextMenuViewModel(EyeNurseService servcies, IWindowManager windowManager, IEventAggregator eventAggregator) { eventAggregator.Subscribe(this); _eventAggregator = eventAggregator; _windowManager = windowManager; Services = servcies; IsVIP = Services.AppData.Purchased; //开机启动 DesktopBridge.Helpers helpers = new DesktopBridge.Helpers(); if (helpers.IsRunningAsUwp()) { _startupManager = new DesktopBridgeStartupManager("EyeNurse"); } else { _startupManager = new DesktopStartupHelper("EyeNurse"); } Init(); }
public async Task ActivateAsync(ISelectionManager taskListSelectionManager) { if (taskListSelectionManager == null) { throw new ArgumentNullException(nameof(taskListSelectionManager)); } this.selectionManager = taskListSelectionManager; IStartupManager startupManager = Ioc.Resolve <IStartupManager>(); bool canPerformSync = await startupManager.HandleStartupAsync(); if (!this.platformService.IsNetworkAvailable) { canPerformSync = false; } if (canPerformSync && this.synchronizationManager.CanSyncOnStartup) { await this.synchronizationManager.Sync(); } }
// public void OnSceneChange(Scene from, Scene to){ // Debug.Log("from: " + from.buildIndex.ToString() + ", to: " + to.buildIndex.ToString()); // if(to.buildIndex == 1){ // StartUp(); // } // } // public void Start(){ // StartUp(); // } public void StartUp() { SetActiveUIRoots(); SetUp(); ActivateRootUI(); WarmUp(); IPlayerDataManager playerDataManager = playerDataManagerAdaptor.GetPlayerDataManager(); playerDataManager.MakeSurePlayerDataFileExists(); SetInputScrollerAxisInversion(); SetVolume(); IStartupManager startupManager = startupManagerAdaptor.GetStartupManager(); startupManager.StartStartupSequence(); // InitializeAD(); ResetInterstitialADManager(); PlayBGM(); thisGameIsReady = true; }
public static void Start(IStartupManager startupManager) { startupManager.RegisterServices(); }
public void Start(Application application, string[] args, IStartupManager appStartupManager) { _application = application; _bootstrapper.Boot(args, appStartupManager, _messengerService); }
public static Task Exit(IStartupManager startupManager) => startupManager.Exit();
public MainWindowViewModel( IAppArguments appArguments, IFactory <IStartupManager, StartupManagerArgs> startupManagerFactory, IMicSwitchOverlayViewModel overlay, IMicrophoneControllerViewModel microphoneControllerViewModel, IOverlayWindowController overlayWindowController, IAudioNotificationsManager audioNotificationsManager, IFactory <IAudioNotificationSelectorViewModel> audioSelectorFactory, IApplicationUpdaterViewModel appUpdater, [Dependency(WellKnownWindows.MainWindow)] IWindowTracker mainWindowTracker, IConfigProvider <MicSwitchConfig> configProvider, IConfigProvider <MicSwitchOverlayConfig> overlayConfigProvider, IImageProvider imageProvider, IAudioNotificationsManager notificationsManager, IWindowViewController viewController, [Dependency(WellKnownSchedulers.UI)] IScheduler uiScheduler) { Title = $"{(appArguments.IsDebugMode ? "[D]" : "")} {appArguments.AppName} v{appArguments.Version}"; this.appArguments = appArguments; this.MicrophoneController = microphoneControllerViewModel.AddTo(Anchors); this.mainWindowTracker = mainWindowTracker; this.configProvider = configProvider; this.overlayConfigProvider = overlayConfigProvider; this.notificationsManager = notificationsManager; this.viewController = viewController; ApplicationUpdater = appUpdater.AddTo(Anchors); ImageProvider = imageProvider; AudioSelectorWhenMuted = audioSelectorFactory.Create().AddTo(Anchors); AudioSelectorWhenUnmuted = audioSelectorFactory.Create().AddTo(Anchors); WindowState = WindowState.Minimized; Overlay = overlay.AddTo(Anchors); var startupManagerArgs = new StartupManagerArgs { UniqueAppName = $"{appArguments.AppName}{(appArguments.IsDebugMode ? "-debug" : string.Empty)}", ExecutablePath = appUpdater.GetLatestExecutable().FullName, CommandLineArgs = appArguments.StartupArgs, AutostartFlag = appArguments.AutostartFlag }; this.startupManager = startupManagerFactory.Create(startupManagerArgs); this.RaiseWhenSourceValue(x => x.IsActive, mainWindowTracker, x => x.IsActive, uiScheduler).AddTo(Anchors); this.RaiseWhenSourceValue(x => x.RunAtLogin, startupManager, x => x.IsRegistered, uiScheduler).AddTo(Anchors); this.RaiseWhenSourceValue(x => x.ShowOverlaySettings, Overlay, x => x.OverlayVisibilityMode).AddTo(Anchors); audioNotificationSource = Observable.Merge( AudioSelectorWhenMuted.ObservableForProperty(x => x.SelectedValue, skipInitial: true), AudioSelectorWhenUnmuted.ObservableForProperty(x => x.SelectedValue, skipInitial: true)) .Select(x => new TwoStateNotification { On = AudioSelectorWhenUnmuted.SelectedValue, Off = AudioSelectorWhenMuted.SelectedValue }) .ToPropertyHelper(this, x => x.AudioNotification) .AddTo(Anchors); this.WhenAnyValue(x => x.AudioNotificationVolume) .Subscribe(x => { AudioSelectorWhenUnmuted.Volume = AudioSelectorWhenMuted.Volume = x; }) .AddTo(Anchors); MicrophoneController.ObservableForProperty(x => x.MicrophoneMuted, skipInitial: true) .DistinctUntilChanged() .Where(x => !MicrophoneController.MicrophoneLine.IsEmpty) .SubscribeSafe(x => { var notificationToPlay = (x.Value ? AudioNotification.On : AudioNotification.Off) ?? default(AudioNotificationType).ToString(); Log.Debug($"Playing notification {notificationToPlay} (cfg: {AudioNotification.DumpToTextRaw()})"); audioNotificationsManager.PlayNotification(notificationToPlay, audioNotificationVolume); }, Log.HandleUiException) .AddTo(Anchors); this.WhenAnyValue(x => x.WindowState) .SubscribeSafe(x => ShowInTaskbar = x != WindowState.Minimized, Log.HandleUiException) .AddTo(Anchors); viewController .WhenClosing .SubscribeSafe(x => HandleWindowClosing(viewController, x), Log.HandleUiException) .AddTo(Anchors); ToggleOverlayLockCommand = CommandWrapper.Create(ToggleOverlayCommandExecuted); ExitAppCommand = CommandWrapper.Create(ExitAppCommandExecuted); ShowAppCommand = CommandWrapper.Create(ShowAppCommandExecuted); OpenAppDataDirectoryCommand = CommandWrapper.Create(OpenAppDataDirectory); ResetOverlayPositionCommand = CommandWrapper.Create(ResetOverlayPositionCommandExecuted); RunAtLoginToggleCommand = CommandWrapper.Create <bool>(RunAtLoginCommandExecuted); SelectMicrophoneIconCommand = CommandWrapper.Create(SelectMicrophoneIconCommandExecuted); SelectMutedMicrophoneIconCommand = CommandWrapper.Create(SelectMutedMicrophoneIconCommandExecuted); ResetMicrophoneIconsCommand = CommandWrapper.Create(ResetMicrophoneIconsCommandExecuted); AddSoundCommand = CommandWrapper.Create(AddSoundCommandExecuted); Observable.Merge(configProvider.ListenTo(x => x.Notification).ToUnit(), configProvider.ListenTo(x => x.NotificationVolume).ToUnit()) .Select(_ => new { configProvider.ActualConfig.Notification, configProvider.ActualConfig.NotificationVolume }) .ObserveOn(uiScheduler) .SubscribeSafe(cfg => { Log.Debug($"Applying new notification configuration: {cfg.DumpToTextRaw()} (current: {AudioNotification.DumpToTextRaw()}, volume: {AudioNotificationVolume})"); AudioSelectorWhenMuted.SelectedValue = cfg.Notification.Off; AudioSelectorWhenUnmuted.SelectedValue = cfg.Notification.On; AudioNotificationVolume = cfg.NotificationVolume; }, Log.HandleException) .AddTo(Anchors); configProvider.ListenTo(x => x.MinimizeOnClose) .ObserveOn(uiScheduler) .SubscribeSafe(x => MinimizeOnClose = x, Log.HandleException) .AddTo(Anchors); viewController .WhenLoaded .Take(1) .Select(_ => configProvider.ListenTo(y => y.StartMinimized)) .Switch() .Take(1) .ObserveOn(uiScheduler) .SubscribeSafe( x => { if (x) { Log.Debug($"StartMinimized option is active - minimizing window, current state: {WindowState}"); StartMinimized = true; viewController.Hide(); } else { Log.Debug($"StartMinimized option is not active - showing window as Normal, current state: {WindowState}"); StartMinimized = false; viewController.Show(); } }, Log.HandleUiException) .AddTo(Anchors); configProvider.WhenChanged .Subscribe() .AddTo(Anchors); Observable.Merge( microphoneControllerViewModel.ObservableForProperty(x => x.MuteMode, skipInitial: true).ToUnit(), this.ObservableForProperty(x => x.AudioNotification, skipInitial: true).ToUnit(), this.ObservableForProperty(x => x.MinimizeOnClose, skipInitial: true).ToUnit(), this.ObservableForProperty(x => x.AudioNotificationVolume, skipInitial: true).ToUnit(), this.ObservableForProperty(x => x.StartMinimized, skipInitial: true).ToUnit()) .Throttle(ConfigThrottlingTimeout) .ObserveOn(uiScheduler) .SubscribeSafe(() => { var config = configProvider.ActualConfig.CloneJson(); config.Notification = AudioNotification; config.NotificationVolume = AudioNotificationVolume; config.StartMinimized = StartMinimized; config.MinimizeOnClose = MinimizeOnClose; configProvider.Save(config); }, Log.HandleUiException) .AddTo(Anchors); viewController.WhenLoaded .SubscribeSafe(() => { Log.Debug($"Main window loaded - loading overlay, current process({CurrentProcess.ProcessName} 0x{CurrentProcess.Id:x8}) main window: {CurrentProcess.MainWindowHandle} ({CurrentProcess.MainWindowTitle})"); overlayWindowController.RegisterChild(Overlay).AddTo(Anchors); Log.Debug("Overlay loaded successfully"); }, Log.HandleUiException) .AddTo(Anchors); var theme = Theme.Create( Theme.Light, primary: SwatchHelper.Lookup[(MaterialDesignColor)PrimaryColor.BlueGrey], accent: SwatchHelper.Lookup[(MaterialDesignColor)SecondaryColor.LightBlue]); var paletteHelper = new PaletteHelper(); paletteHelper.SetTheme(theme); }
public void SetStartupManager(IStartupManager manager) { thisStartupManager = manager; }
public static void Initiliaze(IStartupManager startupManager) { startupManager.Init(null); }
public static Task Exit(IStartupManager startupManager) => startupManager.Exit();
public MainWindowViewModel( IAppArguments appArguments, IApplicationAccessor applicationAccessor, IFactory <IStartupManager, StartupManagerArgs> startupManagerFactory, IMicSwitchOverlayViewModel overlay, IMicrophoneControllerViewModel microphoneControllerViewModel, IOverlayWindowController overlayWindowController, IWaveOutDeviceSelectorViewModel waveOutDeviceSelector, IAudioNotificationsManager audioNotificationsManager, IFactory <IAudioNotificationSelectorViewModel> audioSelectorFactory, IApplicationUpdaterViewModel appUpdater, [Dependency(WellKnownWindows.MainWindow)] IWindowTracker mainWindowTracker, IConfigProvider <MicSwitchConfig> configProvider, IConfigProvider <MicSwitchOverlayConfig> overlayConfigProvider, IImageProvider imageProvider, IErrorMonitorViewModel errorMonitor, IAudioNotificationsManager notificationsManager, IWindowViewController viewController, [Dependency(WellKnownSchedulers.UI)] IScheduler uiScheduler) { Title = $"{(appArguments.IsDebugMode ? "[D]" : "")} {appArguments.AppName} v{appArguments.Version}"; this.appArguments = appArguments; this.applicationAccessor = applicationAccessor; this.MicrophoneController = microphoneControllerViewModel.AddTo(Anchors); this.mainWindowTracker = mainWindowTracker; this.configProvider = configProvider; this.overlayConfigProvider = overlayConfigProvider; this.notificationsManager = notificationsManager; this.viewController = viewController; ApplicationUpdater = appUpdater.AddTo(Anchors); WaveOutDeviceSelector = waveOutDeviceSelector; ImageProvider = imageProvider; ErrorMonitor = errorMonitor; AudioSelectorWhenMuted = audioSelectorFactory.Create().AddTo(Anchors); AudioSelectorWhenUnmuted = audioSelectorFactory.Create().AddTo(Anchors); WindowState = WindowState.Minimized; Overlay = overlay.AddTo(Anchors); try { var startupManagerArgs = new StartupManagerArgs { UniqueAppName = $"{appArguments.AppName}{(appArguments.IsDebugMode ? "-debug" : string.Empty)}", ExecutablePath = appUpdater.LauncherExecutable.FullName, CommandLineArgs = appArguments.StartupArgs, AutostartFlag = appArguments.AutostartFlag }; this.startupManager = startupManagerFactory.Create(startupManagerArgs); RunAtLoginToggleCommand = CommandWrapper.Create <bool>(RunAtLoginCommandExecuted, Observable.Return(startupManager?.IsReady ?? false)); } catch (Exception e) { Log.Warn("Failed to initialize startup manager", e); } this.RaiseWhenSourceValue(x => x.IsActive, mainWindowTracker, x => x.IsActive, uiScheduler).AddTo(Anchors); this.RaiseWhenSourceValue(x => x.RunAtLogin, startupManager, x => x.IsRegistered, uiScheduler).AddTo(Anchors); this.RaiseWhenSourceValue(x => x.ShowOverlaySettings, Overlay, x => x.OverlayVisibilityMode).AddTo(Anchors); audioNotificationSource = Observable.Merge( AudioSelectorWhenMuted.ObservableForProperty(x => x.SelectedValue, skipInitial: true), AudioSelectorWhenUnmuted.ObservableForProperty(x => x.SelectedValue, skipInitial: true)) .Select(x => new TwoStateNotification { On = AudioSelectorWhenUnmuted.SelectedValue, Off = AudioSelectorWhenMuted.SelectedValue }) .ToProperty(this, x => x.AudioNotification) .AddTo(Anchors); this.WhenAnyValue(x => x.AudioNotificationVolume) .Subscribe(x => { AudioSelectorWhenUnmuted.Volume = AudioSelectorWhenMuted.Volume = x; }) .AddTo(Anchors); MicrophoneController.ObservableForProperty(x => x.MicrophoneMuted, skipInitial: true) .DistinctUntilChanged() .Where(x => !MicrophoneController.MicrophoneLine.IsEmpty) .Select(isMuted => (isMuted.Value ? AudioNotification.Off : AudioNotification.On) ?? default(AudioNotificationType).ToString()) .Where(notificationToPlay => !string.IsNullOrEmpty(notificationToPlay)) .Select(notificationToPlay => Observable.FromAsync(async token => { Log.Debug($"Playing notification {notificationToPlay}, volume: {audioNotificationVolume}"); try { await audioNotificationsManager.PlayNotification(notificationToPlay, audioNotificationVolume, waveOutDeviceSelector.SelectedItem, token); Log.Debug($"Played notification {notificationToPlay}"); } catch (Exception ex) { Log.Debug($"Failed to play notification {notificationToPlay}", ex); } })) .Switch() .SubscribeToErrors(Log.HandleUiException) .AddTo(Anchors); this.WhenAnyValue(x => x.WindowState) .SubscribeSafe(x => ShowInTaskbar = x != WindowState.Minimized, Log.HandleUiException) .AddTo(Anchors); viewController .WhenClosing .SubscribeSafe(x => HandleWindowClosing(viewController, x), Log.HandleUiException) .AddTo(Anchors); ToggleOverlayLockCommand = CommandWrapper.Create(ToggleOverlayCommandExecuted); ExitAppCommand = CommandWrapper.Create(ExitAppCommandExecuted); ShowAppCommand = CommandWrapper.Create(ShowAppCommandExecuted); OpenAppDataDirectoryCommand = CommandWrapper.Create(OpenAppDataDirectory); ResetOverlayPositionCommand = CommandWrapper.Create(ResetOverlayPositionCommandExecuted); RunAtLoginToggleCommand = CommandWrapper.Create <bool>(RunAtLoginCommandExecuted, startupManager.WhenAnyValue(x => x.IsReady)); SelectMicrophoneIconCommand = CommandWrapper.Create(SelectMicrophoneIconCommandExecuted); SelectMutedMicrophoneIconCommand = CommandWrapper.Create(SelectMutedMicrophoneIconCommandExecuted); ResetMicrophoneIconsCommand = CommandWrapper.Create(ResetMicrophoneIconsCommandExecuted); AddSoundCommand = CommandWrapper.Create(AddSoundCommandExecuted); Observable.Merge(configProvider.ListenTo(x => x.Notifications).ToUnit(), configProvider.ListenTo(x => x.NotificationVolume).ToUnit()) .Select(_ => new { configProvider.ActualConfig.Notifications, configProvider.ActualConfig.NotificationVolume }) .ObserveOn(uiScheduler) .SubscribeSafe(cfg => { Log.Debug($"Applying new notification configuration: {cfg.DumpToTextRaw()} (current: {AudioNotification.DumpToTextRaw()}, volume: {AudioNotificationVolume})"); AudioSelectorWhenMuted.SelectedValue = cfg.Notifications.Off; AudioSelectorWhenUnmuted.SelectedValue = cfg.Notifications.On; AudioNotificationVolume = cfg.NotificationVolume; }, Log.HandleException) .AddTo(Anchors); configProvider.ListenTo(x => x.MinimizeOnClose) .ObserveOn(uiScheduler) .SubscribeSafe(x => MinimizeOnClose = x, Log.HandleException) .AddTo(Anchors); configProvider.ListenTo(x => x.OutputDeviceId) .ObserveOn(uiScheduler) .SubscribeSafe(x => WaveOutDeviceSelector.SelectById(x), Log.HandleException) .AddTo(Anchors); viewController .WhenLoaded .Take(1) .Select(_ => configProvider.ListenTo(y => y.StartMinimized)) .Switch() .Take(1) .ObserveOn(uiScheduler) .SubscribeSafe( x => { if (x) { Log.Debug($"StartMinimized option is active - minimizing window, current state: {WindowState}"); StartMinimized = true; viewController.Hide(); } else { Log.Debug($"StartMinimized option is not active - showing window as Normal, current state: {WindowState}"); StartMinimized = false; viewController.Show(); } }, Log.HandleUiException) .AddTo(Anchors); Observable.Merge( microphoneControllerViewModel.ObservableForProperty(x => x.MuteMode, skipInitial: true).ToUnit(), waveOutDeviceSelector.ObservableForProperty(x => x.SelectedItem, skipInitial: true).ToUnit(), this.ObservableForProperty(x => x.AudioNotification, skipInitial: true).ToUnit(), this.ObservableForProperty(x => x.MinimizeOnClose, skipInitial: true).ToUnit(), this.ObservableForProperty(x => x.Width, skipInitial: true).ToUnit(), this.ObservableForProperty(x => x.Height, skipInitial: true).ToUnit(), this.ObservableForProperty(x => x.Top, skipInitial: true).ToUnit(), this.ObservableForProperty(x => x.Left, skipInitial: true).ToUnit(), this.ObservableForProperty(x => x.AudioNotificationVolume, skipInitial: true).ToUnit(), this.ObservableForProperty(x => x.StartMinimized, skipInitial: true).ToUnit()) .Throttle(ConfigThrottlingTimeout) .ObserveOn(uiScheduler) .SubscribeSafe(() => { var config = configProvider.ActualConfig.CloneJson(); config.Notifications = AudioNotification; config.NotificationVolume = AudioNotificationVolume; config.StartMinimized = StartMinimized; config.MinimizeOnClose = MinimizeOnClose; config.OutputDeviceId = waveOutDeviceSelector.SelectedItem?.Id; config.MainWindowBounds = new Rect(Left, Top, Width, Height); configProvider.Save(config); }, Log.HandleUiException) .AddTo(Anchors); viewController.WhenLoaded .SubscribeSafe(() => { Log.Debug($"Main window loaded - loading overlay, current process({CurrentProcess.ProcessName} 0x{CurrentProcess.Id:x8}) main window: {CurrentProcess.MainWindowHandle} ({CurrentProcess.MainWindowTitle})"); overlayWindowController.RegisterChild(Overlay).AddTo(Anchors); Log.Debug("Overlay loaded successfully"); }, Log.HandleUiException) .AddTo(Anchors); configProvider.ListenTo(x => x.MainWindowBounds) .WithPrevious() .ObserveOn(uiScheduler) .SubscribeSafe(x => { Log.Debug($"Main window config bounds updated: {x}"); Rect bounds; if (x.Current == null) { var monitorBounds = UnsafeNative.GetMonitorBounds(Rectangle.Empty).ScaleToWpf(); var monitorCenter = monitorBounds.Center(); bounds = new Rect( monitorCenter.X - DefaultSize.Width / 2f, monitorCenter.Y - DefaultSize.Height / 2f, DefaultSize.Width, DefaultSize.Height); } else { bounds = x.Current.Value; } Left = bounds.Left; Top = bounds.Top; Width = bounds.Width; Height = bounds.Height; }, Log.HandleUiException) .AddTo(Anchors); var theme = Theme.Create( Theme.Light, primary: SwatchHelper.Lookup[(MaterialDesignColor)PrimaryColor.BlueGrey], accent: SwatchHelper.Lookup[(MaterialDesignColor)SecondaryColor.LightBlue]); var paletteHelper = new PaletteHelper(); paletteHelper.SetTheme(theme); }
public MainWindowViewModel( [NotNull] IAppArguments appArguments, [NotNull] IFactory <IStartupManager, StartupManagerArgs> startupManagerFactory, [NotNull] IMicrophoneControllerEx microphoneController, [NotNull] IMicSwitchOverlayViewModel overlay, [NotNull] IAudioNotificationsManager audioNotificationsManager, [NotNull] IFactory <IAudioNotificationSelectorViewModel> audioSelectorFactory, [NotNull] IApplicationUpdaterViewModel appUpdater, [NotNull][Dependency(WellKnownWindows.MainWindow)] IWindowTracker mainWindowTracker, [NotNull] IConfigProvider <MicSwitchConfig> configProvider, [NotNull] IComplexHotkeyTracker hotkeyTracker, [NotNull] IMicrophoneProvider microphoneProvider, [NotNull] IImageProvider imageProvider, [NotNull] IViewController viewController, [NotNull][Dependency(WellKnownSchedulers.UI)] IScheduler uiScheduler) { var startupManagerArgs = new StartupManagerArgs { UniqueAppName = $"{appArguments.AppName}{(appArguments.IsDebugMode ? "-debug" : string.Empty)}", ExecutablePath = appUpdater.GetLatestExecutable().FullName, CommandLineArgs = appArguments.StartupArgs, AutostartFlag = appArguments.AutostartFlag }; this.startupManager = startupManagerFactory.Create(startupManagerArgs); this.appArguments = appArguments; this.microphoneController = microphoneController; ApplicationUpdater = appUpdater; this.mainWindowTracker = mainWindowTracker; this.configProvider = configProvider; this.imageProvider = imageProvider; this.RaiseWhenSourceValue(x => x.IsActive, mainWindowTracker, x => x.IsActive).AddTo(Anchors); AudioSelectorWhenMuted = audioSelectorFactory.Create(); AudioSelectorWhenUnmuted = audioSelectorFactory.Create(); Observable.Merge( AudioSelectorWhenMuted.ObservableForProperty(x => x.SelectedValue, skipInitial: true), AudioSelectorWhenUnmuted.ObservableForProperty(x => x.SelectedValue, skipInitial: true)) .Subscribe(() => this.RaisePropertyChanged(nameof(AudioNotification)), Log.HandleException) .AddTo(Anchors); configProvider.ListenTo(x => x.Notification) .ObserveOn(uiScheduler) .Subscribe(cfg => { Log.Debug($"Applying new notification configuration: {cfg.DumpToTextRaw()} (current: {AudioNotification.DumpToTextRaw()})"); AudioNotification = cfg; }, Log.HandleException) .AddTo(Anchors); configProvider.ListenTo(x => x.IsPushToTalkMode) .ObserveOn(uiScheduler) .Subscribe(x => { IsPushToTalkMode = x; if (isPushToTalkMode) { MuteMicrophoneCommand.Execute(true); } }, Log.HandleException) .AddTo(Anchors); configProvider.ListenTo(x => x.SuppressHotkey) .ObserveOn(uiScheduler) .Subscribe(x => SuppressHotkey = x, Log.HandleException) .AddTo(Anchors); Observable.Merge(configProvider.ListenTo(x => x.MicrophoneHotkey), configProvider.ListenTo(x => x.MicrophoneHotkeyAlt)) .Select(x => new { Hotkey = (HotkeyGesture) new HotkeyConverter().ConvertFrom(configProvider.ActualConfig.MicrophoneHotkey ?? string.Empty), HotkeyAlt = (HotkeyGesture) new HotkeyConverter().ConvertFrom(configProvider.ActualConfig.MicrophoneHotkeyAlt ?? string.Empty), }) .ObserveOn(uiScheduler) .Subscribe(cfg => { Log.Debug($"Setting new hotkeys configuration: {cfg.DumpToTextRaw()} (current: {hotkey}, alt: {hotkeyAlt})"); Hotkey = cfg.Hotkey; HotkeyAlt = cfg.HotkeyAlt; }, Log.HandleException) .AddTo(Anchors); Overlay = overlay; this.RaiseWhenSourceValue(x => x.RunAtLogin, startupManager, x => x.IsRegistered, uiScheduler).AddTo(Anchors); this.RaiseWhenSourceValue(x => x.MicrophoneVolume, microphoneController, x => x.VolumePercent, uiScheduler).AddTo(Anchors); this.RaiseWhenSourceValue(x => x.MicrophoneMuted, microphoneController, x => x.Mute, uiScheduler).AddTo(Anchors); ImageProvider = imageProvider; microphoneProvider.Microphones .ToObservableChangeSet() .ObserveOn(uiScheduler) .Bind(out var microphones) .Subscribe() .AddTo(Anchors); Microphones = microphones; this.ObservableForProperty(x => x.MicrophoneMuted, skipInitial: true) .DistinctUntilChanged() .Where(x => !MicrophoneLine.IsEmpty) .Skip(1) // skip initial setup .Subscribe(x => { var cfg = configProvider.ActualConfig.Notification; var notificationToPlay = x.Value ? cfg.On : cfg.Off; Log.Debug($"Playing notification {notificationToPlay} (cfg: {cfg.DumpToTextRaw()})"); audioNotificationsManager.PlayNotification(notificationToPlay); }, Log.HandleUiException) .AddTo(Anchors); this.WhenAnyValue(x => x.MicrophoneLine) .DistinctUntilChanged() .Subscribe(x => microphoneController.LineId = x, Log.HandleUiException) .AddTo(Anchors); Observable.Merge( configProvider.ListenTo(x => x.MicrophoneLineId).ToUnit(), Microphones.ToObservableChangeSet().ToUnit()) .Select(_ => configProvider.ActualConfig.MicrophoneLineId) .ObserveOn(uiScheduler) .Subscribe(configLineId => { Log.Debug($"Microphone line configuration changed, lineId: {configLineId}, known lines: {Microphones.DumpToTextRaw()}"); var micLine = Microphones.FirstOrDefault(line => line.Equals(configLineId)); if (micLine.IsEmpty) { Log.Debug($"Selecting first one of available microphone lines, known lines: {Microphones.DumpToTextRaw()}"); micLine = Microphones.FirstOrDefault(); } MicrophoneLine = micLine; MuteMicrophoneCommand.ResetError(); }, Log.HandleUiException) .AddTo(Anchors); hotkeyTracker .WhenAnyValue(x => x.IsActive) .ObserveOn(uiScheduler) .Subscribe(async isActive => { if (isPushToTalkMode) { await MuteMicrophoneCommandExecuted(!isActive); } else { await MuteMicrophoneCommandExecuted(!MicrophoneMuted); } }, Log.HandleUiException) .AddTo(Anchors); ToggleOverlayLockCommand = CommandWrapper.Create( () => { if (overlay.IsLocked && overlay.UnlockWindowCommand.CanExecute(null)) { overlay.UnlockWindowCommand.Execute(null); } else if (!overlay.IsLocked && overlay.LockWindowCommand.CanExecute(null)) { overlay.LockWindowCommand.Execute(null); } }); ExitAppCommand = CommandWrapper.Create( () => { Log.Debug("Closing application"); configProvider.Save(configProvider.ActualConfig); Application.Current.Shutdown(); }); this.WhenAnyValue(x => x.WindowState) .Subscribe(x => ShowInTaskbar = x != WindowState.Minimized, Log.HandleUiException) .AddTo(Anchors); ShowAppCommand = CommandWrapper.Create( () => { if (Visibility != Visibility.Visible) { viewController.Show(); } else { viewController.Hide(); } }); OpenAppDataDirectoryCommand = CommandWrapper.Create(OpenAppDataDirectory); ResetOverlayPositionCommand = CommandWrapper.Create(ResetOverlayPositionCommandExecuted); RunAtLoginToggleCommand = CommandWrapper.Create <bool>(RunAtLoginCommandExecuted); MuteMicrophoneCommand = CommandWrapper.Create <bool>(MuteMicrophoneCommandExecuted); SelectMicrophoneIconCommand = CommandWrapper.Create(SelectMicrophoneIconCommandExecuted); SelectMutedMicrophoneIconCommand = CommandWrapper.Create(SelectMutedMicrophoneIconCommandExecuted); ResetMicrophoneIconsCommand = CommandWrapper.Create(ResetMicrophoneIconsCommandExecuted); var executingAssemblyName = Assembly.GetExecutingAssembly().GetName(); Title = $"{(appArguments.IsDebugMode ? "[D]" : "")} {executingAssemblyName.Name} v{executingAssemblyName.Version}"; WindowState = WindowState.Minimized; viewController .WhenLoaded .Take(1) .Select(() => configProvider.ListenTo(y => y.StartMinimized)) .Switch() .Take(1) .ObserveOn(uiScheduler) .Subscribe( x => { if (x) { Log.Debug($"StartMinimized option is active - minimizing window, current state: {WindowState}"); StartMinimized = true; viewController.Hide(); } else { Log.Debug($"StartMinimized option is not active - showing window as Normal, current state: {WindowState}"); StartMinimized = false; viewController.Show(); } }, Log.HandleUiException) .AddTo(Anchors); // config processing Observable.Merge( this.ObservableForProperty(x => x.MicrophoneLine, skipInitial: true).ToUnit(), this.ObservableForProperty(x => x.IsPushToTalkMode, skipInitial: true).ToUnit(), this.ObservableForProperty(x => x.AudioNotification, skipInitial: true).ToUnit(), this.ObservableForProperty(x => x.HotkeyAlt, skipInitial: true).ToUnit(), this.ObservableForProperty(x => x.Hotkey, skipInitial: true).ToUnit(), this.ObservableForProperty(x => x.SuppressHotkey, skipInitial: true).ToUnit(), this.ObservableForProperty(x => x.StartMinimized, skipInitial: true).ToUnit()) .Throttle(ConfigThrottlingTimeout) .ObserveOn(uiScheduler) .Subscribe(() => { var config = configProvider.ActualConfig.CloneJson(); config.IsPushToTalkMode = IsPushToTalkMode; config.MicrophoneHotkey = (Hotkey ?? new HotkeyGesture()).ToString(); config.MicrophoneHotkeyAlt = (HotkeyAlt ?? new HotkeyGesture()).ToString(); config.MicrophoneLineId = MicrophoneLine; config.Notification = AudioNotification; config.SuppressHotkey = SuppressHotkey; config.StartMinimized = StartMinimized; configProvider.Save(config); }, Log.HandleUiException) .AddTo(Anchors); }
public static Task Exit(IStartupManager startupManager) { return startupManager.Exit(); }
protected MainPageViewModelBase(IWorkbook workbook, ISynchronizationManager synchronizationManager, IStartupManager startupManager, IMessageBoxService messageBoxService, INotificationService notificationService, INavigationService navigationService, IPlatformService platformService, ITileManager tileManager, ITrackingManager trackingManager, ISpeechService speechService) : base(workbook, navigationService) { if (startupManager == null) { throw new ArgumentNullException(nameof(startupManager)); } if (synchronizationManager == null) { throw new ArgumentNullException(nameof(synchronizationManager)); } if (messageBoxService == null) { throw new ArgumentNullException(nameof(messageBoxService)); } if (platformService == null) { throw new ArgumentNullException(nameof(platformService)); } if (notificationService == null) { throw new ArgumentNullException(nameof(notificationService)); } if (tileManager == null) { throw new ArgumentNullException(nameof(tileManager)); } if (trackingManager == null) { throw new ArgumentNullException(nameof(trackingManager)); } if (speechService == null) { throw new ArgumentNullException(nameof(speechService)); } this.synchronizationManager = synchronizationManager; this.messageBoxService = messageBoxService; this.notificationService = notificationService; this.platformService = platformService; this.tileManager = tileManager; this.trackingManager = trackingManager; this.speechService = speechService; this.synchronizationManager.OperationStarted += this.OnSyncStarted; this.synchronizationManager.OperationProgressChanged += this.OnSyncProgressChanged; this.synchronizationManager.OperationCompleted += this.OnSyncOperationCompleted; this.synchronizationManager.OperationFailed += this.OnSyncOperationFailed; this.synchronizationManager.PropertyChanged += (s, e) => { if (e.PropertyName == "ActiveService") { this.RaisePropertyChanged("SyncPrioritySupport"); } }; this.Workbook.Settings.KeyChanged += this.OnSettingsChanged; this.Workbook.TaskAdded += this.OnTaskAddded; this.Workbook.FoldersReordered += this.OnFolderReordered; this.Workbook.ContextsReordered += this.OnContextReordered; this.addViewCommand = new RelayCommand(this.AddViewExecute); this.addSmartViewCommand = new RelayCommand(this.AddSmartViewExecute); this.addFolderCommand = new RelayCommand(this.AddFolderExecute); this.addContextCommand = new RelayCommand(this.AddContextExecute); this.addTaskCommand = new RelayCommand(this.AddTaskExecute); this.syncCommand = new RelayCommand(this.SyncExecute); this.openSettingsCommand = new RelayCommand(this.OpenSettingsExecute); this.openDebugCommand = new RelayCommand(this.OpenDebugExecute); this.clearSearchCommand = new RelayCommand(this.ClearSearchExecute); this.speechCommand = new RelayCommand(this.SpeechExecute); this.quickSpeechCommand = new RelayCommand(this.QuickSpeechExecute); this.printCommand = new RelayCommand(this.PrintExecute); this.shareCommand = new RelayCommand(this.ShareExecute); this.editCommand = new RelayCommand(this.EditExecute); this.deleteSelectionCommand = new RelayCommand(this.DeleteSelectionExecute); this.completeSelectionCommand = new RelayCommand(this.CompleteSelectionExecute); this.toggleTaskCompletionCommand = new RelayCommand <ITask>(this.ToggleTaskCompletionExecute); this.setPrioritySelectionCommand = new RelayCommand <string>(this.SetPrioritySelectionExecute); this.menuItems = new SortableObservableCollection <MenuItemViewModel>(); bool hasViews = this.Workbook.Views.Any(v => v.IsEnabled); bool hasSmartViews = this.Workbook.SmartViews.Any(); bool hasFolders = this.Workbook.Folders.Any(); bool hasContexts = this.Workbook.Contexts.Any(); // create search view this.viewSearch = new ViewSearch(this.Workbook); this.searchFolderItem = new FolderItemViewModel(this.Workbook, this.viewSearch); // load views foreach (var view in this.Workbook.Views.Where(f => f.IsEnabled)) { this.menuItems.Add(new FolderItemViewModel(workbook, view)); } // load smart views if (this.Workbook.SmartViews.Any()) { if (hasViews) { this.menuItems.Add(new SeparatorItemViewModel(Constants.SeparatorSmartViewId)); } foreach (var smartview in this.Workbook.SmartViews) { this.menuItems.Add(new FolderItemViewModel(workbook, smartview)); } } // load folders if (this.Workbook.Folders.Count > 0) { if (hasViews || hasSmartViews) { this.menuItems.Add(new SeparatorItemViewModel(Constants.SeparatorFolderId)); } foreach (var folder in this.Workbook.Folders) { this.menuItems.Add(new FolderItemViewModel(workbook, folder)); } } // load contexts if (this.Workbook.Contexts.Count > 0) { if (hasViews || hasSmartViews || hasFolders) { this.menuItems.Add(new SeparatorItemViewModel(Constants.SeparatorContextId)); } foreach (var context in this.Workbook.Contexts) { this.menuItems.Add(new FolderItemViewModel(workbook, context)); } } // load tags if (this.Workbook.Tags.Any()) { if (hasViews || hasSmartViews || hasFolders || hasContexts) { this.menuItems.Add(new SeparatorItemViewModel(Constants.SeparatorTagId)); } foreach (var tag in this.Workbook.Tags) { this.menuItems.Add(new FolderItemViewModel(workbook, tag)); } } }
public MainPageViewModel(IWorkbook workbook, ISynchronizationManager synchronizationManager, IStartupManager startupManager, IMessageBoxService messageBoxService, INotificationService notificationService, INavigationService navigationService, IPlatformService platformService, ITileManager tileManager, ITrackingManager trackingManager, ISpeechService speechService) : base(workbook, synchronizationManager, startupManager, messageBoxService, notificationService, navigationService, platformService, tileManager, trackingManager, speechService) { this.printHelper = new PrintHelper(this.messageBoxService); this.jobScheduler = new AppJobScheduler(this.Workbook, this.synchronizationManager, () => this.MenuItems.OfType <FolderItemViewModel>()); }