|
11 | 11 | <button class="btn btn-sm btn-secondary" disabled="@(!IsConnected)" @onclick="RefreshFiles"> |
12 | 12 | <i class="bi bi-arrow-clockwise"></i> @Localizer[Resources.Files_Refresh] |
13 | 13 | </button> |
14 | | - <button class="btn btn-sm btn-outline-info" @onclick="OpenSelectedPrinter" disabled="@(selectedFile == null)"> |
15 | | - <i class="bi bi-eye"></i> Open |
| 14 | + <button class="btn btn-sm btn-outline-info" @onclick="OpenSelectedPrinter" disabled="@(selectedFile == null || _isOpening)"> |
| 15 | + @if (_isOpening) |
| 16 | + { |
| 17 | + <span class="spinner-border spinner-border-sm me-1" role="status" aria-hidden="true"></span> |
| 18 | + <span>Loading...</span> |
| 19 | + } |
| 20 | + else |
| 21 | + { |
| 22 | + <i class="bi bi-eye"></i><span> Open</span> |
| 23 | + } |
16 | 24 | </button> |
17 | 25 | <button class="btn btn-sm btn-outline-success" @onclick="CopySelectedToApp" disabled="@(selectedFile == null)"> |
18 | 26 | <i class="bi bi-arrow-left-square"></i> Copy to App |
|
69 | 77 | @code { |
70 | 78 | private List<FileEntry> _files = new(); |
71 | 79 | private bool _isLoading; |
| 80 | + private bool _isOpening; |
72 | 81 | private FileEntry? selectedFile; |
73 | 82 |
|
74 | 83 | protected override async Task OnInitializedAsync() |
|
161 | 170 | }, "Failed to copy file"); |
162 | 171 | } |
163 | 172 |
|
164 | | - private Task OpenSelectedPrinter() |
| 173 | + private async Task OpenSelectedPrinter() |
165 | 174 | { |
166 | | - if (selectedFile == null) return Task.CompletedTask; |
| 175 | + if (selectedFile == null) return; |
167 | 176 | var file = selectedFile; |
168 | | - return RunAsync(async () => |
| 177 | + _isOpening = true; |
| 178 | + StateHasChanged(); |
| 179 | + try |
169 | 180 | { |
170 | | - await using var stream = await PrinterStorage.OpenReadAsync(file.FullPath) ?? Stream.Null; |
171 | | - if (stream == Stream.Null) return; |
172 | | - using var reader = new StreamReader(stream); |
173 | | - var content = await reader.ReadToEndAsync(); |
174 | | - GCodeDoc.SetGCode(content); |
175 | | - }, "Failed to open file"); |
| 181 | + await RunAsync(async () => |
| 182 | + { |
| 183 | + await using var stream = await PrinterStorage.OpenReadAsync(file.FullPath) ?? Stream.Null; |
| 184 | + if (stream == Stream.Null) return; |
| 185 | + using var reader = new StreamReader(stream); |
| 186 | + var content = await reader.ReadToEndAsync(); |
| 187 | + GCodeDoc.SetGCode(content); |
| 188 | + }, "Failed to open file"); |
| 189 | + } |
| 190 | + finally |
| 191 | + { |
| 192 | + _isOpening = false; |
| 193 | + StateHasChanged(); |
| 194 | + } |
176 | 195 | } |
177 | 196 | } |
0 commit comments