This commit is contained in:
Eugene Pankov 2021-06-19 23:01:22 +02:00
parent f8f58a66ec
commit e74b44a9bc
No known key found for this signature in database
GPG Key ID: 5896FCBBDD1CF4F4
5 changed files with 81 additions and 210 deletions

View File

@ -46,12 +46,8 @@
"sass-loader": "^11.1.1",
"script-loader": "^0.7.2",
"semver": "^7.3.5",
"setimmediate": "^1.0.5",
"source-code-pro": "^2.30.1",
"source-sans-pro": "^2.45.0",
"ssh2": "^1.1.0",
"stream-browserify": "^3.0.0",
"string_decoder": "^1.3.0",
"style-loader": "^0.23.1",
"typescript": "~4.1",
"val-loader": "^4.0.0",

View File

@ -66,7 +66,7 @@ export class MainComponent {
}
loadApp (version) {
this.iframe.nativeElement.src = `/terminal?${version.version}`
this.iframe.nativeElement.src = '/terminal'
this.activeVersion = version
}
@ -78,6 +78,7 @@ export class MainComponent {
// TODO check config incompatibility
this.unloadApp()
setTimeout(() => {
this.appConnector.version = version
this.loadApp(version)
})
}

View File

@ -1,11 +1,53 @@
import { Buffer } from 'buffer'
import { Subject } from 'rxjs'
import { debounceTime } from 'rxjs/operators'
import { HttpClient } from '@angular/common/http'
import { Injectable } from '@angular/core'
export class SocketProxy {
connect$ = new Subject<void>()
data$ = new Subject<Buffer>()
webSocket: WebSocket
initialBuffer: Buffer
constructor (...args) {
console.log('ws ctr', args)
this.initialBuffer = Buffer.from('')
}
connect (...args) {
console.log('ws connect', args)
this.webSocket = new WebSocket(`ws://${location.host}/api/1/gateway/tcp`)
this.webSocket.onopen = event => {
this.connect$.next()
this.connect$.complete()
this.webSocket.send(this.initialBuffer)
this.initialBuffer = Buffer.from('')
}
this.webSocket.onmessage = async event => {
this.data$.next(Buffer.from(await event.data.arrayBuffer()))
}
}
write (chunk: Buffer): void {
if (!this.webSocket.readyState) {
this.initialBuffer = Buffer.concat([this.initialBuffer, chunk])
} else {
this.webSocket.send(chunk)
}
}
close (error: Error): void {
console.warn('socket destroy', error)
}
}
@Injectable({ providedIn: 'root' })
export class AppConnectorService {
config: any
version: any
Socket = SocketProxy
private configUpdate = new Subject<string>()
constructor (private http: HttpClient) {
@ -23,4 +65,8 @@ export class AppConnectorService {
this.configUpdate.next(content)
this.config.content = content
}
getAppVersion (): string {
return this.version.version
}
}

View File

@ -1,6 +1,10 @@
import './terminal-styles.scss'
Object.assign(window, {
// Buffer,
process: {
env: { XWEB: 1, LOGNAME: 'root' },
env: { },
argv: ['terminus'],
platform: 'darwin',
on: () => null,
@ -15,155 +19,28 @@ Object.assign(window, {
})
import { Duplex } from 'stream-browserify'
import 'core-js/proposals/reflect-metadata'
import '@fortawesome/fontawesome-free/css/solid.css'
import '@fortawesome/fontawesome-free/css/brands.css'
import '@fortawesome/fontawesome-free/css/fontawesome.css'
import 'source-code-pro/source-code-pro.css'
import 'source-sans-pro/source-sans-pro.css'
import './terminal-styles.scss'
export class Socket extends Duplex {
webSocket: WebSocket
initialBuffer: Buffer
constructor () {
console.warn('socket constr', arguments)
super({
allowHalfOpen: false,
})
this.initialBuffer = Buffer.from('')
}
connect () {
this.webSocket = new WebSocket(`ws://${location.host}/api/1/gateway/tcp`)
this.webSocket.onopen = event => {
this['emit']('connect')
this.webSocket.send(this.initialBuffer)
this.initialBuffer = Buffer.from('')
}
this.webSocket.onmessage = async event => {
this['emit']('data', Buffer.from(await event.data.arrayBuffer()))
}
}
setNoDelay () {
}
setTimeout () {
}
_read (size: number): void {
}
_write (chunk: Buffer, _encoding: string, callback: (error?: Error | null) => void): void {
if (!this.webSocket.readyState) {
this.initialBuffer = Buffer.concat([this.initialBuffer, chunk])
} else {
this.webSocket.send(chunk)
}
callback()
}
_destroy (error: Error|null, callback: (error: Error|null) => void): void {
console.warn('socket destroy', error)
callback(error)
}
}
async function start () {
const mocks = {
'@electron/remote': {
app: {
getVersion: () => '1.0-web',
getPath: () => 'app-path',
getWindow: () => ({
reload: () => null,
setTrafficLightPosition: () => null,
}),
},
screen: {
on: () => null,
getAllDisplays: () => [],
getPrimaryDisplay: () => ({}),
getCursorScreenPoint: () => ({}),
getDisplayNearestPoint: () => null,
},
globalShortcut: {
unregisterAll: () => null,
register: () => null,
},
autoUpdater: {
on: () => null,
once: () => null,
setFeedURL: () => null,
checkForUpdates: () => null,
},
BrowserWindow: {
fromId: () => ({
setOpacity: () => null,
setProgressBar: () => null,
}),
},
getGlobal: () => window['process'],
},
electron: {
ipcRenderer: { // TODO remove
on: (e, c) => {
console.log('[ipc listen]', e)
},
once: (e, c) => {
console.log('[ipc listen once]', e)
},
send: msg => {
console.log('[ipc]', msg)
}
},
},
net: {
Socket,
},
// winston: {
// Logger,
// transports: {
// File: Object,
// Console: Object,
// }
// },
// 'mz/child_process': {
// exec: (...x) => Promise.reject(),
// },
// 'mz/fs': {
// readFile: path => mocks.fs.readFileSync(path),
// exists: path => mocks.fs.existsSync(path),
// existsSync: path => mocks.fs.existsSync(path),
// },
}
let builtins = {
}
const modules = { }
Object.assign(window, {
require: (path) => {
if (mocks[path]) {
console.warn('requiring mock', path)
return mocks[path]
}
if (builtins[path]) {
return builtins[path]
if (modules[path]) {
return modules[path]
}
console.error('requiring real module', path)
},
})
const appVersion = location.search.substring(1)
await new Promise<void>(resolve => {
window.addEventListener('message', event => {
if (event.data === 'connector-ready') {
resolve()
}
})
window.parent.postMessage('request-connector', '*')
})
const appVersion = window['__connector__'].getAppVersion()
async function loadPlugin (name, file = 'index.js') {
const url = `../app-dist/${appVersion}/${name}/dist/${file}`
@ -192,23 +69,21 @@ async function start () {
'terminus-web',
]) {
const mod = await loadPlugin(plugin)
builtins[`resources/builtin-plugins/${plugin}`] = builtins[plugin] = mod
modules[`resources/builtin-plugins/${plugin}`] = modules[plugin] = mod
pluginModules.push(mod)
}
document.querySelector('app-root')['style'].display = 'flex'
await new Promise<void>(resolve => {
window.addEventListener('message', event => {
if (event.data === 'connector-ready') {
resolve()
}
})
window.parent.postMessage('request-connector', '*')
})
const config = window['__connector__'].loadConfig()
window['bootstrapTerminus'](pluginModules, { config })
window['bootstrapTerminus'](pluginModules, {
config,
executable: 'web',
isFirstWindow: true,
windowID: 1,
installedPlugins: [],
userPluginsPath: '/',
})
}
start()

View File

@ -714,7 +714,7 @@ asap@~2.0.3:
resolved "https://registry.yarnpkg.com/asap/-/asap-2.0.6.tgz#e50347611d7e690943208bbdafebcbc2fb866d46"
integrity sha1-5QNHYR1+aQlDIIu9r+vLwvuGbUY=
asn1@^0.2.4, asn1@~0.2.3:
asn1@~0.2.3:
version "0.2.4"
resolved "https://registry.yarnpkg.com/asn1/-/asn1-0.2.4.tgz#8d2475dfab553bb33e77b54e59e880bb8ce23136"
integrity sha512-jxwzQpLQjSmWXgwaCZE9Nz+glAG01yF1QnWgbhGwHI5A6FRIEY6IVqtHhIepHqI7/kyEyQEagBC5mBEFlIYvdg==
@ -828,7 +828,7 @@ base@^0.11.1:
mixin-deep "^1.2.0"
pascalcase "^0.1.1"
bcrypt-pbkdf@^1.0.0, bcrypt-pbkdf@^1.0.2:
bcrypt-pbkdf@^1.0.0:
version "1.0.2"
resolved "https://registry.yarnpkg.com/bcrypt-pbkdf/-/bcrypt-pbkdf-1.0.2.tgz#a4301d389b6a43f9b67ff3ca11a3f6637e360e9e"
integrity sha1-pDAdOJtqQ/m2f/PKEaP2Y342Dp4=
@ -1208,13 +1208,6 @@ core-util-is@1.0.2, core-util-is@~1.0.0:
resolved "https://registry.yarnpkg.com/core-util-is/-/core-util-is-1.0.2.tgz#b5fd54220aa2bc5ab57aab7140c940754503c1a7"
integrity sha1-tf1UIgqivFq1eqtxQMlAdUUDwac=
cpu-features@0.0.2:
version "0.0.2"
resolved "https://registry.yarnpkg.com/cpu-features/-/cpu-features-0.0.2.tgz#9f636156f1155fd04bdbaa028bb3c2fbef3cea7a"
integrity sha512-/2yieBqvMcRj8McNzkycjW2v3OIUOibBfd2dLEJ0nWts8NobAxwiyw9phVNS6oDL8x8tz9F7uNVFEVpJncQpeA==
dependencies:
nan "^2.14.1"
cross-spawn@^7.0.3:
version "7.0.3"
resolved "https://registry.yarnpkg.com/cross-spawn/-/cross-spawn-7.0.3.tgz#f73a85b9d5d41d045551c177e2882d4ac85728a6"
@ -1980,7 +1973,7 @@ inflight@^1.0.4:
once "^1.3.0"
wrappy "1"
inherits@2, inherits@^2.0.3, inherits@~2.0.3, inherits@~2.0.4:
inherits@2, inherits@~2.0.3:
version "2.0.4"
resolved "https://registry.yarnpkg.com/inherits/-/inherits-2.0.4.tgz#0fa2c64f932917c3433a0ded55363aae37416b7c"
integrity sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==
@ -2628,7 +2621,7 @@ ms@2.1.2:
resolved "https://registry.yarnpkg.com/ms/-/ms-2.1.2.tgz#d09d1f357b443f493382a8eb3ccd183872ae6009"
integrity sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==
nan@^2.13.2, nan@^2.14.1, nan@^2.14.2:
nan@^2.13.2:
version "2.14.2"
resolved "https://registry.yarnpkg.com/nan/-/nan-2.14.2.tgz#f5376400695168f4cc694ac9393d0c9585eeea19"
integrity sha512-M2ufzIiINKCuDfBSAUr1vWQ+vuVcA9kqx8JJUsbQi6yf1uGRyb7HfpdfUr5qLXf3B/t8dPvcjhKMmlfnP47EzQ==
@ -3321,15 +3314,6 @@ readable-stream@^2.0.1, readable-stream@^2.0.6:
string_decoder "~1.1.1"
util-deprecate "~1.0.1"
readable-stream@^3.5.0:
version "3.6.0"
resolved "https://registry.yarnpkg.com/readable-stream/-/readable-stream-3.6.0.tgz#337bbda3adc0706bd3e024426a286d4b4b2c9198"
integrity sha512-BViHy7LKeTz4oNnkcLJ+lVSL6vpiFeX6/d3oSH8zCW7UxP2onchk+vTGB143xuFjHS3deTgkKoXXymXqymiIdA==
dependencies:
inherits "^2.0.3"
string_decoder "^1.1.1"
util-deprecate "^1.0.1"
readdirp@~3.5.0:
version "3.5.0"
resolved "https://registry.yarnpkg.com/readdirp/-/readdirp-3.5.0.tgz#9ba74c019b15d365278d2e91bb8c48d7b4d42c9e"
@ -3515,7 +3499,7 @@ rxjs@^7.1.0:
dependencies:
tslib "~2.1.0"
safe-buffer@^5.0.1, safe-buffer@^5.1.2, safe-buffer@~5.2.0:
safe-buffer@^5.0.1, safe-buffer@^5.1.2:
version "5.2.1"
resolved "https://registry.yarnpkg.com/safe-buffer/-/safe-buffer-5.2.1.tgz#1eaf9fa9bdb1fdd4ec75f58f9cdb4e6b7827eec6"
integrity sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ==
@ -3635,11 +3619,6 @@ set-value@^2.0.0, set-value@^2.0.1:
is-plain-object "^2.0.3"
split-string "^3.0.1"
setimmediate@^1.0.5:
version "1.0.5"
resolved "https://registry.yarnpkg.com/setimmediate/-/setimmediate-1.0.5.tgz#290cbb232e306942d7d7ea9b83732ab7856f8285"
integrity sha1-KQy7Iy4waULX1+qbg3Mqt4VvgoU=
shallow-clone@^3.0.0:
version "3.0.1"
resolved "https://registry.yarnpkg.com/shallow-clone/-/shallow-clone-3.0.1.tgz#8f2981ad92531f55035b01fb230769a40e02efa3"
@ -3793,17 +3772,6 @@ split-string@^3.0.1, split-string@^3.0.2:
dependencies:
extend-shallow "^3.0.0"
ssh2@^1.1.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/ssh2/-/ssh2-1.1.0.tgz#43dd24930e15e317687f519d6b40270d9cd00d00"
integrity sha512-CidQLG2ZacoT0Z7O6dOyisj4JdrOrLVJ4KbHjVNz9yI1vO08FAYQPcnkXY9BP8zeYo+J/nBgY6Gg4R7w4WFWtg==
dependencies:
asn1 "^0.2.4"
bcrypt-pbkdf "^1.0.2"
optionalDependencies:
cpu-features "0.0.2"
nan "^2.14.2"
sshpk@^1.7.0:
version "1.16.1"
resolved "https://registry.yarnpkg.com/sshpk/-/sshpk-1.16.1.tgz#fb661c0bef29b39db40769ee39fa70093d6f6877"
@ -3834,14 +3802,6 @@ stdout-stream@^1.4.0:
dependencies:
readable-stream "^2.0.1"
stream-browserify@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/stream-browserify/-/stream-browserify-3.0.0.tgz#22b0a2850cdf6503e73085da1fc7b7d0c2122f2f"
integrity sha512-H73RAHsVBapbim0tU2JwwOiXUj+fikfiaoYAKHF3VJfA0pe2BCzkhAHBlLG6REzE+2WNZcxOXjK7lkso+9euLA==
dependencies:
inherits "~2.0.4"
readable-stream "^3.5.0"
string-width@^1.0.1:
version "1.0.2"
resolved "https://registry.yarnpkg.com/string-width/-/string-width-1.0.2.tgz#118bdf5b8cdc51a2a7e70d211e07e2b0b9b107d3"
@ -3877,13 +3837,6 @@ string-width@^4.1.0, string-width@^4.2.0:
is-fullwidth-code-point "^3.0.0"
strip-ansi "^6.0.0"
string_decoder@^1.1.1, string_decoder@^1.3.0:
version "1.3.0"
resolved "https://registry.yarnpkg.com/string_decoder/-/string_decoder-1.3.0.tgz#42f114594a46cf1a8e30b0a84f56c78c3edac21e"
integrity sha512-hkRX8U1WjJFd8LsDJ2yQ/wWWxaopEsABU1XfkM8A+j0+85JAGppt16cr1Whg6KIbb4okU6Mql6BOj+uup/wKeA==
dependencies:
safe-buffer "~5.2.0"
string_decoder@~1.1.1:
version "1.1.1"
resolved "https://registry.yarnpkg.com/string_decoder/-/string_decoder-1.1.1.tgz#9cf1611ba62685d7030ae9e4ba34149c3af03fc8"
@ -4179,7 +4132,7 @@ use@^3.1.0:
resolved "https://registry.yarnpkg.com/use/-/use-3.1.1.tgz#d50c8cac79a19fbc20f2911f56eb973f4e10070f"
integrity sha512-cwESVXlO3url9YWlFW/TA9cshCEhtu7IKJ/p5soJ/gGpj7vbvFrAY/eIioQ6Dw23KjZhYgiIo8HOs1nQ2vr/oQ==
util-deprecate@^1.0.1, util-deprecate@~1.0.1:
util-deprecate@~1.0.1:
version "1.0.2"
resolved "https://registry.yarnpkg.com/util-deprecate/-/util-deprecate-1.0.2.tgz#450d4dc9fa70de732762fbd2d4a28981419a0ccf"
integrity sha1-RQ1Nyfpw3nMnYvvS1KKJgUGaDM8=