discord rcp

Needs some work, currently isnt picking up downloading or launching game
This commit is contained in:
Peter 2021-07-13 12:03:46 +01:00
parent b3846d86b0
commit febdbecc22
9 changed files with 194 additions and 10 deletions

View File

@ -115,7 +115,8 @@ const DEFAULT_CONFIG = {
'-XX:+UseConcMarkSweepGC',
'-XX:+CMSIncrementalMode',
'-XX:-UseAdaptiveSizePolicy',
'-Xmn128M'
'-Xmn128M',
'-Dfml.loginTimeout=180'
],
},
game: {
@ -128,6 +129,7 @@ const DEFAULT_CONFIG = {
},
launcher: {
allowPrerelease: false,
discordIntegration: true,
dataDirectory: dataPath,
serverCodes: []
}
@ -797,4 +799,23 @@ exports.getAllowPrerelease = function(def = false){
*/
exports.setAllowPrerelease = function(allowPrerelease){
config.settings.launcher.allowPrerelease = allowPrerelease
}
/**
* Check if the launcher should enable discord presence features
*
* @param {boolean} def Optional. If true, the default value will be returned.
* @returns {boolean} Whether or not the launcher should enable discord presence features
*/
exports.getDiscordIntegration = function(def = false){
return !def ? config.settings.launcher.discordIntegration : DEFAULT_CONFIG.settings.launcher.discordIntegration
}
/**
* Change the status of whether or not the launcher should denable discord presence features
*
* @param {boolean} discordIntegration Whether or not the launcher should enable discord presence features
*/
exports.setDiscordIntegration = function(discordIntegration){
config.settings.launcher.discordIntegration = discordIntegration
}

View File

@ -6,16 +6,14 @@ const {Client} = require('discord-rpc')
let client
let activity
exports.initRPC = function(genSettings, servSettings, initialDetails = 'Waiting for Client..'){
exports.initRPC = function(genSettings, servSettings = null, initialDetails = 'Waiting for Client..'){
logger.log('Now Loading Discord RPC')
client = new Client({ transport: 'ipc' })
activity = {
details: initialDetails,
state: 'Modpack: ' + servSettings.shortId,
largeImageKey: servSettings.largeImageKey,
largeImageText: servSettings.largeImageText,
smallImageKey: genSettings.smallImageKey,
smallImageText: genSettings.smallImageText,
largeImageKey: genSettings.smallImageKey,
largeImageText: genSettings.smallImageText,
startTimestamp: new Date().getTime(),
instance: false
}
@ -34,9 +32,45 @@ exports.initRPC = function(genSettings, servSettings, initialDetails = 'Waiting
})
}
exports.updateState = function(state){
activity.state = state
client.setActivity(activity)
logger.log('Updated discord state to: ' + state)
}
exports.clearState = function(){
activity = {
details: activity.details,
largeImageKey: activity.largeImageKey,
largeImageText: activity.largeImageText,
startTimestamp: activity.startTimestamp,
instance: activity.instance
}
client.setActivity(activity)
logger.log('Cleared the activity state!')
}
exports.updateDetails = function(details){
activity.details = details
client.setActivity(activity)
logger.log('Updated discord details to: ' + details)
}
exports.clearDetails = function(){
activity = {
state: activity.state,
largeImageKey: activity.largeImageKey,
largeImageText: activity.largeImageText,
startTimestamp: activity.startTimestamp,
instance: activity.instance
}
logger.log('Cleared the activity details!')
}
exports.resetTime = function(){
activity.startTimestamp = new Date().getTime()
client.setActivity(activity)
logger.log('Reset the activity time!')
}
exports.shutdownRPC = function(){
@ -45,4 +79,8 @@ exports.shutdownRPC = function(){
client.destroy()
client = null
activity = null
}
exports.getClient = function(){
return client
}

View File

@ -118,6 +118,10 @@ document.getElementById('launch_button').addEventListener('click', function(e){
document.getElementById('settingsMediaButton').onclick = (e) => {
prepareSettings()
switchView(getCurrentView(), VIEWS.settings)
if(hasRPC){
DiscordWrapper.updateDetails('In the Settings...')
DiscordWrapper.clearState()
}
}
document.getElementById('openInstanceMediaButton').onclick = (e) => {
@ -262,6 +266,17 @@ const refreshServerStatus = async function(fade = false){
}
function loadDiscord(){
if(!ConfigManager.getDiscordIntegration()) return
const distro = DistroManager.getDistribution()
if(!hasRPC){
if(distro.discord != null){
DiscordWrapper.initRPC(distro.discord, null, '...')
hasRPC = true
}
}
}
refreshMojangStatuses()
// Server Status is refreshed in uibinder.js on distributionIndexDone.
@ -337,7 +352,7 @@ function asyncSystemScan(mcVersion, launchAfter = true){
// Show this information to the user.
setOverlayContent(
'No Compatible<br>Java Installation Found',
'In order to join WesterosCraft, you need a 64-bit installation of Java 8. Would you like us to install a copy? By installing, you accept <a href="http://www.oracle.com/technetwork/java/javase/terms/license/index.html">Oracle\'s license agreement</a>.',
'In order to join any Vicarious Network Modpack, you need a 64-bit installation of Java 8. Would you like us to install a copy? By installing, you accept <a href="http://www.oracle.com/technetwork/java/javase/terms/license/index.html">Oracle\'s license agreement</a>.',
'Install Java',
'Install Manually'
)
@ -668,7 +683,8 @@ function dlAsync(login = true){
const onLoadComplete = () => {
toggleLaunchArea(false)
if(hasRPC){
DiscordWrapper.updateDetails('Loading game..')
DiscordWrapper.updateDetails('Launching game...')
DiscordWrapper.resetTime()
}
proc.stdout.on('data', gameStateChange)
proc.stdout.on('data', gameCrashReportListener)
@ -698,7 +714,7 @@ function dlAsync(login = true){
if(SERVER_JOINED_REGEX.test(data)){
DiscordWrapper.updateDetails('Exploring the Realm!')
} else if(GAME_JOINED_REGEX.test(data)){
DiscordWrapper.updateDetails('Sailing to Westeros!')
DiscordWrapper.updateDetails('Sailing to Vicarious Network!')
}
}
@ -743,6 +759,14 @@ function dlAsync(login = true){
proc.stderr.on('data', gameErrorListener)
setLaunchDetails('Done. Enjoy the modpack!')
proc.on('close', (code, signal) => {
if(hasRPC){
const serv = DistroManager.getDistribution().getServer(ConfigManager.getSelectedServer())
DiscordWrapper.updateDetails('Ready to Play!')
DiscordWrapper.updateState('Modpack: ' + serv.getName())
DiscordWrapper.resetTime()
}
})
// Init Discord Hook
const distro = DistroManager.getDistribution()
@ -907,6 +931,15 @@ document.getElementById('newsButton').onclick = () => {
if(newsActive){
$('#landingContainer *').removeAttr('tabindex')
$('#newsContainer *').attr('tabindex', '-1')
if(hasRPC){
if(ConfigManager.getSelectedServer()){
const serv = DistroManager.getDistribution().getServer(ConfigManager.getSelectedServer())
DiscordWrapper.updateDetails('Ready to Play!')
DiscordWrapper.updateState('Modpack: ' + serv.getName())
} else {
DiscordWrapper.updateDetails('Landing Screen...')
}
}
} else {
$('#landingContainer *').attr('tabindex', '-1')
$('#newsContainer, #newsContainer *, #lower, #lower #center *').removeAttr('tabindex')
@ -915,6 +948,10 @@ document.getElementById('newsButton').onclick = () => {
newsAlertShown = false
ConfigManager.setNewsCacheDismissed(true)
ConfigManager.save()
if(hasRPC){
DiscordWrapper.updateDetails('Reading the News...')
DiscordWrapper.clearState()
}
}
}
slide_(!newsActive)

View File

@ -249,6 +249,22 @@ loginCancelButton.onclick = (e) => {
loginViewCancelHandler()
loginViewCancelHandler = null
}
if(loginViewOnSuccess === VIEWS.settings){
if(hasRPC){
DiscordWrapper.updateDetails('In the Settings...')
DiscordWrapper.clearState()
}
} else {
if(hasRPC){
if(ConfigManager.getSelectedServer()){
const serv = DistroManager.getDistribution().getServer(ConfigManager.getSelectedServer())
DiscordWrapper.updateDetails('Ready to Play!')
DiscordWrapper.updateState('Server: ' + serv.getName())
} else {
DiscordWrapper.updateDetails('Landing Screen...')
}
}
}
})
}
@ -273,6 +289,20 @@ loginButton.addEventListener('click', () => {
// Temporary workaround
if(loginViewOnSuccess === VIEWS.settings){
prepareSettings()
if(hasRPC){
DiscordWrapper.updateDetails('In the Settings...')
DiscordWrapper.clearState()
}
} else {
if(hasRPC){
if(ConfigManager.getSelectedServer()){
const serv = DistroManager.getDistribution().getServer(ConfigManager.getSelectedServer())
DiscordWrapper.updateDetails('Ready to Play!')
DiscordWrapper.updateState('Modpack: ' + serv.getName())
} else {
DiscordWrapper.updateDetails('Landing Screen...')
}
}
}
loginViewOnSuccess = VIEWS.landing // Reset this for good measure.
loginCancelEnabled(false) // Reset this for good measure.

View File

@ -120,6 +120,7 @@ function toggleOverlay(toggleState, dismissable = false, content = 'overlayConte
function toggleServerSelection(toggleState) {
prepareServerSelectionList()
toggleOverlay(toggleState, true, 'serverSelectContent')
DiscordWrapper.updateDetails('Selecting modpack...')
}
/**
@ -179,6 +180,8 @@ document.getElementById('serverSelectConfirm').addEventListener('click', () => {
updateSelectedServer(serv)
refreshServerStatus(true)
toggleOverlay(false)
DiscordWrapper.updateDetails('Ready to Play!')
DiscordWrapper.updateState('Modpack: ' + serv.getName())
return
}
}

View File

@ -312,6 +312,15 @@ settingsNavDone.onclick = () => {
saveDropinModConfiguration()
saveShaderpackSettings()
switchView(getCurrentView(), VIEWS.landing)
if(hasRPC){
if(ConfigManager.getSelectedServer()){
const serv = DistroManager.getDistribution().getServer(ConfigManager.getSelectedServer())
DiscordWrapper.updateDetails('Ready to Play!')
DiscordWrapper.updateState('Modpack: ' + serv.getName())
} else {
DiscordWrapper.updateDetails('Landing Screen...')
}
}
}
/**
@ -324,6 +333,10 @@ document.getElementById('settingsAddAccount').onclick = (e) => {
loginViewOnCancel = VIEWS.settings
loginViewOnSuccess = VIEWS.settings
loginCancelEnabled(true)
if(hasRPC){
DiscordWrapper.updateDetails('Adding an Account...')
DiscordWrapper.clearState()
}
})
}
@ -410,6 +423,10 @@ function bindAuthAccountLogOut(){
processLogOut(val, isLastAccount)
toggleOverlay(false)
switchView(getCurrentView(), VIEWS.login)
if(hasRPC){
DiscordWrapper.updateDetails('Adding an Account...')
DiscordWrapper.clearState()
}
})
setDismissHandler(() => {
toggleOverlay(false)

View File

@ -65,6 +65,7 @@ function showMainUI(data){
prepareSettings(true)
updateSelectedServer(data.getServer(ConfigManager.getSelectedServer()))
refreshServerStatus()
loadDiscord()
setTimeout(() => {
document.getElementById('frameBar').style.backgroundColor = 'rgba(0, 0, 0, 0.5)'
document.body.style.backgroundImage = `url('assets/images/backgrounds/${document.body.getAttribute('bkid')}.jpg')`
@ -81,13 +82,30 @@ function showMainUI(data){
if(ConfigManager.isFirstLaunch()){
currentView = VIEWS.welcome
$(VIEWS.welcome).fadeIn(1000)
if(hasRPC){
DiscordWrapper.updateDetails('Welcome and continue.')
DiscordWrapper.updateState('Launcher Setup')
}
} else {
if(isLoggedIn){
currentView = VIEWS.landing
$(VIEWS.landing).fadeIn(1000)
if(hasRPC && !ConfigManager.isFirstLaunch()){
if(ConfigManager.getSelectedServer()){
const serv = DistroManager.getDistribution().getServer(ConfigManager.getSelectedServer())
DiscordWrapper.updateDetails('Ready to Play!')
DiscordWrapper.updateState('Modpack: ' + serv.getName())
} else {
DiscordWrapper.updateDetails('Landing Screen...')
}
}
} else {
currentView = VIEWS.login
$(VIEWS.login).fadeIn(1000)
if(hasRPC){
DiscordWrapper.updateDetails('Adding an Account...')
DiscordWrapper.clearState()
}
}
}
@ -343,6 +361,10 @@ async function validateSelectedAccount(){
}
toggleOverlay(false)
switchView(getCurrentView(), VIEWS.login)
if(hasRPC){
DiscordWrapper.updateDetails('Adding an Account...')
DiscordWrapper.clearState()
}
})
setDismissHandler(() => {
if(accLen > 1){

View File

@ -3,4 +3,8 @@
*/
document.getElementById('welcomeButton').addEventListener('click', e => {
switchView(VIEWS.welcome, VIEWS.login)
if(hasRPC){
DiscordWrapper.updateDetails('Adding an Account...')
DiscordWrapper.updateState('Launcher Setup')
}
})

View File

@ -259,6 +259,18 @@
</label>
</div>
</div>
<div class="settingsFieldContainer">
<div class="settingsFieldLeft">
<span class="settingsFieldTitle">Enable Discord Integration</span>
<span class="settingsFieldDesc">This option will allow the launcher to control your presence on Discord. If you close the launcher at any time, this feature will no longer work.</span>
</div>
<div class="settingsFieldRight">
<label class="toggleSwitch">
<input type="checkbox" cValue="DiscordIntegration">
<span class="toggleSwitchSlider"></span>
</label>
</div>
</div>
<div class="settingsFileSelContainer">
<div class="settingsFileSelContent">
<div class="settingsFieldTitle" id="settingsDataDirTitle">Data Directory</div>