Exemple #1
0
        public MainWindow()
        {
            InitializeComponent();
            this.AttachDevTools();

            this.PropertyChanged += (s, e) =>
            {
                if (e.Property == Control.DataContextProperty)
                {
                    ctx = (MainWindowViewModel)e.NewValue !;

                    ctx.OnUpdateAction = ManualUpdate_Click;
                }
            };

            Closing += (sender, args) => MainViewClosing?.Invoke(sender, args);

            InputManager.Instance.PreProcess.OfType <RawInputEventArgs>()
            .Throttle(TimeSpan.FromMilliseconds(500))
            .Subscribe(
                (_) =>
            {
                if (_inactivityControlEnabled && _activityTimer != null)
                {
                    _activityTimer.Stop();
                    _activityTimer.Start();
                }
            });

            _sparkle = new SparkleUpdater(
                "https://github.com/atomex-me/atomex.client.desktop/releases/latest/download/appcast.xml",
                new Ed25519Checker(SecurityMode.OnlyVerifySoftwareDownloads,
                                   "76FH2gIo7D5mpPPfnard5C9cVwq8TFaxpo/Wi2Iem/E="))
            {
                UserInteractionMode = UserInteractionMode.DownloadNoInstall
            };
            _sparkle.LogWriter            = new SparkleLogger();
            _sparkle.SecurityProtocolType = System.Net.SecurityProtocolType.Tls12;
            _sparkle.StartLoop(false, false);

            CheckForUpdates(null, null);
            var checkUpdateReadyTimer = new Timer(TimeSpan.FromMinutes(5).TotalMilliseconds);

            checkUpdateReadyTimer.AutoReset = true;
            checkUpdateReadyTimer.Elapsed  += CheckForUpdates;
            checkUpdateReadyTimer.Start();

            _sparkle.DownloadStarted  += (item, path) => { Console.WriteLine($"Updating download started {path}"); };
            _sparkle.DownloadFinished += (item, path) =>
            {
                Console.WriteLine($"Updating download finished ${path}");
                ctx.UpdateDownloadProgress = 100;
            };

            _sparkle.DownloadMadeProgress += (sender, item, args) =>
            {
                ctx.UpdateDownloadProgress =
                    (int)((double)args.BytesReceived / (double)args.TotalBytesToReceive * 100);
            };
        }
        public MainWindow()
        {
            InitializeComponent();

            Closing += (sender, args) => MainViewClosing?.Invoke(sender, args);

            InputManager.Current.PreProcessInput += (sender, args) =>
            {
                var inputEventArgs = args.StagingItem.Input;

                if (inputEventArgs is MouseEventArgs || inputEventArgs is KeyboardEventArgs)
                {
                    if (args.StagingItem.Input is MouseEventArgs mouseEventArgs)
                    {
                        // no button is pressed and the position is still the same as the application became inactive
                        if (mouseEventArgs.LeftButton == MouseButtonState.Released &&
                            mouseEventArgs.RightButton == MouseButtonState.Released &&
                            mouseEventArgs.MiddleButton == MouseButtonState.Released &&
                            mouseEventArgs.XButton1 == MouseButtonState.Released &&
                            mouseEventArgs.XButton2 == MouseButtonState.Released &&
                            _inactiveMousePosition == mouseEventArgs.GetPosition(MainDockerPanel))
                        {
                            return;
                        }
                    }

                    if (_inactivityControlEnabled && _activityTimer != null)
                    {
                        _activityTimer.Stop();
                        _activityTimer.Start();
                    }
                }
            };
        }
 protected override void OnClosing(CancelEventArgs e)
 {
     MainViewClosing?.Invoke();
     base.OnClosing(e);
 }