private void Button_Submit(object sender, RoutedEventArgs e)
 {
     SaveSettings();
     TelegramBotHandler.Restart();
     KworkEventsFacade.RestartChecking();
     TrayIconHelper.ShowNotification("", "Submited.");
 }
        public MainWindow()
        {
            InitializeComponent();
            Inst = this;
            try
            {
                Uri iconUri = new Uri(System.IO.Path.Combine(Environment.CurrentDirectory, "icon.jpg"), UriKind.Absolute);
                Icon = BitmapFrame.Create(iconUri);
            }
            catch { }

            WebViewWindow.Inst.Visibility = Visibility.Visible;
            WebViewWindow.Inst.Visibility = Visibility.Hidden;
            LoadSettings();
            TelegramBotHandler.Restart();
            KworkEventsFacade.OnNewRecords += (records) =>
            {
                WindowLogger.Log("Send to telegram");
                TelegramBotHandler.Send(records);
            };
//#if RELEASE
            KworkEventsFacade.RestartChecking();
//#endif

            TrayIconHelper.InitTrayIcon(TrayIconHelper.MenuFromDict(new Dictionary <string, Action>()
            {
                {
                    "Show",
                    () =>
                    {
                        Dispatcher.Invoke(() => {
                            MainWindow.Inst.Visibility = Visibility.Visible;
                        });
                    }
                },
                {
                    "Exit",
                    () =>
                    {
                        Application.Current.Shutdown();
                    }
                }
            }));

            TrayIconHelper.ShowNotification("", "Kwork telegram bot launched successfully.");

            if (App.IsLaunchedWithSystem)
            {
                Task.Run(async() =>
                {
                    await Task.Delay(500);
                    Dispatcher.Invoke(() =>
                    {
                        this.Visibility = Visibility.Hidden;
                        WebViewWindow.Inst.Visibility = Visibility.Hidden;
                    });
                });
            }
        }