【发布时间】:2021-08-04 23:40:02
【问题描述】:
我正在使用 Go-Astilectron(Go 的 Electron 框架)创建一个应用程序。
我的应用有一个无框透明窗口,应根据其内容调整大小。据我所知,我有义务在 Electron 中设置窗口的 width 和 height 属性,否则它将默认为 800x600。
我想知道的是,Electron 是否有办法根据其内容自动调整窗口大小。
我可以使用“一刀切”的方法,但是由于我的窗口是无框透明的,它的某些部分最终会在其他东西之上,并且由于没有点击,用户会感到困惑以为他在点击其他应用程序,而他实际上是在点击我的应用程序。
这是我创建窗口的代码:
var w *astilectron.Window
log.Debug("Starting astilectron...")
window := []*bootstrap.Window{{
Homepage: "http://localhost:3000",
Adapter: func(i *astilectron.Window) {
w = i
},
Options: &astilectron.WindowOptions{
MinHeight: astilectron.PtrInt(50),
MinWidth: astilectron.PtrInt(50),
AlwaysOnTop: astilectron.PtrBool(true),
Transparent: astilectron.PtrBool(true),
Closable: astilectron.PtrBool(false),
Minimizable: astilectron.PtrBool(false),
Frame: astilectron.PtrBool(false),
Movable: astilectron.PtrBool(true),
SkipTaskbar: astilectron.PtrBool(false),
Resizable: astilectron.PtrBool(false),
},
}}
go func() {
err := bootstrap.Run(bootstrap.Options{
Windows: window,
Debug: true,
})
if err != nil {
log.WithError(err).Fatal("Error with Astilectron")
}
}()
【问题讨论】: