CG Local

Hey there,

Some time ago I created a comment in the CG Sync discussion about Chrome moving away from Chrome Apps, and eventually removing the ability to run Chrome Apps on non-Chrome OS systems. This would mean that CG Sync would stop working, because it uses a Chrome App to watch the selected file for changes.

Therefore, I created CG Local. It is basically a copy of CG Sync that works with both Chrome and Firefox, and instead of a Chrome App it uses a Java application to watch the selected file for changes. Besides that, it also makes it easier to work in different files for different puzzles and is completely open-source.

Installation

CG Local consists of a browser extension and a Java application. The browser extension can be downloaded via the following links:

The application can be downloaded here and requires Java 8 or newer. From version 1.2.0 onwards the application uses Swing instead of JavaFX, so a JRE or a JDK with JavaFX is no longer required. On top of that, from version 1.2.0 onwards, the application also works on Java versions newer than 8.

How to use

The first step to using CG Local is to make sure that the CG Local application is running. Then, open a puzzle and click on Settings in the sidebar. In the settings panel, toggle Use an external code editor on.

Now, you need to select a local file to synchronize with the CodinGame IDE. Open the CG Local application and choose whether you want to select a file, or use a previously selected file. The latter is only available when you have previously selected a file.

When you have selected a file, it is time to choose the first action. The three options are self-explanatory.

That’s it! You can now start working in your personal editor.

Settings

An explanation of the available settings, available via the gear icon in the top-right corner of the application.

Use one file for all puzzles (default: No)
When set to No, the “Previously selected file” will be different for every puzzle. This makes it easier to have a workflow where you use one file per puzzle. If you prefer to use one file for all puzzles, I recommend to set this to Yes.

Auto Play (default: Off)
When set to On, the current puzzle will automatically be played when the local file is changed.

Enable 2-way data binding (default: No)
When set to Yes, the CodinGame IDE will not be set to read-only mode so you can still use it. Changes in the CodinGame IDE will simultaneously be reflected in the local file. When Auto Play is also set to On, the puzzle will only be automatically played if you manually edit the local file.

Default first action (default: Ask me)
This specifies what happens when you select a file. When set to Download or Upload, the First Action part after you select a file is skipped. When set to Ask me, you will be asked what to do with the selected file every time you select a file.

Source

The source for both the extension and the application can be found on GitHub. Contributions are welcome.

Changelogs

The changelog for both the extension and the application can be found on GitHub.

19 Likes

How do I run the jar file? I’m on Linux and the auto-launch fails and I get Could not find or load main class fxlauncher.Launcher if I do java -jar CG\ Local.jar

openjdk version “1.8.0_151”

Same thing happens with newest JRE.

1 Like

I have the local one running now – using the newest JRE and not message up the path helps. :slight_smile:

But the connection isn’t working in CodingGame.

Can I see logs anywhere?

The CGLocal client says “Listening on port 53135”

Alright, I don’t know why this happens exactly, but I was able to reproduce the bug in an Ubuntu VM and it seems to be the case that CG Local does not work with OpenJDK, but does work with the Oracle JDK.

I will look into the issue and update the launcher when it does work with OpenJDK, but till then the only advice I can give is to use the Oracle JDK (I tested it with 1.8.0_161).

By the way, logs should appear when running with java -jar CG\ Local.jar like this:

1 Like

I have it working after a few hiccups. I like it. This will help a lot.

A few notes for others:

  • It connects to 127.0.0.1, thus if using a proxy be sure that isn’t proxied
  • Java keeps listening to the local address after ending (Ctrl+C) the program, thus wait a before launching again
  • If something goes wrong reload the CodinGame page and editor, then toggle the external edtiro on/off
  • If the connection works the external editor will turn to “On”, if it stays “Off” or nothing is highlighted it isn’t working.
  • The "Synchrnonizing " means the initial download worked,
  • Test that it works now by typing in the local file and pressing save.
1 Like

The issue with OpenJDK is that OpenJDK does not include JavaFX. When running on Ubuntu, that bug can be fixed by running the following:

sudo apt-get install openjfx

On other systems a similar command should be possible.

Not directly related but:

With the Java Platform Module System in place since Java SE 9, it now more viable to decouple JavaFX from the JDK, in order to make it available as a separate download. This will make it easier for developers using JavaFX to have more freedom and flexibility with the framework. Moreover, with our focus on increasing the release cadence of OpenJDK, JavaFX needs to be able to move forward at a pace driven by the contributions from Oracle and others in the OpenJFX community. Oracle plans to implement this decoupling starting with Java 11 (18.9 LTS).

