Esempio n. 1
0
 public void AfterMainWindowLoaded(IMainWindowViewModel _)
 {
     if (checkUpdatesOnStartUp.GetValue <bool>())
     {
         Task.Run(CheckForUpdates);
     }
 }
Esempio n. 2
0
        private async void CheckForUpdates()
        {
            try
            {
                using (var webclient = new WebClient())
                {
                    webclient.Headers.Add(HttpRequestHeader.UserAgent, appInfo.Name);
                    var releases = await JsonSerializer.DeserializeAsync <List <Release> >(await webclient.OpenReadTaskAsync($"https://api.github.com/repos/WClipboard/{appInfo.Name}/releases"), new JsonSerializerOptions(JsonSerializerDefaults.Web) { PropertyNamingPolicy = new SnakeCaseJsonNamingPolicy() });

                    var checkForPrereleases = checkPrereleasesSetting.GetValue <bool>();
                    newestRelease = releases?.Where(r => !r.Draft && (!r.Prerelease || checkForPrereleases)).MaxBy(r => r.GetVersion());

                    if (newestRelease != null && newestRelease.GetVersion() > appInfo.Version)
                    {
                        var toast = new ToastContentBuilder()
                                    .AddText($"New version of {appInfo.Name} available")
                                    .AddText($"v{appInfo.Version} => {newestRelease.TagName}{(newestRelease.Prerelease ? " (prerelease)" : "")}")
                                    .AddButton(new ToastButton().SetContent("Download").SetProtocolActivation(new Uri(newestRelease.HtmlUrl)))
                                    .SetToastDuration(ToastDuration.Long);
                        await notificationsManager.ShowNotification(toast, (n) =>
                        {
                            n.ExpirationTime  = new DateTimeOffset(DateTime.Now).Add(new TimeSpan(0, 10, 0));
                            n.ExpiresOnReboot = true;
                        });
                    }
                }
            }
            catch (UriFormatException ex)
            {
                logger.Log(LogLevel.Critical, "Could not parse newest release html page to uri", ex);
            }
            catch (JsonException ex)
            {
                logger.Log(LogLevel.Warning, "Could not parse github api response to Json", ex);
            }
            catch (WebException ex)
            {
                logger.Log(LogLevel.Info, "Something went wrong when checking for updates", ex);
            }
        }
Esempio n. 3
0
        public bool ShouldFilter(ClipboardTrigger clipboardTrigger, IEnumerable <EqualtableFormat> equaltableFormats)
        {
            if (clipboardTrigger.AdditionalInfo.TryGetValue <Windows10HistoryInfo>(out var historyInfo) && !historyInfo.Allowed && historySetting.GetValue <bool>())
            {
                return(true);
            }
            if (clipboardTrigger.AdditionalInfo.TryGetValue <Windows10CloudInfo>(out var cloudInfo) && !cloudInfo.Allowed && cloudSetting.GetValue <bool>())
            {
                return(true);
            }

            return(false);
        }