antosdk-apps/vTerm/build/debug/main.js

1 line
294 KiB
JavaScript
Raw Normal View History

2020-09-15 12:40:06 +02:00
var e,t;(function(){var e;e=class extends this.OS.application.BaseApplication{constructor(e){super("vTerm",e)}main(){var e;return this.mterm=this.find("myterm"),this.term=new Terminal({cursorBlink:!0}),this.fitAddon=new FitAddon.FitAddon,this.term.loadAddon(this.fitAddon),this.term.setOption("fontSize","12"),this.term.open(this.mterm),this.sub=void 0,this.term.onKey(e=>{if(this.sub)return this.sub.send(Antunnel.Msg.DATA,new TextEncoder("utf-8").encode(e.key))}),this.on("focus",()=>this.term.focus()),this.mterm.contextmenuHandle=(e,t)=>(t.items=[{text:"__(Copy)",id:"copy"},{text:"__(Paste)",id:"paste"}],t.onmenuselect=e=>{if(e)return this.mctxHandle(e.data.item.data)},t.show(e)),this.resizeContent(),this.systemsetting.desktop.menu[this.name]||(this.systemsetting.desktop.menu[this.name]={text:"__(Open terminal)",app:"vTerm"}),this.on("hboxchange",e=>this.resizeContent()),e=()=>Antunnel.tunnel?(this.tunnel=Antunnel.tunnel,this.openSession()):(this.error(__("The Antunnel service is not started, please start it first")),this._gui.pushService("Antunnel/AntunnelService").catch(e=>this.error(e.toString(),e)),this.quit()),window.Antunnel?e():(console.log("require Antunnel"),this._api.requires("pkg://Antunnel/main.js").then(()=>e()).catch(e=>(this.error(__("Unable to load Antunnel: {0}",e.toString()),e),this.quit())))}mctxHandle(e){var t;switch(e.id){case"paste":return this._api.getClipboard().then(e=>{if(e&&""!==e)return this.sub&&this.sub.send(Antunnel.Msg.DATA,new TextEncoder("utf-8").encode(e)),this.term.focus()}).catch(e=>this.error(__("Unable to paste"),e));case"copy":if(!(t=this.term.getSelection())||""===t)return;return this._api.setClipboard(t)}}resizeContent(){var e,t,r;if(this.fitAddon.fit(),t=this.term.cols,r=this.term.rows,this.sub)return(e=new Uint8Array(8)).set(Antunnel.Msg.bytes_of(t),0),e.set(Antunnel.Msg.bytes_of(r),4),this.sub.send(Antunnel.Msg.CTRL,e)}openSession(){return this.term.clear(),this.term.focus(),this.sub=new Antunnel.Subscriber("vterm"),this.sub.onopen=()=>(console.log("Subscribed"),this.resizeContent($(this.mterm).width(),$(this.mterm).height()),this.term.focus()),this.sub.onerror=e=>(this.error(__("Unable to connect to: vterm"),e),this.sub=void 0),this.sub.onmessage=e=>{if(this.term&&e.data)return this.term.write(new TextDecoder("utf-8").decode(e.data))},this.sub.onclose=()=>(this.sub=void 0,this.notify(__("Terminal connection closed")),this.quit()),this.tunnel.subscribe(this.sub)}cleanup(e){if(this.sub)return this.sub.close()}},this.OS.register("vTerm",e)}).call(this),e=window,t=function(){return function(e){var t={};function r(i){if(t[i])return t[i].exports;var n=t[i]={i:i,l:!1,exports:{}};return e[i].call(n.exports,n,n.exports,r),n.l=!0,n.exports}return r.m=e,r.c=t,r.d=function(e,t,i){r.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:i})},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var i=Object.create(null);if(r.r(i),Object.defineProperty(i,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var n in e)r.d(i,n,function(t){return e[t]}.bind(null,n));return i},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="",r(r.s=0)}([function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.FitAddon=void 0;var i=function(){function e(){}return e.prototype.activate=function(e){this._terminal=e},e.prototype.dispose=function(){},e.prototype.fit=function(){var e=this.proposeDimensions();if(e&&this._terminal){var t=this._terminal._core;this._terminal.rows===e.rows&&this._terminal.cols===e.cols||(t._renderService.clear(),this._terminal.resize(e.cols,e.rows))}},e.prototype.proposeDimensions=function(){if(this._terminal&&this._terminal.element&&this._terminal.element.parentElement){var e=this._terminal._core,t=window.g