From 58e0d86d5212efebc84a22c8a626c863d08909c3 Mon Sep 17 00:00:00 2001 From: Thorsten Sommer Date: Sun, 12 Feb 2023 13:49:01 +0100 Subject: [PATCH] Ask user for API token when no one was set --- I18N Commander/Processor/Version.cs | 2 +- I18N Commander/UI WinForms/Components/Main.cs | 29 ++++++++++++++++++- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/I18N Commander/Processor/Version.cs b/I18N Commander/Processor/Version.cs index d02d278..26ad95d 100644 --- a/I18N Commander/Processor/Version.cs +++ b/I18N Commander/Processor/Version.cs @@ -2,5 +2,5 @@ public static class Version { - public static string Text => $"v0.8.4 (2023-02-12), .NET {Environment.Version}"; + public static string Text => $"v0.8.5 (2023-02-12), .NET {Environment.Version}"; } \ No newline at end of file diff --git a/I18N Commander/UI WinForms/Components/Main.cs b/I18N Commander/UI WinForms/Components/Main.cs index ec44a6e..976b26c 100644 --- a/I18N Commander/UI WinForms/Components/Main.cs +++ b/I18N Commander/UI WinForms/Components/Main.cs @@ -1,4 +1,6 @@ -using Processor; +using DataModel.Database; +using Processor; +using UI_WinForms.Dialogs; namespace UI_WinForms.Components; @@ -11,6 +13,31 @@ public partial class Main : UserControl // 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)