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