2021-06-19 20:59:15 +00:00
|
|
|
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
|
2021-06-19 20:52:18 +00:00
|
|
|
/* eslint-disable @typescript-eslint/no-empty-function */
|
|
|
|
/* eslint-disable @typescript-eslint/no-extraneous-class */
|
2021-06-15 21:43:02 +00:00
|
|
|
import * as angularCoreModule from '@angular/core'
|
2021-07-21 20:59:58 +00:00
|
|
|
import * as angularCDKModule from '@angular/cdk'
|
2021-06-15 21:43:02 +00:00
|
|
|
import * as angularCompilerModule from '@angular/compiler'
|
|
|
|
import * as angularCommonModule from '@angular/common'
|
|
|
|
import * as angularFormsModule from '@angular/forms'
|
|
|
|
import * as angularPlatformBrowserModule from '@angular/platform-browser'
|
|
|
|
import * as angularPlatformBrowserAnimationsModule from '@angular/platform-browser/animations'
|
|
|
|
import * as angularPlatformBrowserDynamicModule from '@angular/platform-browser-dynamic'
|
|
|
|
import * as angularAnimationsModule from '@angular/animations'
|
|
|
|
import * as ngBootstrapModule from '@ng-bootstrap/ng-bootstrap'
|
|
|
|
import * as ngxToastrModule from 'ngx-toastr'
|
|
|
|
|
2021-06-19 20:52:18 +00:00
|
|
|
import './polyfills.buffer'
|
|
|
|
import { Duplex } from 'stream-browserify'
|
2021-06-15 21:43:02 +00:00
|
|
|
|
2021-06-29 21:57:04 +00:00
|
|
|
const Tabby = window['Tabby']
|
2021-06-15 21:43:02 +00:00
|
|
|
|
2021-06-19 20:52:18 +00:00
|
|
|
export class SocketProxy extends Duplex {
|
|
|
|
socket: any
|
2021-06-15 21:43:02 +00:00
|
|
|
|
2021-06-19 20:59:15 +00:00
|
|
|
constructor (...args: any[]) {
|
2021-06-19 20:52:18 +00:00
|
|
|
super({
|
|
|
|
allowHalfOpen: false,
|
|
|
|
})
|
2021-06-22 09:51:52 +00:00
|
|
|
this.socket = window['__connector__'].createSocket(...args)
|
2021-06-19 20:52:18 +00:00
|
|
|
this.socket.connect$.subscribe(() => this['emit']('connect'))
|
|
|
|
this.socket.data$.subscribe(data => this['emit']('data', Buffer.from(data)))
|
2021-06-22 09:51:52 +00:00
|
|
|
this.socket.error$.subscribe(error => this['emit']('error', error))
|
2021-06-19 20:52:18 +00:00
|
|
|
}
|
|
|
|
|
2021-06-19 20:59:15 +00:00
|
|
|
connect (...args: any[]) {
|
2021-06-19 20:52:18 +00:00
|
|
|
this.socket.connect(...args)
|
|
|
|
}
|
|
|
|
|
|
|
|
setNoDelay () { }
|
|
|
|
|
|
|
|
setTimeout () { }
|
|
|
|
|
|
|
|
_read (_size: number): void { }
|
|
|
|
|
|
|
|
_write (chunk: Buffer, _encoding: string, callback: (error?: Error | null) => void): void {
|
|
|
|
this.socket.write(chunk)
|
|
|
|
callback()
|
|
|
|
}
|
|
|
|
|
|
|
|
_destroy (error: Error|null, callback: (error: Error|null) => void): void {
|
|
|
|
this.socket.close(error)
|
|
|
|
callback(error)
|
|
|
|
}
|
|
|
|
}
|
2021-06-15 21:43:02 +00:00
|
|
|
|
2021-06-29 21:57:04 +00:00
|
|
|
Tabby.registerMock('fs', {
|
2021-06-25 19:55:34 +00:00
|
|
|
realpathSync: () => null,
|
|
|
|
readdir: () => null,
|
|
|
|
stat: () => null,
|
|
|
|
appendFile: () => null,
|
|
|
|
constants: {},
|
|
|
|
})
|
2021-06-29 21:57:04 +00:00
|
|
|
Tabby.registerMock('any-promise', Promise)
|
|
|
|
Tabby.registerMock('tls', {})
|
|
|
|
Tabby.registerMock('module', {
|
2021-06-25 19:55:34 +00:00
|
|
|
globalPaths: [],
|
|
|
|
prototype: { require: window['require'] },
|
|
|
|
})
|
|
|
|
|
2021-06-29 21:57:04 +00:00
|
|
|
Tabby.registerMock('url', {
|
2021-06-25 19:55:34 +00:00
|
|
|
parse: () => null,
|
|
|
|
})
|
2021-06-29 21:57:04 +00:00
|
|
|
Tabby.registerMock('http', {
|
2021-06-25 19:55:34 +00:00
|
|
|
Agent: class {},
|
|
|
|
request: {},
|
|
|
|
})
|
2021-06-29 21:57:04 +00:00
|
|
|
Tabby.registerMock('https', {
|
2021-06-25 19:55:34 +00:00
|
|
|
Agent: class {},
|
|
|
|
request: {},
|
|
|
|
})
|
2021-06-29 21:57:04 +00:00
|
|
|
Tabby.registerMock('querystring', {})
|
|
|
|
Tabby.registerMock('tty', { isatty: () => false })
|
|
|
|
Tabby.registerMock('child_process', {})
|
|
|
|
Tabby.registerMock('readable-stream', {})
|
|
|
|
Tabby.registerMock('os', {
|
2021-06-25 19:55:34 +00:00
|
|
|
platform: () => 'web',
|
|
|
|
homedir: () => '/home',
|
|
|
|
})
|
2021-06-29 21:57:04 +00:00
|
|
|
Tabby.registerModule('buffer', {
|
2021-06-25 19:55:34 +00:00
|
|
|
Buffer: window['Buffer'],
|
|
|
|
})
|
2021-06-29 21:57:04 +00:00
|
|
|
Tabby.registerModule('crypto', {
|
2021-06-25 19:55:34 +00:00
|
|
|
...require('crypto-browserify'),
|
|
|
|
getHashes () {
|
|
|
|
return ['sha1', 'sha224', 'sha256', 'sha384', 'sha512', 'md5', 'rmd160']
|
2021-06-15 21:43:02 +00:00
|
|
|
},
|
2021-06-25 19:55:34 +00:00
|
|
|
timingSafeEqual (a, b) {
|
|
|
|
return a.equals(b)
|
2021-06-15 21:43:02 +00:00
|
|
|
},
|
2021-06-25 19:55:34 +00:00
|
|
|
})
|
2021-06-29 21:57:04 +00:00
|
|
|
Tabby.registerMock('hterm-umdjs', {
|
2021-06-25 19:55:34 +00:00
|
|
|
hterm: {
|
|
|
|
PreferenceManager: class { set () {} },
|
|
|
|
VT: {
|
|
|
|
ESC: {},
|
|
|
|
CSI: {},
|
|
|
|
OSC: {},
|
2021-06-15 21:43:02 +00:00
|
|
|
},
|
2021-06-25 19:55:34 +00:00
|
|
|
Terminal: class {},
|
|
|
|
Keyboard: class {},
|
2021-06-15 21:43:02 +00:00
|
|
|
},
|
2021-06-25 19:55:34 +00:00
|
|
|
lib: {
|
|
|
|
wc: {},
|
|
|
|
Storage: {
|
|
|
|
Memory: class {},
|
2021-06-15 21:43:02 +00:00
|
|
|
},
|
|
|
|
},
|
2021-06-25 19:55:34 +00:00
|
|
|
})
|
2021-06-29 21:57:04 +00:00
|
|
|
Tabby.registerMock('dns', {})
|
|
|
|
Tabby.registerMock('socksv5', {})
|
|
|
|
Tabby.registerMock('util', require('util/'))
|
|
|
|
Tabby.registerMock('keytar', {
|
2021-06-25 19:55:34 +00:00
|
|
|
getPassword: () => null,
|
|
|
|
})
|
2021-07-11 20:59:39 +00:00
|
|
|
Tabby.registerMock('@serialport/bindings', {})
|
2021-06-15 21:43:02 +00:00
|
|
|
|
2021-06-29 21:57:04 +00:00
|
|
|
Tabby.registerModule('net', {
|
2021-06-25 19:55:34 +00:00
|
|
|
Socket: SocketProxy,
|
|
|
|
})
|
2021-06-29 21:57:04 +00:00
|
|
|
Tabby.registerModule('events', require('events'))
|
|
|
|
Tabby.registerModule('path', require('path-browserify'))
|
|
|
|
Tabby.registerModule('zlib', {
|
2021-06-25 19:55:34 +00:00
|
|
|
...require('browserify-zlib'),
|
|
|
|
constants: require('browserify-zlib'),
|
|
|
|
})
|
2021-06-29 21:57:04 +00:00
|
|
|
Tabby.registerModule('assert', Object.assign(
|
2021-06-25 19:55:34 +00:00
|
|
|
require('assert'),
|
|
|
|
{
|
|
|
|
assertNotStrictEqual: () => true,
|
|
|
|
notStrictEqual: () => true,
|
|
|
|
},
|
|
|
|
))
|
2021-06-29 21:57:04 +00:00
|
|
|
Tabby.registerModule('constants', require('constants-browserify'))
|
|
|
|
Tabby.registerModule('stream', require('stream-browserify'))
|
2021-07-11 20:59:39 +00:00
|
|
|
Tabby.registerModule('readline', {
|
|
|
|
...require('readline-browserify'),
|
|
|
|
cursorTo: () => null,
|
|
|
|
clearLine: stream => stream.write('\r'),
|
|
|
|
})
|
2021-06-25 19:55:34 +00:00
|
|
|
|
2021-06-29 21:57:04 +00:00
|
|
|
Tabby.registerModule('@angular/core', angularCoreModule)
|
2021-07-21 20:59:58 +00:00
|
|
|
Tabby.registerModule('@angular/cdk', angularCDKModule)
|
2021-06-29 21:57:04 +00:00
|
|
|
Tabby.registerModule('@angular/compiler', angularCompilerModule)
|
|
|
|
Tabby.registerModule('@angular/common', angularCommonModule)
|
|
|
|
Tabby.registerModule('@angular/forms', angularFormsModule)
|
|
|
|
Tabby.registerModule('@angular/platform-browser', angularPlatformBrowserModule)
|
|
|
|
Tabby.registerModule('@angular/platform-browser/animations', angularPlatformBrowserAnimationsModule)
|
|
|
|
Tabby.registerModule('@angular/platform-browser-dynamic', angularPlatformBrowserDynamicModule)
|
|
|
|
Tabby.registerModule('@angular/animations', angularAnimationsModule)
|
|
|
|
Tabby.registerModule('@ng-bootstrap/ng-bootstrap', ngBootstrapModule)
|
|
|
|
Tabby.registerModule('ngx-toastr', ngxToastrModule)
|
|
|
|
Tabby.registerModule('deepmerge', require('deepmerge'))
|
|
|
|
Tabby.registerModule('rxjs', require('rxjs'))
|
2021-07-06 23:22:50 +00:00
|
|
|
Tabby.registerModule('rxjs/operators', require('rxjs'))
|
2021-06-29 21:57:04 +00:00
|
|
|
Tabby.registerModule('js-yaml', require('js-yaml'))
|
|
|
|
Tabby.registerModule('zone.js/dist/zone.js', require('zone.js/dist/zone.js'))
|
2021-06-15 21:43:02 +00:00
|
|
|
|
|
|
|
Object.assign(window, {
|
2021-06-19 20:52:18 +00:00
|
|
|
__dirname: '__dirname',
|
|
|
|
setImmediate: setTimeout as any,
|
2021-06-15 21:43:02 +00:00
|
|
|
})
|