Exemplo n.º 1
0
        public CoreViewModel(
            SettingsService settingsService,
            GammaService gammaService,
            HotKeyService hotKeyService,
            ExternalApplicationService externalApplicationService)
        {
            _settingsService            = settingsService;
            _gammaService               = gammaService;
            _hotKeyService              = hotKeyService;
            _externalApplicationService = externalApplicationService;

            _updateConfigurationTimer = Timer.Create(TimeSpan.FromMilliseconds(50), UpdateConfiguration);
            _updateInstantTimer       = Timer.Create(TimeSpan.FromMilliseconds(50), UpdateInstant);
            _updateIsPausedTimer      = Timer.Create(TimeSpan.FromSeconds(1), UpdateIsPaused);

            // Cancel 'disable temporarily' when switching to enabled
            this.Bind(o => o.IsEnabled, (sender, args) =>
            {
                if (IsEnabled)
                {
                    _enableAfterDelayRegistration?.Dispose();
                }
            });

            // Handle settings changes
            _settingsService.SettingsSaved += (sender, args) =>
            {
                Refresh();
                RegisterHotKeys();
            };
        }
Exemplo n.º 2
0
 protected override void OnSourceInitialized(EventArgs e)
 {
     base.OnSourceInitialized(e);
     _hotKeys = new HotKeyService(this, HandleHotKey);
     hotKey1  = _hotKeys.ListenForHotKey(System.Windows.Forms.Keys.F8, HotKeyModifiers.Control);
     hotKey2  = _hotKeys.ListenForHotKey(System.Windows.Forms.Keys.F9, HotKeyModifiers.Shift);
 }
Exemplo n.º 3
0
        private void Application_Startup(object sender, StartupEventArgs e)
        {
            if (!tryToCreateMutex())
            {
                return;
            }

            var configurationManager = new ConfigurationManagerXML <PowerSwitcherSettings>(Path.Combine(
                                                                                               Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),
                                                                                               "Petrroll", "PowerSwitcher", "PowerSwitcherSettings.xml"
                                                                                               ));

            Configuration = new ConfigurationInstance <PowerSwitcherSettings>(configurationManager);

            HotKeyManager = new HotKeyService();

            PowerManager = new PowerManager();
            MainWindow   = new MainWindow();
            TrayApp      = new TrayApp(PowerManager, Configuration); //Has to be last because it hooks to MainWindow

            Configuration.Data.PropertyChanged += Configuration_PropertyChanged;
            if (Configuration.Data.ShowOnShortcutSwitch)
            {
                registerHotkeyFromConfiguration();
            }
        }
Exemplo n.º 4
0
        public MainForm(BaseSettings settings,
                        Uploader uploader,
                        PipeServer pipeServer,
                        SingleInstance tasks,
                        HotKeyService hotkeyService,
                        SettingsService settingsService,
                        IEnumerable <IImageUploader> uploaders,
                        MusicPlayerService musicPlayerService,
                        ShotrApiService shotrApiService)
        {
            _settings           = settings;
            _uploader           = uploader;
            _pipeServer         = pipeServer;
            _tasks              = tasks;
            _hotkeyService      = hotkeyService;
            _settingsService    = settingsService;
            _uploaders          = uploaders;
            _musicPlayerService = musicPlayerService;
            _shotrApiService    = shotrApiService;

            InitializeComponent();

            Shown += MainFormShown;
            _pipeServer.PipeServerReceivedClient += _pipeserver_PipeServerReceivedClient;
            _pipeServer.StartServer();

            _shotrIcon = Icon;
        }
