Skip to content

Commit

Permalink
added "Cancelling" message
Browse files Browse the repository at this point in the history
Signed-off-by: OsakaRuma <[email protected]>
  • Loading branch information
iamscottxu committed Aug 25, 2024
1 parent 1def457 commit daa4bbd
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 14 deletions.
11 changes: 10 additions & 1 deletion src/Starward.Language/Lang.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions src/Starward.Language/Lang.resx
Original file line number Diff line number Diff line change
Expand Up @@ -1482,6 +1482,9 @@ Do you accept the risk and continue to use it?</value>
<data name="DownloadGamePage_Pausing" xml:space="preserve">
<value>Pausing</value>
</data>
<data name="DownloadGamePage_Cancelling" xml:space="preserve">
<value>Cancelling</value>
</data>
<data name="InstallGameManager_DownloadTaskCompleted" xml:space="preserve">
<value>Download task completed</value>
</data>
Expand Down
3 changes: 3 additions & 0 deletions src/Starward.Language/Lang.zh-CN.resx
Original file line number Diff line number Diff line change
Expand Up @@ -1482,6 +1482,9 @@
<data name="DownloadGamePage_Pausing" xml:space="preserve">
<value>暂停中</value>
</data>
<data name="DownloadGamePage_Cancelling" xml:space="preserve">
<value>取消中</value>
</data>
<data name="InstallGameManager_DownloadTaskCompleted" xml:space="preserve">
<value>下载任务已完成</value>
</data>
Expand Down
3 changes: 3 additions & 0 deletions src/Starward.Language/Lang.zh-TW.resx
Original file line number Diff line number Diff line change
Expand Up @@ -1482,6 +1482,9 @@
<data name="DownloadGamePage_Pausing" xml:space="preserve">
<value>暫停中</value>
</data>
<data name="DownloadGamePage_Cancelling" xml:space="preserve">
<value>取消中</value>
</data>
<data name="InstallGameManager_DownloadTaskCompleted" xml:space="preserve">
<value>下載任務已完成</value>
</data>
Expand Down
1 change: 1 addition & 0 deletions src/Starward/Controls/InstallGameController.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
Command="{Binding CancelCommand}"
IsEnabled="{Binding IsCancelButtonEnabled}"
Style="{ThemeResource DateTimePickerFlyoutButtonStyle}">
<FontIcon FontSize="14"
Glyph="&#xE711;"
Expand Down
16 changes: 9 additions & 7 deletions src/Starward/Services/Download/InstallGameManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -142,13 +142,15 @@ private void Model_InstallCanceled(object? sender, EventArgs e)
{
if (sender is InstallGameStateModel model)
{
model.Service.Pause();
model.Service.ClearState();
_services.TryRemove(model.GameBiz, out _);
model.InstallFinished -= Model_InstallFinished;
model.InstallFailed -= Model_InstallFailed;
model.InstallCanceled -= Model_InstallCanceled;
InstallTaskRemoved?.Invoke(this, model);
model.Service.Pause(() =>
{
model.Service.ClearState();
_services.TryRemove(model.GameBiz, out _);
model.InstallFinished -= Model_InstallFinished;
model.InstallFailed -= Model_InstallFailed;
model.InstallCanceled -= Model_InstallCanceled;
InstallTaskRemoved?.Invoke(this, model);
});
}
}

Expand Down
6 changes: 4 additions & 2 deletions src/Starward/Services/Download/InstallGameService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -690,12 +690,13 @@ public void Continue()



public void Pause()
public void Pause(Action? onPaused = null)
{
try
{
if (State is InstallGameState.None or InstallGameState.Cancel)
{
if (State == InstallGameState.None) onPaused?.Invoke();
return;
}
_pausedState = State;
Expand All @@ -707,8 +708,9 @@ public void Pause()
{
await Task.Delay(100);
}
}).ConfigureAwait(false).GetAwaiter().OnCompleted(() => {
}).ConfigureAwait(true).GetAwaiter().OnCompleted(() => {
State = InstallGameState.None;
onPaused?.Invoke();
});
}
catch (Exception ex)
Expand Down
17 changes: 13 additions & 4 deletions src/Starward/Services/Download/InstallGameStateModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,16 @@ internal InstallGameStateModel(InstallGameService service)
private bool _isContinueOrPauseButtonEnabled = true;


[ObservableProperty]
private bool _isCancelButtonEnabled = true;


private long _lastTimestamp;

private long _lastFinishedBytes;

private bool _isCancel = false;

public double _speedBytesPerSecond;


Expand All @@ -116,6 +122,7 @@ private void ContinueOrPause()
[RelayCommand]
private void Cancel()
{
_isCancel = true;
InstallCanceled?.Invoke(this, EventArgs.Empty);
}

Expand All @@ -126,11 +133,13 @@ public void UpdateState()
try
{
IsContinueOrPauseButtonEnabled = true;
IsCancelButtonEnabled = true;
switch (Service.State)
{
case InstallGameState.None:
StateText = Lang.DownloadGamePage_Paused;
ButtonGlyph = PlayGlyph;
_isCancel = false;
break;
case InstallGameState.Download:
StateText = Lang.DownloadGamePage_Downloading;
Expand Down Expand Up @@ -197,9 +206,9 @@ public void UpdateState()
ButtonGlyph = PlayGlyph;
break;
case InstallGameState.Cancel:
StateText = Lang.DownloadGamePage_Pausing;
ButtonGlyph = PlayGlyph;
IsContinueOrPauseButtonEnabled = false;
StateText = _isCancel ? Lang.DownloadGamePage_Cancelling : Lang.DownloadGamePage_Pausing;
ButtonGlyph = PauseGlyph;
IsContinueOrPauseButtonEnabled = IsCancelButtonEnabled = false;
break;
default:
break;
Expand All @@ -223,7 +232,7 @@ private void ComputeSpeed(InstallGameState state)
_speedBytesPerSecond = Math.Clamp((double)(bytes - _lastFinishedBytes) / (ts - _lastTimestamp) * Stopwatch.Frequency, 0, long.MaxValue);
_lastFinishedBytes = bytes;
_lastTimestamp = ts;
if (state is InstallGameState.None or InstallGameState.Finish or InstallGameState.Error)
if (state is InstallGameState.None or InstallGameState.Finish or InstallGameState.Error or InstallGameState.Cancel)
{
SpeedText = null;
RemainingTimeText = null;
Expand Down

0 comments on commit daa4bbd

Please sign in to comment.