shareManage

This commit is contained in:
mossimo
2021-06-21 17:55:51 +08:00
parent 3ff117ecec
commit a669560415
9 changed files with 433 additions and 9 deletions
@@ -0,0 +1,182 @@
<Window xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
Width="600" Height="450"
x:Class="System.Application.UI.Views.Windows.ShareManageWindow"
xmlns:resx="clr-namespace:System.Application.UI.Resx;assembly=System.Application.SteamTools.Client.Desktop"
xmlns:vm="clr-namespace:System.Application.UI.ViewModels;assembly=System.Application.SteamTools.Client.Desktop"
xmlns:controls="clr-namespace:System.Application.UI.Views.Controls"
xmlns:ms="clr-namespace:System.Application.Models.Settings;assembly=System.Application.SteamTools.Client.Desktop"
xmlns:gif="using:AvaloniaGif"
xmlns:i="using:Avalonia.Xaml.Interactivity"
xmlns:ia="using:Avalonia.Xaml.Interactions.Core"
FontFamily="{Binding Source={x:Static ms:UISettings.FontName},Path=Value, Mode=OneWay,Converter={StaticResource NameToFontFamilyConverter}}"
Background="Transparent"
ExtendClientAreaTitleBarHeightHint="30"
x:Name="u"
Title="{Binding Title}"
x:DataType="vm:ShareManageViewModel"
x:CompileBindings="True">
<Panel>
<controls:TitleBar></controls:TitleBar>
<Menu
Margin="0 0 145 0" Height="30"
HorizontalAlignment="Right"
VerticalAlignment="Top">
<MenuItem Width="50" Command="{ReflectionBinding Refresh_Click}"
ToolTip.Tip="{ReflectionBinding Path=Res.RefreshList,Mode=OneWay,Source={x:Static resx:R.Current}}">
<MenuItem.Header>
<PathIcon Data="{StaticResource RefreshDrawing}" Width="14"></PathIcon>
</MenuItem.Header>
</MenuItem>
</Menu>
<TextBlock IsVisible="{CompiledBinding IsAuthorizedListEmpty}"
Text="{ReflectionBinding Path=Res.GameList_AddHideAppEmpty,Mode=OneWay,Source={x:Static resx:R.Current}}"
TextWrapping="WrapWithOverflow"
VerticalAlignment="Center" HorizontalAlignment="Center"></TextBlock>
<ScrollViewer HorizontalScrollBarVisibility="Disabled"
VerticalScrollBarVisibility="Auto"
Padding="{StaticResource TitleBarAfterMargin}">
<ItemsRepeater Items="{CompiledBinding AuthorizedList}">
<ItemsRepeater.Layout>
<!--<UniformGridLayout ItemsJustification="SpaceEvenly" MinRowSpacing="20" Orientation="Horizontal"
MaximumRowsOrColumns="6" />-->
<StackLayout Orientation="Vertical" Spacing="10"></StackLayout>
</ItemsRepeater.Layout>
<ItemsRepeater.ItemTemplate>
<DataTemplate>
<Border x:Name="card"
Classes="paper" Background="{DynamicResource ThemeBrushKey}" Margin="10" >
<i:Interaction.Behaviors>
<ia:EventTriggerBehavior EventName="PointerEnter" SourceObject="{ReflectionBinding #card}">
<ia:ChangePropertyAction TargetObject="{ReflectionBinding #delete_btn}" PropertyName="IsVisible" Value="True"/>
</ia:EventTriggerBehavior>
<ia:EventTriggerBehavior EventName="PointerLeave" SourceObject="{ReflectionBinding #card}">
<ia:ChangePropertyAction TargetObject="{ReflectionBinding #delete_btn}" PropertyName="IsVisible" Value="False"/>
</ia:EventTriggerBehavior>
</i:Interaction.Behaviors>
<Grid Height="92"
ColumnDefinitions="Auto,*,Auto">
<Panel x:Name="avatar" Cursor="Hand"
ToolTip.Tip="{ReflectionBinding Path=Res.UserChange_OpenUserUrl,Mode=OneWay,Source={x:Static resx:R.Current}}">
<!--OpenUserProfileUrl-->
<i:Interaction.Behaviors>
<ia:EventTriggerBehavior EventName="Tapped" SourceObject="{ReflectionBinding #avatar}">
<ia:InvokeCommandAction Command="{ReflectionBinding #u.DataContext.OpenUserProfileUrl}" CommandParameter="{Binding}"/>
</ia:EventTriggerBehavior>
</i:Interaction.Behaviors>
<gif:Image2
Width="92"
AutoStart="true"
Stretch="Uniform"
Source="{Binding AvatarStream^}">
</gif:Image2>
<Image Width="92" Stretch="Uniform" IsVisible="{Binding AvatarStream^,Converter={StaticResource IsNullConverter}}"
Source="avares://System.Application.SteamTools.Client.Desktop.Avalonia/Application/UI/Assets/AppResources/avater.jpg">
</Image>
<!--<gif:Image2 Width="184" Height="184"
AutoStart="true"
Source="{Binding MiniProfile.AvatarFrameStream^}"
Stretch="Uniform"
IsVisible="{Binding MiniProfile.AvatarFrameStream^,Converter={StaticResource IsNullConverter},ConverterParameter=invert}"/>-->
</Panel>
<Panel Grid.Column="1" Margin="10 5">
<StackPanel>
<DockPanel LastChildFill="True">
<Ellipse VerticalAlignment="Center"
HorizontalAlignment="Center" x:Name="circle" Margin="2 0 5 0" Height="10" Width="10" StrokeThickness="0" ToolTip.Tip="{Binding OnlineState}">
<i:Interaction.Behaviors>
<ia:DataTriggerBehavior Binding="{Binding OnlineState}" ComparisonCondition="Equal" Value="online">
<ia:ChangePropertyAction TargetObject="{ReflectionBinding #circle}" PropertyName="Fill" Value="#08D969"/>
</ia:DataTriggerBehavior>
<ia:DataTriggerBehavior Binding="{Binding OnlineState}" ComparisonCondition="Equal" Value="offline">
<ia:ChangePropertyAction TargetObject="{ReflectionBinding #circle}" PropertyName="Fill" Value="#adadad"/>
</ia:DataTriggerBehavior>
</i:Interaction.Behaviors>
</Ellipse>
<controls:ScrollingTextBlock x:Name="nickname"
Text="{Binding SteamNickName}"
FontSize="20"
Foreground="{DynamicResource HighlightForegroundBrushKey}"
Cursor="Hand"
ToolTip.Tip="{ReflectionBinding Path=Res.UserChange_BtnTootlip,Mode=OneWay,Source={x:Static resx:R.Current}}">
<i:Interaction.Behaviors>
<ia:EventTriggerBehavior EventName="Tapped"
SourceObject="{ReflectionBinding #nickname}">
<ia:InvokeCommandAction Command="{ReflectionBinding #u.DataContext.SteamId_Click}"
CommandParameter="{Binding}"/>
</ia:EventTriggerBehavior>
</i:Interaction.Behaviors>
</controls:ScrollingTextBlock>
<!--<WrapPanel VerticalAlignment="Center" IsVisible="{Binding Remark,Converter={StaticResource IsNullConverter},ConverterParameter=invert}">-->
<WrapPanel VerticalAlignment="Center">
<!--<TextBlock Text="("></TextBlock>-->
<!--<controls:ScrollingTextBlock Text="{Binding Remark}">
</controls:ScrollingTextBlock>-->
<!--<TextBlock Text=")"></TextBlock>-->
<!--<PathIcon Data="{StaticResource EditDrawing}" Width="10" Height="10"></PathIcon>-->
<TextBox VerticalAlignment="Center"
VerticalContentAlignment="Center"
Padding="15 0 15 0"
FontSize="14"
Watermark="{ReflectionBinding Path=Res.UserChange_EditRemark,Mode=OneWay,Source={x:Static resx:R.Current}}"
ToolTip.Tip="{ReflectionBinding Path=Res.UserChange_EditRemark,Mode=OneWay,Source={x:Static resx:R.Current}}"
Text="{Binding Remark,Mode=TwoWay}"
Classes="readonlybox"
Foreground="{DynamicResource InactiveForegroundBrushKey}">
<TextBox.InnerRightContent>
<PathIcon Data="{StaticResource EditDrawing}"
Width="10" Height="10"
Opacity="0.8"
VerticalAlignment="Center" HorizontalAlignment="Left"
Margin="0"
IsVisible="{Binding Remark,Converter={StaticResource IsNullConverter}}"/>
</TextBox.InnerRightContent>
</TextBox>
</WrapPanel>
</DockPanel>
<WrapPanel Orientation="Horizontal">
<TextBlock Text="{Binding AccountName}" FontSize="12" Foreground="{DynamicResource InactiveForegroundBrushKey}"/>
<TextBlock Text="(" FontSize="12" Foreground="{DynamicResource InactiveForegroundBrushKey}"/>
<TextBox Text="{Binding SteamId64_Int,Mode=OneWay}" FontSize="12" Classes="readonlybox" Padding="0" Foreground="{DynamicResource InactiveForegroundBrushKey}" IsReadOnly="True"></TextBox>
<TextBlock Text=")" FontSize="12" Foreground="{DynamicResource InactiveForegroundBrushKey}"/>
</WrapPanel>
</StackPanel>
<WrapPanel VerticalAlignment="Bottom" Orientation="Horizontal">
<PathIcon Data="{StaticResource ClockDrawing}" Width="12" VerticalAlignment="Center" Margin="5 0" Foreground="{DynamicResource InactiveForegroundBrushKey}">
</PathIcon>
<TextBlock Text="{Binding TimeusedTime,StringFormat={}{0:yyyy-MM-dd HH:mm:ss}}" FontSize="12" VerticalAlignment="Center" Foreground="{DynamicResource InactiveForegroundBrushKey}"/>
</WrapPanel>
</Panel>
<Grid Grid.Column="3" RowDefinitions="*,Auto">
<Panel>
<Button Classes="flatbutton"
IsVisible="False"
x:Name="delete_btn"
Background="Transparent"
Cursor="Hand"
HorizontalAlignment="Right"
Margin="0,0,0,68"
ToolTip.Tip="{ReflectionBinding Path=Res.UserChange_DeleteUser,Mode=OneWay,Source={x:Static resx:R.Current}}"
Command="{ReflectionBinding #u.DataContext.DeleteUserButton_Click}" CommandParameter="{Binding}">
<PathIcon Width="12" Data="{DynamicResource CloseDrawing}">
</PathIcon>
</Button>
</Panel>
</Grid>
</Grid>
</Border>
</DataTemplate>
</ItemsRepeater.ItemTemplate>
</ItemsRepeater>
</ScrollViewer>
</Panel>
</Window>
@@ -0,0 +1,23 @@
using Avalonia;
using Avalonia.Controls;
using Avalonia.Markup.Xaml;
using System.Application.UI.ViewModels;
namespace System.Application.UI.Views.Windows
{
public class ShareManageWindow : FluentWindow<IdleAppWindowViewModel>
{
public ShareManageWindow() : base()
{
InitializeComponent();
#if DEBUG
this.AttachDevTools();
#endif
}
private void InitializeComponent()
{
AvaloniaXamlLoader.Load(this);
}
}
}
@@ -57,4 +57,10 @@
<PackageReference Include="Avalonia.Diagnostics" Version="0.10.999-cibuild0014488-beta" />
</ItemGroup>
<ItemGroup>
<Compile Update="Application\UI\Views\Windows\ShareManagePage\ShareManageWindow.axaml.cs">
<DependentUpon>ShareManageWindow.axaml</DependentUpon>
</Compile>
</ItemGroup>
</Project>
+1
View File
@@ -17,6 +17,7 @@ namespace System.Application
ScriptStore,
HideApp,
IdleApp,
ShareManage,
ChangeBindPhoneNumber,
UserProfile,
NewVersion,
@@ -8,12 +8,62 @@ namespace System.Application.Models
{
public class AuthorizedDevice : ReactiveObject
{
public string? SteamId3 { get; set; }
public const long UndefinedId = 76561197960265728;
public AuthorizedDevice(){}
public AuthorizedDevice(string vdfString) :this(){
OriginVdfString = vdfString;
}
public string ProfileUrl => string.Format(STEAM_PROFILES_URL, SteamId64_Int);
public long SteamId3_Int { get; set; }
public long SteamId64_Int => UndefinedId + SteamId3_Int;
private string? _OnlineState;
public string? OnlineState
{
get => _OnlineState;
set => this.RaiseAndSetIfChanged(ref _OnlineState, value);
}
private string? _Remark;
/// <summary>
/// 备注
/// </summary>
public string? Remark
{
get => _Remark;
set => this.RaiseAndSetIfChanged(ref _Remark, value);
}
public string? SteamID { get; set; }
public string? ShowName { get; set; }
public string? SteamNickName { get; set; }
/// <summary>
/// 用户名
/// </summary>
public string? AccountName { get; set; }
public long Timeused { get; set; }
public DateTime TimeusedTime => Timeused.ToDateTimeS();
public string? Description { get; set; }
public string? Tokenid { get; set; }
public string AvatarIcon { get; set; }
public string AvatarMedium { get; set; }
private Task<string?>? _AvatarStream;
public Task<string?>? AvatarStream
{
get => _AvatarStream;
set => this.RaiseAndSetIfChanged(ref _AvatarStream, value);
}
public string? OriginVdfString { get; set; }
public string CurrentVdfString =>
"\"" + SteamId3_Int + "\"\n{\n" +
"\t\t\"timeused\"\t\t\"" + Timeused + "\"\n" +
"\t\t\"description\"\t\t\"" + Description + "\"\n" +
"\t\t\"tokenid\"\t\t\"" + Tokenid + "\"\n";
}
}
@@ -71,6 +71,8 @@ namespace System.Application.Services
/// <returns></returns>
List<SteamUser> GetRememberUserList();
bool UpdateAuthorizedDeviceList(AuthorizedDevice list);
bool RemoveAuthorizedDeviceList(AuthorizedDevice list);
/// <summary>
/// 获取所有当前PC共享授权信息
/// </summary>
@@ -42,7 +42,7 @@ namespace System.Application.Services.Implementation
readonly IDesktopPlatformService platformService;
readonly string? mSteamDirPath;
readonly string? mSteamProgramPath;
readonly string[] steamProcess = new[] { "steam","steam_osx", "steamservice", "steamwebhelper" };
readonly string[] steamProcess = new[] { "steam", "steam_osx", "steamservice", "steamwebhelper" };
readonly Lazy<IHttpService> _http = new(() => DI.Get<IHttpService>());
IHttpService Http => _http.Value;
@@ -189,7 +189,40 @@ namespace System.Application.Services.Implementation
}
return users;
}
public bool UpdateAuthorizedDeviceList(AuthorizedDevice model)
{
try
{
if (!string.IsNullOrWhiteSpace(ConfigVdfPath) && File.Exists(ConfigVdfPath))
{
VdfHelper.UpdateValueByReplace(ConfigVdfPath, model.OriginVdfString.ThrowIsNull(nameof(model.OriginVdfString)), model.CurrentVdfString);
return true;
}
}
catch (Exception e)
{
Log.Error(TAG, e, "UpdateAuthorizedDeviceList Fail(0).");
return false;
}
return false;
}
public bool RemoveAuthorizedDeviceList(AuthorizedDevice model)
{
try
{
if (!string.IsNullOrWhiteSpace(ConfigVdfPath) && File.Exists(ConfigVdfPath))
{
VdfHelper.DeleteValueByKey(ConfigVdfPath, model.OriginVdfString.ThrowIsNull(nameof(model.OriginVdfString)));
return true;
}
}
catch (Exception e)
{
Log.Error(TAG, e, "RemoveAuthorizedDeviceList Fail(0).");
return false;
}
return false;
}
public List<AuthorizedDevice> GetAuthorizedDeviceList()
{
var authorizeds = new List<AuthorizedDevice>();
@@ -199,7 +232,7 @@ namespace System.Application.Services.Implementation
{
// 注意:动态类型在移动端受限,且运行时可能抛出异常
dynamic v = VdfHelper.Read(ConfigVdfPath);
var authorizedDevice = v.Value.AuthorizedDevice.Value;
var authorizedDevice = v.Value.AuthorizedDevice;
if (authorizedDevice != null)
{
foreach (var item in authorizedDevice)
@@ -207,12 +240,12 @@ namespace System.Application.Services.Implementation
try
{
var i = item.Value;
authorizeds.Add(new AuthorizedDevice()
authorizeds.Add(new AuthorizedDevice(item.ToString())
{
SteamId3 = item.Key,
Timeused = i.timeused,
Description = i.description,
Tokenid = i.tokenid,
SteamId3_Int = Convert.ToInt64(item.Key.ToString()),
Timeused = Convert.ToInt64(i.timeused.ToString()),
Description = i.description.ToString(),
Tokenid = i.tokenid.ToString(),
});
}
catch (Exception e)
@@ -38,6 +38,7 @@ namespace System.Application.UI.ViewModels
LoginAccountCommand = ReactiveCommand.Create(LoginNewSteamAccount);
RefreshCommand = ReactiveCommand.Create(Initialize);
ShareManageCommand = ReactiveCommand.Create(OpenShareManageWindow);
MenuItems = new ObservableCollection<MenuItemViewModel>()
{
//new MenuItemViewModel(nameof(AppResources.More))
@@ -47,6 +48,8 @@ namespace System.Application.UI.ViewModels
new MenuItemViewModel(nameof(AppResources.UserChange_LoginNewAccount))
{ IconKey="SteamDrawing", Command=LoginAccountCommand },
new MenuItemViewModel (),
new MenuItemViewModel(nameof(AppResources.GameList_HideGameManger)){
IconKey ="EyeHideDrawing", Command = ShareManageCommand },
new MenuItemViewModel (nameof(AppResources.Refresh))
{ IconKey="RefreshDrawing" , Command = RefreshCommand},
// }
@@ -66,6 +69,11 @@ namespace System.Application.UI.ViewModels
public ReactiveCommand<Unit, Unit> LoginAccountCommand { get; }
public ReactiveCommand<Unit, Unit> RefreshCommand { get; }
public ReactiveCommand<Unit, Unit> ShareManageCommand { get; }
public void OpenShareManageWindow()
{
IShowWindowService.Instance.Show(CustomWindow.ShareManage, new ShareManageViewModel(), string.Empty, ResizeModeCompat.CanResize);
}
/// <summary>
/// steam记住的用户列表
@@ -0,0 +1,119 @@
using DynamicData;
using DynamicData.Binding;
using Newtonsoft.Json.Linq;
using ReactiveUI;
using System.Application.Models;
using System.Application.Models.Settings;
using System.Application.Services;
using System.Application.UI.Resx;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Globalization;
using System.Linq;
using System.Properties;
using System.Reactive.Linq;
using System.Threading.Tasks;
namespace System.Application.UI.ViewModels
{
public class ShareManageViewModel : WindowViewModel
{
readonly ISteamService steamService = DI.Get<ISteamService>();
readonly IHttpService httpService = DI.Get<IHttpService>();
readonly ISteamworksWebApiService webApiService = DI.Get<ISteamworksWebApiService>();
public ShareManageViewModel() : base()
{
Title = ThisAssembly.AssemblyTrademark + " q| " + AppResources.GameList_HideGameManger;
this.WhenAnyValue(x => x.AuthorizedList)
.Subscribe(s => this.RaisePropertyChanged(nameof(IsAuthorizedListEmpty)));
_AuthorizedSourceList = new SourceCache<AuthorizedDevice, long>(t => t.SteamId3_Int);
_AuthorizedSourceList
.Connect()
.ObserveOn(RxApp.MainThreadScheduler)
.Sort(SortExpressionComparer<AuthorizedDevice>.Descending(x => x.Timeused))
.Bind(out _AuthorizedList)
.Subscribe();
Refresh_Click();
}
public bool _IsAuthorizedListEmpty;
public bool IsAuthorizedListEmpty
{
get => _IsAuthorizedListEmpty;
set => this.RaiseAndSetIfChanged(ref _IsAuthorizedListEmpty, value);
}
private ReadOnlyObservableCollection<AuthorizedDevice>? _AuthorizedList;
public ReadOnlyObservableCollection<AuthorizedDevice>? AuthorizedList => _AuthorizedList;
public SourceCache< AuthorizedDevice, long> _AuthorizedSourceList;
public SourceCache<AuthorizedDevice, long> AuthorizedSourceList
{
get => _AuthorizedSourceList;
set => this.RaiseAndSetIfChanged(ref _AuthorizedSourceList, value);
}
//private string? _SearchText;
//public string? SearchText
//{
// get => _SearchText;
// set => this.RaiseAndSetIfChanged(ref _SearchText, value);
//}
public void Refresh_Click()
{
var list = new List<AuthorizedDevice>();
var userlist = steamService.GetRememberUserList();
var id = string.Empty;
foreach (var item in steamService.GetAuthorizedDeviceList())
{
var user = userlist.FirstOrDefault(x => x.SteamId3_Int == item.SteamId3_Int);
item.SteamNickName = user?.SteamNickName;
item.ShowName = item.SteamNickName + $"({item.SteamId64_Int})";
item.AccountName = user?.AccountName;
list.Add( item);
}
if (list.Count == 0)
IsAuthorizedListEmpty = true;
else
IsAuthorizedListEmpty = false;
_AuthorizedSourceList.AddOrUpdate(list);
_AuthorizedSourceList.Refresh();
Refresh_Cash().ConfigureAwait(false);
}
public async Task Refresh_Cash() {
var accountRemarks = Serializable.Clone<IReadOnlyDictionary<long, string?>?>(SteamAccountSettings.AccountRemarks.Value);
foreach (var user in _AuthorizedSourceList.Items)
{
string? remark = null;
var temp = await webApiService.GetUserInfo(user.SteamId64_Int);
accountRemarks?.TryGetValue(user.SteamId64_Int, out remark);
user.Remark = remark;
user.SteamID = temp.SteamID;
user.OnlineState = temp.OnlineState;
user.SteamNickName = temp.SteamNickName;
user.AvatarIcon = temp.AvatarIcon;
user.AvatarMedium = temp.AvatarMedium;
user.AvatarStream = httpService.GetImageAsync(temp.AvatarFull, ImageChannelType.SteamAvatars);
}
_AuthorizedSourceList.Refresh();
}
public void SteamId_Click(AuthorizedDevice user)
{
}
public void DeleteButton_Click(AuthorizedDevice user)
{
}
public void SetActivity_Click(AuthorizedDevice item)
{
steamService.UpdateAuthorizedDeviceList(item);
Refresh_Click();
}
}
}