Skip to content

Commit

Permalink
Quality of Life Update
Browse files Browse the repository at this point in the history
  • Loading branch information
VRCWizard authored Jun 15, 2022
1 parent 3e783fe commit c525d21
Show file tree
Hide file tree
Showing 5 changed files with 274 additions and 153 deletions.
58 changes: 34 additions & 24 deletions OSCVRCWiz/OutputText.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public async void outputVRChat(VoiceWizardWindow MainForm, string textstring)
{
// currentlyPrinting = true;

var sender2 = new SharpOSC.UDPSender("127.0.0.1", 9000);
//MainForm.sender3 = new SharpOSC.UDPSender("127.0.0.1", 9000);



Expand Down Expand Up @@ -137,8 +137,9 @@ public async void outputVRChat(VoiceWizardWindow MainForm, string textstring)


var message0 = new SharpOSC.OscMessage("/avatar/parameters/KAT_Visible", true);
sender2.Send(message1);
sender2.Send(message0);
MainForm.sender3.Send(message1);
Task.Delay(100).Wait(); // this delay is to fix text box showing your previous message for a brief second
MainForm.sender3.Send(message0);


message1 = new SharpOSC.OscMessage("/avatar/parameters/KAT_Pointer", 1);
Expand Down Expand Up @@ -526,12 +527,12 @@ public async void outputVRChat(VoiceWizardWindow MainForm, string textstring)
message5 = new SharpOSC.OscMessage("/avatar/parameters/KAT_CharSync3", letterFloat3);
message0 = new SharpOSC.OscMessage("/avatar/parameters/KAT_Visible", true);

sender2.Send(message1);
sender2.Send(message2);
sender2.Send(message3);
sender2.Send(message4);
sender2.Send(message5);
sender2.Send(message0);
MainForm.sender3.Send(message1);
MainForm.sender3.Send(message2);
MainForm.sender3.Send(message3);
MainForm.sender3.Send(message4);
MainForm.sender3.Send(message5);
MainForm.sender3.Send(message0);


stringPoint += 1;
Expand Down Expand Up @@ -574,18 +575,18 @@ public async void outputVRChat(VoiceWizardWindow MainForm, string textstring)
message9 = new SharpOSC.OscMessage("/avatar/parameters/KAT_CharSync7", letterFloat7);
message0 = new SharpOSC.OscMessage("/avatar/parameters/KAT_Visible", true);

sender2.Send(message1);
sender2.Send(message2);
sender2.Send(message3);
sender2.Send(message4);
sender2.Send(message5);
MainForm.sender3.Send(message1);
MainForm.sender3.Send(message2);
MainForm.sender3.Send(message3);
MainForm.sender3.Send(message4);
MainForm.sender3.Send(message5);

sender2.Send(message6);
sender2.Send(message7);
sender2.Send(message8);
sender2.Send(message9);
MainForm.sender3.Send(message6);
MainForm.sender3.Send(message7);
MainForm.sender3.Send(message8);
MainForm.sender3.Send(message9);

sender2.Send(message0);
MainForm.sender3.Send(message0);


stringPoint += 1;
Expand Down Expand Up @@ -620,16 +621,25 @@ public async void outputVRChat(VoiceWizardWindow MainForm, string textstring)

if (MainForm.rjToggleButtonHideDelay2.Checked) //inactive hide
{
//make timer function start here or be reset here
System.Diagnostics.Debug.WriteLine("Outputing text to vrchat finished");

System.Diagnostics.Debug.WriteLine("Begun scheduled hide text");
Task.Delay(MainForm.eraseDelay).Wait();

message0 = new SharpOSC.OscMessage("/avatar/parameters/KAT_Visible", false);
// message1 = new SharpOSC.OscMessage("/avatar/parameters/KAT_Pointer", 255); HIDE TEXT SHOULD NOT CLEAR TEXT, THIS WILL FIX THE ISSUE OF DELAYED HIDE
// MainForm.hideDelayTimer.Enabled = false;

// MainForm.hideDelayTimer.Enabled = true;
// MainForm.hideDelayTimer.Enabled = true;
System.Diagnostics.Debug.WriteLine("restart/start timer");
MainForm.testtimer.Change(MainForm.eraseDelay, 0);

// Task.Delay(MainForm.eraseDelay).Wait();

// message0 = new SharpOSC.OscMessage("/avatar/parameters/KAT_Visible", false);


// sender2.Send(message0);

sender2.Send(message0);
/// sender2.Send(message1);
}
// currentlyPrinting = false; //does not work as intended, look into sharing betwwen threads possibly?
// int startingPoint = stringPoint;
Expand Down
24 changes: 24 additions & 0 deletions OSCVRCWiz/Settings1.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

79 changes: 46 additions & 33 deletions OSCVRCWiz/SpotifyAddon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@ public class SpotifyAddon
{
// private const string CredentialsPath = "credentials.json";
// private static readonly string? clientId = Environment.GetEnvironmentVariable("SPOTIFY_CLIENT_ID");
private static readonly string? clientId = "8ed3657eca864590843f45a659ec2976";
private static string clientId = "8ed3657eca864590843f45a659ec2976";
//private static EmbedIOAuthServer _server = new EmbedIOAuthServer(new Uri("http://localhost:5000/callback"), 5000);
private static EmbedIOAuthServer _server;
private static SpotifyClient myClient =null;
private static PKCETokenResponse myPKCEToken = null;
// public static string PKCEcode= "";
private static string lastSong = "";
private static string globalVerifier = "";

Expand Down Expand Up @@ -57,23 +58,41 @@ private static async Task OnImplicitGrantReceived(object sender, ImplictGrantRes
*/
public static async Task getCurrentSongInfo(VoiceWizardWindow MainForm)
{
// var newResponse = await new OAuthClient().RequestToken(
// new AuthorizationCodeRefreshRequest(clientId, clientSecret, myToken.RefreshToken));

// myClient = new SpotifyClient(newResponse.AccessToken);



if(myClient==null)
{
myClient = new SpotifyClient(Settings1.Default.PKCEAccessToken);
}
if (myClient != null)
{
try
{
System.Diagnostics.Debug.WriteLine("----Token refreshed Attempt-----");
PKCETokenRefreshRequest refreshRequest = new PKCETokenRefreshRequest(clientId, Settings1.Default.PKCERefreshToken);
PKCETokenResponse refreshResponse = await new OAuthClient().RequestToken(refreshRequest);
myClient = new SpotifyClient(refreshResponse.AccessToken);
// var authenticator = new PKCEAuthenticator(clientId, refreshResponse);

// var config = SpotifyClientConfig.CreateDefault()
// .WithAuthenticator(authenticator);
// myClient = new SpotifyClient(config);
Settings1.Default.PKCERefreshToken = refreshResponse.RefreshToken;
Settings1.Default.PKCEAccessToken = refreshResponse.AccessToken;
Settings1.Default.Save();
System.Diagnostics.Debug.WriteLine("----Token refreshed Successful-----");

var authenticator = new PKCEAuthenticator(clientId, myPKCEToken);
}
catch (APIException ex)
{
System.Diagnostics.Debug.WriteLine("-----Token doesn't need to refresh-----"+ ex.Response.Body.ToString());

var config = SpotifyClientConfig.CreateDefault()
.WithAuthenticator(authenticator);
var spotify = new SpotifyClient(config);
myClient = spotify;
}
// catch (Exception ex)
// {
// System.Diagnostics.Debug.WriteLine("-----Token doesn't need to refresh-----", ex.Message);

if (myClient != null)
{
// }


// var spotify = new SpotifyClient(tokenResponse.AccessToken);
Expand Down Expand Up @@ -134,23 +153,15 @@ private static async Task OnErrorReceived(object sender, string error, string st
}


public async Task SpotifyConnect()
public async Task SpotifyConnect(VoiceWizardWindow MainForm)
{
MainForm.getSpotify = true;

System.Diagnostics.Debug.WriteLine("Connect spotify");
/*
// Make sure "http://localhost:5000/callback" is in your spotify application as redirect uri!
_server = new EmbedIOAuthServer(new Uri("http://localhost:5000/callback"), 5000);
await _server.Start();
// _server.AuthorizationCodeReceived += OnAuthorizationCodeReceived;
_server.ImplictGrantReceived += OnImplicitGrantReceived;
_server.ErrorReceived += OnErrorReceived;
// var request = new LoginRequest(_server.BaseUri, clientId, LoginRequest.ResponseType.Code)//for OnAuthorizationCodeReceived (do not use 'yet' requires putting secret in code or server)
var request = new LoginRequest(_server.BaseUri, clientId, LoginRequest.ResponseType.Token) //for OnImplicitGrantReceived
{
Scope = new List<string> { Scopes.UserReadCurrentlyPlaying }
};
BrowserUtil.Open(request.ToUri());
*/
Expand All @@ -175,16 +186,18 @@ public async Task SpotifyConnect()
}

// This method should be called from your web-server when the user visits "http://localhost:5000/callback"
private static async Task GetCallback(object sender, AuthorizationCodeResponse response)
public static async Task GetCallback(object sender, AuthorizationCodeResponse response)
{
System.Diagnostics.Debug.WriteLine("code: " + response.Code.ToString());
System.Diagnostics.Debug.WriteLine("Getcallback code: " + response.Code.ToString());
// Note that we use the verifier calculated above!
var initialResponse = await new OAuthClient().RequestToken(new PKCETokenRequest(clientId, response.Code, new Uri("http://localhost:5000/callback"), globalVerifier));
var initialResponse = await new OAuthClient().RequestToken(new PKCETokenRequest(clientId, response.Code, new Uri("http://localhost:5000/callback"), globalVerifier));

Settings1.Default.PKCERefreshToken = initialResponse.RefreshToken;
Settings1.Default.PKCEAccessToken= initialResponse.AccessToken;
Settings1.Default.Save();



//var spotify = new SpotifyClient(initialResponse.AccessToken);
// Also important for later: response.RefreshToken
myPKCEToken = initialResponse;

}


Expand Down
Loading

0 comments on commit c525d21

Please sign in to comment.