1
1
mirror of https://github.com/Eugeny/tabby.git synced 2024-12-24 11:02:47 +03:00
tabby/web/polyfills.ts

148 lines
4.7 KiB
TypeScript
Raw Normal View History

2021-06-19 23:59:15 +03:00
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
2021-06-19 23:52:18 +03:00
/* eslint-disable @typescript-eslint/no-empty-function */
/* eslint-disable @typescript-eslint/no-extraneous-class */
2021-06-16 00:43:02 +03:00
2021-06-19 23:52:18 +03:00
import './polyfills.buffer'
import { Duplex } from 'stream-browserify'
2021-06-16 00:43:02 +03:00
2021-06-30 00:57:04 +03:00
const Tabby = window['Tabby']
2021-06-16 00:43:02 +03:00
2021-06-19 23:52:18 +03:00
export class SocketProxy extends Duplex {
socket: any
2021-06-16 00:43:02 +03:00
2021-06-19 23:59:15 +03:00
constructor (...args: any[]) {
2021-06-19 23:52:18 +03:00
super({
allowHalfOpen: false,
})
2021-06-22 12:51:52 +03:00
this.socket = window['__connector__'].createSocket(...args)
2021-06-19 23:52:18 +03:00
this.socket.connect$.subscribe(() => this['emit']('connect'))
this.socket.data$.subscribe(data => this['emit']('data', Buffer.from(data)))
2021-06-22 12:51:52 +03:00
this.socket.error$.subscribe(error => this['emit']('error', error))
2021-06-19 23:52:18 +03:00
}
2021-06-19 23:59:15 +03:00
connect (...args: any[]) {
2021-06-19 23:52:18 +03: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-16 00:43:02 +03:00
2021-06-30 00:57:04 +03:00
Tabby.registerMock('fs', {
2021-06-25 22:55:34 +03:00
realpathSync: () => null,
readdir: () => null,
stat: () => null,
appendFile: () => null,
constants: {},
})
2021-06-30 00:57:04 +03:00
Tabby.registerMock('any-promise', Promise)
Tabby.registerMock('tls', {})
Tabby.registerMock('module', {
2021-06-25 22:55:34 +03:00
globalPaths: [],
prototype: { require: window['require'] },
})
2021-06-30 00:57:04 +03:00
Tabby.registerMock('http', {
2021-06-25 22:55:34 +03:00
Agent: class {},
request: {},
})
2021-06-30 00:57:04 +03:00
Tabby.registerMock('https', {
2021-06-25 22:55:34 +03:00
Agent: class {},
request: {},
})
2021-06-30 00:57:04 +03:00
Tabby.registerMock('querystring', {})
Tabby.registerMock('tty', { isatty: () => false })
Tabby.registerMock('child_process', {})
Tabby.registerMock('readable-stream', {})
Tabby.registerMock('os', {
2022-02-07 18:36:20 +03:00
arch: () => 'web',
2021-06-25 22:55:34 +03:00
platform: () => 'web',
homedir: () => '/home',
})
2021-06-30 00:57:04 +03:00
Tabby.registerModule('buffer', {
2021-06-25 22:55:34 +03:00
Buffer: window['Buffer'],
})
2021-06-30 00:57:04 +03:00
Tabby.registerModule('crypto', {
2021-06-25 22:55:34 +03:00
...require('crypto-browserify'),
getHashes () {
return ['sha1', 'sha224', 'sha256', 'sha384', 'sha512', 'md5', 'rmd160']
2021-06-16 00:43:02 +03:00
},
2021-06-25 22:55:34 +03:00
timingSafeEqual (a, b) {
return a.equals(b)
2021-06-16 00:43:02 +03:00
},
2021-06-25 22:55:34 +03:00
})
2021-06-30 00:57:04 +03:00
Tabby.registerMock('dns', {})
Tabby.registerMock('@luminati-io/socksv5', {})
2021-06-30 00:57:04 +03:00
Tabby.registerMock('util', require('util/'))
Tabby.registerMock('keytar', {
2021-06-25 22:55:34 +03:00
getPassword: () => null,
})
2021-07-11 23:59:39 +03:00
Tabby.registerMock('@serialport/bindings', {})
2022-02-07 18:36:20 +03:00
Tabby.registerMock('@serialport/bindings-cpp', {})
2021-06-16 00:43:02 +03:00
2021-06-30 00:57:04 +03:00
Tabby.registerModule('net', {
2021-06-25 22:55:34 +03:00
Socket: SocketProxy,
})
2021-06-30 00:57:04 +03:00
Tabby.registerModule('events', require('events'))
Tabby.registerModule('path', require('path-browserify'))
2021-08-25 02:25:40 +03:00
Tabby.registerModule('url', {
...require('url'),
pathToFileURL: x => `file://${x}`,
})
2021-06-30 00:57:04 +03:00
Tabby.registerModule('zlib', {
2021-06-25 22:55:34 +03:00
...require('browserify-zlib'),
constants: require('browserify-zlib'),
})
2021-06-30 00:57:04 +03:00
Tabby.registerModule('assert', Object.assign(
2021-06-25 22:55:34 +03:00
require('assert'),
{
assertNotStrictEqual: () => true,
notStrictEqual: () => true,
},
))
2021-06-30 00:57:04 +03:00
Tabby.registerModule('constants', require('constants-browserify'))
Tabby.registerModule('stream', require('stream-browserify'))
2021-07-11 23:59:39 +03:00
Tabby.registerModule('readline', {
...require('readline-browserify'),
cursorTo: () => null,
clearLine: stream => stream.write('\r'),
})
2021-06-25 22:55:34 +03:00
2021-07-24 17:30:55 +03:00
Tabby.registerModule('@angular/core', require('@angular/core'))
Tabby.registerModule('@angular/cdk', require('@angular/cdk'))
Tabby.registerModule('@angular/cdk/clipboard', require('@angular/cdk/clipboard'))
Tabby.registerModule('@angular/cdk/drag-drop', require('@angular/cdk/drag-drop'))
Tabby.registerModule('@angular/compiler', require('@angular/compiler'))
Tabby.registerModule('@angular/common', require('@angular/common'))
Tabby.registerModule('@angular/forms', require('@angular/forms'))
Tabby.registerModule('@angular/platform-browser', require('@angular/platform-browser'))
Tabby.registerModule('@angular/platform-browser/animations', require('@angular/platform-browser/animations'))
Tabby.registerModule('@angular/platform-browser-dynamic', require('@angular/platform-browser-dynamic'))
Tabby.registerModule('@angular/animations', require('@angular/animations'))
Tabby.registerModule('@ng-bootstrap/ng-bootstrap', require('@ng-bootstrap/ng-bootstrap'))
Tabby.registerModule('ngx-toastr', require('ngx-toastr'))
2021-06-30 00:57:04 +03:00
Tabby.registerModule('deepmerge', require('deepmerge'))
Tabby.registerModule('rxjs', require('rxjs'))
Tabby.registerModule('rxjs/operators', require('rxjs'))
2022-02-07 17:33:34 +03:00
Tabby.registerModule('string_decoder', require('string_decoder'))
2021-06-30 00:57:04 +03:00
Tabby.registerModule('js-yaml', require('js-yaml'))
Tabby.registerModule('zone.js/dist/zone.js', require('zone.js/dist/zone.js'))
2021-06-16 00:43:02 +03:00
Object.assign(window, {
2021-06-19 23:52:18 +03:00
__dirname: '__dirname',
setImmediate: setTimeout as any,
2021-06-16 00:43:02 +03:00
})