11
11
namespace TwitchStreamingTools . Services ;
12
12
13
13
/// <summary>
14
- /// Manages the credentials in the application, ensuring credentials are kept up-to- date.
14
+ /// Manages the credentials in the application, ensuring credentials are kept up to date.
15
15
/// </summary>
16
16
public class TwitchAccountService : ITwitchAccountService {
17
+ /// <summary>
18
+ /// The application configuration.
19
+ /// </summary>
20
+ private readonly IConfiguration _configuration ;
21
+
17
22
/// <summary>
18
23
/// The timer used to check the twitch OAuth token against the API.
19
24
/// </summary>
@@ -28,7 +33,9 @@ public class TwitchAccountService : ITwitchAccountService {
28
33
/// Initializes a new instance of the <see cref="TwitchAccountService" /> class.
29
34
/// </summary>
30
35
/// <param name="twitchClient">The twitch chat client.</param>
31
- public TwitchAccountService ( ITwitchClientProxy twitchClient ) {
36
+ /// <param name="configuration">The application configuration.</param>
37
+ public TwitchAccountService ( ITwitchClientProxy twitchClient , IConfiguration configuration ) {
38
+ _configuration = configuration ;
32
39
_twitchClient = twitchClient ;
33
40
_timer = new DispatcherTimer {
34
41
Interval = TimeSpan . FromSeconds ( 5 )
@@ -68,14 +75,14 @@ public async Task UpdateCredentials(string bearer, string refresh, DateTime expi
68
75
// Do nothing
69
76
}
70
77
71
- Configuration . Instance . OAuth = new OAuthResponse {
78
+ _configuration . OAuth = new OAuthResponse {
72
79
Bearer = bearer ,
73
80
Refresh = refresh ,
74
81
ExpiresUtc = expires
75
82
} ;
76
83
77
- Configuration . Instance . TwitchUsername = user ? . username ;
78
- Configuration . Instance . WriteConfiguration ( ) ;
84
+ _configuration . TwitchUsername = user ? . username ;
85
+ _configuration . WriteConfiguration ( ) ;
79
86
_twitchClient . TwitchOAuthToken = bearer ;
80
87
_twitchClient . TwitchUsername = user ? . username ;
81
88
@@ -85,13 +92,13 @@ public async Task UpdateCredentials(string bearer, string refresh, DateTime expi
85
92
86
93
/// <inheritdoc />
87
94
public void DeleteCredentials ( ) {
88
- Configuration . Instance . OAuth = null ;
89
- Configuration . Instance . TwitchUsername = null ;
95
+ _configuration . OAuth = null ;
96
+ _configuration . TwitchUsername = null ;
90
97
_twitchClient . TwitchOAuthToken = null ;
91
98
_twitchClient . TwitchUsername = null ;
92
99
CredentialsAreValid = false ;
93
100
TwitchUsername = null ;
94
- Configuration . Instance . WriteConfiguration ( ) ;
101
+ _configuration . WriteConfiguration ( ) ;
95
102
96
103
OnCredentialsChanged ? . Invoke ( null ) ;
97
104
OnCredentialsStatusChanged ? . Invoke ( false ) ;
@@ -152,11 +159,11 @@ private async Task DoTokenRefreshIfNearExpiration() {
152
159
await twitchApi . RefreshAccessToken ( ) ;
153
160
154
161
// Update the configuration
155
- Configuration . Instance . OAuth = new OAuthResponse {
162
+ _configuration . OAuth = new OAuthResponse {
156
163
Bearer = twitchApi . OAuth . AccessToken ,
157
164
Refresh = twitchApi . OAuth . RefreshToken ,
158
165
ExpiresUtc = twitchApi . OAuth . ExpiresUtc ?? DateTime . MinValue
159
166
} ;
160
- Configuration . Instance . WriteConfiguration ( ) ;
167
+ _configuration . WriteConfiguration ( ) ;
161
168
}
162
169
}
0 commit comments