2.6.0
This commit is contained in:
@@ -4,12 +4,50 @@
|
||||
''' 刷新页面显示的所有信息。
|
||||
''' </summary>
|
||||
Public Sub Reload(KeepInput As Boolean)
|
||||
Dim IndexBefore = ComboAccounts.SelectedIndex
|
||||
'刷新下拉框列表
|
||||
ComboAccounts.Items.Clear()
|
||||
ComboAccounts.Items.Add(New MyComboBoxItem With {.Content = "添加新账号"})
|
||||
Try
|
||||
Dim MsJson As JObject = GetJson(Setup.Get("LoginMsJson"))
|
||||
For Each Account In MsJson
|
||||
Dim Item As MyListItem = CType(FindResource("ComboBoxItemTemplateWithDelete"), DataTemplate).LoadContent()
|
||||
Item.Tag = Account.Value.ToString
|
||||
Item.Title = Account.Key
|
||||
CType(Item.Buttons(0), MyIconButton).Tag = Account.Key
|
||||
ComboAccounts.Items.Add(Item)
|
||||
Next
|
||||
Catch ex As Exception
|
||||
Log(ex, $"微软登录信息出错,登录信息已被重置({Setup.Get("LoginMsJson")})", LogLevel.Hint)
|
||||
Setup.Set("LoginMsJson", "{}")
|
||||
End Try
|
||||
'如果不保留输入,刷新列表后自动选择第一项
|
||||
ComboAccounts.SelectedIndex = If(KeepInput, Math.Max(0, IndexBefore), 0)
|
||||
End Sub
|
||||
Private Sub ComboAccounts_SelectionChanged(sender As Object, e As SelectionChangedEventArgs) Handles ComboAccounts.SelectionChanged
|
||||
If AniControlEnabled <> 0 OrElse ComboAccounts.SelectedItem Is Nothing Then Exit Sub
|
||||
If TypeOf ComboAccounts.SelectedItem Is MyListItem Then
|
||||
ComboAccounts.ContentPresenter.Content = CType(ComboAccounts.SelectedItem, MyListItem).Title
|
||||
ElseIf TypeOf ComboAccounts.SelectedItem Is MyComboBoxItem Then
|
||||
ComboAccounts.ContentPresenter.Content = CType(ComboAccounts.SelectedItem, MyComboBoxItem).Content
|
||||
End If
|
||||
End Sub
|
||||
|
||||
''' <summary>
|
||||
''' 获取当前页面的登录信息。
|
||||
''' </summary>
|
||||
Public Shared Function GetLoginData() As McLoginMs
|
||||
Return New McLoginMs With {.OAuthRefreshToken = Setup.Get("CacheMsOAuthRefresh"), .UserName = Setup.Get("CacheMsName")}
|
||||
If FrmLoginMs Is Nothing Then Return New McLoginMs With {.OAuthRefreshToken = Setup.Get("CacheMsOAuthRefresh"), .UserName = Setup.Get("CacheMsName")}
|
||||
Dim Result As McLoginMs = Nothing
|
||||
RunInUiWait(Sub()
|
||||
If FrmLoginMs.ComboAccounts.SelectedIndex = 0 Then
|
||||
Result = New McLoginMs
|
||||
Else
|
||||
Dim Item As MyListItem = FrmLoginMs.ComboAccounts.SelectedItem
|
||||
Result = New McLoginMs With {.OAuthRefreshToken = Item.Tag, .UserName = Item.Title}
|
||||
End If
|
||||
End Sub)
|
||||
Return Result
|
||||
End Function
|
||||
''' <summary>
|
||||
''' 当前页面的登录信息是否有效。
|
||||
@@ -26,13 +64,14 @@
|
||||
End Function
|
||||
|
||||
Private Sub BtnLogin_Click(sender As Object, e As EventArgs) Handles BtnLogin.Click
|
||||
ComboAccounts.IsEnabled = False
|
||||
BtnLogin.IsEnabled = False
|
||||
BtnLogin.Text = "登录中 0%"
|
||||
BtnLogin.Text = "0%"
|
||||
RunInNewThread(Sub()
|
||||
Try
|
||||
McLoginMsLoader.Start(GetLoginData(), IsForceRestart:=True)
|
||||
Do While McLoginMsLoader.State = LoadState.Loading
|
||||
RunInUi(Sub() BtnLogin.Text = "登录中 " & Math.Round(McLoginMsLoader.Progress * 100) & "%")
|
||||
RunInUi(Sub() BtnLogin.Text = Math.Round(McLoginMsLoader.Progress * 100) & "%")
|
||||
Thread.Sleep(50)
|
||||
Loop
|
||||
If McLoginMsLoader.State = LoadState.Finished Then
|
||||
@@ -45,7 +84,7 @@
|
||||
Throw New Exception(McLoginMsLoader.Error.Message, McLoginMsLoader.Error)
|
||||
End If
|
||||
Catch ex As ThreadInterruptedException
|
||||
Hint("登录已取消!")
|
||||
Hint("已取消登录!")
|
||||
Catch ex As Exception
|
||||
If ex.Message = "$$" Then
|
||||
ElseIf ex.Message.StartsWith("$") Then
|
||||
@@ -55,8 +94,9 @@
|
||||
End If
|
||||
Finally
|
||||
RunInUi(Sub()
|
||||
ComboAccounts.IsEnabled = True
|
||||
BtnLogin.IsEnabled = True
|
||||
BtnLogin.Text = "添加账号"
|
||||
BtnLogin.Text = "登录"
|
||||
End Sub)
|
||||
End Try
|
||||
End Sub, "Ms Login")
|
||||
|
||||
Reference in New Issue
Block a user