DEV Community

Cover image for Creating desktop applications in Golang
energy
energy

Posted on

Creating desktop applications in Golang


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

Enter fullscreen mode Exit fullscreen mode

demo preview

Heroku

Deliver your unique apps, your own way.

Heroku tackles the toil — patching and upgrading, 24/7 ops and security, build systems, failovers, and more. Stay focused on building great data-driven applications.

Learn More

Top comments (0)

Image of PulumiUP 2025

Let's talk about the current state of cloud and IaC, platform engineering, and security.

Dive into the stories and experiences of innovators and experts, from Startup Founders to Industry Leaders at PulumiUP 2025.

Register Now

👋 Kindness is contagious

Dive into this informative piece, backed by our vibrant DEV Community

Whether you’re a novice or a pro, your perspective enriches our collective insight.

A simple “thank you” can lift someone’s spirits—share your gratitude in the comments!

On DEV, the power of shared knowledge paves a smoother path and tightens our community ties. Found value here? A quick thanks to the author makes a big impact.

Okay