@@ -143,9 +143,9 @@ export interface SandboxBetaCreateOpts extends SandboxBetaCreateOptsBase {
143143
144144export class Sandbox extends SandboxBase {
145145 protected static override readonly defaultTemplate : string = 'desktop'
146- private lastXfce4Pid : number | null = null
147146 public display : string = ':0'
148147 public stream : VNCServer = new VNCServer ( this )
148+ private lastXfce4Pid : number | null = null
149149
150150 /**
151151 * Use {@link Sandbox.create} to create a new Sandbox instead.
@@ -323,28 +323,6 @@ export class Sandbox extends SandboxBase {
323323 return false
324324 }
325325
326- /**
327- * Start xfce4 session if logged out or not running.
328- */
329- private async startXfce4 ( ) : Promise < void > {
330- if (
331- this . lastXfce4Pid === null ||
332- (
333- await this . commands . run (
334- `ps aux | grep ${ this . lastXfce4Pid } | grep -v grep | head -n 1`
335- )
336- ) . stdout
337- . trim ( )
338- . includes ( '[xfce4-session] <defunct>' )
339- ) {
340- const result = await this . commands . run ( 'startxfce4' , {
341- background : true ,
342- timeoutMs : 0 ,
343- } )
344- this . lastXfce4Pid = result . pid
345- }
346- }
347-
348326 /**
349327 * Take a screenshot and save it to the given name.
350328 * @param format - The format of the screenshot.
@@ -507,26 +485,6 @@ export class Sandbox extends SandboxBase {
507485 }
508486 }
509487
510- private * breakIntoChunks ( text : string , n : number ) : Generator < string > {
511- for ( let i = 0 ; i < text . length ; i += n ) {
512- yield text . slice ( i , i + n )
513- }
514- }
515-
516- private quoteString ( s : string ) : string {
517- if ( ! s ) {
518- return "''"
519- }
520-
521- if ( ! / [ ^ \w @ % + = : , . / - ] / . test ( s ) ) {
522- return s
523- }
524-
525- // use single quotes, and put single quotes into double quotes
526- // the string $'b is then quoted as '$'"'"'b'
527- return "'" + s . replace ( / ' / g, "'\"'\"'" ) + "'"
528- }
529-
530488 /**
531489 * Write the given text at the current cursor position.
532490 * @param text - The text to write.
@@ -708,47 +666,6 @@ class VNCServer {
708666 return this . password
709667 }
710668
711- /**
712- * Set the VNC command to start the VNC server.
713- */
714- private async getVNCCommand ( windowId ?: string ) : Promise < string > {
715- let pwdFlag = '-nopw'
716- if ( this . novncAuthEnabled ) {
717- // Create .vnc directory if it doesn't exist
718- await this . desktop . commands . run ( 'mkdir -p ~/.vnc' )
719- await this . desktop . commands . run (
720- `x11vnc -storepasswd ${ this . password } ~/.vnc/passwd`
721- )
722- pwdFlag = '-usepw'
723- }
724-
725- return (
726- `x11vnc -bg -display ${ this . desktop . display } -forever -wait 50 -shared ` +
727- `-rfbport ${ this . vncPort } ${ pwdFlag } 2>/tmp/x11vnc_stderr.log` +
728- ( windowId ? ` -id ${ windowId } ` : '' )
729- )
730- }
731-
732- private async waitForPort ( port : number ) : Promise < boolean > {
733- return await this . desktop . waitAndVerify (
734- `netstat -tuln | grep ":${ port } "` ,
735- ( r : CommandResult ) => r . stdout . trim ( ) !== ''
736- )
737- }
738-
739- /**
740- * Check if the VNC server is running.
741- * @returns Whether the VNC server is running.
742- */
743- private async checkVNCRunning ( ) : Promise < boolean > {
744- try {
745- const result = await this . desktop . commands . run ( 'pgrep -x x11vnc' )
746- return result . stdout . trim ( ) !== ''
747- } catch ( error ) {
748- return false
749- }
750- }
751-
752669 /**
753670 * Get the URL to a web page with a stream of the desktop sandbox.
754671 * @param autoConnect - Whether to automatically connect to the server after opening the URL.
@@ -767,7 +684,7 @@ class VNCServer {
767684 throw new Error ( 'Server is not running' )
768685 }
769686
770- let url = new URL ( this . url )
687+ const url = new URL ( this . url )
771688 if ( autoConnect ) {
772689 url . searchParams . set ( 'autoconnect' , 'true' )
773690 }
@@ -823,4 +740,45 @@ class VNCServer {
823740 this . novncHandle = null
824741 }
825742 }
743+
744+ /**
745+ * Set the VNC command to start the VNC server.
746+ */
747+ private async getVNCCommand ( windowId ?: string ) : Promise < string > {
748+ let pwdFlag = '-nopw'
749+ if ( this . novncAuthEnabled ) {
750+ // Create .vnc directory if it doesn't exist
751+ await this . desktop . commands . run ( 'mkdir -p ~/.vnc' )
752+ await this . desktop . commands . run (
753+ `x11vnc -storepasswd ${ this . password } ~/.vnc/passwd`
754+ )
755+ pwdFlag = '-usepw'
756+ }
757+
758+ return (
759+ `x11vnc -bg -display ${ this . desktop . display } -forever -wait 50 -shared ` +
760+ `-rfbport ${ this . vncPort } ${ pwdFlag } 2>/tmp/x11vnc_stderr.log` +
761+ ( windowId ? ` -id ${ windowId } ` : '' )
762+ )
763+ }
764+
765+ private async waitForPort ( port : number ) : Promise < boolean > {
766+ return await this . desktop . waitAndVerify (
767+ `netstat -tuln | grep ":${ port } "` ,
768+ ( r : CommandResult ) => r . stdout . trim ( ) !== ''
769+ )
770+ }
771+
772+ /**
773+ * Check if the VNC server is running.
774+ * @returns Whether the VNC server is running.
775+ */
776+ private async checkVNCRunning ( ) : Promise < boolean > {
777+ try {
778+ const result = await this . desktop . commands . run ( 'pgrep -x x11vnc' )
779+ return result . stdout . trim ( ) !== ''
780+ } catch ( error ) {
781+ return false
782+ }
783+ }
826784}
0 commit comments