Skip to content

Commit

Permalink
add nyaovim#browser_window runtime API
Browse files Browse the repository at this point in the history
  • Loading branch information
rhysd committed Oct 19, 2016
1 parent 65521dd commit 58bb597
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
10 changes: 10 additions & 0 deletions docs/runtime-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,16 @@ call nyaovim#execute_javascript('(function(){

TODO: This function currently doesn't return the result of evaluating JavaScript.

### `nyaovim#browser_window(method, args)`

Call [`BrowserWindow` API in Electron](https://github.com/electron/electron/blob/master/docs/api/browser-window.md) for the main window. This function is currently using notification. So Vim script side can't receive the return value.

```vim
" Calls `window.setFullScreen(true);` in the main window
call nyaovim#browser_window('setFullScreen', [v:true])
```


## Subscriable events

With Neovim msgpack API, you can receive rpc nortifications.
Expand Down
9 changes: 8 additions & 1 deletion renderer/nyaovim-app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,14 @@ const runtime_api = new RuntimeApi({
eval(code);
/* tslint:enable */
} catch (e) {
console.error('While executing javascript:', e);
console.error('While executing javascript:', e, ' Code:', code);
}
},
'nyaovim:browser-window': (method: string, args: RPCValue[]) => {
try {
(ThisBrowserWindow as any)[method].apply(ThisBrowserWindow, args);
} catch (e) {
console.error("Error while executing 'nyaovim:browser-window':", e, ' Method:', method, ' Args:', args);
}
},
});
Expand Down
5 changes: 5 additions & 0 deletions runtime/autoload/nyaovim.vim
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,8 @@ endfunction
function! nyaovim#execute_javascript(code) abort
call rpcnotify(0, 'nyaovim:execute-javascript', a:code)
endfunction

" TODO: Send request and get the return value
function! nyaovim#browser_window(method, args) abort
call rpcnotify(0, 'nyaovim:browser-window', a:method, a:args)
endfunction

0 comments on commit 58bb597

Please sign in to comment.