antosdk-apps/wTerm/build/debug/main.js
2020-12-18 21:52:44 +01:00

1 line
2.4 KiB
JavaScript

(function(){var t;(t=class extends this.OS.application.BaseApplication{constructor(t){super("wTerm",t)}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(t=>{if(this.socket)return this.socket.send("i"+t.key)}),this.socket=void 0,this.on("focus",()=>this.term.focus()),this.mterm.contextmenuHandle=(t,e)=>(e.items=[{text:"__(Copy)",id:"copy"},{text:"__(Paste)",id:"paste"}],e.onmenuselect=t=>{if(t)return this.mctxHandle(t.data.item.data)},e.show(t)),this.resizeContent(),this.openSession(),this.systemsetting.desktop.menu[this.name]||(this.systemsetting.desktop.menu[this.name]={text:"__(Open terminal)",app:"wTerm"}),this.on("hboxchange",t=>this.resizeContent())}mctxHandle(t){var e;switch(t.id){case"paste":return this._api.getClipboard().then(t=>{var e,s,i,n;if(t&&""!==t){for(i=[],e=0,s=t.length;e<s;e++)n=t[e],i.push(this.socket.send("i"+n));return i}}).catch(t=>this.error(__("Unable to paste"),t));case"copy":if(!(e=this.term.getSelection())||""===e)return;return this._api.setClipboard(e)}}resizeContent(){var t,e;if(this.fitAddon.fit(),t=this.term.cols,e=this.term.rows,this.socket)return this.socket.send(`s${t}:${e}`)}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=t=>(this.error(__("Unable to connect to: {0}",this.setting.uri),t),this.socket=void 0),this.socket.onmessage=t=>{if(this.term&&t.data)return this.term.write(t.data)},this.socket.onclose=()=>(this.socket=void 0,this.notify(__("Terminal connection closed")))):this.configure()}cleanup(t){if(this.socket)return this.socket.close()}menu(){return{text:"__(Edit)",nodes:[{text:"__(Terminal URI)",dataid:this.name+"-termuri"}],onchildselect:t=>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(t=>{if(t&&""!==t)return this.setting.uri=t,this.openSession()})}}).dependencies=["pkg://xTerm/main.js","pkg://xTerm/main.css"],this.OS.register("wTerm",t)}).call(this);