-
Notifications
You must be signed in to change notification settings - Fork 17
/
GoogleAccountControl.xaml.cs
63 lines (55 loc) · 1.9 KB
/
GoogleAccountControl.xaml.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media.Imaging;
namespace GoogleAssistantWindows
{
/// <summary>
/// Interaction logic for GoogleAccountControl.xaml
/// </summary>
public partial class GoogleAccountControl : UserControl
{
private readonly UserManager _userManager;
public GoogleAccountControl()
{
InitializeComponent();
_userManager = UserManager.Instance;
_userManager.OnUserUpdate += OnUserUpdate;
}
private void OnUserUpdate(UserManager.GoogleUserData userdata)
{
UpdateProfile(userdata);
}
private void UpdateProfile(UserManager.GoogleUserData userData)
{
if (TextBlockName.Dispatcher.CheckAccess())
{
GridSignedIn.Visibility = userData != null ? Visibility.Visible : Visibility.Hidden;
ImageGoogleSignIn.Visibility = userData == null ? Visibility.Visible : Visibility.Hidden;
if (userData != null)
{
TextBlockName.Text = userData.name;
ImageAvatar.Source = new BitmapImage(new Uri(Utils.GetDataStoreFolder() + userData.id + ".png"));
}
}
else
{
TextBlockName.Dispatcher.BeginInvoke(new Action(() => UpdateProfile(userData)));
}
}
private void ImageGoogleSignIn_PreviewMouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{
_userManager.GetOrRefreshCredential();
}
private void TextBlockSignOut_OnPreviewMouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{
SignOut();
}
private void SignOut()
{
UpdateProfile(null);
_userManager.SignOut();
}
}
}