vTerm now start Antunnel service automatically if needed

This commit is contained in:
mrsang 2021-03-22 19:37:34 +01:00
parent 882b57dd87
commit 536446bca2
7 changed files with 16 additions and 9 deletions

View File

@ -1,5 +1,4 @@
local args=... local args=...
local web = require("web")
local vfs = require("vfs") local vfs = require("vfs")
if not args then if not args then

View File

@ -295,7 +295,7 @@
"description": "https://raw.githubusercontent.com/lxsang/antosdk-apps/master/vTerm/README.md", "description": "https://raw.githubusercontent.com/lxsang/antosdk-apps/master/vTerm/README.md",
"category": "System", "category": "System",
"author": "Xuan Sang LE", "author": "Xuan Sang LE",
"version": "0.1.12-a", "version": "0.1.13-a",
"dependencies": ["Antunnel@0.1.8-a","xTerm@4.8.1-r"], "dependencies": ["Antunnel@0.1.8-a","xTerm@4.8.1-r"],
"download": "https://raw.githubusercontent.com/lxsang/antosdk-apps/master/vTerm/build/release/vTerm.zip" "download": "https://raw.githubusercontent.com/lxsang/antosdk-apps/master/vTerm/build/release/vTerm.zip"
}, },

View File

@ -1 +1 @@
(function(){var t;(t=class extends this.OS.application.BaseApplication{constructor(t){super("vTerm",t)}main(){var t;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.bindKey("CTRL-SHIFT-C",t=>(this.mctxHandle({id:"copy"}),this.term.focus())),this.bindKey("CTRL-SHIFT-V",t=>this.mctxHandle({id:"paste"})),this.term.onKey(t=>{if(this.sub)return this.sub.send(Antunnel.Msg.DATA,new TextEncoder("utf-8").encode(t.key))}),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.systemsetting.desktop.menu[this.name]||(this.systemsetting.desktop.menu[this.name]={text:"__(Open terminal)",app:"vTerm"}),this.on("hboxchange",t=>this.resizeContent()),t=()=>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(t=>this.error(t.toString(),t)),this.quit()),window.Antunnel?t():(console.log("require Antunnel"),this._api.requires("pkg://Antunnel/main.js").then(()=>t()).catch(t=>(this.error(__("Unable to load Antunnel: {0}",t.toString()),t),this.quit())))}mctxHandle(t){var e,s;switch(t.id){case"paste":return e=t=>{if(t&&""!==t)return t=t.replace(/\n/g,"\r"),this.sub&&this.sub.send(Antunnel.Msg.DATA,new TextEncoder("utf-8").encode(t)),this.term.focus()},this._api.getClipboard().then(t=>e(t)).catch(t=>(this.error(__("Unable to paste"),t),this.openDialog("TextDialog",{title:"Paste text"}).then(t=>e(t)).catch(t=>this.error(t.toString(),t))));case"copy":if(!(s=this.term.getSelection())||""===s)return;return this._api.setClipboard(s)}}resizeContent(){var t,e,s;if(this.fitAddon.fit(),e=this.term.cols,s=this.term.rows,this.sub)return(t=new Uint8Array(8)).set(Antunnel.Msg.bytes_of(e),0),t.set(Antunnel.Msg.bytes_of(s),4),this.sub.send(Antunnel.Msg.CTRL,t)}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=t=>(this.error(__("Unable to connect to: vterm"),t),this.sub=void 0),this.sub.onmessage=t=>{if(this.term&&t.data)return this.term.write(new TextDecoder("utf-8").decode(t.data))},this.sub.onclose=()=>(this.sub=void 0,this.notify(__("Terminal connection closed")),this.quit()),this.tunnel.subscribe(this.sub)}cleanup(t){if(this.sub)return this.sub.close()}}).dependencies=["pkg://xTerm/main.js","pkg://xTerm/main.css","pkg://Antunnel/main.js"],this.OS.register("vTerm",t)}).call(this); (function(){var t;(t=class extends this.OS.application.BaseApplication{constructor(t){super("vTerm",t)}main(){var t;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.bindKey("CTRL-SHIFT-C",t=>(this.mctxHandle({id:"copy"}),this.term.focus())),this.bindKey("CTRL-SHIFT-V",t=>this.mctxHandle({id:"paste"})),this.term.onKey(t=>{if(this.sub)return this.sub.send(Antunnel.Msg.DATA,new TextEncoder("utf-8").encode(t.key))}),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.systemsetting.desktop.menu[this.name]||(this.systemsetting.desktop.menu[this.name]={text:"__(Open terminal)",app:"vTerm"}),this.on("hboxchange",t=>this.resizeContent()),t=()=>Antunnel.tunnel?(this.tunnel=Antunnel.tunnel,this.openSession()):this._gui.pushService("Antunnel/AntunnelService").then(t=>{if(this.systemsetting.system.tunnel_uri)return Antunnel.init(this.systemsetting.system.tunnel_uri).then(t=>(this.notify(__("Tunnel now connected to the server at: {0}",this.systemsetting.system.tunnel_uri)),this.tunnel=Antunnel.tunnel,this.openSession())).catch(t=>(Antunnel.tunnel&&Antunnel.tunnel.close(),this.error(__("Unable to connect to the tunnel: {0}",t.toString()),t),this.quit()))}).catch(t=>(this.error(__("Unable to run Antunnel service: {0}",t.toString()),t),this.quit())),window.Antunnel?t():this._api.requires("pkg://Antunnel/main.js").then(()=>t()).catch(t=>(this.error(__("Unable to load Antunnel: {0}",t.toString()),t),this.quit()))}mctxHandle(t){var e,n;switch(t.id){case"paste":return e=t=>{if(t&&""!==t)return t=t.replace(/\n/g,"\r"),this.sub&&this.sub.send(Antunnel.Msg.DATA,new TextEncoder("utf-8").encode(t)),this.term.focus()},this._api.getClipboard().then(t=>e(t)).catch(t=>(this.error(__("Unable to paste"),t),this.openDialog("TextDialog",{title:"Paste text"}).then(t=>e(t)).catch(t=>this.error(t.toString(),t))));case"copy":if(!(n=this.term.getSelection())||""===n)return;return this._api.setClipboard(n)}}resizeContent(){var t,e,n;if(this.fitAddon.fit(),e=this.term.cols,n=this.term.rows,this.sub)return(t=new Uint8Array(8)).set(Antunnel.Msg.bytes_of(e),0),t.set(Antunnel.Msg.bytes_of(n),4),this.sub.send(Antunnel.Msg.CTRL,t)}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=t=>(this.error(__("Unable to connect to: vterm"),t),this.sub=void 0),this.sub.onmessage=t=>{if(this.term&&t.data)return this.term.write(new TextDecoder("utf-8").decode(t.data))},this.sub.onclose=()=>(this.sub=void 0,this.notify(__("Terminal connection closed")),this.quit()),this.tunnel.subscribe(this.sub)}cleanup(t){if(this.sub)return this.sub.close()}}).dependencies=["pkg://xTerm/main.js","pkg://xTerm/main.css","pkg://Antunnel/main.js"],this.OS.register("vTerm",t)}).call(this);

