Skip to content

Commit

Permalink
Merge pull request #87 from spdermn02/patch-3
Browse files Browse the repository at this point in the history
Patch 3 - Audio Device Change Event & Mute/Deafen State Fix
  • Loading branch information
gitagogaming authored Aug 14, 2024
2 parents 8a0cfb2 + 98c0446 commit f013d97
Show file tree
Hide file tree
Showing 7 changed files with 95 additions and 52 deletions.
2 changes: 1 addition & 1 deletion base/buildentry.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ const combineInfo = (TP_PLUGIN_INFO, TP_PLUGIN_SETTINGS, categoriesArray) => {

// Write the JSON object to a file
const writeToFile = (jsonString) => {
fs.writeFile('tppentry.tp', jsonString, (err) => {
fs.writeFile('./base/entry.tp', jsonString, (err) => {
if (err) {
console.error(err);
return;
Expand Down
29 changes: 27 additions & 2 deletions base/entry.js
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,17 @@ Object.assign(states, {
"Connected",
"Disconnected"
]
},
"24":{
id: "discord_default_audio_device_change_eventState",
category: "Discord",
type: "choice",
desc: "Discord Default Audio Device Change Event",
default: "",
valueChoices:[
"Input",
"Output"
]
}
})

Expand Down Expand Up @@ -1009,7 +1020,7 @@ Object.assign(connectors, {
Object.assign(events, {
"1":{
id: "discord_newDM",
category: "Direct Message",
category: "Discord",
name: "Discord: New Direct Message (DM)",
format: "When receiving a new Direct Message $val",
type: "communicate",
Expand All @@ -1022,7 +1033,7 @@ Object.assign(events, {
},
"2": {
id: "discord_newMention",
category: "Direct Message",
category: "Discord",
name: "Discord | New Mention",
format: "When receiving a new Mention $val",
type: "communicate",
Expand All @@ -1032,7 +1043,21 @@ Object.assign(events, {
],
valueType: "choice",
valueStateId: "discord_newMention_eventState"
},
"3":{
id: "discord_default_audio_device_change",
category: "Discord",
name: "Discord: Default Audio Device Changed",
format: "When Default $val Device Changed",
type: "communicate",
valueChoices: [
"Input",
"Output"
],
valueType: "choice",
valueStateId: "discord_default_audio_device_change_eventState"
}

})


Expand Down
86 changes: 49 additions & 37 deletions base/entry.tp
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,44 @@
]
}
],
"events": [],
"events": [
{
"id": "discord_newDM",
"name": "Discord: New Direct Message (DM)",
"format": "When receiving a new Direct Message $val",
"type": "communicate",
"valueChoices": [
"True",
"False"
],
"valueType": "choice",
"valueStateId": "discord_newDM_eventState"
},
{
"id": "discord_newMention",
"name": "Discord | New Mention",
"format": "When receiving a new Mention $val",
"type": "communicate",
"valueChoices": [
"True",
"False"
],
"valueType": "choice",
"valueStateId": "discord_newMention_eventState"
},
{
"id": "discord_default_audio_device_change",
"name": "Discord: Default Audio Device Changed",
"format": "When Default $val Device Changed",
"type": "communicate",
"valueChoices": [
"Input",
"Output"
],
"valueType": "choice",
"valueStateId": "discord_default_audio_device_change_eventState"
}
],
"states": [
{
"id": "discord_inputDevice",
Expand Down Expand Up @@ -639,6 +676,16 @@
"Connected",
"Disconnected"
]
},
{
"id": "discord_default_audio_device_change_eventState",
"type": "choice",
"desc": "Discord Default Audio Device Change Event",
"default": "",
"valueChoices": [
"Input",
"Output"
]
}
]
},
Expand All @@ -650,16 +697,6 @@
"actions": [],
"events": [],
"states": [
{
"id": "discord_voice_channel_connected",
"type": "choice",
"desc": "Discord Voice Channel Connected",
"default": "No",
"valueChoices": [
"No",
"Yes"
]
},
{
"id": "discord_voice_channel_server_id",
"type": "text",
Expand Down Expand Up @@ -786,32 +823,7 @@
"imagepath": "%TP_PLUGIN_FOLDER%tpdiscord/tpdiscord.png",
"connectors": [],
"actions": [],
"events": [
{
"id": "discord_newDM",
"name": "Discord: New Direct Message (DM)",
"format": "When receiving a new Direct Message $val",
"type": "communicate",
"valueChoices": [
"True",
"False"
],
"valueType": "choice",
"valueStateId": "discord_newDM_eventState"
},
{
"id": "discord_newMention",
"name": "Discord | New Mention",
"format": "When receiving a new Mention $val",
"type": "communicate",
"valueChoices": [
"True",
"False"
],
"valueType": "choice",
"valueStateId": "discord_newMention_eventState"
}
],
"events": [],
"states": [
{
"id": "discord_DM_user",
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "tpdiscord",
"version": "5.0.0-alpha-2",
"version": "5.0.0-alpha-3",
"description": "Touch Portal Plugin for Discord using RPC",
"main": "src/index.js",
"bin": {
Expand Down
17 changes: 14 additions & 3 deletions src/handlers/discord/voiceStateHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,18 @@ class VoiceStateHandler {
this.DG = DG
this.userStateHandler = userStateHandler;
this.voiceChannelHandler = voiceChannelHandler;
this.doLogin = null;

// not using?
// this.repopulateUserStates = this.userStateHandler.repopulateUserStates;

this.notification = notificationHandler;
}

initiate_doLogin = (doLogin) => {
this.doLogin = doLogin;
}

registerEvents = () => {
this.DG.Client.on("ready", async () => {
if (
Expand Down Expand Up @@ -149,9 +154,8 @@ class VoiceStateHandler {
this.TPClient.settingUpdate("Plugin Connected", "Disconnected");
this.TPClient.stateUpdate("discord_connected", "Disconnected");
this.DG.connected = false;
if (platform != "win32") {
// return this.Discord.doLogin();
print("wooopsie.. this is not windows.., gitago forgot to fix the reglogin he didnt think was needed");
if (platform != "win32" || this.DG.pluginSettings["Skip Process Watcher"].toLowerCase() == "yes") {
return this.doLogin();
}
});
};
Expand Down Expand Up @@ -231,6 +235,8 @@ class VoiceStateHandler {

if (matchedDevice) {
this.TPClient.stateUpdate(`discord_${type}Device`, matchedDevice.name);
this.TPClient.stateUpdate(`discord_default_audio_device_change_eventState`, `${type.charAt(0).toUpperCase() + type.slice(1)}`);

logIt("DEBUG", `${type.charAt(0).toUpperCase() + type.slice(1)} Device:`, matchedDevice.name);
} else {
logIt("ERROR", `No ${type} device matched the ID.`);
Expand All @@ -243,9 +249,13 @@ class VoiceStateHandler {
const matchedDevice = this.DG.voiceSettings[`${type}Devices`].find(device => device.id === this.DG.voiceSettings[`${type}DeviceId`]);
if (matchedDevice) {
this.TPClient.stateUpdate(`discord_${type}Device`, matchedDevice.name);
this.TPClient.stateUpdate(`discord_default_audio_device_change_eventState`, `${type.charAt(0).toUpperCase() + type.slice(1)}`);
}
logIt("DEBUG", `Using ${type} device ID:`, this.DG.voiceSettings[`${type}DeviceId`]);
}

this.TPClient.stateUpdate(`discord_default_audio_device_change_eventState`, ``);

} else {
logIt("INFO", `No ${type} device data found.`);
}
Expand Down Expand Up @@ -284,6 +294,7 @@ class VoiceStateHandler {
this.DG.voiceSettings.muteState = 1;
} else {
this.DG.voiceSettings.deafState = 0;
this.DG.voiceSettings.muteState = 0;
}
states.push({id: "discord_deafen", value: this.DG.voiceSettings.deafState ? "On" : "Off"});
states.push({id: "discord_mute", value: this.DG.voiceSettings.muteState ? "On" : "Off"});
Expand Down
7 changes: 1 addition & 6 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -267,12 +267,7 @@ const voiceChannelHandler = new VoiceChannelHandler(DG, TPClient, userStateHandl
const voiceStateHandler = new VoiceStateHandler(DG, TPClient, userStateHandler, notificationHandler, voiceChannelHandler);
const Discord = new DiscordConnector(TPClient, DG, RPC, userStateHandler, notificationHandler, voiceStateHandler);







voiceStateHandler.initiate_doLogin(Discord.doLogin);


// Process Watcher
Expand Down

0 comments on commit f013d97

Please sign in to comment.