Skip to content

Commit

Permalink
[main] Use new tp-api exitOnClose option and 'disconnected' event t…
Browse files Browse the repository at this point in the history
…o remove process 'onexit' handler workaround.
  • Loading branch information
mpaperno committed Sep 11, 2023
1 parent 72e79cc commit 4b69a8d
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,11 @@ TPClient.on("Close", function() {
quit("Touch Portal disconnected");
})

TPClient.on("disconnected", function(/* hasError */) {
// no-op if already quitting
quit("Touch Portal socket disconnected");
})

process.on('uncaughtException', function(e) {
logger.error("Exception: %s\n%s", e.message, e.stack)
// quit("Uncaught Exception", 1);
Expand All @@ -571,17 +576,10 @@ process.on('SIGBREAK', () => quit("Keyboard break") ) // ctrl-break (Windo
process.on('SIGHUP', () => quit("Console host closed") )
process.on('SIGTERM', () => quit("Process terminated") ) // not on Windows

// This is a workaround for TPClient calling process.exit() automatically upon a socket error,
// which usually means TP has crashed or shut down w/out a 'closePlugin' message.
process.on('exit', function() {
// no-op if already quitting
quit("Process exiting");
})


// -------------------------------
// Run

logger.info("=============== %s started, connecting to Touch Portal... ===============", pluginId)

TPClient.connect({pluginId})
TPClient.connect( { pluginId: pluginId, exitOnClose: false })

0 comments on commit 4b69a8d

Please sign in to comment.