tonylukasavage / triple

REPL for Titanium
MIT License
96 stars 21 forks source link

Spinners keeps running after app has started in GenyMotion #95

Closed FokkeZB closed 9 years ago

FokkeZB commented 9 years ago

I know the readme only mentions support for Android Emulator. Is that because you are aware it doesn't seem to be working on GenyMotion or because you haven't tested it?

I can't get it to work in GenyMotion because the spinner of the REPL keeps running:

geny

tonylukasavage commented 9 years ago

I simply haven't tested genymotion. I'm guessing it's because a particular "I'm ready" message is never being delivered from genymotion. I'll bet this is a network config thing. Look at the constants: https://github.com/tonylukasavage/triple/blob/master/lib/constants.js

Notice that "android" uses 10.0.2.2 for connecting. I'm guessing genymotion uses a different address? Do you know off-hand what that is? Also, what's the exact set of commands you use to run triple via genymotion? Most likely in the end, the fix will be ID'ing that genymotion is being used, then using a different network address to connect.

FokkeZB commented 9 years ago

For Genymotion, I think every emulator has its own IP, as it is a Virtual Box machine.

I just ran triple -p android and it picked the oldest Gennymotion device I have (an Android 2.3). I idon't have any Android Emulators installed. That's the same behaviour a ti build -p android has.

tonylukasavage commented 9 years ago

Ah, so it seems then that adding a -h, --host <host> arg and using that to connect would be the solution. I can look at this at some point in the future, but a PR is also welcome.

FokkeZB commented 9 years ago

You mean to add that option to the triple CLI? But since Triple builds the app (and starts Genymotion) it should be able to tell right? How is this different from the ti build command picking up the logs from Genymotion devices?

tonylukasavage commented 9 years ago

I have no idea how Titanium identifies the genymotion emulator, maybe it can be done without a new option, maybe it can't. But I doubt there's any clean way to get the IP of it. It will likely require either scraping log output, or reimplementing large parts of the titanium code that interacts with genymotion. On Dec 18, 2014 3:23 AM, "Fokke Zandbergen" notifications@github.com wrote:

You mean to add that option to the triple CLI? But since Triple builds the app (and starts Genymotion) it should be able to tell right? How is this different from the ti build command picking up the logs from Genymotion devices?

— Reply to this email directly or view it on GitHub https://github.com/tonylukasavage/triple/issues/95#issuecomment-67454784 .

FokkeZB commented 9 years ago

Maybe @cb1kenobi has some thoughts on this?

cb1kenobi commented 9 years ago

I don't know much about Triple, but if it is calling ti build, then it should be passing in --no-progress-bars.

FokkeZB commented 9 years ago

Well, @cb1kenobi it's not ti build's spinner we see, it's triple's because it cannot connect to the app on genymotion because it needs its IP, which is known for Android Emulator, but variable for Genymotion.

@tonylukasavage couldn't you better create the TCP connection the other way around? From the app to triple (which would need to start a server then)?

tonylukasavage commented 9 years ago

@FokkeZB yikes, bad idea for a couple reasons:

  1. I don't want to restructure the entire message flow in lieu of determining the IP for an emulator.
  2. Reversing the message flow eliminates any possibility in the future to connect to multiple devices/emulators at the same time and have their messages report centrally.
FokkeZB commented 9 years ago

Not saying you should, just exploring ;)

TiShadow lets multiple clients connect to its server component, so don't see why 2) should be true.

But I'm sure there's a way to get the IP of the Genymotion device that ti build launches.

FokkeZB commented 9 years ago

OK, got it. On my Mac VirtualBox always has 192.168.56.1 as the host-only IP through which I can connect to the Genymotion device. If I set that in constants.js it works.

Maybe it's better to read the exact IP from ifconfig

$ ifconfig vboxnet0 |grep -Eo "inet ([0-9\.]+)"
inet 192.168.56.1
cb1kenobi commented 9 years ago

If the Genymotion VM is running, then simply run ti info -t android -o json and find it in the "emulators" list.

{
    "name": "Google Nexus 4 - 4.4.4 - API 19 - 768x1280",
    "guid": "f8e82cb6-3941-4a82-8caa-f339ac087071",
    "type": "genymotion",
    "abi": "x86",
    "googleApis": false,
    "sdk-version": "4.4.4",
    "hardwareOpenGL": true,
    "display": "768x1280-16",
    "dpi": 320,
    "genymotion": "2.3.0",
    "target": "4.4.4",
    "ipaddress": "192.168.56.101",  <-------------------------------- right here!
    "api-level": null,
    "id": "Google Nexus 4 - 4.4.4 - API 19 - 768x1280"
}

There's also a "genymotion" section of the ti info which would be easier to work with, but in 3.5.0 I've removed the ability to say -t genymotion. I should probably fix that. :)

FokkeZB commented 9 years ago

The problem is triple needs to know before the app is launched.

Your pasted config shows .1 is not always the right one, so my PR needs to be updated to get the right ip via fconfig before build

cb1kenobi commented 9 years ago

OK, so steal https://github.com/appcelerator/titanium_mobile/blob/master/node_modules/titanium-sdk/lib/emulators/genymotion.js, detect(), start(), and profit!

FokkeZB commented 9 years ago

Well, triple just fires ti build to launch so it doesn't need to copy that, but rather just find out the host-only IP for virtual box before building so the app can "call home".

Right between these lines it should call fconfig, get the IP and set that in constants.js as the HOST for when the app runs on Genymotion. Then if the app runs, it can use Ti.Platform.model to check if it's Genymotion and use that IP to call home.

cb1kenobi commented 9 years ago

So, run vboxmanage list hostonlyifs and scrap the output:

$ vboxmanage list hostonlyifs
Name:            vboxnet0
GUID:            786f6276-656e-4074-8000-0a0027000000
DHCP:            Disabled
IPAddress:       192.168.56.1
NetworkMask:     255.255.255.0
IPV6Address:     
IPV6NetworkMaskPrefixLength: 0
HardwareAddress: 0a:00:27:00:00:00
MediumType:      Ethernet
Status:          Up
VBoxNetworkName: HostInterfaceNetworking-vboxnet0
FokkeZB commented 9 years ago

Nah...

            var interfaces = os.networkInterfaces();
            if (interfaces.vboxnet0) {
                console.log(interfaces.vboxnet0[0].address);
            }

Updating PR.

FokkeZB commented 9 years ago

Updated #96, works like a charm