33using System . IO ;
44using System . Linq ;
55using System . Threading . Tasks ;
6- using AppImageDesktopFileCreator ;
6+ using AppImageManager ;
77using Avalonia . Platform . Storage ;
88using Avalonia . Threading ;
99using AvaloniaControls ;
@@ -88,7 +88,7 @@ public MsuWindowViewModel InitializeModel()
8888 Model . DisplaySettingsWindowOnLoad = Model is { MsuWindowDisplayOptionsButton : true , HasMsuFolder : false } ;
8989
9090 if ( OperatingSystem . IsLinux ( ) && Model . MsuWindowDisplayOptionsButton && ! userOptions . MsuUserOptions . SkipDesktopFile &&
91- ! DesktopFileCreator . DoesDesktopFileExist ( "org.mattequalscoder.msurandomizer" ) )
91+ ! AppImage . DoesDesktopFileExist ( App . AppId ) )
9292 {
9393 Model . DisplayDesktopPopupOnLoad = true ;
9494 }
@@ -100,7 +100,7 @@ public void HandleUserDesktopResponse(bool addDesktopFile)
100100 {
101101 if ( addDesktopFile && OperatingSystem . IsLinux ( ) )
102102 {
103- Program . BuildLinuxDesktopFile ( ) ;
103+ App . BuildLinuxDesktopFile ( ) ;
104104 }
105105 else
106106 {
@@ -115,8 +115,11 @@ private void AppInitializationServiceOnInitializationComplete(object? sender, Ev
115115 {
116116 return ;
117117 }
118+
119+ var downloadUrl = appInitializationService . ReleaseDownloadUrl ;
120+ var hasDownloadUrl = ! string . IsNullOrEmpty ( downloadUrl ) ;
118121
119- Dispatcher . UIThread . Invoke ( ( ) =>
122+ Dispatcher . UIThread . Invoke ( async ( ) =>
120123 {
121124 var messageWindow = new MessageWindow ( new MessageWindowRequest
122125 {
@@ -126,17 +129,45 @@ private void AppInitializationServiceOnInitializationComplete(object? sender, Ev
126129 LinkUrl = appInitializationService . LatestFullRelease . Url ,
127130 Icon = MessageWindowIcon . Info ,
128131 CheckBoxText = "Do not check for updates" ,
129- Buttons = MessageWindowButtons . OK
132+ Buttons = hasDownloadUrl ? MessageWindowButtons . YesNo : MessageWindowButtons . OK ,
133+ PrimaryButtonText = hasDownloadUrl ? "Download Update" : "OK" ,
134+ SecondaryButtonText = "Close"
130135 } ) ;
131- messageWindow . Closed += ( _ , _ ) =>
136+ await messageWindow . ShowDialog ( MessageWindow . GlobalParentWindow ! ) ;
137+
138+ if ( messageWindow . DialogResult ? . CheckedBox == true )
139+ {
140+ userOptions . MsuUserOptions . PromptOnUpdate = false ;
141+ userOptions . Save ( ) ;
142+ }
143+
144+ if ( hasDownloadUrl && messageWindow . DialogResult ? . PressedAcceptButton == true )
132145 {
133- if ( messageWindow . DialogResult ? . CheckedBox == true )
146+ if ( OperatingSystem . IsLinux ( ) )
134147 {
135- userOptions . MsuUserOptions . PromptOnUpdate = false ;
136- userOptions . Save ( ) ;
148+ var downloadResult = await AppImage . DownloadAsync ( new DownloadAppImageRequest
149+ {
150+ Url = downloadUrl !
151+ } ) ;
152+
153+ if ( downloadResult . Success )
154+ {
155+ MessageWindow . GlobalParentWindow ! . Close ( ) ;
156+ }
157+ else if ( downloadResult . DownloadedSuccessfully )
158+ {
159+ await MessageWindow . ShowErrorDialog ( "AppImage was downloaded, but it could not be launched." ) ;
160+ }
161+ else
162+ {
163+ await MessageWindow . ShowErrorDialog ( "Failed downloading AppImage" ) ;
164+ }
137165 }
138- } ;
139- messageWindow . ShowDialog ( ) ;
166+ else
167+ {
168+ throw new InvalidOperationException ( "Download functionality is only available on Linux" ) ;
169+ }
170+ }
140171 } ) ;
141172
142173 }
0 commit comments