Exemplo n.º 5
0
        public RootViewModel(IViewModelFactory viewModelFactory, DialogManager dialogManager,
                             SettingsService settingsService, UpdateService updateService,
                             GammaService gammaService, HotKeyService hotKeyService,
                             RegistryService registryService, ExternalApplicationService externalApplicationService,
                             SystemEventService systemEventService)
        {
            _viewModelFactory           = viewModelFactory;
            _dialogManager              = dialogManager;
            _settingsService            = settingsService;
            _updateService              = updateService;
            _gammaService               = gammaService;
            _hotKeyService              = hotKeyService;
            _registryService            = registryService;
            _externalApplicationService = externalApplicationService;
            _systemEventService         = systemEventService;

            // Title
            DisplayName = $"{App.Name} v{App.VersionString}";

            // Cancel 'disable temporarily' when switched on
            this.Bind(o => o.IsEnabled, (sender, args) =>
            {
                if (IsEnabled)
                {
                    _enableAfterDelayTimer.Stop();
                }
            });

            // Initialize timers
            _updateConfigurationTimer = new AutoResetTimer(UpdateConfiguration);
            _updateInstantTimer       = new AutoResetTimer(UpdateInstant);
            _updateIsPausedTimer      = new AutoResetTimer(UpdateIsPaused);
            _checkForUpdatesTimer     = new AutoResetTimer(async() => await _updateService.CheckPrepareUpdateAsync());
            _pollingTimer             = new AutoResetTimer(PollGamma);
            _enableAfterDelayTimer    = new ManualResetTimer(Enable);

            // Reset gamma when power settings change
            _systemEventService.DisplayStateChanged += (sender, args) => InvalidateGamma();
            SystemEvents.DisplaySettingsChanging    += (sender, args) => InvalidateGamma();
            SystemEvents.DisplaySettingsChanged     += (sender, args) => InvalidateGamma();
        }
Exemplo n.º 6
0
        public CoreViewModel(
            SettingsService settingsService,
            GammaService gammaService,
            HotKeyService hotKeyService,
            ExternalApplicationService externalApplicationService)
        {
            _settingsService            = settingsService;
            _gammaService               = gammaService;
            _hotKeyService              = hotKeyService;
            _externalApplicationService = externalApplicationService;

            _updateConfigurationTimer = new AutoResetTimer(UpdateConfiguration);
            _updateInstantTimer       = new AutoResetTimer(UpdateInstant);
            _updateIsPausedTimer      = new AutoResetTimer(UpdateIsPaused);
            _pollingTimer             = new AutoResetTimer(PollGamma);
            _enableAfterDelayTimer    = new ManualResetTimer(Enable);

            // Cancel 'disable temporarily' when switched to enabled
            this.Bind(o => o.IsEnabled, (sender, args) =>
            {
                if (IsEnabled)
                {
                    _enableAfterDelayTimer.Stop();
                }
            });

            // Handle settings changes
            _settingsService.SettingsSaved += (sender, args) =>
            {
                _isStale = true;
                Refresh();
                RegisterHotKeys();
            };

            // Handle display settings changes
            _systemEvents.DisplaySettingsChanged += (sender, args) => _isStale = true;
            _systemEvents.DisplayStateChanged    += (sender, args) => _isStale = true;
        }
        protected override void OnStartup(StartupEventArgs e)
        {
            base.OnStartup(e);

            // UI and ViewModels
            var window       = new MainWindow();
            var windowHandle = new WindowInteropHelper(window).EnsureHandle();

            // Services
            IMonitorService   monitorService   = new MonitorService();
            ISettingsProvider settingsProvider = new SettingsProvider();
            IStartupService   startupService   = new RegistryStartupService();
            IDialogService    dialogService    = new DialogService();

            // HotKeys
            IHotKeyProcessor hotKeyProcessor = new HotKeyProcessor(windowHandle);
            IHotKeyService   hotKeyService   = new HotKeyService(hotKeyProcessor);

            // Set window DataContext and show.
            var vm = new MainViewModel(monitorService, hotKeyService, settingsProvider, startupService, dialogService);

            window.DataContext = vm;
            window.Visibility  = Visibility.Collapsed;
        }
Exemplo n.º 8
0
 public MainWindow()
 {
     _hotKeyService = new HotKeyService();
     InitializeComponent();
     Loaded += Window_Loaded;
 }