示例#1
0
        public MainWindow()
        {
            Instance = this;

            ServiceProvider.RegionProvider = new RegionSelector();

            ServiceProvider.MessageProvider = new MessageProvider();

            ServiceProvider.WebCamProvider = new WebCamProvider();

            FFMpegService.FFMpegDownloader += () =>
            {
                if (_downloader == null)
                {
                    _downloader         = new FFMpegDownloader();
                    _downloader.Closed += (Sender, Args) => _downloader = null;
                }

                _downloader.ShowAndFocus();
            };

            InitializeComponent();

            ServiceProvider.MainWindow = new MainWindowProvider(this);

            if (App.CmdOptions.Tray)
            {
                Hide();
            }

            // Register for Windows Messages
            ComponentDispatcher.ThreadPreprocessMessage += (ref MSG Message, ref bool Handled) =>
            {
                const int wmHotkey = 786;

                if (Message.message == wmHotkey)
                {
                    var id = Message.wParam.ToInt32();

                    ServiceProvider.RaiseHotKeyPressed(id);
                }
            };

            ServiceProvider.SystemTray = new SystemTray(SystemTray);

            Closing += (Sender, Args) =>
            {
                if (!TryExit())
                {
                    Args.Cancel = true;
                }
            };

            Loaded += (Sender, Args) =>
            {
                RepositionWindowIfOutside();

                if (DataContext is MainViewModel vm)
                {
                    ServiceProvider.MainViewModel = vm;

                    vm.Init(!App.CmdOptions.NoPersist, true, !App.CmdOptions.Reset, !App.CmdOptions.NoHotkeys);
                }
            };
        }
示例#2
0
        public MainWindow()
        {
            Instance = this;

            FFmpegService.FFmpegDownloader += () =>
            {
                if (_downloader == null)
                {
                    _downloader         = new FFmpegDownloaderWindow();
                    _downloader.Closed += (Sender, Args) => _downloader = null;
                }

                _downloader.ShowAndFocus();
            };

            InitializeComponent();

            var mainModel = ServiceProvider.Get <MainModel>();

            mainModel.Init(!App.CmdOptions.NoPersist, !App.CmdOptions.Reset, !App.CmdOptions.NoHotkeys);
            ServiceProvider.Get <HotkeyActionRegisterer>().Register();
            ServiceProvider.Get <TimerModel>().Init();

            var listener = new HotkeyListener();

            var hotkeyManager = ServiceProvider.Get <HotKeyManager>();

            listener.HotkeyReceived += Id => hotkeyManager.ProcessHotkey(Id);

            ServiceProvider.Get <HotKeyManager>().HotkeyPressed += Service =>
            {
                switch (Service)
                {
                case ServiceName.OpenImageEditor:
                    new ImageEditorWindow().ShowAndFocus();
                    break;

                case ServiceName.ShowMainWindow:
                    this.ShowAndFocus();
                    break;
                }
            };

            Loaded += (Sender, Args) =>
            {
                RepositionWindowIfOutside();

                SetupWebcamPreview();

                mainModel.ViewLoaded();
            };

            if (App.CmdOptions.Tray || ServiceProvider.Get <Settings>().Tray.MinToTrayOnStartup)
            {
                Hide();
            }

            Closing += (Sender, Args) =>
            {
                if (!TryExit())
                {
                    Args.Cancel = true;
                }
            };
        }