dev-resources.site
for different kinds of informations.
Creating desktop applications in Golang
Published at
6/11/2023
Categories
cef
energy
gui
go
Author
yanghy
Author
6 person written this
yanghy
open
package main
import (
"embed"
"fmt"
"github.com/energye/energy/v2/cef"
"github.com/energye/energy/v2/cef/ipc"
"github.com/energye/energy/v2/cef/ipc/context"
"github.com/energye/energy/v2/common"
"github.com/energye/energy/v2/pkgs/assetserve"
"github.com/energye/golcl/lcl/rtl/version"
)
//go:embed resources
var resources embed.FS
func main() {
cef.GlobalInit(nil, &resources)
cefApp := cef.NewApplication()
cef.BrowserWindow.Config.Url = "http://localhost:22022/index.html"
if common.IsLinux() {
cef.BrowserWindow.Config.IconFS = "resources/icon.png"
} else {
cef.BrowserWindow.Config.IconFS = "resources/icon.ico"
}
if !common.IsDarwin() {
cef.BrowserWindow.Config.EnableHideCaption = true
}
cef.BrowserWindow.Config.Title = "Energy Vue + ElementUI Demo"
cef.BrowserWindow.Config.Width = 1200
chromiumConfig := cef.BrowserWindow.Config.ChromiumConfig()
chromiumConfig.SetEnableMenu(false)
ipc.On("window-state", func(context context.IContext) {
bw := cef.BrowserWindow.GetWindowInfo(context.BrowserId())
state := context.ArgumentList().GetIntByIndex(0)
if state == 0 {
bw.Minimize()
} else if state == 1 {
bw.Maximize()
}
})
ipc.On("window-close", func(context context.IContext) {
bw := cef.BrowserWindow.GetWindowInfo(context.BrowserId())
bw.CloseBrowserWindow()
})
ipc.On("os-info", func(context context.IContext) {version.OSVersion.ToString())
context.Result(version.OSVersion.ToString())
})
cef.BrowserWindow.SetBrowserInit(func(event *cef.BrowserEvent, window cef.IBrowserWindow) {
//
})
cef.SetBrowserProcessStartAfterCallback(func(b bool) {
server := assetserve.NewAssetsHttpServer()
server.PORT = 22022
server.AssetsFSName = "resources"
server.Assets = &resources
go server.StartHttpServer()
})
cef.Run(cefApp)
}
cef Article's
3 articles in total
A New Era of Cross-Platform Desktop Application Development in Go Language: A Comprehensive Analysis of LCL, CEF, and Webview
read article
Creating desktop applications in Golang
currently reading
Building cross platform desktop applications using JavaScript, HTML, and CSS in GO
read article
Featured ones: