admin管理员组文章数量:1277322
I am working on an Electron app and as part of the interface I want to increase the size of the window once something has happened (I have bound this to a button for now) so I can display additional data. I have attempted to do this with the following code that is activated on a onclick=resize()
:
require('./renderer.js');
let remote = require('electron').remote;
function resize() {
let win = remote.getCurrentWindow().setBounds({
height: 1000
});
}
However, I am getting the following error in the window/browser console:
Uncaught Error: Could not call remote function 'setBounds'. Check that the function signature is correct. Underlying error: Error processing argument at index 0, conversion failure from #<Object>
Error: Could not call remote function 'setBounds'. Check that the function signature is correct. Underlying error: Error processing argument at index 0, conversion failure from #<Object>
at callFunction (C:\Users\Thomas\AppData\Roaming\npm\node_modules\electron\dist\resources\electron.asar\browser\rpc-server.js:257:11)
at EventEmitter.<anonymous> (C:\Users\Thomas\AppData\Roaming\npm\node_modules\electron\dist\resources\electron.asar\browser\rpc-server.js:357:5)
at emitMany (events.js:127:13)
at EventEmitter.emit (events.js:204:7)
at WebContents.<anonymous> (C:\Users\Thomas\AppData\Roaming\npm\node_modules\electron\dist\resources\electron.asar\browser\api\web-contents.js:256:13)
at emitTwo (events.js:106:13)
at WebContents.emit (events.js:194:7)
at callFunction (C:\Users\Thomas\AppData\Roaming\npm\node_modules\electron\dist\resources\electron.asar\browser\rpc-server.js:257:11)
at EventEmitter.<anonymous> (C:\Users\Thomas\AppData\Roaming\npm\node_modules\electron\dist\resources\electron.asar\browser\rpc-server.js:357:5)
at emitMany (events.js:127:13)
at EventEmitter.emit (events.js:204:7)
at WebContents.<anonymous> (C:\Users\Thomas\AppData\Roaming\npm\node_modules\electron\dist\resources\electron.asar\browser\api\web-contents.js:256:13)
at emitTwo (events.js:106:13)
at WebContents.emit (events.js:194:7)
at metaToValue (C:\Users\Thomas\AppData\Roaming\npm\node_modules\electron\dist\resources\electron.asar\renderer\api\remote.js:234:13)
at Object.remoteMemberFunction (C:\Users\Thomas\AppData\Roaming\npm\node_modules\electron\dist\resources\electron.asar\renderer\api\remote.js:118:18)
at resize (file:///D:/Documents/Development/Projects/ShortenMeURL/V1/index.html:41:45)
at HTMLButtonElement.onclick (file:///D:/Documents/Development/Projects/ShortenMeURL/V1/index.html:22:86)
Any suggestions on how I can fix this?
I am working on an Electron app and as part of the interface I want to increase the size of the window once something has happened (I have bound this to a button for now) so I can display additional data. I have attempted to do this with the following code that is activated on a onclick=resize()
:
require('./renderer.js');
let remote = require('electron').remote;
function resize() {
let win = remote.getCurrentWindow().setBounds({
height: 1000
});
}
However, I am getting the following error in the window/browser console:
Uncaught Error: Could not call remote function 'setBounds'. Check that the function signature is correct. Underlying error: Error processing argument at index 0, conversion failure from #<Object>
Error: Could not call remote function 'setBounds'. Check that the function signature is correct. Underlying error: Error processing argument at index 0, conversion failure from #<Object>
at callFunction (C:\Users\Thomas\AppData\Roaming\npm\node_modules\electron\dist\resources\electron.asar\browser\rpc-server.js:257:11)
at EventEmitter.<anonymous> (C:\Users\Thomas\AppData\Roaming\npm\node_modules\electron\dist\resources\electron.asar\browser\rpc-server.js:357:5)
at emitMany (events.js:127:13)
at EventEmitter.emit (events.js:204:7)
at WebContents.<anonymous> (C:\Users\Thomas\AppData\Roaming\npm\node_modules\electron\dist\resources\electron.asar\browser\api\web-contents.js:256:13)
at emitTwo (events.js:106:13)
at WebContents.emit (events.js:194:7)
at callFunction (C:\Users\Thomas\AppData\Roaming\npm\node_modules\electron\dist\resources\electron.asar\browser\rpc-server.js:257:11)
at EventEmitter.<anonymous> (C:\Users\Thomas\AppData\Roaming\npm\node_modules\electron\dist\resources\electron.asar\browser\rpc-server.js:357:5)
at emitMany (events.js:127:13)
at EventEmitter.emit (events.js:204:7)
at WebContents.<anonymous> (C:\Users\Thomas\AppData\Roaming\npm\node_modules\electron\dist\resources\electron.asar\browser\api\web-contents.js:256:13)
at emitTwo (events.js:106:13)
at WebContents.emit (events.js:194:7)
at metaToValue (C:\Users\Thomas\AppData\Roaming\npm\node_modules\electron\dist\resources\electron.asar\renderer\api\remote.js:234:13)
at Object.remoteMemberFunction (C:\Users\Thomas\AppData\Roaming\npm\node_modules\electron\dist\resources\electron.asar\renderer\api\remote.js:118:18)
at resize (file:///D:/Documents/Development/Projects/ShortenMeURL/V1/index.html:41:45)
at HTMLButtonElement.onclick (file:///D:/Documents/Development/Projects/ShortenMeURL/V1/index.html:22:86)
Any suggestions on how I can fix this?
Share Improve this question asked Dec 3, 2017 at 22:57 Thomas SmythThomas Smyth 5223 gold badges9 silver badges39 bronze badges 3-
1
Have you tried providing every props for rectangular object? Docs doesn't mark any prop as optional. And have you tried
setSize(w, h)
? – pergy Commented Dec 4, 2017 at 5:30 - @pergy that worked, thanks. Would you like to post it as an answer so I can give you the rep, etc. – Thomas Smyth Commented Dec 4, 2017 at 10:56
- Glad to hear! ;) posted it as answer! – pergy Commented Dec 4, 2017 at 18:28
3 Answers
Reset to default 6Definition of Rectangle
object (which is the first argument of setBounds
) is more strict than you expected. Since its properties don't have default values you have to define all of them.
For example:
remote.getCurrentWindow().setBounds({
x: 1621,
y: 611,
width: 10,
height: 1000
});
Also, if you want to adjust only size you can use setSize
of BrowserWindow
Just use plain old javascript from the renderer, I would not add an unnecessary messaging between main and renderer process if it is just a resize ;)
window.resizeTo(1000,900);
If anyone's getting a similar error, make sure you provide integer values, for example 123
, not 123,45
. Math.round
them to make sure.
I don't see a mention of this in the documentation sadly.
本文标签: javascriptElectronResize Window from renderer processStack Overflow
版权声明:本文标题:javascript - Electron - Resize Window from renderer process - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741291356a2370565.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论