Found a secret repository on the JetBrains github called Projector. Thanks to him, he wrote a piece of code in IntelliJ IDEA running on an Android tablet. I’m telling you how to repeat it.


ITKarma picture


Problem


We all love IntelliJ IDEA, but there is a problem with it - it eats up computer resources. Maybe the crypt is mined, no one knows.


We all have something like an old laptop that you really like, but you can’t work on it anymore - it's too weak. On some devices, Ideas never happened. For example, on Android tablets. Go to the site - there is no assembly under Arm.


In a separate hell followers of the DevOps sect are fried. If you are a developer in an environment with a bunch of modern DevOps tools, then your runtime locally on the macbook and on the prod are two completely different things. From here come all kinds of mini-cubs, tillers, loopback proxies and other crutches. From here - a laptop that burns knees during a build.


About the same problems for C++ users. Large projects like the Chromium browser can take tens of gigabytes on your hard drive and compile for days on end. When the laptop goes into throttling from overheating, it is not very convenient to use it. SSDs are wiped to holes, and if the SSD is soldered and the warranty is over, you will have to throw it away with your laptop.


The solution would be to separate the frontend and backend of the IDE. We launch a heavy computing backend in the data center, or simply on our home Threadripper 3990X. Connecting to the backend from a local Java application.


Unfortunately, IntelliJ IDEA is so designed that until recently it could not be done. Almost. You don’t have to be a genius to guess that Rider somehow communicates with each other Java front and.NET back, but you can’t use this for your own selfish purposes.


Remote Desktop sucks


Of course, many tried to launch the Idea through TeamViewer, Microsoft Remote Desktop, VNC, and so on. There are companies that only work this way - employees sit on a remote site and code through Remote Desktop.


See this as a problem? Here, take a look:


ITKarma picture


Now I owe you new eyes!


This is what you see when connecting through the remote desktop. All the sensations of the elegance of the interfaces, the clarity of the fonts, all the magic of the Idea disappears somewhere, and in the mouth there remains only the bitterness of the soap squeezed by the jeep.


Some experience can be learned from this. For example, TeamViewer slows down less, but the image is more artifact. RDP gives a better picture, but godlessly slows down. Both there and there are questions about the quality of mobile applications - if you want to run on a tablet.


What to do? How much should you rinse your mouth in order to extract the smack of soap from there?


Your word, Comrade Projector!


Here's what the picture looks like on my Huawei MediaPad M5 tablet:


ITKarma picture


At first I wanted to photograph fonts at close range, but the inability of the Sony RX100 v5 to focus at such a distance buried this idea. Instead, keep a notarized screenshot:


ITKarma picture


See the shoals in jeepeg fonts?


Do not work, they are not there. These are real vector fonts, and the Idea is real too. Well, almost.


The magic is that in the repository of the Projector project on GitHub lies the IntelliJ IDEA launcher in the server mode.


Why does this work?


Apparently, Projector runs on an AWT renderer from OpenJDK, rewritten from the inside. Now AWT does not draw everything on ordinary surfaces from the operating system, but directly in the browser. How exactly this magic works, I find it difficult to quickly describe now - this is a topic for a separate article.


But the effect is amazing - any application written in Java and Swing automatically starts working in the browser without rewriting the code!


I want! What to do?


It is immediately clear that the project is very experimental. This thing is for those who love everything new and want to try to use it in everyday life. But I wouldn’t bet my life on this thing.


I’ll tell you how to start all this and start to understand. Then you yourself.


General instructions are in the official repository .


Algorithm of actions:


  • Prepare the server (for use in the cloud only)
  • Build and launch docker images
  • Open IDEA in browser
  • PROFIT

Preparing the server


You will need a computer with Docker.


You can get all this without Docker, but this article specifically implies its existence, because without Docker everything becomes much more complicated.


A “server” can be either a machine in the cloud or your regular computer - it doesn’t matter.


I tested everything in two configurations: Linux on the desktop and Linux on the remote virtual machine with four cores and 4 gigabytes of RAM. Other operating systems may require adjustments.


In Ubuntu 16.04, docker installation is done here for this instruction . If you have a different operating system, you'll have to google it yourself.


Summary of installing Docker on Ubuntu 16.04:


curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" sudo apt-get update sudo apt-get install -y docker-ce sudo usermod -aG docker ${USER} sudo reboot 

Next, you need to slightly adjust the OS itself. If you use Linux desktop as a working machine in graphical mode, then you do not need to do anything.


If you want to deploy something like a test server in the cloud (the benefit is now done with two clicks of the mouse in Amazon and other cloud services), you will need to put a couple of packages.


The bottom line is that you have xvfb (virtual framebuffer) and dbus-launch appear on the command line. I don’t know why a framebuffer is needed, but build scripts do not work without it. Probably the heavy legacy of AWT.


Here's what you need to install for Ubuntu 16.04:


apt install xvfb dbus dbus-x11 gnome-keyring 

