scripting: add setFocus(id)

This commit is contained in:
bordun 2021-03-01 10:41:55 +01:00
parent b5446c08ac
commit e9a829b323
4 changed files with 35 additions and 1 deletions

View file

@ -326,8 +326,28 @@ class ScriptVm extends Vm {
}
this.sandbox.contentWindow.setFocus = (id)=>{
if (id) {
var widgets = this.resolveId(id)
if (widgets.length) {
setTimeout(()=>{
widgets[0].widget.focus()
})
}
}
// built-in client only: electron will call window.focus()
console.debug('ELECTRON.FOCUS()')
}
this.sandbox.contentWindow.unfocus = ()=>{
window.blur()
// built-in client only: electron will call window.blur()
console.debug('ELECTRON.BLUR()')
@ -354,7 +374,7 @@ class ScriptVm extends Vm {
}
for (var imports of ['set', 'get', 'getProp', 'getIndex', 'updateProp', 'send', 'httpGet', 'stateGet', 'stateSet', 'storage',
'setInterval', 'clearInterval', 'setTimeout', 'clearTimeout', 'unfocus', 'setScroll', 'getScroll', 'toolbar']) {
'setInterval', 'clearInterval', 'setTimeout', 'clearTimeout', 'setFocus', 'unfocus', 'setScroll', 'getScroll', 'toolbar']) {
this.sanitize(this.sandbox.contentWindow[imports])
}

View file

@ -101,6 +101,7 @@ module.exports = function(options={}) {
window.webContents.on('console-message', (event, level, message)=>{
if (level === 0 && message === 'ELECTRON.BLUR()') window.blur()
if (level === 0 && message === 'ELECTRON.FOCUS()') window.focus()
})