View File

@ -6,7 +6,7 @@
"author": "Xuan Sang LE", "author": "Xuan Sang LE",
"email": "xsang.le@gmail.com" "email": "xsang.le@gmail.com"
}, },
"version":"0.1.12-a", "version":"0.1.13-a",
"category":"System", "category":"System",
"iconclass":"fa fa-terminal", "iconclass":"fa fa-terminal",
"mimes":["none"], "mimes":["none"],

Binary file not shown.

View File

@ -61,17 +61,25 @@ class vTerm extends this.OS.application.BaseApplication
checklib = () => checklib = () =>
if not Antunnel.tunnel if not Antunnel.tunnel
@error __("The Antunnel service is not started, please start it first")
@_gui.pushService("Antunnel/AntunnelService") @_gui.pushService("Antunnel/AntunnelService")
.then (d) =>
return unless @systemsetting.system.tunnel_uri
Antunnel.init(@systemsetting.system.tunnel_uri).then (t) =>
@notify __("Tunnel now connected to the server at: {0}", @systemsetting.system.tunnel_uri)
@tunnel = Antunnel.tunnel
@openSession()
.catch (e) => .catch (e) =>
@error e.toString(), e Antunnel.tunnel.close() if Antunnel.tunnel
@error __("Unable to connect to the tunnel: {0}", e.toString()), e
@quit()
.catch (e) =>
@error __("Unable to run Antunnel service: {0}",e.toString()), e
@quit() @quit()
else else
@tunnel = Antunnel.tunnel @tunnel = Antunnel.tunnel
@openSession() @openSession()
if not window.Antunnel if not window.Antunnel
console.log "require Antunnel"
@_api.requires("pkg://Antunnel/main.js").then () => @_api.requires("pkg://Antunnel/main.js").then () =>
checklib() checklib()
.catch (e) => .catch (e) =>

View File

@ -6,7 +6,7 @@
"author": "Xuan Sang LE", "author": "Xuan Sang LE",
"email": "xsang.le@gmail.com" "email": "xsang.le@gmail.com"
}, },
"version":"0.1.12-a", "version":"0.1.13-a",
"category":"System", "category":"System",
"iconclass":"fa fa-terminal", "iconclass":"fa fa-terminal",
"mimes":["none"], "mimes":["none"],