Skip to content

Commit

Permalink
Added a config option for auto spotify overlay
Browse files Browse the repository at this point in the history
  • Loading branch information
tttsaurus committed Jan 8, 2025
1 parent 824d402 commit be13a03
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 12 deletions.
2 changes: 2 additions & 0 deletions src/main/java/com/tttsaurus/ingameinfo/IgiConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ public class IgiConfig
{
public static String SPOTIFY_CLIENT_ID;
public static String SPOTIFY_CLIENT_SECRET;
public static boolean SPOTIFY_AUTO_DISPLAY;

public static Configuration CONFIG;

Expand All @@ -17,6 +18,7 @@ public static void loadConfig()

SPOTIFY_CLIENT_ID = CONFIG.getString("Spotify Client Id", "spotify", "", "Input client id of your spotify app \nDeclaration: this mod doesn't record or share your client id \nand it's not recommended for you to share your client id \nGuide: you have to create a spotify app to get client id & secrete \nhttps://developer.spotify.com/documentation/web-api/concepts/apps \nRedirect URI should be set to http://localhost:8888 for this mod to listen");
SPOTIFY_CLIENT_SECRET = CONFIG.getString("Spotify Client Secret", "spotify", "", "Input client secret of your spotify app \nDeclaration: this mod doesn't record or share your client secret \nand it's not recommended for you to share your client secret");
SPOTIFY_AUTO_DISPLAY = CONFIG.getBoolean("Try Auto Display Overlay", "spotify", true, "Whether to try displaying the overlay when the game starts \nMay fail due to token/auth issues");
}
catch (Exception ignored) { }
finally
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,18 +71,7 @@ else if (message.startsWith("#spotify-gui"))
{
player.sendMessage(new TextComponentString(TextFormatting.DARK_PURPLE + message));
boolean flag = param.equals("true");
if (flag)
{
if (SpotifyUserInfo.token.accessToken.isEmpty())
{
player.sendMessage(new TextComponentString(TextFormatting.AQUA + "[SpotifyBot]" + TextFormatting.RESET + " The access token is empty."));
player.sendMessage(new TextComponentString(TextFormatting.AQUA + "[SpotifyBot]" + TextFormatting.RESET + " Please run the command #spotify-oauth first."));
return;
}
EventCenter.spotifyOverlayEvent.trigger(true);
}
else
EventCenter.spotifyOverlayEvent.trigger(false);
EventCenter.spotifyOverlayEvent.trigger(flag);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.tttsaurus.ingameinfo.common.impl.appcommunication.spotify;

import com.tttsaurus.ingameinfo.IgiConfig;
import com.tttsaurus.ingameinfo.common.api.appcommunication.spotify.SpotifyAccessUtils;
import com.tttsaurus.ingameinfo.common.api.appcommunication.spotify.SpotifyOAuthUtils;
import com.tttsaurus.ingameinfo.common.api.appcommunication.spotify.SpotifyUserInfo;
Expand All @@ -8,6 +9,10 @@
import com.tttsaurus.ingameinfo.common.api.mvvm.binding.ReactiveObject;
import com.tttsaurus.ingameinfo.common.api.mvvm.viewmodel.ViewModel;
import com.tttsaurus.ingameinfo.common.impl.igievent.EventCenter;
import net.minecraft.client.Minecraft;
import net.minecraft.client.entity.EntityPlayerSP;
import net.minecraft.util.text.TextComponentString;
import net.minecraft.util.text.TextFormatting;
import java.io.File;
import java.io.RandomAccessFile;
import java.time.Duration;
Expand Down Expand Up @@ -110,6 +115,17 @@ public void start()
{
if (flag)
{
if (SpotifyUserInfo.token.accessToken.isEmpty())
{
EntityPlayerSP player = Minecraft.getMinecraft().player;
if (player != null)
{
player.sendMessage(new TextComponentString(TextFormatting.AQUA + "[SpotifyBot]" + TextFormatting.RESET + " The access token is empty."));
player.sendMessage(new TextComponentString(TextFormatting.AQUA + "[SpotifyBot]" + TextFormatting.RESET + " Please run the command #spotify-oauth first."));
}
return;
}

activeSetter.invoke(true);
trackTitleText.set("Please wait...");

Expand Down Expand Up @@ -177,6 +193,8 @@ public void start()
SpotifyUserInfo.userName = SpotifyAccessUtils.getUserName(SpotifyUserInfo.token.accessToken);
}
catch (Exception ignored) { }
if (IgiConfig.SPOTIFY_AUTO_DISPLAY)
EventCenter.spotifyOverlayEvent.trigger(true);
}
return null;
});
Expand Down

0 comments on commit be13a03

Please sign in to comment.