<commit_before>﻿using GifWin.Data;
using Squirrel;
using System;
using System.ComponentModel;
using System.Diagnostics;
using System.Threading.Tasks;
using System.Timers;
using System.Windows;
using System.Windows.Input;

namespace GifWin
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        Timer updateCheckTimer;

        public MainWindow ()
        {
            InitializeComponent ();
            ((MainWindowViewModel)DataContext).PropertyChanged += OnPropertyChanged;

            updateCheckTimer = new Timer (TimeSpan.FromSeconds (10).TotalSeconds);
            updateCheckTimer.Elapsed += CheckForUpdatesAsync;
            updateCheckTimer.Start ();
        }

        async void CheckForUpdatesAsync (object sender, ElapsedEventArgs e)
        {
            try {
                using (var updateMgr = new UpdateManager ("https://gifwin-releases.s3.amazonaws.com/")) {
                    await updateMgr.UpdateApp ();
                }
            } catch (Exception ex) {
                Debug.WriteLine ($"Error while calling UpdateManager!UpdateApp: {ex.Message}.");
                Debug.WriteLine (ex.ToString ());
            }
        }

        public new void Show ()
        {
            base.Show ();
            search.Focus ();
        }

        public new void Hide ()
        {
            search.Clear ();
            tag.Clear ();
            base.Hide ();
        }

        void AddNewGif (string gifUrl, string tags)<commit_msg>Fix update checking to not check every 10 seconds.<commit_after>﻿using GifWin.Data;
using Squirrel;
using System;
using System.ComponentModel;
using System.Diagnostics;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Input;

namespace GifWin
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        Timer updateCheckTimer;

        public MainWindow ()
        {
            InitializeComponent ();
            ((MainWindowViewModel)DataContext).PropertyChanged += OnPropertyChanged;
            updateCheckTimer = new Timer (CheckForUpdatesAsync, null, TimeSpan.FromMilliseconds(0), TimeSpan.FromHours(24));
        }

        async void CheckForUpdatesAsync (object sender)
        {
            try {
                using (var updateMgr = new UpdateManager ("https://gifwin-releases.s3.amazonaws.com/")) {
                    await updateMgr.UpdateApp ();
                }
            } catch (Exception ex) {
                DirectoryInfo storage = new DirectoryInfo (Path.Combine (Environment.GetFolderPath (Environment.SpecialFolder.LocalApplicationData), "GifWin", "Logs"));
                storage.Create ();
                var logPath = Path.Combine (storage.ToString (), $"Exception-Squirrel-{DateTimeOffset.UtcNow.ToUnixTimeSeconds ()}.log");
                using (var sw = new StreamWriter (logPath)) {
                    sw.WriteLine (ex.ToString ());
                }
            }
        }

        public new void Show ()
        {
            base.Show ();
            search.Focus ();
        }

        public new void Hide ()
        {
            search.Clear ();
            tag.Clear ();
            base.Hide ();
        }

        void AddNewGif (string gifUrl, string tags)
{'fraction_non_alphanumeric': 0.10131771595900439, 'fraction_numerical': 0.0026354319180087846, 'mean_word_length': 1.8973706530958439, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4414347', 'n_tokens_mistral': 886, 'n_tokens_neox': 855, 'n_words': 206}