Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix suggestion for RECONNECTDATA and RECONNECTACCOUNT which never worked on macOS (probably) #242

Closed
ownrepo1s opened this issue Dec 9, 2023 · 2 comments

Comments

@ownrepo1s
Copy link

ownrepo1s commented Dec 9, 2023

#!/bin/bash

# Sends a command to the specified instance of IBC, for example to cause it
# to initiate a tidy closedown or restart of TWS or Gateway

# You must supply the command as the first argument when you call this
# script. It is case-insensitive.


# Please read the notes below and make any required changes, then save this
# file before running it.

# You may need to change this line. Set it to the name or IP address of the 
# computer that is running IBC. Note that you can use the local loopback 
# address (127.0.0.1) if IBC is running on the current machine.

server_address=127.0.0.1

# You may need to change this line. Make sure it's set to the value of the 
# CommandServerPort setting in config.ini:

command_server_port=7462


# You shouldn't need to change anything below this line.
# ==============================================================================


if [[ -z "$1" ]]; then
>&2 echo -e "Error: you must supply a valid IBC command as the first argument"
>&2 exit 1
fi

# send the required command to IBC 
(echo "$1"; sleep 1; echo "EXIT" ) | /usr/local/bin/telnet "$server_address" $command_server_port

I noticed on macOS the correct key combination for RECONNECTDATA is actually:
Command + Option(Alt) + F
instead of
Ctrl + Alt + F

So that the above script doesn't work on macOS.

What i think needs to be done is to change the code from:

int modifiers = KeyEvent.CTRL_DOWN_MASK | KeyEvent.ALT_DOWN_MASK;

and
int modifiers = KeyEvent.CTRL_DOWN_MASK | KeyEvent.ALT_DOWN_MASK;

from int modifiers = KeyEvent.CTRL_DOWN_MASK | KeyEvent.ALT_DOWN_MASK;
to int modifiers = KeyEvent.VK_META | KeyEvent.ALT_DOWN_MASK;

As per GavriYashar/Matlab-Editor-Plugin#150 (comment) for the key Command
https://stackoverflow.com/a/7375073/1889814

Of course with the check of platform is macOS
https://stackoverflow.com/questions/228477/how-do-i-programmatically-determine-operating-system-in-java

I'm not a Java developer, so the alternatives i'm considering until this is resolved are:

  1. Run TW in linux virtualized (docker or something else) and use the command to send a telnet command to the linux TW instance, maybe that one receives it correctly.
  2. Another option would be to implement a library in Objective-C or python to send that key combo to the TW window
  3. Another option would be to investigate the JAVA library and find the bug and fix it directly in the implementation and send a Pull Request to the library as well - this requires knowledge of ant
  4. Another option would be to RESTART the TW app each time, this is the simplest solution that i tested and works out of the box, just need to write handling code for waiting until fully reconnected.
    Got the RESTART from this undocumented API:
    @Override public void run() {
    String cmd = mChannel.getCommand();
    while (cmd != null) {
    if (cmd.equalsIgnoreCase("EXIT")) {
    mChannel.writeAck("Goodbye");
    break;
    } else if (cmd.equalsIgnoreCase("STOP")) {
    handleStopCommand();
    } else if (cmd.equalsIgnoreCase("ENABLEAPI")) {
    handleEnableAPICommand();
    } else if (cmd.equalsIgnoreCase("RECONNECTDATA")) {
    handleReconnectDataCommand();
    } else if (cmd.equalsIgnoreCase("RECONNECTACCOUNT")) {
    handleReconnectAccountCommand();
    } else if (cmd.equalsIgnoreCase("RESTART")) {
    handleRestartCommand();
    } else {
    handleInvalidCommand(cmd);
    }
    mChannel.writePrompt();
    cmd = mChannel.getCommand();
    }
    mChannel.close();
    }
  5. Might be an option to decompile the library and update it, but I'm not familiar on how to do this.

Cheers and thanks for this wonderful library!

@ownrepo1s
Copy link
Author

Any comments here?

@rlktradewright
Copy link
Member

Apologies for the delay in responding to this.

You seem to have a pretty good handle on what needs to be done, so it shouldn't be a big deal to fix it. But that doesn't make it any easier to find the time for it! I'll try to do so soon.

But I'm curious. What are the circumstances where you find it necessary to use it? Is this a frequent occurrence? Although I have used the manual equivalent of these commands on rare occasions, I've never found that they actually help solve any problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants