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

Image of Datadog

Create and maintain end-to-end frontend tests

Learn best practices on creating frontend tests, testing on-premise apps, integrating tests into your CI/CD pipeline, and using Datadog’s testing tunnel.

Download The Guide

Top comments (0)

Heroku

This site is powered by Heroku

Heroku was created by developers, for developers. Get started today and find out why Heroku has been the platform of choice for brands like DEV for over a decade.

Sign Up

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay