Le copie esterne diventano usabili dall'interfaccia: ExportHub costruisce l'unico ExportService del web (segna «interrotto» ciò che l'arresto ha fermato e avvisa le pagine a lavoro finito), ExportApi espone cartelle, scelta e controllo della cartella, «Copia in…» (piano e avvio), «Copia di nuovo», avanzamento, lavori, ripresa, annullamento e resoconto. Gli endpoint esistenti portano le copie: filtro copies= della Libreria, segno «Copiato» / «Copiato in parte 1/3» sulle tessere, copie di ogni file nel visualizzatore, riquadro «Copie esterne» e interruttore «Esporta questo account» nella scheda. Una cartella di account o della libreria che finirebbe dentro (o attorno a) una cartella delle copie è rifiutata; dopo una ricostruzione le cartelle in conflitto vanno in pausa. Composizione: in Docker le copie si scrivono solo sotto /esporta, e solo con --esporta/FEBE_ESPORTA e un montaggio (riga di avvio e avviso se manca); sul desktop qualsiasi cartella con la finestra del sistema e lo spazio libero misurato anche sulle condivisioni di rete. La dimostrazione ha una cartella generale, una propria, un account non esportato e copie vere in ogni stato, scritte dal motore nella sua cartella temporanea. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
114 lines
3.8 KiB
C#
114 lines
3.8 KiB
C#
using System.Diagnostics;
|
|
using System.Windows;
|
|
using System.Windows.Media;
|
|
using System.Windows.Threading;
|
|
using Febe.App;
|
|
using Febe.Desktop.Browser;
|
|
using Febe.Desktop.Core;
|
|
using Febe.Core.Security;
|
|
using Febe.Desktop.Native;
|
|
using Febe.Desktop.Security;
|
|
using Febe.Web.Native;
|
|
using Microsoft.Web.WebView2.Core;
|
|
using Microsoft.Win32;
|
|
|
|
namespace Febe.Desktop;
|
|
|
|
/// <summary>The Windows-only part the desktop platform needs (WebView2, Edge's window, native shell with notifications).</summary>
|
|
internal sealed class DesktopShell(Dispatcher ui, ImageSource? icon, INativeShell native) : IDesktopShell
|
|
{
|
|
public INativeShell Native { get; } = native;
|
|
|
|
public ISessionProtector SessionProtector { get; } = new DpapiSessionProtector();
|
|
|
|
public Febe.Core.Export.IExportDisk? ExportDisk { get; } = new Native.WindowsExportDisk();
|
|
|
|
public string? WebView2Version()
|
|
{
|
|
try
|
|
{
|
|
return CoreWebView2Environment.GetAvailableBrowserVersionString();
|
|
}
|
|
catch (WebView2RuntimeNotFoundException)
|
|
{
|
|
return null;
|
|
}
|
|
}
|
|
|
|
public IFebeBrowser CreateWebView2Browser(WebView2BrowserSettings settings, FebePlatformContext context) =>
|
|
new WebView2Browser(ui, settings, context, icon);
|
|
|
|
public string? FindEdge()
|
|
{
|
|
string? appPath = null;
|
|
foreach (var hive in new[] { Registry.CurrentUser, Registry.LocalMachine })
|
|
{
|
|
using var key = hive.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\App Paths\msedge.exe", writable: false);
|
|
if (key?.GetValue(null) is string value && !string.IsNullOrWhiteSpace(value))
|
|
{
|
|
appPath = value;
|
|
break;
|
|
}
|
|
}
|
|
|
|
return EdgeLocator.Find(EdgeLocator.Candidates(
|
|
appPath,
|
|
Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86),
|
|
Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles),
|
|
Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData)));
|
|
}
|
|
|
|
public Task ShowProcessWindowAsync(int processId, CancellationToken ct) => ui.InvokeAsync(() =>
|
|
{
|
|
if (MainWindowOf(processId) is not { } window)
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (Win32.IsIconic(window))
|
|
{
|
|
Win32.ShowWindow(window, Win32.SwRestore);
|
|
}
|
|
|
|
var area = SystemParameters.WorkArea;
|
|
var dpi = Win32.SystemScale;
|
|
Win32.SetWindowPos(window, IntPtr.Zero, (int)(area.Left * dpi) + 40, (int)(area.Top * dpi) + 40, 0, 0, Win32.SwpNoSize | Win32.SwpNoZOrder);
|
|
Win32.SetForegroundWindow(window);
|
|
}).Task;
|
|
|
|
public Task HideProcessWindowAsync(int processId, CancellationToken ct) => ui.InvokeAsync(() =>
|
|
{
|
|
if (MainWindowOf(processId) is not { } window)
|
|
{
|
|
return;
|
|
}
|
|
|
|
// Out of view, never minimised (S2): just right of every screen.
|
|
var dpi = Win32.SystemScale;
|
|
var x = (int)((SystemParameters.VirtualScreenLeft + SystemParameters.VirtualScreenWidth) * dpi) + 64;
|
|
var y = (int)(SystemParameters.VirtualScreenTop * dpi);
|
|
if (Win32.IsIconic(window))
|
|
{
|
|
Win32.ShowWindow(window, Win32.SwShowNoActivate);
|
|
}
|
|
|
|
Win32.SetWindowPos(window, IntPtr.Zero, x, y, 0, 0, Win32.SwpNoSize | Win32.SwpNoZOrder | Win32.SwpNoActivate);
|
|
}).Task;
|
|
|
|
public bool EndWithFebe(Process process) => ProcessJob.Add(process);
|
|
|
|
private static IntPtr? MainWindowOf(int processId)
|
|
{
|
|
try
|
|
{
|
|
using var process = Process.GetProcessById(processId);
|
|
process.Refresh();
|
|
return process.MainWindowHandle == IntPtr.Zero ? null : process.MainWindowHandle;
|
|
}
|
|
catch (Exception ex) when (ex is ArgumentException or InvalidOperationException)
|
|
{
|
|
return null;
|
|
}
|
|
}
|
|
}
|