Skip to content

Commit 190497d

Browse files
authored
Added desktop.launch method to launch GUI applications (#83)
* add gtk-launch and desktop.launch SDK method * updated readme with examples for .launch
1 parent c719c15 commit 190497d

7 files changed

Lines changed: 72 additions & 2 deletions

File tree

.changeset/witty-buttons-smell.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'@e2b/desktop-python': patch
3+
'@e2b/desktop': patch
4+
---
5+
6+
added gtk-launch and launch SDK method

README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,29 @@ await desktop.files.write('/home/user/index.js', "console.log('hello')") // Firs
386386
await desktop.open('/home/user/index.js') // Then open it
387387
```
388388

389+
### Launch applications
390+
391+
**Python**
392+
393+
```python
394+
from e2b_desktop import Sandbox
395+
desktop = Sandbox()
396+
397+
# Launch the application
398+
desktop.launch('google-chrome')
399+
```
400+
401+
**JavaScript**
402+
403+
```javascript
404+
import { Sandbox } from '@e2b/desktop'
405+
406+
const desktop = await Sandbox.create()
407+
408+
// Launch the application
409+
await desktop.launch('google-chrome')
410+
```
411+
389412
### Run any bash commands
390413

391414
**Python**

packages/js-sdk/README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,17 @@ await desktop.files.write('/home/user/index.js', "console.log('hello')") // Firs
198198
await desktop.open('/home/user/index.js') // Then open it
199199
```
200200

201+
### Launch applications
202+
203+
```javascript
204+
import { Sandbox } from '@e2b/desktop'
205+
206+
const desktop = await Sandbox.create()
207+
208+
// Launch the application
209+
await desktop.launch('google-chrome')
210+
```
211+
201212
### Run any bash commands
202213

203214
```javascript

packages/js-sdk/src/sandbox.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -581,6 +581,18 @@ export class Sandbox extends SandboxBase {
581581

582582
return result.stdout.trim()
583583
}
584+
585+
/**
586+
* Launch an application.
587+
* @param application - The application to launch.
588+
* @param uri - The URI to open in the application.
589+
*/
590+
async launch(application: string, uri?: string): Promise<void> {
591+
await this.commands.run(`gtk-launch ${application} ${uri ?? ''}`, {
592+
background: true,
593+
timeoutMs: 0,
594+
})
595+
}
584596
}
585597

586598
interface VNCServerOptions {

packages/python-sdk/README.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,6 @@ desktop.press(["ctrl", "c"]) # Key combination
155155

156156
### Window control
157157

158-
**Python**
159-
160158
```python
161159
from e2b_desktop import Sandbox
162160
desktop = Sandbox()
@@ -195,6 +193,16 @@ desktop.files.write("/home/user/index.js", "console.log('hello')") # First creat
195193
desktop.open("/home/user/index.js") # Then open it
196194
```
197195

196+
### Launch applications
197+
198+
```python
199+
from e2b_desktop import Sandbox
200+
desktop = Sandbox()
201+
202+
# Launch the application
203+
desktop.launch('google-chrome')
204+
```
205+
198206
### Run any bash commands
199207

200208
```python

packages/python-sdk/e2b_desktop/main.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -505,3 +505,9 @@ def get_window_title(self, window_id: str) -> str:
505505
Get the title of the window with the given ID.
506506
"""
507507
return self.commands.run(f"xdotool getwindowname {window_id}").stdout.strip()
508+
509+
def launch(self, application: str, uri: Optional[str] = None):
510+
"""
511+
Launch an application.
512+
"""
513+
self.commands.run(f"gtk-launch {application} {uri or ''}", background=True, timeout=0)

template/e2b.Dockerfile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,10 @@ COPY ./wallpaper.png /usr/share/backgrounds/xfce/wallpaper.png
9090
RUN mkdir -p /home/user/.config/xfce4/xfconf/xfce-perchannel-xml/
9191
COPY ./xfce4-desktop.xml /home/user/.config/xfce4/xfconf/xfce-perchannel-xml/xfce4-desktop.xml
9292

93+
# Install gtk-launch and update desktop database
94+
RUN apt-get install -y libgtk-3-bin && \
95+
update-desktop-database /usr/share/applications/
96+
9397
# Copy firefox policies
9498
COPY firefox-policies.json /usr/lib/firefox-esr/distribution/policies.json
9599
COPY firefox-autoconfig.js /usr/lib/firefox-esr/defaults/pref/autoconfig.js

0 commit comments

Comments
 (0)