This commit is contained in:
lxsang 2019-06-11 18:33:30 +02:00
commit 8a9941f6ed
6 changed files with 120 additions and 3 deletions

3
package-lock.json generated Normal file
View File

@ -0,0 +1,3 @@
{
"lockfileVersion": 1
}

View File

@ -1,4 +1,4 @@
coffee_files = main.coffee coffee_files = extensions/extensions.coffee extensions/RemoteRunExtension.coffee main.coffee
jsfiles = jsfiles =

View File

@ -0,0 +1,68 @@
class RemoteRunExtension extends BaseExtension
constructor: () ->
super "RemoteRunExtension"
init: () ->
@_gui.htmlToScheme RemoteRunExtension.scheme, @, @host
main: () ->
me = @
@output = @find "output"
(@find "log-clear").set "onbtclick", (e) ->
me.log "clean"
(@find "restart").set "onbtclick", (e) ->
me.run()
@socket = null
# Now run the file
@run()
log: (t, m) ->
return $(@output).empty() if t is "clean"
p = ($ "<p>").attr("class", t.toLowerCase())[0]
$(p).html "#{t}: #{m.__()}"
($ @output).append p
($ @output).scrollTop @output.scrollHeight
run: () ->
me = @
return @log "ERROR", __("No target file found") unless @data
@gateway = @gw()
return @log "ERROR", __("No backend found for file: {0}", @data.path) unless @gateway
$((@find "stat")).html(@data.path)
@socket.close() if @socket
proto = if window.location.protocol is "https:" then "wss://" else "ws://"
@socket = new WebSocket proto + @_api.HOST + @gateway
@socket.onopen = () ->
#send data to server
me.socket.send( JSON.stringify {path:me.data.path} )
@socket.onmessage = (e) -> me.log "INFO", e.data if e.data
@socket.onclose = () ->
me.socket = null
console.log "socket closed"
gw: () ->
return unless @data
for k,v of RemoteRunExtension.backends
if @data.info.mime.match (new RegExp k, "g") then return v
return null
cleanup: (e)->
@socket.close() if @socket
RemoteRunExtension.backends = {
"text/lua": "/system/apigateway?ws=1"
}
RemoteRunExtension.scheme = """
<afx-app-window apptitle="RemoteRun Ouput" width="300" height="450" data-id="win-remote-run">
<afx-vbox >
<afx-hbox data-height="20" data-id="bottom-vbox">
<afx-button data-id = "restart" data-width="25" iconclass="fa fa-repeat"></afx-button>
<afx-button data-id = "log-clear" data-width="25" iconclass="fa fa-trash"></afx-button>
<div data-id="stat"></div>
</afx-hbox>
<div data-id="output"></div>
</afx-vbox>
</afx-app-window>
"""

View File

@ -0,0 +1,4 @@
class BaseExtension extends this.OS.GUI.BaseDialog
constructor: (name) ->
super name

View File

@ -126,6 +126,7 @@ class NotePad extends this.OS.GUI.BaseApplication
@bindKey "ALT-O", () -> me.actionFile "#{me.name}-Open" @bindKey "ALT-O", () -> me.actionFile "#{me.name}-Open"
@bindKey "CTRL-S", () -> me.actionFile "#{me.name}-Save" @bindKey "CTRL-S", () -> me.actionFile "#{me.name}-Save"
@bindKey "ALT-W", () -> me.actionFile "#{me.name}-Saveas" @bindKey "ALT-W", () -> me.actionFile "#{me.name}-Saveas"
@bindKey "ALT-R", () -> me.actionFile "#{me.name}-Run"
@open @currfile @open @currfile
open: (file) -> open: (file) ->
@ -266,7 +267,8 @@ class NotePad extends this.OS.GUI.BaseApplication
{ text: "__(New)", dataid: "#{@name}-New", shortcut: "A-N" }, { text: "__(New)", dataid: "#{@name}-New", shortcut: "A-N" },
{ text: "__(Open)", dataid: "#{@name}-Open", shortcut: "A-O" }, { text: "__(Open)", dataid: "#{@name}-Open", shortcut: "A-O" },
{ text: "__(Save)", dataid: "#{@name}-Save", shortcut: "C-S" }, { text: "__(Save)", dataid: "#{@name}-Save", shortcut: "C-S" },
{ text: "__(Save as)", dataid: "#{@name}-Saveas", shortcut: "A-W" } { text: "__(Save as)", dataid: "#{@name}-Saveas", shortcut: "A-W" },
{ text: "__(Run)", dataid: "#{@name}-Run", shortcut: "A-R" }
], ],
onmenuselect: (e) -> me.actionFile e.item.data.dataid onmenuselect: (e) -> me.actionFile e.item.data.dataid
}] }]
@ -301,7 +303,12 @@ class NotePad extends this.OS.GUI.BaseApplication
saveas() saveas()
when "#{@name}-New" when "#{@name}-New"
@open "Untitled".asFileHandler() @open "Untitled".asFileHandler()
when "#{@name}-Run"
if @currfile.dirty
return @notify __("Please save the file before running it")
else
if @dialog then @dialog.quit()
@openDialog new RemoteRunExtension(), null, null, @currfile
cleanup: (evt) -> cleanup: (evt) ->
dirties = ( v for v in @tabarea.get "items" when v.dirty ) dirties = ( v for v in @tabarea.get "items" when v.dirty )
return if dirties.length is 0 return if dirties.length is 0
@ -320,4 +327,5 @@ NotePad.dependencies = [
"ace/ext-modelist", "ace/ext-modelist",
"ace/ext-themelist" "ace/ext-themelist"
] ]
NotePad.extensions = {}
this.OS.register "NotePad", NotePad this.OS.register "NotePad", NotePad

View File

@ -43,3 +43,37 @@ afx-tab-bar[data-id="tabarea"] afx-list-view > div.list-container > ul > li.sel
background-color: #f6F6F6; background-color: #f6F6F6;
border-radius: 0; border-radius: 0;
} }
afx-app-window[data-id="win-remote-run"] div[data-id="output"] p{
margin:0;
padding:0;
font-family: "HermitLight";
text-align: left;
}
afx-app-window[data-id="win-remote-run"] div[data-id="output"]{
background-color: #2f3129;
padding: 10px;
color:white;
overflow: auto;
}
afx-app-window[data-id="win-remote-run"] div[data-id="stat"]{
background-color: #2f3129;
padding: 5px;
color:white;
font-weight: bold;
font-size: 10px;
}
afx-app-window[data-id="win-remote-run"] afx-resizer{
border-top: 1px solid #a6a6a6;
background-color: #2f3129;
border-right: 0;
}
afx-app-window[data-id="win-remote-run"] afx-hbox[data-id="bottom-vbox"] {
background-color:#2f3129;
}
afx-app-window[data-id="win-remote-run"] afx-hbox[data-id="bottom-vbox"] afx-button button{
background-color:#2f3129;
color:white;
border:0;
border-radius: 0;
}