Skip to content

Commit

Permalink
Process runner event (#57)
Browse files Browse the repository at this point in the history
* Prepping for v4.3.0 release
Adding in new State for Discord Process Running (windows only really)

* Adding in new state Discord Connected

* Fixing initial state value of Discord Connected

* adding Documentation

* 4.3.0

* Prepping Build for v4.3.0
  • Loading branch information
spdermn02 authored Jul 23, 2022
1 parent f7acda9 commit 5d0c009
Show file tree
Hide file tree
Showing 11 changed files with 75 additions and 9 deletions.
Binary file modified Installers/TPDiscord-Mac.tpp
Binary file not shown.
Binary file removed Installers/TPDiscord-Win-DEVELOPMENT.tpp
Binary file not shown.
Binary file modified Installers/TPDiscord-Win-DiscordCanary.tpp
Binary file not shown.
Binary file modified Installers/TPDiscord-Win-PTB.tpp
Binary file not shown.
Binary file modified Installers/TPDiscord-Win.tpp
Binary file not shown.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,11 @@ v4.2.2
Bug Fix:
- Mute and Deafen state value correction from `0ff` to `Off`
- removed uneeded scope `messages.read` from discord scope list
v4.3.0
Updates:
- New State - Discord Process Running, will be `Yes`, `No`, `Unknown` (starts out as Unknown)
- Notes: Windows Only will have all 3 values, MacOS will always be Unknown until a process watcher is implemented for MacOS
- New State - Discord Connected, will be `Connected` or `Disconnected`
```

## Plugin Capabilities
Expand Down Expand Up @@ -128,6 +133,11 @@ v4.2.2
- Value: Voice Host connected to at Discord
- Discord Voice Mode Type
- Valid Values: PUSH_TO_TALK, VOICE_ACTIVITY
- Discord Process Running
- Valid Values: Yes, No, Unknown
- Note: Windows only, Mac will always be Unknown (until I find a good process watcher script for MacOS)
- Discord Connected
- Valid Values: Connected, Disconnected

## Installation and Configuration
1. Make sure Discord app is open on your PC or Mac
Expand Down
25 changes: 23 additions & 2 deletions base/Mac/TPDiscord/entry.tp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"sdk": 3,
"version": 4202,
"TPDiscord_Version": "4.2.2",
"version": 4300,
"TPDiscord_Version": "4.3.0",
"name": "Touch Portal Discord Plugin",
"id": "TPDiscord",
"plugin_start_cmd": "sh %TP_PLUGIN_FOLDER%TPDiscord/start_tpdiscord.sh",
Expand Down Expand Up @@ -257,6 +257,27 @@
"type": "text",
"desc": "Discord Voice Volume",
"default": "0.00"
},
{
"id": "discord_running",
"type": "choice",
"desc": "Discord Process Running",
"default": "",
"valueChoices":[
"Yes",
"No",
"Unknown"
]
},
{
"id": "discord_connected",
"type": "choice",
"desc": "Discord Connected",
"default": "",
"valueChoices":[
"Connected",
"Disconnected"
]
}
],
"events": []
Expand Down
31 changes: 29 additions & 2 deletions base/Win/TPDiscord/entry.tp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"sdk": 3,
"version": 4202,
"TPDiscord_Version":"4.2.2",
"version": 4300,
"TPDiscord_Version":"4.3.0",
"name": "Touch Portal Discord Plugin",
"id": "TPDiscord",
"plugin_start_cmd": "\"%TP_PLUGIN_FOLDER%TPDiscord\\tpdiscord.exe\"",
Expand Down Expand Up @@ -258,6 +258,33 @@
"PUSH_TO_TALK",
"VOICE_ACTIVITY"
]
},
{
"id": "discord_voice_volume",
"type": "text",
"desc": "Discord Voice Volume",
"default": "0.00"
},
{
"id": "discord_running",
"type": "choice",
"desc": "Discord Process Running",
"default": "",
"valueChoices":[
"Yes",
"No",
"Unknown"
]
},
{
"id": "discord_connected",
"type": "choice",
"desc": "Discord Connected",
"default": "",
"valueChoices":[
"Connected",
"Disconnected"
]
}
],
"events": []
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": "4.2.2",
"version": "4.3.0",
"description": "Touch Portal Plugin for Discord using RPC",
"bin": {
"tpdiscord": "src/index.js"
Expand Down
12 changes: 10 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,11 +193,13 @@ TPClient.on("Info", (data) => {
logIt("DEBUG","Info : We received info from Touch-Portal");

TPClient.choiceUpdate(pttKeyStateId,Object.keys(discordKeyMap.keyboard.keyMap));

TPClient.stateUpdate('discord_running','Unknown');
TPClient.stateUpdate("discord_connected","Disconnected");
if( platform != 'darwin' && pluginSettings['Skip Process Watcher'].toLowerCase() == 'no' ){
logIt('INFO',`Starting process watcher for ${app_monitor[platform]}`);
procWatcher.watch(app_monitor[platform]);
}

});

TPClient.on("Settings", (data) => {
Expand All @@ -208,6 +210,7 @@ TPClient.on("Settings", (data) => {
logIt("DEBUG","Settings: Setting received for |"+key+"|");
});
if( platform == 'darwin' || pluginSettings['Skip Process Watcher'].toLowerCase() == 'yes') {
TPClient.stateUpdate('discord_running','Unknown');
procWatcher.stopWatch();
doLogin();
}
Expand All @@ -218,6 +221,7 @@ TPClient.on("Update", (curVersion, newVersion) => {

TPClient.on("Close", (data) => {
logIt("WARN","Closing due to TouchPortal sending closePlugin message");
TPClient.stateUpdate('discord_running','Unknown');
TPClient.settingUpdate(PLUGIN_CONNECTED_SETTING,"Disconnected");
});
// - END - TP
Expand Down Expand Up @@ -421,6 +425,8 @@ const connectToDiscord = function () {
accessToken = DiscordClient.accessToken;
}

TPClient.stateUpdate("discord_connected","Connected");

//DiscordClient.setVoiceSettings({'mode':{'type':'PUSH_TO_TALK','shortcut':[{'type':0,'code':16,'name':'shift'},{'type':0,'code':123,'name':'F12'}]}});
// Left Shift 160
// Right Shift = 161
Expand Down Expand Up @@ -460,10 +466,10 @@ const connectToDiscord = function () {
DiscordClient.on("disconnected", () => {
logIt("WARN","discord connection closed, will attempt reconnect, once process detected");
TPClient.settingUpdate(PLUGIN_CONNECTED_SETTING,"Disconnected");
TPClient.stateUpdate("discord_connected","Disconnected");
if( platform == 'darwin' ) {
return doLogin();
}
discordRunning = false;
});

const prompt = 'none';
Expand Down Expand Up @@ -540,6 +546,7 @@ async function doLogin() {
// Process Watcher
procWatcher.on('processRunning', (processName) => {
discordRunning = true;
TPClient.stateUpdate('discord_running',discordRunning ? 'Yes' : 'No');
// Lets shutdown the connection so we can re-establish it
setTimeout(function() {
logIt('INFO', "Discord is running, attempting to Connect");
Expand All @@ -554,6 +561,7 @@ procWatcher.on('processTerminated', (processName) => {
}
logIt('WARN',`Disconnect active connections to Discord`);
discordRunning = false;
TPClient.stateUpdate('discord_running',discordRunning ? 'Yes' : 'No');
if ( DiscordClient ) {
DiscordClient.removeAllListeners();
DiscordClient.destroy();
Expand Down

0 comments on commit 5d0c009

Please sign in to comment.