gpt4 book ai didi

javascript - Electron - 从渲染器进程调整窗口大小

转载 作者:行者123 更新时间:2023-11-30 11:27:03 25 4
gpt4 key购买 nike

我正在开发一个 Electron 应用程序,作为界面的一部分,我想在发生某些事情后增加窗口的大小(我现在已将其绑定(bind)到一个按钮),以便我可以显示其他数据。我尝试使用在 onclick=resize() 上激活的以下代码来执行此操作:

require('./renderer.js');

let remote = require('electron').remote;
function resize() {
let win = remote.getCurrentWindow().setBounds({
height: 1000
});
}

但是,我在窗口/浏览器控制台中收到以下错误:

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)

关于如何解决这个问题有什么建议吗?

最佳答案

Rectangle的定义对象(这是 setBounds 的第一个参数)比您预期的更严格。由于它的属性没有默认值,因此您必须定义所有这些属性。

例如:

remote.getCurrentWindow().setBounds({
x: 1621,
y: 611,
width: 10,
height: 1000
});

此外,如果您只想调整尺寸,您可以使用 setSize浏览器窗口

关于javascript - Electron - 从渲染器进程调整窗口大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47624252/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com