private async void MainWindow_Loaded(object sender, RoutedEventArgs e) { var dataContext = (MainWindowModel)DataContext; var updates = await UpdateClient.Check(); if (updates.Length > 0) { dataContext.UpdateStatus = UpdateStatus.Confirmation; return; } // XXX: 微妙な依存関係... if (Program.silent) { this.Close(); return; } dataContext.UpdatedResultMessage = "アップデートはありません。最新の状態です。"; dataContext.UpdateStatus = UpdateStatus.Updated; }
private async void UpdateButton_Click(object sender, RoutedEventArgs e) { var dataContext = (MainWindowModel)DataContext; dataContext.UpdateStatus = UpdateStatus.Updating; var updates = await Task.Run(async() => { return(await UpdateClient.Check()); }); var result = await Task.Run(async() => { return(await UpdateClient.Update(updates)); }); switch (result) { case UpdateClient.UpdateResult.SuccessAndRestart: Close(); return; case UpdateClient.UpdateResult.Failure: dataContext.UpdatedResultMessage = $"アップデートに失敗しました。"; break; case UpdateClient.UpdateResult.Success: dataContext.UpdatedResultMessage = "アップデートが完了しました。"; break; default: break; } dataContext.UpdateStatus = UpdateStatus.Updated; }
//comon events private async void windowLoaded(object sender, RoutedEventArgs e) { if (CanWork) { CreateIcon(); var list = await LoadLanguages(); list.Add(new LanguageObject() { LanguageIso = "en", LanguageName = "English" }); cbLanguage.ItemsSource = list; var selectedLang = from lang in list where lang.LanguageIso == settings.GetValue("LanguageIso", "en") select lang; cbLanguage.SelectedItem = selectedLang.FirstOrDefault(); cbLanguage.SelectionChanged += CbLanguageSelectionChanged; if (settings.GetValue("AutomaticDetection", false)) { location = new PCLocation(); cbAutomaticLocation.IsChecked = settings.GetValue <bool>("AutomaticDetection"); cbCuntry.IsEnabled = false; cbCity.IsEnabled = false; } else { cbCuntry.IsEnabled = true; cbCuntry.ItemsSource = weather.geonames.geonames; var selectedContry = from contry in weather.geonames.geonames where contry.geonameId == settings.GetValue("GeonameID", 6252001) select contry; cbCuntry.SelectedItem = selectedContry.FirstOrDefault(); cbCuntry.SelectionChanged += CbCuntrySelectionChanged; cbCity.IsEnabled = true; var cityList = await LoadCity((cbCuntry.SelectedItem as Geoname).countryCode); cbCity.ItemsSource = cityList; var selectedCity = from city in cityList where city.geonameId == settings.GetValue("CityGeonameID", 5128581) select city; cbCity.SelectedItem = selectedCity.FirstOrDefault(); cbCity.SelectionChanged += CbCitySelectionChanged; } cbAutomaticLocation.Click += CbAutomaticLocationClick; cbThemperature.SelectedIndex = settings.GetValue("Celsium", 0); cbThemperature.SelectionChanged += CbThemperatureSelectionChanged; cbIcon.IsChecked = settings.GetValue("LoadIcon", true); cbIcon.Click += CbIconClick; cbCondition.IsChecked = settings.GetValue("ShowCondition", true); cbCondition.Click += CbConditionClick; cbThemperatureShow.IsChecked = settings.GetValue("ShowThemperatue", true); cbThemperatureShow.Click += CbThemperatureShowClick; cbLocationShow.IsChecked = settings.GetValue("ShowLocation", true); cbLocationShow.Click += CbLocationShowClick; cbShowInetMessage.IsChecked = settings.GetValue("ShowInetDis", false); cbShowInetMessage.Click += CbShowInetMessageClick; RegistryKey key = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true); if ((string)key.GetValue("Weather Widget") == null) { cbStartUP.IsChecked = false; } else { cbStartUP.IsChecked = true; } cbStartUP.Click += CbStartUPClick; colorPicker.SelectedColor = settings.GetValue("TextColor", new WeatherColor(255, 255, 255, 255)).GetColor(); colorPicker.SelectedColorChanged += colorPickerSelectionColorChanged; colorPickerBackground.SelectedColor = settings.GetValue("BackgroundColor", new WeatherColor(0, 255, 255, 255)).GetColor(); colorPickerBackground.SelectedColorChanged += ColorPickerBackgroundSelectedColorChanged; colorPickerBorder.SelectedColor = settings.GetValue("BorderColor", new WeatherColor(0, 255, 255, 255)).GetColor(); colorPickerBorder.SelectedColorChanged += ColorPickerBorderSelectedColorChanged; var th = settings.GetValue("WidgetBorder", new WidgetBorder(1, 1, 1, 1)).GetBorder(); tbBorderLeft.Text = th.Left.ToString(); tbBorderRight.Text = th.Right.ToString(); tbBorderTop.Text = th.Top.ToString(); tbBorderBottom.Text = th.Bottom.ToString(); tbBorderLeft.TextChanged += TbBorderTextChanged; tbBorderRight.TextChanged += TbBorderTextChanged; tbBorderTop.TextChanged += TbBorderTextChanged; tbBorderBottom.TextChanged += TbBorderTextChanged; widget.SetWidgetBorder(); widget.SetWidgetTextColor(); widget.SetWidgetBackgroundColor(); widget.SetWidgetBorderColor(); UpdateWidget(); widget.ShowWidget(true); Update = new UpdateClient("https://ogycode.github.io/WeatherWidget/update.json"); Update.NewVersion += UpdateNewVersion; var assembly = Assembly.GetExecutingAssembly(); var version = assembly.GetName().Version; Update.Check(new Verloka.HelperLib.Update.Version(version.Major, version.Minor, version.MajorRevision, version.MinorRevision)); } }