using DataModel.Database; using Processor; using UI_WinForms.Dialogs; namespace UI_WinForms.Components; public partial class Main : UserControl { public Main() { this.InitializeComponent(); Program.RestartMainApp = false; // Register the something changed event to trigger the export: AppEvents.WhenSomethingChanged += async (_, _) => await ExportProcessor.TriggerExport(); // Check, if the DeepL integration is enabled, but no API key is set: this.Load += async (sender, args) => { var deepLAPIKey = await AppSettings.GetDeepLAPIKey(); var deepLMode = await AppSettings.GetDeepLMode(); if (deepLMode is not SettingDeepLMode.DISABLED && string.IsNullOrWhiteSpace(deepLAPIKey)) { // Show the input dialog to ask the user for the DeepL API key: var inputDialog = InputDialog.Show(new InputDialog.Options { Title = "I18NCommander - DeepL API Key", Message = "The DeepL integration is enabled, but there is no API key set. Do you want to set one now?", OkButtonText = "Set API key", CancelButtonText = "No, thanks", ShowQuestionCheckbox = false, }); if (inputDialog.DialogResult == DialogResult.OK) { await AppSettings.SetDeepLAPIKey(inputDialog.Text); AppEvents.SettingsChanged(); } } }; } private void tabControl_SelectedIndexChanged(object sender, EventArgs e) { if (this.settings.NeedRestart()) { var result = MessageBox.Show("You need to restart the app for the changes to take effect. Do you want to restart?", "Restart required", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1); if(result == DialogResult.Yes) { Program.RestartMainApp = true; AppEvents.ResetAllSubscriptions(); this.ParentForm!.Close(); } } } }