mirror of
https://github.com/2dust/v2rayN.git
synced 2025-12-01 04:03:00 +00:00
Handle indeterminate subscription progress display
This commit is contained in:
parent
d04b8fa018
commit
39cc4f9aab
4 changed files with 47 additions and 7 deletions
|
|
@ -146,6 +146,10 @@ public sealed class SubscriptionInfoManager
|
|||
{
|
||||
try
|
||||
{
|
||||
if (config == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var subs = await AppManager.Instance.SubItems();
|
||||
if (subs is not { Count: > 0 }) return;
|
||||
foreach (var s in subs)
|
||||
|
|
@ -160,6 +164,10 @@ public sealed class SubscriptionInfoManager
|
|||
{
|
||||
try
|
||||
{
|
||||
if (config == null || s == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var originalUrl = Utils.GetPunycode(s.Url.TrimEx());
|
||||
if (originalUrl.IsNullOrEmpty()) return;
|
||||
|
||||
|
|
|
|||
|
|
@ -47,12 +47,18 @@ public class ProfilesViewModel : MyReactiveObject
|
|||
[Reactive]
|
||||
public string SubUsageText { get; set; }
|
||||
|
||||
[Reactive]
|
||||
public bool SubUsageIndeterminate { get; set; }
|
||||
|
||||
[Reactive]
|
||||
public int SubExpirePercent { get; set; }
|
||||
|
||||
[Reactive]
|
||||
public string SubExpireText { get; set; }
|
||||
|
||||
[Reactive]
|
||||
public bool SubExpireIndeterminate { get; set; }
|
||||
|
||||
[Reactive]
|
||||
public SubItem SelectedMoveToGroup { get; set; }
|
||||
|
||||
|
|
@ -306,10 +312,12 @@ public class ProfilesViewModel : MyReactiveObject
|
|||
SelectedMoveToGroup = new();
|
||||
|
||||
BlSubInfoVisible = true;
|
||||
SubUsagePercent = -1;
|
||||
SubExpirePercent = -1;
|
||||
SubUsagePercent = 0;
|
||||
SubExpirePercent = 0;
|
||||
SubUsageText = string.Empty;
|
||||
SubExpireText = string.Empty;
|
||||
SubUsageIndeterminate = true;
|
||||
SubExpireIndeterminate = true;
|
||||
|
||||
await RefreshSubscriptions();
|
||||
//await RefreshServers();
|
||||
|
|
@ -383,6 +391,13 @@ public class ProfilesViewModel : MyReactiveObject
|
|||
{
|
||||
if (!c)
|
||||
{
|
||||
SubUsageIndeterminate = true;
|
||||
SubExpireIndeterminate = true;
|
||||
SubUsagePercent = 0;
|
||||
SubExpirePercent = 0;
|
||||
SubUsageText = "—";
|
||||
SubExpireText = "—";
|
||||
BlSubInfoVisible = true;
|
||||
return;
|
||||
}
|
||||
_config.SubIndexId = SelectedSub?.Id;
|
||||
|
|
@ -407,6 +422,9 @@ public class ProfilesViewModel : MyReactiveObject
|
|||
SubExpirePercent = 0;
|
||||
SubUsageText = "—";
|
||||
SubExpireText = "—";
|
||||
SubUsageIndeterminate = true;
|
||||
SubExpireIndeterminate = true;
|
||||
BlSubInfoVisible = true;
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -421,11 +439,14 @@ public class ProfilesViewModel : MyReactiveObject
|
|||
SubExpirePercent = 0;
|
||||
SubUsageText = "—";
|
||||
SubExpireText = "—";
|
||||
SubUsageIndeterminate = true;
|
||||
SubExpireIndeterminate = true;
|
||||
// 尝试即时抓取一次响应头,避免必须“更新订阅”才显示
|
||||
try { await SubscriptionInfoManager.Instance.FetchHeaderForSub(_config, SelectedSub); } catch { }
|
||||
info = SubscriptionInfoManager.Instance.Get(subId);
|
||||
if (info == null)
|
||||
{
|
||||
BlSubInfoVisible = true;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
|
@ -435,11 +456,13 @@ public class ProfilesViewModel : MyReactiveObject
|
|||
{
|
||||
SubUsagePercent = info.UsagePercent;
|
||||
SubUsageText = string.Format("{0} / {1} ({2}%)", Utils.HumanFy(info.UsedBytes), Utils.HumanFy(info.Total), SubUsagePercent);
|
||||
SubUsageIndeterminate = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
SubUsagePercent = -1;
|
||||
SubUsagePercent = 0;
|
||||
SubUsageText = string.Format("{0}", Utils.HumanFy(info.UsedBytes));
|
||||
SubUsageIndeterminate = true;
|
||||
}
|
||||
|
||||
// Expire
|
||||
|
|
@ -456,16 +479,19 @@ public class ProfilesViewModel : MyReactiveObject
|
|||
int baseDays = daysLeft <= 31 ? 31 : (daysLeft <= 92 ? 92 : 365);
|
||||
var percentRemain = (int)Math.Round(Math.Min(daysLeft, baseDays) * 100.0 / baseDays);
|
||||
SubExpirePercent = Math.Clamp(percentRemain, 0, 100);
|
||||
SubExpireIndeterminate = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
SubExpirePercent = -1;
|
||||
SubExpirePercent = 0;
|
||||
SubExpireIndeterminate = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
SubExpireText = string.Empty;
|
||||
SubExpirePercent = -1;
|
||||
SubExpirePercent = 0;
|
||||
SubExpireIndeterminate = true;
|
||||
}
|
||||
|
||||
BlSubInfoVisible = true;
|
||||
|
|
@ -474,6 +500,10 @@ public class ProfilesViewModel : MyReactiveObject
|
|||
{
|
||||
// 出错也别隐藏
|
||||
BlSubInfoVisible = true;
|
||||
SubUsageIndeterminate = true;
|
||||
SubExpireIndeterminate = true;
|
||||
SubUsagePercent = 0;
|
||||
SubExpirePercent = 0;
|
||||
}
|
||||
await Task.CompletedTask;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -79,12 +79,12 @@
|
|||
<StackPanel Margin="{StaticResource MarginLr8}" IsVisible="{Binding BlSubInfoVisible}">
|
||||
<StackPanel Orientation="Horizontal" Spacing="6" HorizontalAlignment="Left" Margin="0,0,0,2">
|
||||
<TextBlock Width="56" VerticalAlignment="Center" Text="流量" />
|
||||
<ProgressBar Height="16" Minimum="0" Maximum="100" Value="{Binding SubUsagePercent}" Width="240" />
|
||||
<ProgressBar Height="16" Minimum="0" Maximum="100" Value="{Binding SubUsagePercent}" Width="240" IsIndeterminate="{Binding SubUsageIndeterminate}" />
|
||||
<TextBlock VerticalAlignment="Center" Text="{Binding SubUsageText}" />
|
||||
</StackPanel>
|
||||
<StackPanel Orientation="Horizontal" Spacing="6" HorizontalAlignment="Left">
|
||||
<TextBlock Width="56" VerticalAlignment="Center" Text="到期" />
|
||||
<ProgressBar Height="16" Minimum="0" Maximum="100" Value="{Binding SubExpirePercent}" Width="240" />
|
||||
<ProgressBar Height="16" Minimum="0" Maximum="100" Value="{Binding SubExpirePercent}" Width="240" IsIndeterminate="{Binding SubExpireIndeterminate}" />
|
||||
<TextBlock VerticalAlignment="Center" Text="{Binding SubExpireText}" />
|
||||
</StackPanel>
|
||||
</StackPanel>
|
||||
|
|
|
|||
|
|
@ -96,6 +96,7 @@
|
|||
Minimum="0"
|
||||
Maximum="100"
|
||||
Value="{Binding SubUsagePercent}"
|
||||
IsIndeterminate="{Binding SubUsageIndeterminate}"
|
||||
Style="{StaticResource MaterialDesignProgressBar}"
|
||||
Margin="4,0,4,0"
|
||||
Width="240" />
|
||||
|
|
@ -114,6 +115,7 @@
|
|||
Minimum="0"
|
||||
Maximum="100"
|
||||
Value="{Binding SubExpirePercent}"
|
||||
IsIndeterminate="{Binding SubExpireIndeterminate}"
|
||||
Style="{StaticResource MaterialDesignProgressBar}"
|
||||
Margin="4,0,4,0"
|
||||
Width="240" />
|
||||
|
|
|
|||
Loading…
Reference in a new issue