自动尺寸主窗口

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")
    }
}()

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 .

Try setting UseContentSize: astilectron.PtrBool(true).

UseContentSize Resizes the window according to how big the page is. This is what it says in the documentation:

The width and height would be used as web page's size, which means the actual window's size will include window frame's size and be slightly larger. Default is false.

Docs