Exemple #1
0
        private async void Run(int interval, CancellationToken token)
        {
            while (true)
            {
                await Task.Run(() => {
                    ReleaseInfo = RequestInfo();

                    // Same version check
                    if (GetVersionTagName() == ReleaseInfo.TagName)
                    {
                        return;
                    }

                    // Subscriber check
                    if (OnUpdateAvailable == null)
                    {
                        return;
                    }

                    // Trigger event on main thread
                    Application.Current.Dispatcher.Invoke(() => {
                        OnUpdateAvailable.Invoke(this, ReleaseInfo);
                    });
                });

                await Task.Delay(interval, token);

                if (token.IsCancellationRequested)
                {
                    return;
                }
            }
        }
Exemple #2
0
        private void WC_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
        {
            if (e.Error != null)
            {
                return;
            }

            try
            {
                using (MemoryStream ms = new MemoryStream(System.Text.Encoding.ASCII.GetBytes(e.Result)))
                {
                    updInfo        = jsonSerializer.ReadObject(ms) as UpdateInfo;
                    updInfo.Loaded = true;
                }

                if (IsNewerVersionAvailable())
                {
                    OnUpdateAvailable?.Invoke();
                }
            }
            catch (Exception ex)
            {
                OnExceptionRaised?.Invoke(ex);
            }
        }
Exemple #3
0
        private async Task SetupUpdateCheckAsync()
        {
            updateChecker = new UpdateChecker("mibbio", "satisfactoryoverlay");
            updateChecker.OnUpdateAvailable += HandleUpdateAvailable;

            var latestUpdate = await updateChecker.CheckForUpdateAsync();

            if (latestUpdate != null)
            {
                OnUpdateAvailable?.Invoke(this, latestUpdate);
            }

            updateChecker.CheckWithInterval(TimeSpan.FromMinutes(15));
        }
Exemple #4
0
        public void CheckWithInterval(TimeSpan interval)
        {
            if (_timer == null)
            {
                _timer       = new DispatcherTimer(DispatcherPriority.Background);
                _timer.Tick += new EventHandler(async(s, e) =>
                {
                    var update = await CheckForUpdateAsync();
                    if (update != null)
                    {
                        OnUpdateAvailable?.Invoke(this, update);
                    }
                });
            }

            _timer.Stop();
            _timer.Interval = interval;
            _timer.Start();
        }
Exemple #5
0
        /// <summary>
        /// Checks for a new version of the application and prompts the user to update if a new version is available
        /// </summary>
        /// <returns></returns>
        public async Task CheckForUpdatesAsync()
        {
            _log.Debug("Checking for updates");

            OnCheckingForUpdates?.Invoke(this, new());

            string json = await _http.GetStringAsync(URL);

            _latestRelease = JsonSerializer.Deserialize <LatestRelease>(json);
            var latestVersion = new Version(_latestRelease.tag_name.Replace("v", ""));
            var compare       = Common.Constants.Version.AsDotNetVersion().CompareTo(latestVersion);

            if (compare < 0)
            {
                OnUpdateAvailable?.Invoke(this, new(latestVersion));
            }
            else
            {
                OnUpToDate?.Invoke(this, new());
            }
        }
Exemple #6
0
 private void HandleUpdateAvailable(object sender, ReleaseData update)
 {
     OnUpdateAvailable?.Invoke(sender, update);
 }
Exemple #7
0
        private async Task MakeUpdateableAsync()
        {
            await OnUpdateAvailable.InvokeAsync();

            await Tooltip.ShowAsync(Button);
        }