9
9
using System . Threading . Tasks ;
10
10
using K8sFileBrowser . Models ;
11
11
using K8sFileBrowser . Services ;
12
- using Microsoft . IdentityModel . Tokens ;
13
12
using ReactiveUI ;
14
13
using ReactiveUI . Fody . Helpers ;
15
14
using Serilog ;
@@ -65,14 +64,11 @@ public class MainWindowViewModel : ViewModelBase
65
64
#endregion Properties
66
65
67
66
#region Commands
68
-
69
- public ReactiveCommand < Unit , Unit > DownloadCommand { get ; private set ; } = null ! ;
67
+
70
68
public ReactiveCommand < Unit , Unit > DownloadLogCommand { get ; private set ; } = null ! ;
71
69
public ReactiveCommand < Unit , Unit > RefreshCommand { get ; private set ; } = null ! ;
72
70
public ReactiveCommand < Unit , Unit > ParentCommand { get ; private set ; } = null ! ;
73
- public ReactiveCommand < Unit , Unit > OpenCommand { get ; private set ; } = null ! ;
74
71
public ReactiveCommand < FileInformation , Unit > OpenContextCommand { get ; private set ; } = null ! ;
75
-
76
72
public ReactiveCommand < FileInformation , Unit > DownloadContextCommand { get ; private set ; } = null ! ;
77
73
private ReactiveCommand < Namespace , IEnumerable < Pod > > GetPodsForNamespace { get ; set ; } = null ! ;
78
74
@@ -85,9 +81,7 @@ public MainWindowViewModel()
85
81
Version = Assembly . GetExecutingAssembly ( ) . GetName ( ) . Version ? . ToString ( ) ;
86
82
87
83
// commands
88
- ConfigureOpenDirectoryCommand ( ) ;
89
84
ConfigureOpenDirectoryContextCommand ( ) ;
90
- ConfigureDownloadFileCommand ( kubernetesService ) ;
91
85
ConfigureDownloadFileContextCommand ( kubernetesService ) ;
92
86
ConfigureRefreshCommand ( kubernetesService ) ;
93
87
ConfigureDownloadLogCommand ( kubernetesService ) ;
@@ -275,32 +269,7 @@ await Observable.Start(() =>
275
269
. Subscribe ( ShowErrorMessage ) ;
276
270
}
277
271
278
- private void ConfigureDownloadFileCommand ( IKubernetesService kubernetesService )
279
- {
280
- var isFile = this
281
- . WhenAnyValue ( x => x . SelectedFile , x => x . Message . IsVisible )
282
- . Select ( x => x is { Item1 . Type : FileType . File , Item2 : false } ) ;
283
-
284
- DownloadCommand = ReactiveCommand . CreateFromTask ( async ( ) =>
285
- {
286
- await Observable . StartAsync ( async ( ) =>
287
- {
288
- var fileName = SelectedFile ! . Name . Substring ( SelectedFile ! . Name . LastIndexOf ( '/' ) + 1 ,
289
- SelectedFile ! . Name . Length - SelectedFile ! . Name . LastIndexOf ( '/' ) - 1 ) ;
290
- var saveFileName = await ApplicationHelper . SaveFile ( _lastDirectory , fileName ) ;
291
- if ( saveFileName != null )
292
- {
293
- SetLastDirectory ( saveFileName ) ;
294
- ShowWorkingMessage ( "Downloading File..." ) ;
295
- await kubernetesService . DownloadFile ( SelectedNamespace , SelectedPod , SelectedContainer , SelectedFile , saveFileName ) ;
296
- HideWorkingMessage ( ) ;
297
- }
298
- } , RxApp . TaskpoolScheduler ) ;
299
- } , isFile , RxApp . MainThreadScheduler ) ;
300
-
301
- DownloadCommand . ThrownExceptions . ObserveOn ( RxApp . MainThreadScheduler )
302
- . Subscribe ( ShowErrorMessage ) ;
303
- }
272
+
304
273
305
274
private void ConfigureDownloadFileContextCommand ( IKubernetesService kubernetesService )
306
275
{
@@ -322,33 +291,15 @@ await Observable.StartAsync(async () =>
322
291
} , RxApp . TaskpoolScheduler ) ;
323
292
} , outputScheduler : RxApp . MainThreadScheduler ) ;
324
293
325
- DownloadCommand . ThrownExceptions . ObserveOn ( RxApp . MainThreadScheduler )
294
+ DownloadContextCommand . ThrownExceptions . ObserveOn ( RxApp . MainThreadScheduler )
326
295
. Subscribe ( ShowErrorMessage ) ;
327
296
}
328
297
329
298
private void SetLastDirectory ( string saveFileName )
330
299
{
331
300
_lastDirectory = saveFileName . Substring ( 0 , saveFileName . LastIndexOf ( Path . DirectorySeparatorChar ) ) ;
332
301
}
333
-
334
- private void ConfigureOpenDirectoryCommand ( )
335
- {
336
- var isDirectory = this
337
- . WhenAnyValue ( x => x . SelectedFile , x => x . Message . IsVisible )
338
- . Select ( x => x is { Item1 . Type : FileType . Directory , Item2 : false } ) ;
339
-
340
- OpenCommand = ReactiveCommand . Create ( ( ) =>
341
- {
342
- if ( ".." == SelectedFile ? . Name )
343
- SelectedPath = SelectedFile ? . Parent ;
344
- else
345
- SelectedPath = SelectedFile != null ? SelectedFile ! . Name : "/" ;
346
- } ,
347
- isDirectory , RxApp . MainThreadScheduler ) ;
348
-
349
- OpenCommand . ThrownExceptions . ObserveOn ( RxApp . MainThreadScheduler )
350
- . Subscribe ( ShowErrorMessage ) ;
351
- }
302
+
352
303
353
304
private void ConfigureOpenDirectoryContextCommand ( )
354
305
{
@@ -357,7 +308,7 @@ private void ConfigureOpenDirectoryContextCommand()
357
308
SelectedPath = ".." == file . Name ? file . Parent : file . Name ;
358
309
} , outputScheduler : RxApp . MainThreadScheduler ) ;
359
310
360
- OpenCommand . ThrownExceptions . ObserveOn ( RxApp . MainThreadScheduler )
311
+ OpenContextCommand . ThrownExceptions . ObserveOn ( RxApp . MainThreadScheduler )
361
312
. Subscribe ( ShowErrorMessage ) ;
362
313
}
363
314
0 commit comments