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

Integrating Stylus to external text editors #91

Open
schomery opened this issue Jun 14, 2017 · 11 comments
Open

Integrating Stylus to external text editors #91

schomery opened this issue Jun 14, 2017 · 11 comments

Comments

@schomery
Copy link
Contributor

So I am working on a new extension that brings the power of external editing to Stylus. We can integrate it directly to Stylus when the project is usable.

For now here is the summary:

  1. We have a multiple platform compatible native integration; https://github.com/openstyles/native-client. This project is forked from https://github.com/andy-portmen/native-client. I have modified the source code so we can now write native NodeJS code inside our extension code. The native client can be installed in Windows, Mac, and Linux for now. I've tried the Mac version, not the rest! We have automated OS specific installers here; https://github.com/openstyles/native-client/releases. The project is automatically compiled here https://travis-ci.org/openstyles/native-client
  2. There is a simple extension to demonstrate how native integration works. https://github.com/openstyles/sample-native-extension. Basically, we can compile a NodeJS code in the extension side like https://github.com/openstyles/sample-native-extension/blob/master/background.js#L18-L20. Note that all required modules need permission before they are functional; https://github.com/openstyles/sample-native-extension/blob/master/background.js#L16. The native client only understands two commands:
    • {method: 'spec'}
    • {permissions:[], script: "/*NodeJS script here*/"}
  3. The actual external editor integration is in https://github.com/openstyles/stylus-external-editor. For now, it performs the following actions when called.
    • creates a temporary file in the OS level temporary directory
    • Opens the temporary file in Sublime Text (this part is written to work for Mac OS for now)
    • Watches file changes and prints the entire file in the console when a change is registered.

Notes:

  1. Since the "stylus-external-editor" extension has no id, you need to modify https://github.com/openstyles/native-client/blob/master/config.js with the correct extension id before running the installer.
@tophf
Copy link
Member

tophf commented Jun 14, 2017

Is it possible to provide support for the use case in #86 e.g. the ability to open&watch an arbitrary existing file?

@schomery
Copy link
Contributor Author

We have it now on openstyles/stylus-external-editor@9057f60

It is now possible to call observeFile to only observe an existing file or call openTmpFile to create a new tmp file and observe its changes.

@schomery
Copy link
Contributor Author

@silverwind
Copy link
Contributor

Wow, this sounds too good to be true. What interface is used between the extension and node?

@schomery
Copy link
Contributor Author

schomery commented Jun 14, 2017

Here is the summary on how the stylus-external-editor extension can be tested on Chrome/Opera:

  1. Download https://github.com/openstyles/stylus-external-editor/archive/master.zip and extract it in a local directory
  2. Download the latest version of our native client https://github.com/openstyles/native-client/releases
  3. Open chrome://extensions, turn the developer mode on and install stylus-external-editor.
  4. Replace or add id in step 3 to https://github.com/openstyles/native-client/blob/master/config.js
  5. Run install.sh or install.bat
  6. Restart stylus-external-editor from chrome://extensions

You should get an empty style file in your default text editor (Mac and Windows are tested). Whenever a change is made, you will get a notification in the background console of stylus-external-editor

@schomery
Copy link
Contributor Author

What interface is used between the extension and node

hmmm, nothing! See https://github.com/openstyles/native-client/blob/master/host.js#L61-L66

@schomery
Copy link
Contributor Author

Here is the summary on how the stylus-external-editor extension can be tested on Firefox:

  1. Download https://github.com/openstyles/stylus-external-editor/archive/master.zip and extract it in a local directory
  2. Download the latest version of our native client https://github.com/openstyles/native-client/releases
  3. Open about:debugging, turn "Enable add-on debugging" on and install stylus-external-editor.
  4. Open about:support and find stylus-external-editor GUID.
  5. Replace or add id in step 4 to https://github.com/openstyles/native-client/blob/master/config.js
  6. Run install.sh or install.bat
  7. Restart stylus-external-editor from about:debugging

You should get an empty style file in your default text editor (Mac and Windows are tested). Whenever a change is made, you will get a notification in the background console of stylus-external-editor

@Mottie
Copy link
Member

Mottie commented Jun 16, 2017

I got this working, and I see it has potential to be awesome!

Would you still implement this method if @tambry's C++ solution in #86 works out?

@schomery
Copy link
Contributor Author

Would you still implement this method if @tambry's C++ solution in #86 works out?

I don't mind if we go with the C++ version. I personally like how the entire native side is written in our extension side for NodeJS version. Anyway, if the C++ works as expected and can be compiled for all major operation systems, we can drop the NodeJS client.

@ghost
Copy link

ghost commented Sep 5, 2017

@tambry I thought this was supposed to be a small C application? When did it turn into bloatware holding not 1 but 2 Node EXEs?

http://github.com/andy-portmen/native-client/releases

@tambry
Copy link

tambry commented Sep 5, 2017

@svnpenn I didn't implement that. I would never implement such a bloated solution. I'm unable to implement my solution yet, as I'm waiting on this Chromium issue (Firefox equivalent). You can try staring the Chromium issue. The issue has been assigned for Chromium 62, which will release on 17th October. Only one more month of waiting!

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

5 participants