You have to install gnome-keyring for internal ubunt reasons. Otherwise, it turns out that you have problems with the secrets for the desktop. If you do not have Ubuntu, then most likely this is not necessary.


Next you need to create a framebuffer:


Xvfb :99 export DISPLAY=:99 

This script should be put somewhere in the startup. For example, in the systemd unit. Well, or just with your hands each time to type again.


Build and run the Projector image


Download the repository with assembly scripts:


git clone https://github.com/JetBrains/projector-docker.git cd./projector-docker 

Build and run the image:


./clone-projector-core.sh./build-container.sh./run-container.sh 

Go to IntelliJ IDEA from the browser


If you have been working on your (local) computer all this time, the link looks like this: http://localhost: 8080/projector/ .


If you run all this on a remote machine (for example, in the cloud), then the link looks like this: http://hostname: 8080/projector/? host=hostname & amp; port=8887 .


Instead of CDMY0CDMY you need to enter the IP address of your server or domain name. Note that hostname in the URL occurs twice. It won’t work without it.


Problems:


  • If you use a proxy (namely a proxy, not a VPN), temporarily disable it. Problems with forwarding web sockets through proxies still exist in the 21st century.
  • If you use Google Chrome as a browser, it may start to redirect you from HTTP to HTTPS. Try this link: http://host: 8080/projector/? Host =//hostname & amp; port=8887 . Notice that two slashes (CDMY1CDMY) appeared to the left of CDMY2CDMY. In Firefox, everything should work without this hack. Warning the question, you can partially enable encryption (for a web socket), but it is so dreary that I would not bother with it right now.

How to work in Android


The standard Google Chrome browser on Android spends too much space on all sorts of unnecessary things like the address bar. To solve this problem, the free application Fully Kiosk Browser will help.


If the address bar doesn’t bother you, but Android controls interfere, then you can use the free application Fullscreen Immersive .


At the same time, it makes no sense to use both of them, because FUlly Kiosk Browser already knows how to disable Android shell controls and does this by default.


How to work in iOS


I have no idea! Of all the Apple devices, I only have a service macbook and a personal iPhone. On the iPhone, it’s pointless to check all this (the screen is too small), and on the MacBook there are no problems.


How to password protect the connection?


We go to the project files that we downloaded earlier, open the CDMY3CDMY file and look for the line:


docker run --rm -p 8080:8080 -p 8887:8887 -it "$containerName" bash -c "nginx &&./run.sh" 

And we add one more parameter with a non-humanoid name, the value of which is your password:


docker run --rm \ --env ORG_JETBRAINS_PROJECTOR_SERVER_HANDSHAKE_TOKEN=mypassword \ -p 8080:8080 -p 8887:8887 -it "$containerName" bash -c "nginx &&./run.sh" 

Now you can run the container!


./run-container.sh 

Now you can go to the browser and connect to the new URL. The new one differs from the old one by the presence of the token parameter with your password.


For the local machine: https://localhost: 8080/projector/? token=mypassword


For the cloud server: https://hostname: 8080/projector/? host =//hostname & amp; port=8887 & amp; token=mypassword


How to make a secure connection?


About this I wrote on Habr a separate article . Get ready to have a bunch of tedious work in the console.


Perspectives


You can instantly come up with a lot of areas where this project will help:


  • Remote development;
  • Collaborative development;
  • Comfortable remote debugging;
  • Speeding up the roundtrip in big data applications;
  • Work in a protected circuit;
  • Instant deployment of a workplace;
  • Work with Very Large Monorepositories;
  • Integration into the infrastructure of cloud companies;

Who knows what else awaits us! The prospects are limitless .


Problems


I must say that the MediaPad M5 two years ago on the Kirin 960 chipset is not the most powerful machine in history. (But this is a thick reliable metal brick with which you can dig the earth in the garden!) And of course, when editing a large amount of text, redraw brakes appear. It's hard for a browser to draw as many graphics quickly.


Nevertheless, to debug something - this is already quite enough. The debugger will be beautiful, clear and pleasant, and not like through Remote Desktop.


If you run all this on a laptop, there are almost no brakes. Especially if there is a video card there, and not like a MediaPad M5 tablet, where instead of the video card Mali-G71 works.


Conclusions


Found a wonderful solution to run IntelliJ IDEA (and all JetBrains IDEs) on a remote server.


To be honest, this is almost the best news about IDEA in recent years. The new hotkey is nice, but overall it doesn’t change anything. Projector changes everything.It is surprising that no one writes anything about this, that the victory song of the Projector project is not heard from each iron.


I myself am now trying to pack the IDEA launcher as a native application for Windows, Android, and iOS using native platform tools (Electron and WebView). Some time still needs to be written in the code, and then publication on the pages can take a long time. How will it turn out - I’ll write an article on Habr.


Somewhere in a godforsaken GitHub repository, a real mountain of gold was discovered. Unfortunately, miracles do not happen, and for sure, dragons harbor this gold. Let's see who comes into the world!

.

Source