JavaFX was not the best choice :stuck_out_tongue: Will require a extra download in all OS in the future.

But thanks, I was searching this plugin for some time.

Open JFX isn’t that hard to install (on Ubuntu it’s a simple sudo apt-get install openjfx), so I don’t think it’ll be a huge problem. The bigger problem is that, currently, CG Local is not compatible with Java versions greater than 8 because of the launcher that is being used.

Hi, finally got your tool working @Jasperr! On ubuntu I went for the oracle-java instead of openJdk+openFX (I followed this tuto on medium to handle the different versions of Java). Thank you, my efficiency is already improving :slight_smile:

No problem! The project is kinda on hold (it works, so there’s no need to edit it), but if I ever find some motivation again I will look into packaging a compatible JRE + JavaFX with the application to get rid of the extra dependency.

If you want a better Java version manager, SDKMAN might be interesting for you. When installed, you can simply install Oracle Java 8 with sdk install java 8.0.181-oracle (and similarly with other versions/distributions/JVM-related software).

1 Like

Hi Jasperr,
I’m trying to install CG Local on Firefox on a Windows system. The extension seems to work well but I can’t download the CG App. The link https://jaspervanmerle.com/cg-local/files/CG%20Local.jar is broken. The site seems to be suspended. Like I’m not a Java devlopper I haven’t any tool to compile the source. Is there another link to download the jar file ?

Whoops. I forgot that those files were still on that website, which I stopped paying for because I wasn’t using it anymore.

I will update the application this weekend (probably saturday, got other priorities at the moment) and release the jar file on GitHub. I’ll add a post to this topic once that’s done.

If you want to use it before that, you can clone https://github.com/jmerle/cg-local-app, move into the directory with your preferred commandline and run the application with the gradlew run command.

1 Like

I released version 1.1.0 of the application which fixes the issue. The application is now distributed as a single jar with all dependencies inside, instead of the previous version which was merely a launcher which downloaded all necessary files at runtime.

You can download the new jar file on the repository’s GitHub releases page. The readme of the repository and the initial post of this topic are updated to reflect those changes.

4 Likes

Cool, thank you!

it didn’t work with java 10, so i used this
https://docs.datastax.com/en/cassandra/3.0/cassandra/install/installOpenJdkDeb.html
to install java 8 and then i reinstalled openjfx and now it works

1 Like

I’ll just leave this here, might help someone:

aptitude install openjdk-8-jdk openjdk-8-jdk-headless openjdk-8-jre openjdk-8-jre-headless
aptitude install openjfx=8u111-b14-1 libopenjfx-jni=8u111-b14-1 libopenjfx-java=8u111-b14-1
1 Like

It has been a while since CG Local has gotten an update, but in preparation for the Spring Challenge and because Chrome has decided to continue phasing out Chrome Apps I decided to perform some well needed maintenance on both the extension as well as the application.

Extension changelog:

  • Removed the usage of innerHTML.
  • Fixed a bug where the extension would not disconnect from the CG Local application when moving away from CodinGame while being connected to the application.

Application changelog:

  • Moved the UI from JavaFX with TornadoFX to Swing. This change makes the application work with Java versions newer than 8 and means it is no longer required to run the application with a JRE or JDK with JavaFX available.
  • Fixed a bug where the server would sometimes not be able to bind to its port if the application was quit a short time ago.

If you have the extension installed your browser will automatically update it. If you have the application installed, you can download the new version here. I have also updated the opening post of this topic to reflect these changes.

5 Likes

That’s very useful tool.

The thing I’m missing is possibility to choose which Auto Play action is preferable. In a contest it’s usually “Play in same conditions” as want to compare results after code change. Now Auto Play must be off and one have to press it manually in the CG.

Sorry for the late reply, I completely forgot about your feature request.

Unfortunately this is not possible. The API which CG Local uses to communicate with the CodinGame IDE has a “play” action, but does not have a way to configure what gets played nor is there a “replay” action. I have tried to come up with a workaround, but there doesn’t seem to be a reliable way to acquire a reference to the IDE’s internal API so that’s a no-go too.

1 Like

Still, typing via CG Local is way more enjoyable then fighting with CG editor
I appreciate your work :wink:

Edit: This option is not important any more as one can “Play in same conditions” just setting up manual seed in the CG puzzle option.

1 Like