-
Notifications
You must be signed in to change notification settings - Fork 29.4k
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
access electron API from vscode extension #3011
Comments
@drywolf The extension host is spawned as a regular node process (meaning only node API). It is very unlikely we will spawn it as an electron renderer (to give access to electron API). Perhaps we can enhance our own vscode API to accomodate your use case if you would explain what you want to do. |
Thanks for the reply. I would like to integrate some minimal UI to see what are my currently open "projects" among all the VSCode windows. You could think of it as a very minimal and lightweight form of a solution explorer, but where each project in the solution explorer actually just refers to the related VSCode window. My usecase that I want to address, is to be able to more comfortably keep track and switch between the 3-5+ vscode windows that I often have opened when working on a project that is composed of several modules (each is a separate VSCode project). E.g. this would be five open VSCode projects in the windows taskbar that I have to navigate between... To integrate such a feature with an extension, at least I would need to have access to...
For the implementation of my extension I can imagine three different UX solutions that I would like to try out and mix/match to see what works best:
the currently opened windows could maybe be placed below the "New Window" task via the electron desktop integration API, and the user could have a very minimalistic overview over the currently open windows/projects and switch more easily between them. Thanks |
@drywolf You could spawn a new process from the extension that launches electron, shows the UI and returns the user selection on stdout that you read from your extensin. |
That's an interesting approach, thanks for the inspiration. Edit: The only concern that I have is that electron will take "too long" to boot, maybe I'll have to keep it running in the tray to circumvent that. But I can figure that out. Thanks again |
@drywolf pls let us know how it goes. I would start with the |
A first POC is working out quite well, I can switch between vscode windows from my electron UI when I start it manually from the command line. But when I try to run electron from within my vscode extension it does not find the electron module for some reason:
The error:
I have not been able to fix it so far, so any help is much appreciated. |
Now I packaged the eletron app into an exe bundle and I try to run that instead. Now the app seems to be executing but it does have some problem to create the main window, I can't see it anywhere on the desktop. Edit: this might be related to electron/electron#1613 |
@drywolf There is an environmental variable we set to get electron to run as a node process when we spawn it: Hope it helps, I'm just guessing... |
@alexandrudima Thanks for the hint. Thanks |
Yeah, the env variable got renamed in Electron (which still supports the old one): |
Sorry I got mixed up as well, looks like the best is to unset both -- not sure setting to |
@alexandrudima
So the above code fixed the issue and the electron process spawns just fine now. To correctly switch to the selected VSCode window and activate it, I used the 'ffi', 'ref' and 'ref-struct' modules to call the necessary WinAPI methods. So I am currently not using any inter-proccess communication (stdout) in my solution, but I just perform the switching to the selected window directly in the opened electron process.
@egamma For the short time that I tested the window interactions, everything seems to be ok so far. Also the keyboard focus seems to be just fine while switching between the windows. Time will tell if there are any other mishaps that are not immediately obvious right now. Once I have implemented a usable UI experience for the extension I will put it on github / publish it to the extension gallery. Thanks again for the help & feedback 😀 |
@drywolf thanks much for exploring this. The feedback sounds promising. I'd be very interested to use the extension once you are happy with it. |
@drywolf just curious - did you make progress on this? |
I had some busy weeks at work, so I didn't have much of a spirit to develop the prototype any further yet. |
@drywolf thanks for the update, please no stress, I was just curious. |
I put some work into it and made a first experimental alpha release, which can be found on github... The interaction between the vscode's electron window and the extension's electron window works well. There are a few points though that are still making it rough to develop this further into a more meaningful, stable extension:
|
Thanks for the update, the animated GIF looks nice and the appearance looks snappy.
You could use stdin/stdout and a JSON payload. This how the extension process takes to language server processes for typescript.
When Code shuts down the the
This is a lot, I'm not aware of this limit. One option would be to fetch the code from nuget on first An another challenge is how to align the themes between Code and your UI process. |
This is what I already tried, but the spawned electron process keeps running, even when vscode is already closed. I also tried adding a Might be related to #1298 ? |
@alexandrudima, hi,
Will fail with What's nice about allowing access to the Electron api, say, is being able to view the network traffic in the developer tools. The Node modules that provide WS support won't have special treatment so some extra work is required to debug these sorts of connections. |
Has this gone anywhere since? This would be an awesome feature to bring into VSCode |
@drywolf @egamma Awesome work and idea, just like the magic portal in room escape.:thumbsup:
Eventually, we escaped from Is there any way to build a floating window, or something like sticky tool bar ? |
This iteration we focus on issue grooming. This issue is being closed to keep the number of issues in our inbox on a manageable level, we are closing issues that are not going to be addressed in the foreseeable future: We look at the number of votes the issue has received and the number of duplicate issues filed. More details here. If you disagree and feel that this issue is crucial: We are happy to listen and to reconsider. If you wonder what we are up to, please see our roadmap and issue reporting guidelines. Thanks for your understanding and happy coding! |
Why can't call the electron api? Obviously the whole vscode is based on electron, but it is not letting you adjust his api, you are angry? |
Hi,
is there currently a way or is it planned for the future that we can access the electron shell API from VS-Code extensions ?
I would like to implement an extension using the BrowserWindow API of electron (more specifically the BrowserWindow.getAllWindows() API), but I can't find any way to get access to that from the scope of an extension.
Thanks
The text was updated successfully, but these errors were encountered: