-
-
Notifications
You must be signed in to change notification settings - Fork 151
Expand file tree
/
Copy pathFacebookLoginModule.uno
More file actions
89 lines (75 loc) · 1.93 KB
/
FacebookLoginModule.uno
File metadata and controls
89 lines (75 loc) · 1.93 KB
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
using Fuse.Scripting;
using Uno.Permissions;
using Uno.Threading;
using Uno.UX;
using Uno;
[UXGlobalModule]
public class FacebookLoginModule : NativeModule
{
class FacebookLoginPromise : Promise<FacebookLogin.AccessToken>
{
readonly FacebookLogin _facebookLogin;
public FacebookLoginPromise(FacebookLogin facebookLogin)
{
_facebookLogin = facebookLogin;
if defined(Android)
{
Permissions.Request(Permissions.Android.INTERNET).Then(
OnPermissionsPermitted,
OnPermissionsRejected);
}
else
{
Fuse.UpdateManager.AddOnceAction(Login);
}
}
void Login()
{
if defined(iOS || Android)
_facebookLogin.Login(this.Resolve, OnCancelled, OnError);
else
throw new NotImplementedException();
}
void OnCancelled()
{
Reject(new Exception("Cancelled"));
}
void OnError(string error)
{
Reject(new Exception(error));
}
extern(Android) void OnPermissionsPermitted(PlatformPermission p)
{
Fuse.UpdateManager.AddOnceAction(Login);
}
extern(Android) void OnPermissionsRejected(Exception e)
{
Reject(e);
}
}
static readonly FacebookLoginModule _instance;
readonly FacebookLogin _facebookLogin;
public FacebookLoginModule()
{
if (_instance != null)
return;
_facebookLogin = new FacebookLogin();
_instance = this;
Resource.SetGlobalKey(_instance, "FacebookLogin");
AddMember(new NativePromise<FacebookLogin.AccessToken, External>("login", Login, Converter));
AddMember(new NativeFunction("tokenAsString", (NativeCallback)GetAccessTokenAsString));
}
Future<FacebookLogin.AccessToken> Login(object[] args)
{
return new FacebookLoginPromise(_facebookLogin);
}
External Converter(Context context, FacebookLogin.AccessToken accessToken)
{
return new External(accessToken);
}
object GetAccessTokenAsString(Context c, object[] args) {
External obj = (External)args[0];
var token = (FacebookLogin.AccessToken)obj.Object;
return token.AsString();
}
}