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

1 line
293 KiB
JavaScript
Raw Normal View History

2020-05-22 17:58:13 +02:00
var e,t;(function(){var e;e=class extends this.OS.GUI.BaseApplication{constructor(e){super("wTerm",e)}main(){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.term.onKey(e=>{if(this.socket)return this.socket.send("i"+e.key)}),this.socket=void 0,this.on("focus",()=>this.term.focus()),this.mterm.contextmenuHandle=(e,t)=>(t.set("items",[{text:"__(Copy)",id:"copy"},{text:"__(Paste)",id:"paste"}]),t.set("onmenuselect",e=>{if(e)return this.mctxHandle(e.data.item.get("data"))}),t.show(e)),this.resizeContent(),this.openSession(),this.systemsetting.desktop.menu[this.name]||(this.systemsetting.desktop.menu[this.name]={text:"__(Open terminal)",app:"wTerm"}),this.on("hboxchange",e=>this.resizeContent())}mctxHandle(e){var t;switch(e.id){case"paste":return this._api.getClipboard().then(e=>{var t,r,i,n;if(e&&""!==e){for(i=[],t=0,r=e.length;t<r;t++)n=e[t],i.push(this.socket.send("i"+n));return i}}).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;if(this.fitAddon.fit(),e=this.term.cols,t=this.term.rows,this.socket)return this.socket.send(`s${e}:${t}`)}openSession(){return this.term.clear(),this.term.focus(),console.log(this.setting.uri),this.setting.uri?(this.socket=new WebSocket(this.setting.uri),this.socket.onopen=()=>(this.resizeContent($(this.mterm).width(),$(this.mterm).height()),this.term.focus()),this.socket.onerror=e=>(this.error(__("Unable to connect to: {0}",this.setting.uri),e),this.socket=void 0),this.socket.onmessage=e=>{if(this.term&&e.data)return this.term.write(e.data)},this.socket.onclose=()=>(this.socket=void 0,this.notify(__("Terminal connection closed")))):this.configure()}cleanup(e){if(this.socket)return this.socket.close()}menu(){return{text:"__(Edit)",child:[{text:"__(Terminal URI)",dataid:this.name+"-termuri"}],onchildselect:e=>this.configure()}}configure(){return this.socket&&this.socket.close(),this.openDialog("PromptDialog",{title:"__(Please enter terminal URI)",label:"__(URI)",value:this.setting.uri||"wss://lxsang.me/wterm"}).then(e=>{if(e&&""!==e)return this.setting.uri=e,this.openSession()})}},this.OS.register("wTerm",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.getComputedStyle(this._terminal.element.parentElement),r=parseInt(t.getPropertyValue("height")),i=Math.max(0,parseInt(t.getPropertyValue("width"))),n=window.getComputedStyl