UpdateChannelType

This commit is contained in:
Aigio Liu
2021-07-30 10:07:39 +08:00
parent c96af3133e
commit a0968ebcb2
7 changed files with 76 additions and 56 deletions
@@ -431,32 +431,7 @@ namespace System.Application.Models
}
#endif
public async Task<Stream?> GetQrCodeStream()
{
var qrCode = await Task.Run(() =>
{
var bytes = Serializable.SMP(new[] { this.AuthenticatorData.ToLightweightExportDTO() });
#if DEBUG
var bytes_compress_gzip = bytes.CompressByteArray();
#endif
var bytes_compress_br = bytes.CompressByteArrayByBrotli();
#if DEBUG
Toast.Show($"bytesLength, source: {bytes.Length}, gzip: {bytes_compress_gzip.Length}, br: {bytes_compress_br.Length}");
#endif
(var result, var stream, var e) = QRCodeHelper.Create(bytes);
switch (result)
{
case QRCodeHelper.QRCodeCreateResult.DataTooLong:
Toast.Show(AppResources.AuthLocal_ExportToQRCodeTooLongErrorTip);
break;
case QRCodeHelper.QRCodeCreateResult.Exception:
Toast.Show(e!.ToString());
break;
}
return stream;
});
return qrCode;
}
public Task<Stream?> GetQrCodeStream() => AuthService.GetQrCodeStreamAsync(AuthenticatorData);
/// <summary>
/// 编辑令牌自定义名称
@@ -74,5 +74,11 @@ namespace System.Application.Models.Settings
/// </summary>
public static SerializableProperty<IReadOnlyDictionary<Platform, string>> TextReaderProvider { get; }
= GetProperty(defaultValue: (IReadOnlyDictionary<Platform, string>?)null, autoSave: true);
/// <summary>
/// 下载更新渠道
/// </summary>
public static SerializableProperty<UpdateChannelType> UpdateChannel { get; }
= GetProperty(defaultValue: (UpdateChannelType)default, autoSave: true);
}
}
@@ -13,13 +13,18 @@ namespace System.Application.Models.Settings
static UISettings()
{
//Theme.ValueChanged += Theme_ValueChanged;
#if !__MOBILE__
AppGridSize.ValueChanged += AppGridSize_ValueChanged;
#endif
}
#if !__MOBILE__
private static void AppGridSize_ValueChanged(object? sender, ValueChangedEventArgs<int> e)
{
SteamConnectService.Current.SteamApps.Refresh();
}
#endif
//private static void Theme_ValueChanged(object sender, ValueChangedEventArgs<short> e)
//{
@@ -3,6 +3,7 @@ using Newtonsoft.Json.Linq;
using ReactiveUI;
using System.Application.Entities;
using System.Application.Models;
using System.Application.UI;
using System.Application.UI.Resx;
using System.Application.UI.ViewModels;
using System.Collections.Generic;
@@ -729,5 +730,39 @@ namespace System.Application.Services
Toast.Show(ex.Message);
}
}
public static async Task<Stream?> GetQrCodeStreamAsync(IEnumerable<IGAPAuthenticatorDTO> datas)
{
var qrCode = await Task.Run(() =>
{
var dtos = datas.Select(x => x.ToLightweightExportDTO()).ToArray();
var bytes = Serializable.SMP(dtos);
#if DEBUG
var bytes_compress_gzip = bytes.CompressByteArray();
#endif
var bytes_compress_br = bytes.CompressByteArrayByBrotli();
#if DEBUG
Toast.Show($"bytesLength, source: {bytes.Length}, gzip: {bytes_compress_gzip.Length}, br: {bytes_compress_br.Length}");
#endif
(var result, var stream, var e) = QRCodeHelper.Create(bytes);
switch (result)
{
case QRCodeHelper.QRCodeCreateResult.DataTooLong:
Toast.Show(AppResources.AuthLocal_ExportToQRCodeTooLongErrorTip);
break;
case QRCodeHelper.QRCodeCreateResult.Exception:
Toast.Show(e!.ToString());
break;
}
return stream;
});
return qrCode;
}
public static Task<Stream?> GetQrCodeStreamAsync(params IGAPAuthenticatorDTO[] datas)
{
IEnumerable<IGAPAuthenticatorDTO> datas_ = datas;
return GetQrCodeStreamAsync(datas_);
}
}
}
@@ -42,8 +42,19 @@ namespace System.Application.UI.ViewModels
{
}
//async void TestHttp()
//{
// var task1 = IHttpService.Instance.GetAsync<string>("https://developers.google.com/android");
// var task2 = IHttpService.Instance.GetAsync<string>("https://developer.android.google.cn/");
// var str = await Task.WhenAny(task1, task2);
// DebugString = str.Result ?? string.Empty;
//}
public void DebugButton_Click()
{
//TestHttp();
//return;
TestTextBoxWindow(0);
//DebugButton_Click1();
@@ -8,7 +8,6 @@ using System.Linq;
using System.Properties;
using System.Threading.Tasks;
using static System.Application.FilePicker2;
using WinAuth;
namespace System.Application.UI.ViewModels
{
@@ -222,20 +221,7 @@ namespace System.Application.UI.ViewModels
static async Task<Stream?> GetQRCodeAsync(Func<MyAuthenticator, bool>? filter)
{
var datas = AuthService.Current.GetExportSourceAuthenticators(filter);
var qrCode = await Task.Run(() =>
{
var dtos = datas.Select(x => x.ToLightweightExportDTO()).ToArray();
var bytes = Serializable.SMP(dtos);
#if DEBUG
var bytes_compress_gzip = bytes.CompressByteArray();
#endif
var bytes_compress_br = bytes.CompressByteArrayByBrotli();
#if DEBUG
Toast.Show($"bytesLength, source: {bytes.Length}, gzip: {bytes_compress_gzip.Length}, br: {bytes_compress_br.Length}");
#endif
return CreateQRCode(bytes_compress_br);
});
return qrCode;
return await AuthService.GetQrCodeStreamAsync(datas);
}
/// <summary>
@@ -258,21 +244,6 @@ namespace System.Application.UI.ViewModels
async Task ExportAuthToQRCodeAsync() => await ExportAuthCore(async () => QRCode = await GetQRCodeAsync(Filter), ignorePath: true, ignorePassword: true);
static Stream? CreateQRCode(byte[] bytes)
{
(var result, var stream, var e) = QRCodeHelper.Create(bytes);
switch (result)
{
case QRCodeHelper.QRCodeCreateResult.DataTooLong:
Toast.Show(AppResources.AuthLocal_ExportToQRCodeTooLongErrorTip);
break;
case QRCodeHelper.QRCodeCreateResult.Exception:
Toast.Show(e!.ToString());
break;
}
return stream;
}
/// <summary>
/// 默认导出文件名
/// </summary>
+17
View File
@@ -0,0 +1,17 @@
namespace System.Application
{
/// <summary>
/// 下载更新渠道类型
/// </summary>
public enum UpdateChannelType
{
/// <summary>
/// 自动识别
/// </summary>
Auto,
GitHub,
Gitee,
}
}