Closed nkoporec closed 3 years ago
You have 2 options :
go-astilectron
only and you develop yourself all the embed/disembed logicgo-astilectron
, go-astilectron-bundler
and go-astilectron-bootstrap
to make the most of the already developed embed/disembed logicI strongly recommend the 2nd option.
Bottom line is, if you want to use the bundler
, you have to use the bootstrap
in your project.
Luckily for you, it's not that complicated. Your project would look something like :
var (
VersionAstilectron string
VersionElectron string
)
func main() {
// Create logger
l := log.New(log.Writer(), log.Prefix(), log.Flags())
// Run bootstrap
if err := bootstrap.Run(bootstrap.Options{
Asset: Asset,
AssetDir: AssetDir,
AstilectronOptions: astilectron.Options{
AppName: "Ginker",
BaseDirectoryPath: "resources",
AppIconDarwinPath: "icon.ico",
AppIconDefaultPath: "icon.png",
SingleInstance: true,
},
Logger: l,
MenuOptions: menuItems(),
OnWait: func(_ *astilectron.Astilectron, ws []*astilectron.Window, _ *astilectron.Menu, _ *astilectron.Tray, _ *astilectron.Menu) error {
// This will listen to messages sent by Javascript
ws[0].OnMessage(func(m *astilectron.EventMessage) interface{} {
e := handleEvent(m)
return e
})
return nil
},
RestoreAssets: RestoreAssets,
Windows: []*bootstrap.Window{{
Homepage: "resources/app/dist/index.html",
MessageHandler: handleMessages,
Options: &astilectron.WindowOptions{
Center: astikit.BoolPtr(true),
Height: astikit.IntPtr(700),
Width: astikit.IntPtr(700),
},
}},
}); err != nil {
l.Fatal(fmt.Errorf("running bootstrap failed: %w", err))
}
}
At first, Asset
, AssetDir
and RestoreAssets
will be unknown but once you run the bundler, they will be created.
You'll also have to adapt a bit menuItems
and create handleMessages
even if it does nothing.
Let me know if that answers your question.
Yes, thanks for the explanation and the code snippet.
I have a small application that has a one window. I have used the default go-astilectron without the bootstrap package and when running locally (using go run *.go) everything works as expected. When I compile using your bundler package then resources are not added to the output (only .exe, .dmg files are created), the end result is an application that shows a blank window. because it's missing all the html / css / js files.
I have searched the issues and every example is using the bootstrap package, so I'm wondering if this is a required step in order to embed resources ? Do I need to convert my existing code and use the bootstrap ?
Here is the astilectron part of my code: