using System; using System.Windows; using System.Windows.Forms; // Requires UseWindowsForms in csproj using System.IO; namespace ElectronizerWPF { public partial class MainWindow : Window { private readonly ElectronizerLogic _logic; public MainWindow() { InitializeComponent(); _logic = new ElectronizerLogic(); _logic.OnLog += Logic_OnLog; } private void Logic_OnLog(string message) { Dispatcher.Invoke(() => { txtLog.AppendText(message + Environment.NewLine); txtLog.ScrollToEnd(); }); } private void BtnBrowseInput_Click(object sender, RoutedEventArgs e) { using var dialog = new FolderBrowserDialog { Description = "Select Vite/React Project Folder", UseDescriptionForTitle = true, ShowNewFolderButton = false }; if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK) { txtInputPath.Text = dialog.SelectedPath; ValidateInputs(); } } private void BtnBrowseOutput_Click(object sender, RoutedEventArgs e) { using var dialog = new FolderBrowserDialog { Description = "Select Destination Folder for Electron App", UseDescriptionForTitle = true, ShowNewFolderButton = true }; if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK) { txtOutputPath.Text = dialog.SelectedPath; ValidateInputs(); } } private void ValidateInputs() { btnConvert.IsEnabled = !string.IsNullOrWhiteSpace(txtInputPath.Text) && !string.IsNullOrWhiteSpace(txtOutputPath.Text) && Directory.Exists(txtInputPath.Text); } private async void BtnConvert_Click(object sender, RoutedEventArgs e) { btnConvert.IsEnabled = false; txtLog.Clear(); string inputPath = txtInputPath.Text; string outputPath = txtOutputPath.Text; try { bool skipBuild = chkSkipBuild.IsChecked == true; bool buildExe = chkBuildExe.IsChecked == true; await _logic.RunConversionAsync(inputPath, outputPath, skipBuild, buildExe); System.Windows.MessageBox.Show("Conversion Completed Successfully!", "Success", MessageBoxButton.OK, MessageBoxImage.Information); } catch (Exception ex) { System.Windows.MessageBox.Show($"Error: {ex.Message}", "Conversion Failed", MessageBoxButton.OK, MessageBoxImage.Error); Logic_OnLog($"CRITICAL ERROR: {ex.Message}"); } finally { btnConvert.IsEnabled = true; } } } }