Add release packaging and automatic update support
This commit is contained in:
parent
94cd6b984b
commit
f971c374f8
20 changed files with 722 additions and 16 deletions
31
src/AstroFrame.Desktop/AppSettings.cs
Normal file
31
src/AstroFrame.Desktop/AppSettings.cs
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
using System.Text.Json;
|
||||
|
||||
namespace AstroFrame.Desktop;
|
||||
|
||||
public sealed class AppSettings
|
||||
{
|
||||
public bool AutomaticallyCheckForUpdates { get; set; } = true;
|
||||
public DateTimeOffset? LastUpdateCheck { get; set; }
|
||||
public static string DataDirectory => Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "AstroFrame");
|
||||
public static string SettingsPath => Path.Combine(DataDirectory, "settings.json");
|
||||
|
||||
public static AppSettings Load(string? path = null)
|
||||
{
|
||||
path ??= SettingsPath;
|
||||
try
|
||||
{
|
||||
if (!File.Exists(path) || new FileInfo(path).Length > 64 * 1024) return new();
|
||||
return JsonSerializer.Deserialize<AppSettings>(File.ReadAllText(path)) ?? new();
|
||||
}
|
||||
catch (Exception e) when (e is IOException or UnauthorizedAccessException or JsonException) { return new(); }
|
||||
}
|
||||
|
||||
public void Save(string? path = null)
|
||||
{
|
||||
path ??= SettingsPath;
|
||||
Directory.CreateDirectory(Path.GetDirectoryName(Path.GetFullPath(path))!);
|
||||
string temporary = path + ".tmp";
|
||||
File.WriteAllText(temporary, JsonSerializer.Serialize(this, new JsonSerializerOptions { WriteIndented = true }));
|
||||
File.Move(temporary, path, true);
|
||||
}
|
||||
}
|
||||
126
src/AstroFrame.Desktop/AppUpdates.cs
Normal file
126
src/AstroFrame.Desktop/AppUpdates.cs
Normal file
|
|
@ -0,0 +1,126 @@
|
|||
using System.Reflection;
|
||||
using Velopack;
|
||||
using Velopack.Sources;
|
||||
|
||||
namespace AstroFrame.Desktop;
|
||||
|
||||
public interface IUpdateBackend
|
||||
{
|
||||
bool IsInstalled { get; }
|
||||
string InstalledVersion { get; }
|
||||
Task<string?> Check();
|
||||
Task Download(Action<int> progress, CancellationToken cancellation);
|
||||
void ApplyAndRestart(string[] arguments);
|
||||
}
|
||||
|
||||
public sealed class ReleaseUpdateBackend : IUpdateBackend
|
||||
{
|
||||
public const string Repository = "https://git.elijahkuntz.com/Elijah/AstroFrame";
|
||||
readonly UpdateManager manager;
|
||||
UpdateInfo? available;
|
||||
public ReleaseUpdateBackend()
|
||||
{
|
||||
manager = new UpdateManager(new GiteaSource(Repository, null, false), new UpdateOptions
|
||||
{
|
||||
ExplicitChannel = OperatingSystem.IsWindows() ? "win-x64" : "linux-x64",
|
||||
AllowVersionDowngrade = false
|
||||
});
|
||||
}
|
||||
public bool IsInstalled => manager.IsInstalled;
|
||||
public string InstalledVersion => manager.CurrentVersion?.ToString()
|
||||
?? typeof(ReleaseUpdateBackend).Assembly.GetCustomAttribute<AssemblyInformationalVersionAttribute>()?.InformationalVersion.Split('+')[0]
|
||||
?? "1.0.0";
|
||||
public async Task<string?> Check()
|
||||
{
|
||||
available = await manager.CheckForUpdatesAsync();
|
||||
return available?.TargetFullRelease.Version.ToString();
|
||||
}
|
||||
public Task Download(Action<int> progress, CancellationToken cancellation) =>
|
||||
manager.DownloadUpdatesAsync(available ?? throw new InvalidOperationException("Check for updates first."), progress, cancellation);
|
||||
public void ApplyAndRestart(string[] arguments) =>
|
||||
manager.WaitExitThenApplyUpdates(available!.TargetFullRelease, silent: false, restart: true, restartArgs: arguments);
|
||||
}
|
||||
|
||||
// Independent of the settings view so notifications and future settings pages share one state.
|
||||
// All state changes and callbacks run on the UI context when called by the desktop application.
|
||||
public sealed class AppUpdates : IDisposable
|
||||
{
|
||||
readonly IUpdateBackend backend;
|
||||
readonly Action<AppSettings> saveSettings;
|
||||
readonly CancellationTokenSource lifetime = new();
|
||||
public AppSettings Settings { get; }
|
||||
public string InstalledVersion => backend.InstalledVersion;
|
||||
public bool IsInstalled => backend.IsInstalled;
|
||||
public bool Working { get; private set; }
|
||||
public bool Applying { get; private set; }
|
||||
public bool Ready { get; private set; }
|
||||
public string? AvailableVersion { get; private set; }
|
||||
public string Message { get; private set; }
|
||||
public event Action? Changed;
|
||||
|
||||
public AppUpdates(IUpdateBackend? backend = null, AppSettings? settings = null, Action<AppSettings>? saveSettings = null)
|
||||
{
|
||||
this.backend = backend ?? new ReleaseUpdateBackend();
|
||||
Settings = settings ?? AppSettings.Load();
|
||||
this.saveSettings = saveSettings ?? (s => s.Save());
|
||||
Message = IsInstalled ? "Updates have not been checked in this session." : "Install the Windows package or run the Linux AppImage to enable updates.";
|
||||
}
|
||||
void Notify() => Changed?.Invoke();
|
||||
public bool SetAutomaticChecks(bool enabled)
|
||||
{
|
||||
bool previous = Settings.AutomaticallyCheckForUpdates;
|
||||
Settings.AutomaticallyCheckForUpdates = enabled;
|
||||
try { saveSettings(Settings); Notify(); return true; }
|
||||
catch (Exception e) when (e is IOException or UnauthorizedAccessException)
|
||||
{
|
||||
Settings.AutomaticallyCheckForUpdates = previous;
|
||||
Message = "Could not save settings: " + e.Message; Notify(); return false;
|
||||
}
|
||||
}
|
||||
public async Task Check(bool automatic = false)
|
||||
{
|
||||
if (Working || Applying || lifetime.IsCancellationRequested || !IsInstalled || (automatic && !Settings.AutomaticallyCheckForUpdates)) return;
|
||||
Working = true; Message = "Checking for updates…"; Notify();
|
||||
try
|
||||
{
|
||||
string? latest = await backend.Check();
|
||||
if (latest != AvailableVersion) Ready = false;
|
||||
AvailableVersion = latest;
|
||||
if (lifetime.IsCancellationRequested) return;
|
||||
Settings.LastUpdateCheck = DateTimeOffset.UtcNow;
|
||||
Message = AvailableVersion == null ? "You are up to date." : Ready ? $"Version {AvailableVersion} is ready to install." : $"Version {AvailableVersion} is available.";
|
||||
try { saveSettings(Settings); }
|
||||
catch (Exception e) when (e is IOException or UnauthorizedAccessException) { Message += " The check time could not be saved."; }
|
||||
}
|
||||
catch (Exception e) { Message = "Could not check for updates. " + e.Message; }
|
||||
finally { Working = false; Notify(); }
|
||||
}
|
||||
public async Task<bool> Install(Func<bool> canRestart, Func<Task<bool>> saveBeforeRestart, string[] arguments)
|
||||
{
|
||||
if (Working || Applying || AvailableVersion == null || lifetime.IsCancellationRequested) return false;
|
||||
if (!canRestart()) { Message = "Finish analysis, export, or saving before installing the update."; Notify(); return false; }
|
||||
Working = true; Notify();
|
||||
try
|
||||
{
|
||||
if (!Ready)
|
||||
{
|
||||
Message = "Downloading update…"; Notify();
|
||||
var progress = new Progress<int>(value => { if (!lifetime.IsCancellationRequested && Working && !Ready && !Applying) { Message = $"Downloading update… {value}%"; Notify(); } });
|
||||
await backend.Download(value => ((IProgress<int>)progress).Report(value), lifetime.Token);
|
||||
Ready = true;
|
||||
}
|
||||
if (lifetime.IsCancellationRequested) return false;
|
||||
// Work may have started during download. Never interrupt it to install.
|
||||
if (!canRestart()) { Message = "Update downloaded. Finish analysis, export, or saving, then install."; return false; }
|
||||
Applying = true; Notify(); // locks new work while the project is saved
|
||||
if (!await saveBeforeRestart()) { Applying = false; Message = "Update downloaded. Save the project successfully before restarting."; return false; }
|
||||
backend.ApplyAndRestart(arguments);
|
||||
Message = "Restarting to install the update…";
|
||||
return true;
|
||||
}
|
||||
catch (OperationCanceledException) { Applying = false; Message = "Update download cancelled."; return false; }
|
||||
catch (Exception e) { Applying = false; Message = "Could not install the update. " + e.Message; return false; }
|
||||
finally { Working = false; Notify(); }
|
||||
}
|
||||
public void Dispose() { lifetime.Cancel(); }
|
||||
}
|
||||
|
|
@ -16,6 +16,9 @@
|
|||
<PackageReference Include="Avalonia.Desktop" Version="11.3.9" />
|
||||
<PackageReference Include="Avalonia.Themes.Fluent" Version="11.3.9" />
|
||||
<PackageReference Include="Avalonia.Fonts.Inter" Version="11.3.9" />
|
||||
<PackageReference Include="Velopack" Version="1.2.161" />
|
||||
<!-- Compatible security backport for Avalonia's Linux D-Bus dependency (CVE-2026-39959). -->
|
||||
<PackageReference Include="Tmds.DBus.Protocol" Version="0.21.3" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
|
|
|||
47
src/AstroFrame.Desktop/MainWindow.Updates.cs
Normal file
47
src/AstroFrame.Desktop/MainWindow.Updates.cs
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
using Avalonia.Controls;
|
||||
using Avalonia.Threading;
|
||||
using Avalonia.Controls.ApplicationLifetimes;
|
||||
|
||||
namespace AstroFrame.Desktop;
|
||||
|
||||
public sealed partial class MainWindow
|
||||
{
|
||||
readonly AppUpdates updates = new();
|
||||
readonly Button settingsButton = Button("Settings");
|
||||
readonly DispatcherTimer updateTimer = new() { Interval = TimeSpan.FromHours(6) };
|
||||
SettingsWindow? settingsWindow;
|
||||
|
||||
void InitializeUpdates()
|
||||
{
|
||||
settingsButton.Click += (_, _) => ShowSettings();
|
||||
updates.Changed += () =>
|
||||
{
|
||||
settingsButton.Content = updates.AvailableVersion == null ? "Settings" : "Settings · Update available";
|
||||
if (updates.Applying) { analyze.IsEnabled = false; export.IsEnabled = false; }
|
||||
};
|
||||
bool diagnostic = Program.Arguments.Any(a => a.StartsWith("--capture") || a == "--smoke");
|
||||
if (!diagnostic)
|
||||
{
|
||||
Opened += async (_, _) => await updates.Check(automatic: true);
|
||||
updateTimer.Tick += async (_, _) => await updates.Check(automatic: true);
|
||||
updateTimer.Start();
|
||||
}
|
||||
Closed += (_, _) => { updateTimer.Stop(); updates.Dispose(); settingsWindow?.Close(); };
|
||||
}
|
||||
public SettingsWindow ShowSettings()
|
||||
{
|
||||
if (settingsWindow != null) { settingsWindow.Activate(); return settingsWindow; }
|
||||
settingsWindow = new SettingsWindow(updates, InstallUpdate);
|
||||
settingsWindow.Closed += (_, _) => settingsWindow = null;
|
||||
settingsWindow.Show(this);
|
||||
return settingsWindow;
|
||||
}
|
||||
async Task InstallUpdate()
|
||||
{
|
||||
bool analyzeEnabled = analyze.IsEnabled, exportEnabled = export.IsEnabled;
|
||||
bool restarting = await updates.Install(() => !busy && !saving, async () => project == null || await Save(),
|
||||
project == null ? [] : ["--project", projectDirectory]);
|
||||
if (restarting && Avalonia.Application.Current?.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop) desktop.Shutdown();
|
||||
else { analyze.IsEnabled = analyzeEnabled; export.IsEnabled = exportEnabled; }
|
||||
}
|
||||
}
|
||||
|
|
@ -13,7 +13,7 @@ using System.Security.Cryptography;
|
|||
using System.Text;
|
||||
|
||||
namespace AstroFrame.Desktop;
|
||||
public sealed class MainWindow:Window
|
||||
public sealed partial class MainWindow:Window
|
||||
{
|
||||
Project? project;string projectDirectory="";CancellationTokenSource? cancellation;bool busy,refreshing,saving;
|
||||
readonly SemaphoreSlim saveGate=new(1);
|
||||
|
|
@ -65,7 +65,7 @@ public sealed class MainWindow:Window
|
|||
var header=new Grid{ColumnDefinitions=new("*,Auto"),Margin=new(22,0,22,2)};Grid.SetRow(header,1);
|
||||
var heading=new StackPanel{Orientation=Orientation.Horizontal,Spacing=12,VerticalAlignment=VerticalAlignment.Center};title.MinWidth=140;title.MaxWidth=330;title.TextTrimming=TextTrimming.CharacterEllipsis;title.VerticalAlignment=subtitle.VerticalAlignment=VerticalAlignment.Center;heading.Children.Add(title);heading.Children.Add(subtitle);header.Children.Add(heading);
|
||||
var toolbar=new WrapPanel{Orientation=Orientation.Horizontal,HorizontalAlignment=HorizontalAlignment.Right,VerticalAlignment=VerticalAlignment.Center};
|
||||
foreach(var b in new[]{analyze,export}){b.Margin=new(8,1,0,1);toolbar.Children.Add(b);}Grid.SetColumn(toolbar,1);header.Children.Add(toolbar);headerSurface.Children.Add(header);
|
||||
foreach(var b in new[]{analyze,export,settingsButton}){b.Margin=new(8,1,0,1);toolbar.Children.Add(b);}Grid.SetColumn(toolbar,1);header.Children.Add(toolbar);headerSurface.Children.Add(header);
|
||||
var scope=new Grid{ColumnDefinitions=new("*,Auto"),Margin=new(20,7,20,7)};
|
||||
sessions.ItemTemplate=new FuncDataTemplate<string>((text,_)=>SessionRow(text??""));sessions.SelectionChanged+=(_,_)=>{if(!refreshing)RefreshFrames();};scope.Children.Add(sessions);
|
||||
var stats=new StackPanel{Orientation=Orientation.Horizontal,Spacing=28,VerticalAlignment=VerticalAlignment.Center};
|
||||
|
|
@ -96,13 +96,13 @@ public sealed class MainWindow:Window
|
|||
spatial.IsCheckedChanged+=(_,_)=>{preview.Spatial=spatial.IsChecked==true;preview.InvalidateVisual();};compare.IsCheckedChanged+=(_,_)=>UpdateComparison();
|
||||
KeyDown+=async(_,e)=>
|
||||
{
|
||||
if(busy||e.Source is TextBox)return;
|
||||
if(busy||updates.Applying||e.Source is TextBox)return;
|
||||
if(e.Key==Key.J){Move(-1);e.Handled=true;}if(e.Key==Key.K){Move(1);e.Handled=true;}
|
||||
if(e.Key is Key.D1 or Key.NumPad1){await Override(Verdict.Keep);e.Handled=true;}if(e.Key is Key.D2 or Key.NumPad2){await Override(Verdict.Review);e.Handled=true;}if(e.Key is Key.D3 or Key.NumPad3){await Override(Verdict.Reject);e.Handled=true;}
|
||||
if(e.Key==Key.Z&&e.KeyModifiers.HasFlag(KeyModifiers.Control)&&undo.Count>0){var item=undo.Pop();item.Frame.Override=item.Verdict;item.Frame.Note=item.Note;item.Frame.ReviewedAt=item.At;await Save();RefreshFrames(item.Frame);e.Handled=true;}
|
||||
};
|
||||
Closing+=(_,e)=>{if(busy){e.Cancel=true;cancellation?.Cancel();status.Text="Stopping safely; close again when finished";}};
|
||||
Closed+=(_,_)=>{preview.Dispose();comparison.Dispose();};ShowEmpty();
|
||||
Closed+=(_,_)=>{preview.Dispose();comparison.Dispose();};ShowEmpty();InitializeUpdates();
|
||||
}
|
||||
static Button Button(string text,bool primary=false)=>new(){Content=text,Padding=new(12,7),CornerRadius=new(2),Background=primary?Palette.Accent:Palette.Raised,Foreground=primary?Palette.Background:Palette.Text};
|
||||
static Border Panel(Control child)=>new(){Background=Palette.Panel,BorderBrush=Palette.Line,BorderThickness=new(.5),CornerRadius=new(2),ClipToBounds=true,Child=child};
|
||||
|
|
@ -232,7 +232,7 @@ public sealed class MainWindow:Window
|
|||
void Move(int step){if(visible.Count==0)return;int index=selected==null?0:visible.IndexOf(selected);var f=visible[Math.Clamp(index+step,0,visible.Count-1)];frames.SelectedItem=f;frames.ScrollIntoView(f);}
|
||||
async Task Override(Verdict? verdict,bool advance=true)
|
||||
{
|
||||
if(selected==null||busy||saving)return;var f=selected;int index=visible.IndexOf(f);undo.Push((f,f.Override,f.Note,f.ReviewedAt));f.Override=verdict;f.ReviewedAt=DateTime.UtcNow;
|
||||
if(selected==null||busy||saving||updates.Applying)return;var f=selected;int index=visible.IndexOf(f);undo.Push((f,f.Override,f.Note,f.ReviewedAt));f.Override=verdict;f.ReviewedAt=DateTime.UtcNow;
|
||||
if(!await Save()){var previous=undo.Pop();f.Override=previous.Verdict;f.Note=previous.Note;f.ReviewedAt=previous.At;RefreshFrames(f);status.Text="Review could not be saved; decision restored";return;}
|
||||
var next=advance?visible.ElementAtOrDefault(index+1)??visible.ElementAtOrDefault(index-1):f;RefreshFrames(next);status.Text="Manual decision saved · Ctrl+Z to undo";
|
||||
}
|
||||
|
|
@ -241,19 +241,20 @@ public sealed class MainWindow:Window
|
|||
if(project==null)return false;await saveGate.WaitAsync();saving=true;analyze.IsEnabled=export.IsEnabled=false;
|
||||
try{var p=project;var directory=projectDirectory;await Task.Run(()=>ProjectStore.Save(p,directory));return true;}
|
||||
catch(Exception e){await Message("Could not save project",e.Message);return false;}
|
||||
finally{saving=false;analyze.IsEnabled=!busy;export.IsEnabled=!busy&&project.Complete;saveGate.Release();}
|
||||
finally{saving=false;analyze.IsEnabled=!busy&&!updates.Applying;export.IsEnabled=!busy&&!updates.Applying&&project.Complete;saveGate.Release();}
|
||||
}
|
||||
async Task<string?> Folder(string title)
|
||||
{var result=await StorageProvider.OpenFolderPickerAsync(new FolderPickerOpenOptions{Title=title,AllowMultiple=false});return result.FirstOrDefault()?.TryGetLocalPath();}
|
||||
void Busy(bool value){busy=value;analyze.IsEnabled=!value;export.IsEnabled=!value&&project?.Complete==true;frames.IsEnabled=sessions.IsEnabled=chart.IsEnabled=filter.IsEnabled=sort.IsEnabled=metric.IsEnabled=!value;inspector.IsEnabled=!value;stop.IsVisible=progress.IsVisible=value;}
|
||||
async Task Analyze()
|
||||
{
|
||||
if(busy||saving||updates.Applying)return;
|
||||
string? source=project?.Source;
|
||||
if(source!=null)
|
||||
{
|
||||
bool same=await Confirm("Analyze lights","Reanalyze the current source folder using cached measurements, or choose another folder?","Current source","Choose folder");if(!same)source=null;
|
||||
}
|
||||
source??=await Folder("Choose a folder containing raw FITS lights");if(source==null)return;
|
||||
source??=await Folder("Choose a folder containing raw FITS lights");if(source==null||updates.Applying)return;
|
||||
if(project?.Source!=source)
|
||||
{
|
||||
string hash=Convert.ToHexString(SHA256.HashData(Encoding.UTF8.GetBytes(source)))[..16];
|
||||
|
|
@ -261,10 +262,10 @@ public sealed class MainWindow:Window
|
|||
project=File.Exists(System.IO.Path.Combine(projectDirectory,"project.json"))?ProjectStore.Load(projectDirectory):null;
|
||||
}
|
||||
Busy(true);cancellation=new();progress.Value=0;
|
||||
var updates=new Progress<ProgressInfo>(p=>{progress.Value=p.Total==0?0:100.0*p.Done/p.Total;status.Text=$"{p.Stage} · {p.Done:N0} / {p.Total:N0} · {p.File}";});
|
||||
var analysisProgress=new Progress<ProgressInfo>(p=>{progress.Value=p.Total==0?0:100.0*p.Done/p.Total;status.Text=$"{p.Stage} · {p.Done:N0} / {p.Total:N0} · {p.File}";});
|
||||
try
|
||||
{
|
||||
var previous=project;await Task.Run(async()=>project=await new Analyzer().AnalyzeAsync(source,projectDirectory,previous,updates,cancellation.Token));LoadProject(projectDirectory);
|
||||
var previous=project;await Task.Run(async()=>project=await new Analyzer().AnalyzeAsync(source,projectDirectory,previous,analysisProgress,cancellation.Token));LoadProject(projectDirectory);
|
||||
}
|
||||
catch(OperationCanceledException){if(File.Exists(System.IO.Path.Combine(projectDirectory,"project.json")))LoadProject(projectDirectory);status.Text="Cancelled · completed measurements saved; reanalyze to resume";}
|
||||
catch(ResourcePressureException e){if(File.Exists(System.IO.Path.Combine(projectDirectory,"project.json")))LoadProject(projectDirectory);status.Text="Paused safely for RAM pressure · completed measurements saved";await Message("RAM headroom unavailable",e.Message);}
|
||||
|
|
@ -273,7 +274,7 @@ public sealed class MainWindow:Window
|
|||
}
|
||||
async Task ExportAccepted()
|
||||
{
|
||||
if(project?.Complete!=true)return;
|
||||
if(project?.Complete!=true||busy||saving||updates.Applying)return;
|
||||
var options=new Window{Title="Export accepted lights",Width=470,SizeToContent=SizeToContent.Height,CanResize=false,WindowStartupLocation=WindowStartupLocation.CenterOwner,Background=Palette.Panel};
|
||||
var layout=new StackPanel{Margin=new(24),Spacing=14};layout.Children.Add(Palette.Label("Prepare lights for Siril",21));layout.Children.Add(new TextBlock{Text="KEEP frames are included. Originals are opened read-only. Select an empty output folder outside your input tree.",TextWrapping=TextWrapping.Wrap,Foreground=Palette.Muted});
|
||||
var scopes=new List<(string Name,List<Frame> Frames)>();
|
||||
|
|
@ -282,7 +283,7 @@ public sealed class MainWindow:Window
|
|||
scopes.Add(("Entire project · separate target folders",project.Frames));
|
||||
var scope=new ComboBox{ItemsSource=scopes.Select(x=>x.Name).ToArray(),SelectedIndex=sessions.SelectedIndex>0?0:scopes.Count-1,HorizontalAlignment=HorizontalAlignment.Stretch};layout.Children.Add(Palette.Label("EXPORT SCOPE",10,Palette.Muted));layout.Children.Add(scope);
|
||||
var include=new CheckBox{Content="Also include unresolved REVIEW frames",IsChecked=false};var links=new CheckBox{Content="Use hardlinks when available (copy fallback)",IsChecked=true};layout.Children.Add(include);layout.Children.Add(links);layout.Children.Add(new TextBlock{Text="Hardlinks share source bytes. Use Siril to read and process these inputs into separate outputs. Choose copies if another tool may overwrite input files.",FontSize=11,TextWrapping=TextWrapping.Wrap,Foreground=Palette.Muted});var buttons=new WrapPanel();var go=Button("Choose output folder",true);var cancel=Button("Cancel");cancel.Margin=new(8,0,0,0);buttons.Children.Add(go);buttons.Children.Add(cancel);layout.Children.Add(buttons);options.Content=layout;go.Click+=(_,_)=>options.Close(true);cancel.Click+=(_,_)=>options.Close(false);
|
||||
if(!await options.ShowDialog<bool>(this))return;string? output=await Folder("Choose an empty output folder for accepted lights");if(output==null)return;
|
||||
if(!await options.ShowDialog<bool>(this))return;string? output=await Folder("Choose an empty output folder for accepted lights");if(output==null||updates.Applying)return;
|
||||
var exportProject=new Project{Name=project.Name,Source=project.Source,Complete=project.Complete,Frames=scopes[scope.SelectedIndex].Frames};
|
||||
Busy(true);cancellation=new();try{var result=await Export.AcceptedAsync(exportProject,output,include.IsChecked==true,links.IsChecked==true,new Progress<ProgressInfo>(p=>{progress.Value=100.0*p.Done/Math.Max(1,p.Total);status.Text=$"{p.Stage} · {p.Done}/{p.Total}";}),cancellation.Token);status.Text=$"Export complete · {result.Linked} hardlinks, {result.Copied} copies · {output}";}
|
||||
catch(OperationCanceledException){status.Text="Export cancelled · completed output files retained; choose a new empty folder to retry";}catch(Exception e){await Message("Export could not finish",e.Message);}finally{Busy(false);cancellation.Dispose();cancellation=null;}
|
||||
|
|
|
|||
|
|
@ -14,13 +14,15 @@ internal static class Program
|
|||
static Mutex? instance;
|
||||
[STAThread] public static void Main(string[] args)
|
||||
{
|
||||
Velopack.VelopackApp.Build().SetAutoApplyOnStartup(false).Run();
|
||||
if(args.Length>=3&&args[0]=="--verify-update"){Environment.ExitCode=UpdateDiagnostics.Run(args).GetAwaiter().GetResult();return;}
|
||||
instance=new Mutex(true,"AstroFrame.Desktop.OneInstance",out bool created);if(!created)return;
|
||||
try
|
||||
{
|
||||
ResourcePolicy.InstallWindowsLimit();Arguments=args;
|
||||
AppBuilder.Configure<App>().UsePlatformDetect().With(new Win32PlatformOptions{RenderingMode=[Win32RenderingMode.Software]}).WithInterFont().LogToTrace().StartWithClassicDesktopLifetime(args);
|
||||
}
|
||||
catch(Exception e){File.WriteAllText(System.IO.Path.Combine(AppContext.BaseDirectory,"startup-error.log"),e.ToString());Environment.ExitCode=1;}
|
||||
catch(Exception e){try{Directory.CreateDirectory(AppSettings.DataDirectory);File.WriteAllText(System.IO.Path.Combine(AppSettings.DataDirectory,"startup-error.log"),e.ToString());}catch{}Environment.ExitCode=1;}
|
||||
finally{instance.ReleaseMutex();instance.Dispose();}
|
||||
}
|
||||
}
|
||||
|
|
@ -40,7 +42,23 @@ public sealed class App:Application
|
|||
string directory=System.IO.Path.GetFullPath(Program.Arguments[1]);var project=ProjectStore.Load(directory);var frame=project.Frames.First(f=>f.Name.Contains(Program.Arguments[3],StringComparison.OrdinalIgnoreCase));desktop.MainWindow=new StarInspector(project,directory,frame,Program.Arguments[2]);base.OnFrameworkInitializationCompleted();return;
|
||||
}
|
||||
var window=new MainWindow();desktop.MainWindow=window;
|
||||
if(Program.Arguments.Length>=3&&Program.Arguments[0] is "--capture" or "--smoke")
|
||||
if(Program.Arguments.Length>=2&&Program.Arguments[0]=="--capture-settings")
|
||||
{
|
||||
window.Opened+=async(_,_)=>
|
||||
{
|
||||
try
|
||||
{
|
||||
var settings=window.ShowSettings();
|
||||
if(Program.Arguments.Length>2)settings.Width=double.Parse(Program.Arguments[2],System.Globalization.CultureInfo.InvariantCulture);
|
||||
await Task.Delay(400);
|
||||
double dpi=Program.Arguments.Length>3?double.Parse(Program.Arguments[3],System.Globalization.CultureInfo.InvariantCulture):96;
|
||||
using var bitmap=new RenderTargetBitmap(new PixelSize((int)Math.Ceiling(settings.Bounds.Width*dpi/96),(int)Math.Ceiling(settings.Bounds.Height*dpi/96)),new Vector(dpi,dpi));bitmap.Render(settings);bitmap.Save(Program.Arguments[1]);
|
||||
desktop.Shutdown(0);
|
||||
}
|
||||
catch(Exception e){File.WriteAllText(Program.Arguments[1]+".error",e.ToString());desktop.Shutdown(1);}
|
||||
};
|
||||
}
|
||||
else if(Program.Arguments.Length>=3&&Program.Arguments[0] is "--capture" or "--smoke")
|
||||
{
|
||||
window.Opened+=async(_,_)=>
|
||||
{
|
||||
|
|
|
|||
57
src/AstroFrame.Desktop/SettingsWindow.cs
Normal file
57
src/AstroFrame.Desktop/SettingsWindow.cs
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Layout;
|
||||
using Avalonia.Media;
|
||||
|
||||
namespace AstroFrame.Desktop;
|
||||
|
||||
public sealed class SettingsWindow : Window
|
||||
{
|
||||
readonly AppUpdates updates;
|
||||
readonly TextBlock message = Text(""), lastCheck = Text("");
|
||||
readonly Button check = new() { Content = "Check for updates", Padding = new(12, 8) };
|
||||
readonly Button install = new() { Content = "Install update and restart", Padding = new(12, 8) };
|
||||
readonly CheckBox automatic = new() { Content = "Automatically check for updates", FontSize = 13 };
|
||||
|
||||
public SettingsWindow(AppUpdates updates, Func<Task> installUpdate)
|
||||
{
|
||||
this.updates = updates;
|
||||
Title = "AstroFrame settings"; Width = 760; Height = 530; MinWidth = 620; MinHeight = 390;
|
||||
Background = Palette.Background; FontFamily = "Inter"; WindowStartupLocation = WindowStartupLocation.CenterOwner;
|
||||
var root = new Grid { ColumnDefinitions = new("160,*") };
|
||||
// Add categories and their views here as the application gains more settings.
|
||||
var categories = new ListBox { ItemsSource = new[] { "Updates" }, SelectedIndex = 0, Background = Palette.Panel, Padding = new(10, 18) };
|
||||
root.Children.Add(categories);
|
||||
var page = new StackPanel { Spacing = 18, Margin = new(26), MaxWidth = 650 };
|
||||
page.Children.Add(Text("Updates", 23));
|
||||
page.Children.Add(Text($"Installed version {updates.InstalledVersion}", 15));
|
||||
page.Children.Add(Text("Receive stable AstroFrame releases and install them when you are ready to restart."));
|
||||
page.Children.Add(automatic); page.Children.Add(message); page.Children.Add(lastCheck);
|
||||
var buttons = new WrapPanel { Orientation = Orientation.Horizontal };
|
||||
check.Margin = new(0, 0, 10, 10); install.Margin = new(0, 0, 0, 10);
|
||||
buttons.Children.Add(check); buttons.Children.Add(install); page.Children.Add(buttons);
|
||||
var scroll = new ScrollViewer { Content = page, HorizontalScrollBarVisibility = Avalonia.Controls.Primitives.ScrollBarVisibility.Disabled };
|
||||
Grid.SetColumn(scroll, 1); root.Children.Add(scroll); Content = root;
|
||||
check.Click += async (_, _) => await updates.Check();
|
||||
install.Click += async (_, _) => await installUpdate();
|
||||
automatic.IsChecked = updates.Settings.AutomaticallyCheckForUpdates;
|
||||
automatic.IsCheckedChanged += (_, _) =>
|
||||
{
|
||||
bool requested = automatic.IsChecked == true;
|
||||
if (requested != updates.Settings.AutomaticallyCheckForUpdates && !updates.SetAutomaticChecks(requested)) automatic.IsChecked = updates.Settings.AutomaticallyCheckForUpdates;
|
||||
};
|
||||
updates.Changed += Refresh;
|
||||
Closed += (_, _) => updates.Changed -= Refresh;
|
||||
Refresh();
|
||||
}
|
||||
static TextBlock Text(string value, double size = 13) => new() { Text = value, FontSize = size, Foreground = Palette.Text, TextWrapping = TextWrapping.Wrap };
|
||||
void Refresh()
|
||||
{
|
||||
message.Text = updates.Message;
|
||||
lastCheck.Text = updates.Settings.LastUpdateCheck is { } time ? $"Last successful check {time.ToLocalTime():g}" : "Last successful check Never";
|
||||
lastCheck.Foreground = Palette.Muted;
|
||||
check.IsEnabled = updates.IsInstalled && !updates.Working && !updates.Applying;
|
||||
install.IsVisible = updates.AvailableVersion != null;
|
||||
install.IsEnabled = !updates.Working && !updates.Applying;
|
||||
}
|
||||
}
|
||||
29
src/AstroFrame.Desktop/UpdateDiagnostics.cs
Normal file
29
src/AstroFrame.Desktop/UpdateDiagnostics.cs
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
using System.Text.Json;
|
||||
using Velopack;
|
||||
|
||||
namespace AstroFrame.Desktop;
|
||||
|
||||
// Explicit local-feed probe used to verify installed package lifecycle without publishing test releases.
|
||||
internal static class UpdateDiagnostics
|
||||
{
|
||||
public static async Task<int> Run(string[] args)
|
||||
{
|
||||
string report = Path.GetFullPath(args[2]);
|
||||
try
|
||||
{
|
||||
string feed = args[1] == ReleaseUpdateBackend.Repository ? args[1] : Path.GetFullPath(args[1]);
|
||||
var options = new UpdateOptions { ExplicitChannel = OperatingSystem.IsWindows() ? "win-x64" : "linux-x64" };
|
||||
var manager = feed == ReleaseUpdateBackend.Repository
|
||||
? new UpdateManager(new Velopack.Sources.GiteaSource(feed, null, false), options)
|
||||
: new UpdateManager(feed, options);
|
||||
if (!manager.IsInstalled) throw new InvalidOperationException("Probe requires an installed Windows package or Linux AppImage.");
|
||||
var update = await manager.CheckForUpdatesAsync();
|
||||
if (update != null) await manager.DownloadUpdatesAsync(update);
|
||||
var record = new { version = manager.CurrentVersion?.ToString(), available = update?.TargetFullRelease.Version.ToString(), downloaded = manager.UpdatePendingRestart?.Version.ToString() };
|
||||
File.AppendAllText(report, JsonSerializer.Serialize(record) + Environment.NewLine);
|
||||
if (update != null && args.Contains("--apply")) manager.WaitExitThenApplyUpdates(update.TargetFullRelease, silent: true, restart: true, restartArgs: ["--verify-update", feed, report]);
|
||||
return 0;
|
||||
}
|
||||
catch (Exception e) { File.AppendAllText(report, e + Environment.NewLine); return 1; }
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue