dongqiao6730 2018-12-13 18:29
浏览 235

自动尺寸主窗口

I am creating an app using Go-Astilectron (an Electron framework for Go).

My app has a frameless and transparent window that should be resized depending on its content. As far as I could tell, I am obligated to set the width and height properties of a Window in Electron, otherwise it will default to 800x600.

What I would like to know is if there is a way for Electron to automatically resize the window based on its content.

I could use a "One Size Fits All" approach, but since my window is frameless and transparent, some parts of it will eventually be on top of other things, and since there is not click through, the user will get confused thinking that he is clicking on some other application, when he is actually clicking on my app.

Here is my code to create the window:

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")
    }
}()
  • 写回答

2条回答 默认 最新

  • douchao0358 2018-12-13 18:46
    关注

    try to do something like this

      const { screen } = require('electron');
      const size = screen.getPrimaryDisplay().workAreaSize;
      // Create the browser window.
      mainWindow = new BrowserWindow({
       x: 0,
       y: 0,
       width: size.width,
      height: size.height
    });
    

    Hope it will work .

    评论

报告相同问题?

悬赏问题

  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 AT89C51控制8位八段数码管显示时钟。
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题