Is there a way to launch and default open a particular folder as a workspace?

I have been SOL trying to figure out how to open a particular directory on “launch”. I tried on stack overflow but got no help :expressionless:

[original thread by Sean Cavanaugh]

[Sean Cavanaugh]

I think this was also an issue and we got pointed to work on this over here:

Hi @ipvsean . There are probably cleaner ways, but I have a couple of suggestions:

  1. provide a workspace folder as part of Theia app backend start. e.g. “yarn theia start --port=1234 /path/to/workspace-folder”. This provides a default workspace that will be used when you first connect to your app. After the first time, the last used workspace opened will override this value and be used
  1. Your application will have a config folder in the user’s home directory, by default ~/.theia/. In there file “recentworkspace.json” is created/updated each time a workspace is opened in your app. When this file exists, the latest entry will have precedence over the default workspace in 1) above, and be used as workspace next time a client connects. I guess if you deploy in a container, you could yourself create this file and add an entry for the workspace you’d like to open next time. If there is more than one entry, the most recent is default, and the others are accessible as options from the “file->open recent workspace” menu entry
  1. you could probably override default behaviors above and e.g. hardcode a default workspace that will be used instead of re-using the latest one. e.g. /home/workspace, and have that populated with whatever content a specific user needs. You would need to write your own Theia extension to do this I think

I found there are three ways when I read the notes

  • The default entrypoint will handle a very rudimentary CLI to open workspaces by doing app path/to/workspace. To override this behavior, you can extend and rebind the
  • 2 ElectronMainApplication class and overriding the launch method.
  • 3 A JSON-RPC communication between the Electron Main Process and the Renderer Processes is available: You can bind services using the ElectronConnectionHandler and
  • ElectronIpcConnectionProvider APIs, example:
  • From an electron-main module:
  • bind(ElectronConnectionHandler).toDynamicValue(context =>
  •      new JsonRpcConnectionHandler(electronMainWindowServicePath,
  •      () => context.container.get(ElectronMainWindowService))
  • ).inSingletonScope();
  • And from the electron-browser module:
  • bind(ElectronMainWindowService).toDynamicValue(context =>
  •      ElectronIpcConnectionProvider.createProxy(context.container, electronMainWindowServicePath)
  • ).inSingletonScope();

Now I have only succeeded in the first one. How should I realize 2 and 3

yarn electron start F:\vuetest\aa\aaaa.theia-workspace
Why do I execute this that His priority is higher than “.Theia/currentrworkspace”
I use Theia source code

when i “rebind(ElectronMainApplication).to(ElectronReBind).inSingletonScope();”
Could not unbind serviceIdentifier: ElectronMainApplication
what should I do