Feat: UI/UX y Procesos
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
using WhatsappPromo.Core.Models;
|
||||
using WhatsappPromo.Core.Services;
|
||||
|
||||
@@ -28,7 +30,6 @@ namespace WhatsappPromo.Worker.Controllers
|
||||
[HttpPost]
|
||||
public async Task<IActionResult> UpdateConfig([FromBody] SystemConfig config)
|
||||
{
|
||||
// Validar ruta
|
||||
if (!string.IsNullOrEmpty(config.DownloadPath))
|
||||
{
|
||||
try
|
||||
@@ -62,5 +63,64 @@ namespace WhatsappPromo.Worker.Controllers
|
||||
await _configService.UpdateConfigAsync(config);
|
||||
return Ok(new { status = "Stopping" });
|
||||
}
|
||||
|
||||
[System.Runtime.InteropServices.DllImport("user32.dll")]
|
||||
[return: System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.Bool)]
|
||||
private static extern bool SetForegroundWindow(IntPtr hWnd);
|
||||
|
||||
[System.Runtime.InteropServices.DllImport("user32.dll")]
|
||||
private static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int X, int Y, int cx, int cy, uint uFlags);
|
||||
|
||||
private static readonly IntPtr HWND_TOPMOST = new IntPtr(-1);
|
||||
private const uint SWP_NOSIZE = 0x0001;
|
||||
private const uint SWP_NOMOVE = 0x0002;
|
||||
private const uint SWP_SHOWWINDOW = 0x0040;
|
||||
|
||||
[HttpGet("browse")]
|
||||
public IActionResult Browse()
|
||||
{
|
||||
string? selectedPath = null;
|
||||
|
||||
var thread = new Thread(() =>
|
||||
{
|
||||
using (var dummyForm = new Form())
|
||||
{
|
||||
dummyForm.TopMost = true;
|
||||
// El form debe ser "real" para que Windows lo respete
|
||||
dummyForm.Width = 1; dummyForm.Height = 1;
|
||||
dummyForm.Opacity = 0.05;
|
||||
dummyForm.ShowInTaskbar = false;
|
||||
dummyForm.FormBorderStyle = FormBorderStyle.None;
|
||||
dummyForm.StartPosition = FormStartPosition.CenterScreen;
|
||||
|
||||
dummyForm.Show();
|
||||
|
||||
// Forzamos la posición al frente de todo
|
||||
SetWindowPos(dummyForm.Handle, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW);
|
||||
SetForegroundWindow(dummyForm.Handle);
|
||||
dummyForm.Activate();
|
||||
dummyForm.Focus();
|
||||
|
||||
using (var fbd = new FolderBrowserDialog())
|
||||
{
|
||||
fbd.Description = "Selecciona la carpeta para descargas de WhatsApp";
|
||||
fbd.UseDescriptionForTitle = true;
|
||||
fbd.ShowNewFolderButton = true;
|
||||
|
||||
if (fbd.ShowDialog(dummyForm) == DialogResult.OK)
|
||||
{
|
||||
selectedPath = fbd.SelectedPath;
|
||||
}
|
||||
}
|
||||
dummyForm.Close();
|
||||
}
|
||||
});
|
||||
|
||||
thread.SetApartmentState(ApartmentState.STA);
|
||||
thread.Start();
|
||||
thread.Join();
|
||||
|
||||
return Ok(new { path = selectedPath });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user