...
 
Commits (14)
    https://gitcode.net/energye/energy/-/commit/0f4516544a072398c3ad598b9365752368d6696b U: examples, build 2023-07-26T14:46:14+08:00 yanghy snxamdf@126.com https://gitcode.net/energye/energy/-/commit/964b0bbbfe6b549debd0dcfa061962d704986adc U: CEFWindowParent, Add SetFocus, CanFocus Proc Api 2023-07-26T22:39:36+08:00 yanghy snxamdf@126.com https://gitcode.net/energye/energy/-/commit/cd9b7f7e583966009fe897322b6b8e22a740dc81 U: Correcting incorrect annotation instructions 2023-08-14T11:20:38+08:00 杨红岩 snxamdf@126.com https://gitcode.net/energye/energy/-/commit/2898c483dc9bdc875bd6545b03bc9d5361031215 U: README link 2023-08-14T11:34:02+08:00 杨红岩 snxamdf@126.com https://gitcode.net/energye/energy/-/commit/17ab5ca20f9e72ba7670dd1d1433a07ff3697961 U: command-line tool 2023-08-14T11:59:46+08:00 杨红岩 snxamdf@126.com https://gitcode.net/energye/energy/-/commit/930c2ce4d7493d5e42bfd853183f6cba05eeeaca Upgrade: golcl 2023-08-14T20:43:29+08:00 杨红岩 snxamdf@126.com https://gitcode.net/energye/energy/-/commit/0d7b0990d3306262a93cf62676fcd98a2928685f A: demo default-hidden-window 2023-08-14T20:54:29+08:00 杨红岩 snxamdf@126.com https://gitcode.net/energye/energy/-/commit/613acf183c915012b854025ff7916577ba13653f A: demo clipbrd 2023-08-14T23:12:11+08:00 杨红岩 snxamdf@126.com https://gitcode.net/energye/energy/-/commit/3dea5826843c9c1b1943202a0d191e8eca67cab0 A: demo audio-video 2023-08-15T11:29:39+08:00 杨红岩 snxamdf@126.com https://gitcode.net/energye/energy/-/commit/843c89c165be1f8ad0fcc24ea3598eab37330780 U: demo build-examples 2023-08-15T11:32:57+08:00 杨红岩 snxamdf@126.com https://gitcode.net/energye/energy/-/commit/840f015cbe704719376cc4d1d39cf5aa06a8de71 U: demo audio-video 2023-08-15T11:36:12+08:00 杨红岩 snxamdf@126.com https://gitcode.net/energye/energy/-/commit/c1ba58bc15dcf42d5a7760eff2e49d6df890897a A: demo, window-for-hidden, window-for-minimize, default-hidden-window 2023-08-15T15:49:33+08:00 杨红岩 snxamdf@126.com https://gitcode.net/energye/energy/-/commit/1d26c0e90ad6947438ecbd55de99e6eb097c7b94 A: demo, window-for-hidden, window-for-minimize, default-hidden-window 2023-08-15T15:50:00+08:00 杨红岩 snxamdf@126.com https://gitcode.net/energye/energy/-/commit/7fe162efdae63d7cb815c3d842fd5103d7530d53 A: demo, window-for-hidden, window-for-minimize, default-hidden-window 2023-08-15T15:51:01+08:00 杨红岩 snxamdf@126.com
......@@ -20,7 +20,7 @@ English
![go-version](https://img.shields.io/github/go-mod/go-version/energye/energy?logo=git&logoColor=green)
---
### [Project Introduction](https://energy.yanghy.cn/#/course/6342d92c401bfe4d0cdf6065/6350f94ca749ba0318943f25)
### [Project Introduction](https://energy.yanghy.cn/course/100/6350f94ca749ba0318943f25)
Energy is a framework developed by Golang based on CEF(Chromium Embedded Framework), embedded
with [CEF](https://bitbucket.org/chromiumembedded/cef) binary
......@@ -52,7 +52,7 @@ with [CEF](https://bitbucket.org/chromiumembedded/cef) binary
- [![LCL](https://img.shields.io/badge/LCL-green)](https://github.com/energye/golcl)
- [![CEF-CEF4Delphi](https://img.shields.io/badge/CEF(Chromium%20Embedded%20Framework)%20CEF4Delphi-green)](https://github.com/salvadordf/CEF4Delphi)
### [Development environment](https://energy.yanghy.cn/#/course/6342d92c401bfe4d0cdf6065/63511b14a749ba0318943f3a)
### [Development environment](https://energy.yanghy.cn/course/100/63511b14a749ba0318943f3a)
> Install automatically using the energy command line tool
......@@ -65,7 +65,7 @@ with [CEF](https://bitbucket.org/chromiumembedded/cef) binary
> Use the energy command line tool to automatically install the development environment
>
> Get [energy](https://github.com/energye/energy) project, or use the precompiled command line tool
> directly [Download address](https://energy.yanghy.cn/#/course/6342d92c401bfe4d0cdf6065/63511b14a749ba0318943f3a)
> directly [Download address](https://energy.yanghy.cn/course/100/63511b14a749ba0318943f3a)
>
> <p style="color:palevioletred;">If using pre compiled command-line tools, the following steps can be skipped</p>
>
......@@ -85,9 +85,9 @@ with [CEF](https://bitbucket.org/chromiumembedded/cef) binary
### Getting Started Guide - [Transfer gate](https://energy.yanghy.cn)
* [Course](https://energy.yanghy.cn/#/course/6342d92c401bfe4d0cdf6065/6350f94ca749ba0318943f25)
* [Example](https://energy.yanghy.cn/#/example/6342d986401bfe4d0cdf6067/634d3bd5a749ba0318943eb6)
* [Document](https://energy.yanghy.cn/#/document/6342d9a4401bfe4d0cdf6069/0)
* [Course](https://energy.yanghy.cn/course/100/0)
* [Example](https://energy.yanghy.cn/example/200/0)
* [Document](https://energy.yanghy.cn/document/300/0)
### Quick Get Start
......@@ -135,7 +135,7 @@ func main() {
> `go run simple.go energy_env=dev`
### Pack Project [reference](https://energy.yanghy.cn/#/course/6342d92c401bfe4d0cdf6065/636e397ba749ba01d04ff595)
### Pack Project [reference](https://energy.yanghy.cn/course/100/636e397ba749ba01d04ff595)
1. Compile: Go program compilation `go build simple.go` If you use resource built-in (HTML, CSS, JavaScript, Image,
etc.), the resource will be compiled into the execution file
......
......@@ -21,7 +21,7 @@
![go-version](https://img.shields.io/github/go-mod/go-version/energye/energy?logo=git&logoColor=green)
---
### [项目简介](https://energy.yanghy.cn/#/course/6342d92c401bfe4d0cdf6065/6350f94ca749ba0318943f25)
### [项目简介](https://energy.yanghy.cn/course/100/6350f94ca749ba0318943f25)
> [energy](https://github.com/energye/energy) 是 Go 基于 CEF(Chromium Embedded Framework)
> 开发的框架,内嵌 [CEF](https://bitbucket.org/chromiumembedded/cef) 二进制
......@@ -45,7 +45,7 @@
- [![LCL](https://img.shields.io/badge/LCL-green)](https://github.com/energye/golcl)
- [![CEF-CEF4Delphi](https://img.shields.io/badge/CEF(Chromium%20Embedded%20Framework)%20CEF4Delphi-green)](https://github.com/salvadordf/CEF4Delphi)
### [开发环境](https://energy.yanghy.cn/#/course/6342d92c401bfe4d0cdf6065/63511b14a749ba0318943f3a)
### [开发环境](https://energy.yanghy.cn/course/100/63511b14a749ba0318943f3a)
#### 基本需求
......@@ -54,7 +54,7 @@
>
> 使用 energy 命令行工具自动安装开发环境
>
> 获取 [energy](https://github.com/energye/energy) 项目,或直接使用预编译命令行工具 [下载地址](https://energy.yanghy.cn/#/course/6342d92c401bfe4d0cdf6065/63511b14a749ba0318943f3a)
> 获取 [energy](https://github.com/energye/energy) 项目,或直接使用预编译命令行工具 [下载地址](https://energy.yanghy.cn/course/100/63511b14a749ba0318943f3a)
>
> <p style="color:palevioletred;">如果使用预编译命令行工具以下步骤可跳过</p>
>
......@@ -74,9 +74,9 @@
### 入门指南 - [传送门](https://energy.yanghy.cn)
* [教程](https://energy.yanghy.cn/#/course/6342d92c401bfe4d0cdf6065/6350f94ca749ba0318943f25)
* [示例](https://energy.yanghy.cn/#/example/6342d986401bfe4d0cdf6067/634d3bd5a749ba0318943eb6)
* [文档](https://energy.yanghy.cn/#/document/6342d9a4401bfe4d0cdf6069/0)
* [教程](https://energy.yanghy.cn/course/100/0)
* [示例](https://energy.yanghy.cn/example/200/0)
* [文档](https://energy.yanghy.cn/document/300/0)
### 快速入门
......@@ -118,7 +118,7 @@ func main() {
- MacOS
> `go run simple.go energy_env=dev`
### 项目打包 [参考](https://energy.yanghy.cn/#/course/6342d92c401bfe4d0cdf6065/636e397ba749ba01d04ff595)
### 项目打包 [参考](https://energy.yanghy.cn/course/100/636e397ba749ba01d04ff595)
1. 编译:Go 程序编译`go build simple.go` 如果使用资源内置(HTML、CSS、JavaScript、Image等等)会把资源编译到执行文件内
2. 复制:把执行文件复制到ENERGY环境的CEF目录中即可
3. 打包:使用制作安装包工具将其制作为安装包, 查阅各系统平台安装包制作
......
......@@ -23,7 +23,7 @@ import (
var (
//BrowserWindow 是基于LCL和VF窗口组件的浏览器主窗口
// 可以对窗口的属性设置和事件监听,Chromium的配置和事件监听.
// 该窗口是主窗体,因此初始化时必须第一个初始化完成,如果创建子窗口最好在 SetBrowserInitAfter 回调函数中创建
// 该窗口是主窗体,因此初始化时必须第一个初始化完成
// VF 窗口组件默认在Linux平台
// LCL窗口组件默认在Windows、MacOSX平台
BrowserWindow = &browserWindow{
......
......@@ -31,7 +31,7 @@ func createDevtoolsWindow(owner *LCLBrowserWindow) *devToolsWindow {
window.TForm = lcl.NewForm(owner)
window.SetCaption(devToolsName)
window.SetIcon(owner.Icon())
window.SetWindowParent(NewCEFWindow(window))
window.SetWindowParent(NewCEFWindowParent(window))
window.WindowParent().SetParent(window)
window.WindowParent().SetAlign(types.AlClient)
window.SetWidth(1024)
......
......@@ -25,7 +25,7 @@ type BaseWinControl struct {
// IsValid 是否有效
func (m *BaseWinControl) IsValid() bool {
return m.instance != nil
return m != nil && m.instance != nil
}
// Instance 当前实例
......
......@@ -504,6 +504,11 @@ func (m *LCLBrowserWindow) ChromiumCreate(config *TCefChromiumConfig, defaultUrl
}
m.Chromium().SendCaptureLostEvent()
})
m.Chromium().SetOnGotFocus(func(sender lcl.IObject, browser *ICefBrowser) {
if m.IsValid() {
m.WindowParent().SetFocus()
}
})
// 主窗口、子窗口chromium检测
if m.WindowProperty().WindowType != consts.WT_DEV_TOOLS {
window.CurrentBrowseWindowCache = m
......
......@@ -41,7 +41,7 @@ type TCEFChromiumBrowser struct {
func NewChromiumBrowser(owner lcl.IWinControl, config *TCefChromiumConfig) ICEFChromiumBrowser {
var m = new(TCEFChromiumBrowser)
m.chromium = NewChromium(owner, config)
m.windowParent = NewCEFWindow(owner)
m.windowParent = NewCEFWindowParent(owner)
m.windowParent.SetParent(owner)
m.windowParent.SetChromium(m.chromium, 0)
m.createTimer = lcl.NewTimer(owner)
......
......@@ -557,6 +557,8 @@ const (
CEFWindow_OnExit
CEFWindow_SetTag
CEFWindow_GetTag
CEFWindow_SetFocus
CEFWindow_CanFocus
// TCEFLinkedWindowParent
CEFLinkedWindow_Create
CEFLinkedWindow_GetHandle
......@@ -591,6 +593,8 @@ const (
CEFLinkedWindow_SetChromium
CEFLinkedWindow_SetTag
CEFLinkedWindow_GetTag
CEFLinkedWindow_SetFocus
CEFLinkedWindow_CanFocus
// ICefBrowser
CEFBrowser_ShowDevTools
CEFBrowser_CloseDevTools
......
......@@ -557,6 +557,8 @@ func init() {
dllimports.NewEnergyImport("CEFWindow_OnExit", 0),
dllimports.NewEnergyImport("CEFWindow_SetTag", 0),
dllimports.NewEnergyImport("CEFWindow_GetTag", 0),
dllimports.NewEnergyImport("CEFWindow_SetFocus", 0),
dllimports.NewEnergyImport("CEFWindow_CanFocus", 0),
//CEFLinkedParentWindow
dllimports.NewEnergyImport("CEFLinkedWindow_Create", 0),
dllimports.NewEnergyImport("CEFLinkedWindow_GetHandle", 0),
......@@ -591,6 +593,8 @@ func init() {
dllimports.NewEnergyImport("CEFLinkedWindow_SetChromium", 0),
dllimports.NewEnergyImport("CEFLinkedWindow_SetTag", 0),
dllimports.NewEnergyImport("CEFLinkedWindow_GetTag", 0),
dllimports.NewEnergyImport("CEFLinkedWindow_SetFocus", 0),
dllimports.NewEnergyImport("CEFLinkedWindow_CanFocus", 0),
//ICefBrowser
dllimports.NewEnergyImport("CEFBrowser_ShowDevTools", 0),
dllimports.NewEnergyImport("CEFBrowser_CloseDevTools", 0),
......
......@@ -231,7 +231,7 @@ func (m *CEFTray) createTrayWindow() {
})
}
})
m.windowParent = NewCEFWindow(m.TForm)
m.windowParent = NewCEFWindowParent(m.TForm)
m.windowParent.SetParent(m.TForm)
m.windowParent.SetAlign(types.AlClient)
m.windowParent.SetAnchors(types.NewSet(types.AkTop, types.AkLeft, types.AkRight, types.AkBottom))
......
......@@ -13,13 +13,14 @@
package cef
import (
"github.com/energye/energy/v2/common"
"github.com/energye/energy/v2/consts"
"github.com/energye/golcl/lcl"
"github.com/energye/golcl/lcl/types"
)
// ICEFWindowParent 接口定义
// Windows return TCEFWindowParent
// MacOSX, Linux return TCEFLinkedWindowParent
type ICEFWindowParent interface {
lcl.IWinControl
Instance() uintptr
......@@ -58,17 +59,6 @@ type ICEFWindowParent interface {
SetBoundsRect(value types.TRect) // 设置矩形边界
point() (x, y int32) // 坐标点
size() (w, h int32) // 大小
}
// NewCEFWindow 创建CEFWindowParent
//
// # Windows return TCEFWindowParent
//
// MacOSX, Linux return TCEFLinkedWindowParent
func NewCEFWindow(owner lcl.IComponent) ICEFWindowParent {
if common.IsWindows() {
return NewCEFWindowParent(owner)
} else {
return NewCEFLinkedWindowParent(owner)
}
SetFocus() //
CanFocus() bool //
}
......@@ -8,6 +8,8 @@
//
//----------------------------------------
//go:build !windows
// CEFWindowParent组件
// MacOSX, Linux
......@@ -29,8 +31,8 @@ type TCEFLinkedWindowParent struct {
x, y, w, h int32
}
// NewCEFLinkedWindowParent 创建一个新的WindowParent组件
func NewCEFLinkedWindowParent(owner lcl.IComponent) *TCEFLinkedWindowParent {
// NewCEFWindowParent 创建一个新的 TCEFLinkedWindowParent 组件
func NewCEFWindowParent(owner lcl.IComponent) *TCEFLinkedWindowParent {
m := new(TCEFLinkedWindowParent)
r1, _, _ := imports.Proc(def.CEFLinkedWindow_Create).Call(lcl.CheckPtr(owner))
m.instance = unsafe.Pointer(r1)
......@@ -248,3 +250,12 @@ func (m *TCEFLinkedWindowParent) point() (x, y int32) {
func (m *TCEFLinkedWindowParent) size() (w, h int32) {
return m.w, m.h
}
func (m *TCEFLinkedWindowParent) SetFocus() {
imports.Proc(def.CEFWindow_SetFocus).Call(m.Instance())
}
func (m *TCEFLinkedWindowParent) CanFocus() bool {
r1, _, _ := imports.Proc(def.CEFWindow_CanFocus).Call(m.Instance())
return api.GoBool(r1)
}
......@@ -8,6 +8,8 @@
//
//----------------------------------------
//go:build windows
package cef
import (
......@@ -26,7 +28,7 @@ type TCEFWindowParent struct {
x, y, w, h int32
}
// NewCEFWindowParent 创建一个新的WindowParent组件
// NewCEFWindowParent 创建一个新的 TCEFWindowParent 组件
func NewCEFWindowParent(owner lcl.IComponent) *TCEFWindowParent {
m := new(TCEFWindowParent)
r1, _, _ := imports.Proc(def.CEFWindow_Create).Call(lcl.CheckPtr(owner))
......@@ -244,3 +246,12 @@ func (m *TCEFWindowParent) point() (x, y int32) {
func (m *TCEFWindowParent) size() (w, h int32) {
return m.w, m.h
}
func (m *TCEFWindowParent) SetFocus() {
imports.Proc(def.CEFLinkedWindow_SetFocus).Call(m.Instance())
}
func (m *TCEFWindowParent) CanFocus() bool {
r1, _, _ := imports.Proc(def.CEFLinkedWindow_CanFocus).Call(m.Instance())
return api.GoBool(r1)
}
......@@ -13,12 +13,12 @@ package internal
import "runtime"
const (
cefKey = "cef"
energyKey = "energy"
download_version_config_url = "https://energy.yanghy.cn/autoconfig/edv.json"
download_extract_url = "https://energy.yanghy.cn/autoconfig/extract.json"
frameworkCache = "EnergyFrameworkDownloadCache"
ENERGY_HOME_KEY = "ENERGY_HOME"
cefKey = "cef"
energyKey = "energy"
downloadVersionConfigUrl = "https://energy.yanghy.cn/autoconfig/edv.json"
downloadExtractUrl = "https://energy.yanghy.cn/autoconfig/extract.json"
frameworkCache = "EnergyFrameworkDownloadCache"
EnergyHomeKey = "ENERGY_HOME"
)
const (
......
......@@ -28,7 +28,7 @@ func init() {
}
func runGetEnv(c *CommandConfig) error {
envPath := os.Getenv(ENERGY_HOME_KEY)
envPath := os.Getenv(EnergyHomeKey)
println("ENERGY_HOME_KEY", envPath)
return nil
}
......@@ -107,7 +107,7 @@ Your current installation environment is Linux and there are two GTK solutions a
os.MkdirAll(installPathName, fs.ModePerm)
os.MkdirAll(filepath.Join(c.Install.Path, frameworkCache), fs.ModePerm)
println("Start downloading CEF and Energy dependency")
downloadJSON, err := downloadConfig(download_version_config_url)
downloadJSON, err := downloadConfig(downloadVersionConfigUrl)
if err != nil {
fmt.Fprint(os.Stderr, err.Error()+"\n")
os.Exit(1)
......@@ -171,7 +171,7 @@ Your current installation environment is Linux and there are two GTK solutions a
downloadEnergyURL = strings.ReplaceAll(downloadEnergyURL, "{OSARCH}", libEnergyOS)
//提取文件配置
extractData, err := downloadConfig(download_extract_url)
extractData, err := downloadConfig(downloadExtractUrl)
if err != nil {
fmt.Fprint(os.Stderr, err.Error(), "\n")
os.Exit(1)
......@@ -232,7 +232,7 @@ Your current installation environment is Linux and there are two GTK solutions a
println("Remove file", rmFile)
os.Remove(rmFile)
}
setEnergyHomeEnv(ENERGY_HOME_KEY, installPathName)
setEnergyHomeEnv(EnergyHomeKey, installPathName)
println("\n", CmdInstall.Short, "SUCCESS \nVersion:", c.Install.Version, "=>", versionENERGY)
return nil
}
......
......@@ -41,7 +41,7 @@ func runSetenv(c *CommandConfig) error {
if !IsExist(c.Setenv.Path) {
return errors.New("Directory [" + c.Setenv.Path + "] does not exist")
}
setEnergyHomeEnv(ENERGY_HOME_KEY, c.Setenv.Path)
setEnergyHomeEnv(EnergyHomeKey, c.Setenv.Path)
println("SUCCESS")
return nil
}
......
......@@ -32,7 +32,7 @@ func init() {
}
func runVersion(c *CommandConfig) error {
downloadJSON, err := downloadConfig(download_version_config_url)
downloadJSON, err := downloadConfig(downloadVersionConfigUrl)
if err != nil {
fmt.Fprint(os.Stderr, err.Error()+"\n")
os.Exit(1)
......
......@@ -4,39 +4,52 @@
>
> LCL: Various system native UI components
| Example Name | Example Description |
|--------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------|
| app-icon-syso windows | Windows application icon generation, Linux and macOSX not provided |
| context-menu | Customize right-click menu |
| control | The state control of page control refresh, forward, backward, and stop refresh based on LCL components can be combined with various system components in Energy |
| cookie | Setting, obtaining, and deleting cookies |
| cookie-manager | Cookie Management |
| dev-tools | Developer Tools |
| dom-visitor | Document operation display |
| download | Download files |
| execute-dev-tools-method | Execute Developer Tool Method |
| execute-javascript | Executing JS code in the page in Go |
| frameless | Borderless Window |
| i18n | Local multilingual adaptation |
| internal-http-server | Internal Services |
| ipc-on-emit | Event monitoring and triggering for Go and JS |
| key-event | Keyboard events in HTML |
| load-html-url | Display the loaded Html string or Url address on the page |
| msgbox | LCL based system prompts |
| popup-sub-window | Pop up sub window |
| print-pdf | Printing pages as PDF documents |
| process-type | When there are multiple processes, the process type |
| proxy | Proxy configuration |
| response-filter | Resource response filtering |
| scheme | Custom protocol topics, such as http instead of hello |
| bsearch-text | Search page text |
| sysdialog | Various modal functional Windows |
| view-source | Display page source code |
| vue | Example of html+vue |
| webkit-register | webkit callback functions register local js examples |
| zoom | Zoom in and out of the page |
| simple | Simple application example |
| sub-process | Multiprocess, starting the rendering process as a child process |
| tray | Tray - Custom and system tray |
| dev-test | examples of various tests at development time |
| ... | ... |
\ No newline at end of file
| Example Name | Example Description |
|------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [app-icon-gen](app-icon-gen) | Windows application icon generation, Linux and macOSX not provided |
| [audio-video](audio-video) | Music and Videos |
| [build-examples](build-examples) | build all example |
| [clipbrd](clipbrd) | clipbrd |
| [context-menu](context-menu) | Customize right-click menu |
| [control-widget](control-widget) | The state control of page control refresh, forward, backward, and stop refresh based on LCL components can be combined with various system components in Energy |
| [cookie](cookie) | Setting, obtaining, and deleting cookies |
| [cookie-manager](cookie-manager) | Cookie Management |
| [custom-drag-window](custom-drag-window) | custom-drag-window |
| [dev-tools](dev-tools) | Developer Tools |
| [dom-visitor](dom-visitor) | Document operation display |
| [download](download) | Download files |
| [drag-file](drag-file) | Drag and drop the file into the browser window |
| [execute-dev-tools-method](execute-dev-tools-method) | Execute Developer Tool Method |
| [execute-javascript](execute-javascript) | Executing JS code in the page in Go |
| [flash-for-cef-v87](flash-for-cef-v87) | Borderless Window |
| [frameless](frameless) | Borderless Window |
| [i18n](i18n) | Local multilingual adaptation |
| [internal-http-server](internal-http-server) | Internal Services |
| [ipc-on-emit](ipc-on-emit) | Event monitoring and triggering for Go and JS |
| [key-event](key-event) | Keyboard events in HTML |
| [lib-checkupdate](lib-checkupdate) | energy and liblcl update examples |
| [load-html-url](load-html-url) | Display the loaded Html string or Url address on the page |
| [msgbox](msgbox) | LCL based system prompts |
| [osr](osr) | osr |
| [popup-sub-window](popup-sub-window) | Pop up sub window |
| [print-pdf](print-pdf) | Printing pages as PDF documents |
| [process-type](process-type) | When there are multiple processes, the process type |
| [proxy](proxy) | Proxy configuration |
| [response-filter](response-filter) | Resource response filtering |
| [scheme](scheme) | Custom protocol topics, such as http instead of hello |
| [screen](screen) | Search page text |
| [search-text](search-text) | screen |
| [sys-dialog](sys-dialog) | Various modal functional Windows |
| [sys-menu](sys-menu) | System menu |
| [tempdll](tempdll) | underlying library is built into the execution file and released at run time |
| [tray](tray) | Tray - Custom and system tray |
| [view-source](view-source) | Display page source code |
| [vue](vue) | Example of html+vue |
| [webkit-register](webkit-register) | webkit callback functions register local js examples |
| [window](window) | Window operation management |
| [windows](windows) | Examples that support windows only |
| [zoom](zoom) | Zoom in and out of the page |
| [simple](simple) | Simple application example |
| [sub-process](sub-process) | Multiprocess, starting the rendering process as a child process |
| [dev-test](dev-test) | examples of various tests at development time |
| ... | ... |
\ No newline at end of file
## Energy 示例
### 在 Energy 中 CEF 结合 LCL 可以做出各种各样的应用
> CEF: HTML + JS + CSS
>
> LCL: 各种系统原生UI组件
| 示例名称 | 示例描述 |
|--------------------------|--------------------------------------------------------|
| app-icon-syso windows | windows 应用程序图标生成, 未提供 linux 和 macOSX |
| context-menu | 自定义右键菜单 |
| control | 基于LCL组件的页面控制 刷新、前进、后退、停止刷新的状态控制, 在Energy中CEF可以结合各种系统组件 |
| cookie | 设置、获取、删除cookie |
| cookie-manager | cookie 管理 |
| dev-tools | 开发者工具 |
| dom-visitor | document 操作显示 |
| download | 下载文件 |
| execute-dev-tools-method | 执行开发者工具方法 |
| execute-javascript | 在Go中执行页面中的JS代码 |
| frameless | 无边框窗口示例 |
| i18n | 本地多语言适配 |
| internal-http-server | 内部服务 |
| ipc-on-emit | Go和JS的事件监听&触发 |
| key-event | html中键盘事件 |
| load-html-url | 页面中展示加载的Html字符串或Url地址 |
| msgbox | 基于LCL的系统提示 |
| popup-sub-window | 弹出子窗口 |
| print-pdf | 页面打印为PDF文档 |
| process-type | 多进程时, 进程类型 |
| proxy | 代理配置 |
| response-filter | 资源响应过滤 |
| scheme | 自定义协议主题, 例如 http 换成 hello |
| bsearch-text | 搜索页面文本 |
| sysdialog | 各种模态功能性窗口 |
| view-source | 显示页面源代码 |
| vue | html+vue的示例 |
| webkit-register | webkit回调函数注册本地js示例 |
| zoom | 页面的放大和缩小 |
| simple | 简单应用示例 |
| sub-process | 多进程,以子进程的方式启动渲染进程 |
| tray | 托盘-自定义和系统托盘 |
| dev-test | 开发时的各种测试示例 |
| ... | ... |
\ No newline at end of file
//----------------------------------------
//
// Copyright © yanghy. All Rights Reserved.
//
// Licensed under Apache License Version 2.0, January 2004
//
// https://www.apache.org/licenses/LICENSE-2.0
//
//----------------------------------------
package main
import (
"embed"
"fmt"
"github.com/energye/energy/v2/cef"
"github.com/energye/energy/v2/common"
"github.com/energye/energy/v2/pkgs/assetserve"
)
//go:embed resources
var resources embed.FS
func main() {
//全局初始化 每个应用都必须调用的
cef.GlobalInit(nil, &resources)
//创建应用
cefApp := cef.NewApplication()
//指定一个URL地址,或本地html文件目录
cef.BrowserWindow.Config.Url = "http://localhost:22022/audio-video.html"
if common.IsLinux() && cefApp.IsUIGtk3() {
cef.BrowserWindow.Config.IconFS = "resources/icon.png"
} else {
cef.BrowserWindow.Config.IconFS = "resources/icon.ico"
}
//主进程启动成功之后回调
cef.SetBrowserProcessStartAfterCallback(func(b bool) {
fmt.Println("主进程启动 创建一个内置http服务")
//通过内置http服务加载资源
server := assetserve.NewAssetsHttpServer()
server.PORT = 22022
server.AssetsFSName = "resources" //必须设置目录名
server.Assets = &resources
go server.StartHttpServer()
})
//运行应用
cef.Run(cefApp)
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>audio-video</title>
<style>
</style>
<script type="application/javascript">
</script>
</head>
<body style="overflow: hidden;margin: 0px;padding: 0px;width: 100%;">
<div style="margin-top: 100px">
video:<br>
<video controls preload="none" poster='http://video-js.zencoder.com/oceans-clip.jpg'
data-setup='{ "aspectRatio":"640:267", "playbackRates": [1, 1.5, 2] }' onmouseenter="">
<source src="https://vjs.zencdn.net/v/oceans.mp4" type='video/mp4'/>
<source src="https://vjs.zencdn.net/v/oceans.webm" type='video/webm'/>
<source src="https://cdn.letv-cdn.com/2018/12/05/JOCeEEUuoteFrjCg/playlist.m3u8" type='application/x-mpegURL'/>
</video>
<video width="400" controls>
<source src="https://www.w3schools.com/html/mov_bbb.mp4" type="video/mp4">
<source src="https://www.w3schools.com/html/mov_bbb.ogg" type="video/ogg">
Your browser does not support HTML video.
</video>
</div>
<div style="margin-top: 100px">
audio:<br>
<audio controls>
<source src="https://www.w3schools.com/html/horse.ogg" type="audio/ogg">
<source src="https://www.w3schools.com/html/horse.mp3" type="audio/mpeg">
Your browser does not support the audio element.
</audio>
</div>
</body>
</html>
\ No newline at end of file
......@@ -30,10 +30,11 @@ func main() {
"msgbox", "osr/linux", "osr/windows", "popup-sub-window", "print-pdf", "process-type", "proxy", "response-filter",
"scheme", "screen", "search-text", "simple", "sub-process/main-process", "sub-process/sub-process", "sys-dialog",
"sys-menu", "tempdll", "view-source", "vue",
"webkit-register", "zoom"}
"webkit-register", "zoom", "audio-video", "clipbrd", "window/close-for-hidden", "window/close-for-minimize", "window/default-hidden-window"}
var (
ext string
ldflags string
tags = `-tags=tempdll`
)
if isWindows {
......@@ -43,7 +44,19 @@ func main() {
ldflags = `-H windowsgui -s -w`
} else if isLinux || isDarwin {
examples = append(examples, "tray/lcltray", "tray/systray")
ldflags = `-s -w`
var gtk string
if isLinux {
print(`Linst: Please select the GTK version to build, default GTK3
1. GTK2
2. GTK3
Input: `)
fmt.Scan(&gtk)
if gtk == "1" {
tags = `-tags=tempdll gtk2`
} else {
tags = `-tags=tempdll gtk3`
}
}
}
cmd := command.NewCMD()
for i, example := range examples {
......@@ -53,7 +66,7 @@ func main() {
copySyso(dir)
out := filepath.Join(dist, example+ext)
println("build example", example, fmt.Sprintf("%d/%d", i+1, len(examples)), "\n\tbuild-dir:", dir, "\n\tout-dir:", out)
cmd.Command("go", "build", "-ldflags", ldflags, "-o", out, `-tags=tempdll`)
cmd.Command("go", "build", "-ldflags", ldflags, "-o", out, tags)
removeSyso(dir)
println()
} else {
......@@ -88,10 +101,6 @@ Input 1 IS: `)
cmd.Close()
}
func upx() {
}
func isExist(path string) bool {
_, err := os.Stat(path)
if err != nil {
......
......@@ -6,5 +6,5 @@ const (
Syso = false
)
var SysoBytesAMD64 []byte
var SysoBytesx64 []byte
var SysoBytes386 []byte
//----------------------------------------
//
// Copyright © yanghy. All Rights Reserved.
//
// Licensed under Apache License Version 2.0, January 2004
//
// https://www.apache.org/licenses/LICENSE-2.0
//
//----------------------------------------
package main
import (
"embed"
"fmt"
"github.com/energye/energy/v2/cef"
"github.com/energye/energy/v2/cef/ipc"
"github.com/energye/energy/v2/common"
"github.com/energye/energy/v2/pkgs/assetserve"
"github.com/energye/golcl/lcl"
"github.com/energye/golcl/lcl/types"
"os"
"path/filepath"
)
//go:embed resources
var resources embed.FS
func main() {
//全局初始化 每个应用都必须调用的
cef.GlobalInit(nil, &resources)
//创建应用
cefApp := cef.NewApplication()
//指定一个URL地址,或本地html文件目录
cef.BrowserWindow.Config.Url = "http://localhost:22022/clipbrd.html"
if common.IsLinux() && cefApp.IsUIGtk3() {
cef.BrowserWindow.Config.IconFS = "resources/icon.png"
} else {
cef.BrowserWindow.Config.IconFS = "resources/icon.ico"
}
//主进程启动成功之后回调
cef.SetBrowserProcessStartAfterCallback(func(b bool) {
fmt.Println("主进程启动 创建一个内置http服务")
//通过内置http服务加载资源
server := assetserve.NewAssetsHttpServer()
server.PORT = 22022
server.AssetsFSName = "resources" //必须设置目录名
server.Assets = &resources
go server.StartHttpServer()
})
cef.BrowserWindow.SetBrowserInit(func(event *cef.BrowserEvent, window cef.IBrowserWindow) {
ipc.On("setText", func(text string) {
lcl.Clipboard.SetAsText(text)
println("set-text", text)
})
ipc.On("getText", func() string {
text := lcl.Clipboard.AsText()
println("get-text", text)
return text
})
ipc.On("setPic", func() string {
println("setPic")
mem := lcl.NewMemoryStream()
defer mem.Free()
mem.LoadFromFSFile("resources/bg.bmp")
mem.SetPosition(0)
// 预定义格式
format := lcl.PredefinedClipboardFormat(types.PcfBitmap)
fmt.Println("format:", format)
if lcl.Clipboard.SetFormat(format, mem) {
return "设置成功"
} else {
return "设置失败"
}
})
ipc.On("getPic", func() string {
println("getPic")
if !lcl.Clipboard.HasPictureFormat() {
return "false"
}
bmpFormat := lcl.Clipboard.FindPictureFormatID()
mem := lcl.NewMemoryStream()
defer mem.Free()
if lcl.Clipboard.GetFormat(bmpFormat, mem) {
mem.SetPosition(0)
if wd, err := os.Getwd(); err == nil {
path := filepath.Join(wd, "bg.bmp")
mem.SaveToFile(path)
return path
} else {
return err.Error()
}
}
return "获取失败"
})
})
//运行应用
cef.Run(cefApp)
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>clipbrd</title>
<style>
</style>
<script type="application/javascript">
function SetText() {
let time = new Date().getTime()
ipc.emit("setText", ["设置字符串-" + time]);
}
function GetText() {
ipc.emit("getText", function (r) {
let msg = document.getElementById("msg")
msg.innerHTML += "getText: " + r + "<br>"
});
}
function SetPic() {
ipc.emit("setPic", function (r) {
let msg = document.getElementById("msg")
msg.innerHTML += "setPic: "+r + "<br>"
});
}
function GetPic() {
ipc.emit("getPic", function (r) {
let msg = document.getElementById("msg")
msg.innerHTML += "getPic: " + r + "<br>"
});
}
</script>
</head>
<body style="overflow: hidden;margin: 0px;padding: 0px;width: 100%;text-align: center;">
<div id="msg"></div>
<button onclick="SetText()">SetText</button>
<button onclick="GetText()">GetText</button>
<button onclick="SetPic()">SetPic</button>
<button onclick="GetPic()">GetPic</button>
</body>
</html>
\ No newline at end of file
......@@ -3,7 +3,7 @@ package main
import (
"embed"
"github.com/energye/energy/v2/cef"
"github.com/energye/energy/v2/example/control/src"
"github.com/energye/energy/v2/example/control-widget/src"
)
//go:embed resources
......
可将html css javascript image等静态资源放入该目录,编译后将内置到执行程序中
通过内置http server 读取该目录文件,展示到页面中
```go
//内置http服务链接安全配置
assetserve.AssetsServerHeaderKeyName = "energy"
assetserve.AssetsServerHeaderKeyValue = "energy"
//内置http服务链接安全配置
cef.SetBrowserProcessStartAfterCallback(func(b bool) {
fmt.Println("主进程启动 创建一个内置http服务")
//通过内置http服务加载资源
server := assetserve.NewAssetsHttpServer()
server.PORT = 22022
server.AssetsFSName = "resources" //必须设置目录名
server.Assets = &resources
go server.StartHttpServer()
})
```
\ No newline at end of file
//----------------------------------------
//
// Copyright © yanghy. All Rights Reserved.
//
// Licensed under Apache License Version 2.0, January 2004
//
// https://www.apache.org/licenses/LICENSE-2.0
//
//----------------------------------------
package main
import (
"embed"
"github.com/energye/energy/v2/cef"
"github.com/energye/energy/v2/common"
"github.com/energye/energy/v2/consts"
"github.com/energye/golcl/lcl"
"github.com/energye/golcl/lcl/types"
"time"
)
//go:embed resources
var resources embed.FS
func main() {
//全局初始化 每个应用都必须调用的
cef.GlobalInit(nil, &resources)
//创建应用
cefApp := cef.NewApplication()
//强制使用 VF 窗口
//cefApp.SetExternalMessagePump(false)
//cefApp.SetMultiThreadedMessageLoop(false)
//指定一个URL地址,或本地html文件目录
cef.BrowserWindow.Config.Url = "https://energy.yanghy.cn"
if common.IsLinux() && cefApp.IsUIGtk3() {
cef.BrowserWindow.Config.IconFS = "resources/icon.png"
} else {
cef.BrowserWindow.Config.IconFS = "resources/icon.ico"
}
//这个示例演示了两种窗口组件的使用, LCL和VF
cef.BrowserWindow.SetBrowserInit(func(event *cef.BrowserEvent, window cef.IBrowserWindow) {
if window.IsLCL() {
//LCL 窗口是我们创建的,需要我们自己管理窗口
bw := window.AsLCLBrowserWindow().BrowserWindow()
bw.SetOnClose(func(sender lcl.IObject, action *types.TCloseAction) bool {
*action = types.CaHide //隐藏窗口
// 5秒后显示窗口
go func() {
println("LCL 窗口隐藏, 5秒后显示.")
time.Sleep(time.Second * 5)
window.RunOnMainThread(func() {
window.Show() //显示窗口
})
}()
return true //跳过默认事件, 如果想关闭窗口,这里返回false
})
bw.SetOnCloseQuery(func(sender lcl.IObject, canClose *bool) bool {
return true //跳过默认事件, 如果想关闭窗口,这里返回false
})
} else if window.IsViewsFramework() {
//VF 窗口是CEF自己创建的,这里我们只管Chromium的Close事件即可
bw := window.AsViewsFrameworkBrowserWindow().BrowserWindow()
bw.Chromium().SetOnClose(func(sender lcl.IObject, browser *cef.ICefBrowser, aAction *consts.TCefCloseBrowserAction) {
*aAction = consts.CbaCancel //取消关闭 , 如果想关闭窗口, *aAction = consts.CbaClose
window.Hide() //隐藏窗口
// 5秒后显示窗口
go func() {
println("VF 窗口隐藏, 5秒后显示.")
time.Sleep(time.Second * 5)
window.RunOnMainThread(func() {
window.Show() //显示窗口
})
}()
})
}
})
//运行应用
cef.Run(cefApp)
}
//----------------------------------------
//
// Copyright © yanghy. All Rights Reserved.
//
// Licensed under Apache License Version 2.0, January 2004
//
// https://www.apache.org/licenses/LICENSE-2.0
//
//----------------------------------------
package main
import (
"embed"
"github.com/energye/energy/v2/cef"
"github.com/energye/energy/v2/common"
"github.com/energye/energy/v2/consts"
"github.com/energye/golcl/lcl"
"github.com/energye/golcl/lcl/types"
"time"
)
//go:embed resources
var resources embed.FS
func main() {
//全局初始化 每个应用都必须调用的
cef.GlobalInit(nil, &resources)
//创建应用
cefApp := cef.NewApplication()
//强制使用 VF 窗口
//cefApp.SetExternalMessagePump(false)
//cefApp.SetMultiThreadedMessageLoop(false)
//指定一个URL地址,或本地html文件目录
cef.BrowserWindow.Config.Url = "https://energy.yanghy.cn"
if common.IsLinux() && cefApp.IsUIGtk3() {
cef.BrowserWindow.Config.IconFS = "resources/icon.png"
} else {
cef.BrowserWindow.Config.IconFS = "resources/icon.ico"
}
//这个示例演示了两种窗口组件的使用, LCL和VF
cef.BrowserWindow.SetBrowserInit(func(event *cef.BrowserEvent, window cef.IBrowserWindow) {
if window.IsLCL() {
//LCL 窗口是我们创建的,需要我们自己管理窗口
bw := window.AsLCLBrowserWindow().BrowserWindow()
bw.SetOnClose(func(sender lcl.IObject, action *types.TCloseAction) bool {
*action = types.CaMinimize //隐藏窗口
// 5秒后还原窗口
go func() {
println("LCL 最小化窗口, 5秒后还原.")
time.Sleep(time.Second * 5)
window.RunOnMainThread(func() {
window.Restore() //还原窗口
})
}()
return true //跳过默认事件, 如果想关闭窗口,这里返回false
})
bw.SetOnCloseQuery(func(sender lcl.IObject, canClose *bool) bool {
return true //跳过默认事件, 如果想关闭窗口,这里返回false
})
} else if window.IsViewsFramework() {
//VF 窗口是CEF自己创建的,这里我们只管Chromium的Close事件即可
bw := window.AsViewsFrameworkBrowserWindow().BrowserWindow()
bw.Chromium().SetOnClose(func(sender lcl.IObject, browser *cef.ICefBrowser, aAction *consts.TCefCloseBrowserAction) {
*aAction = consts.CbaCancel //取消关闭 , 如果想关闭窗口,*aAction = consts.CbaClose
window.Minimize() //最小化窗口
// 5秒后显示窗口
go func() {
println("VF 最小化窗口, 5秒后还原.")
time.Sleep(time.Second * 5)
window.RunOnMainThread(func() {
window.Restore() //还原窗口
})
}()
})
}
})
//运行应用
cef.Run(cefApp)
}
//----------------------------------------
//
// Copyright © yanghy. All Rights Reserved.
//
// Licensed under Apache License Version 2.0, January 2004
//
// https://www.apache.org/licenses/LICENSE-2.0
//
//----------------------------------------
package main
import (
"embed"
"github.com/energye/energy/v2/cef"
"github.com/energye/energy/v2/common"
"github.com/energye/golcl/lcl"
"time"
)
//go:embed resources
var resources embed.FS
func main() {
//全局初始化 每个应用都必须调用的
cef.GlobalInit(nil, &resources)
//创建应用
cefApp := cef.NewApplication()
//指定一个URL地址,或本地html文件目录
cef.BrowserWindow.Config.Url = "https://energy.yanghy.cn"
if common.IsLinux() && cefApp.IsUIGtk3() {
cef.BrowserWindow.Config.IconFS = "resources/icon.png"
} else {
cef.BrowserWindow.Config.IconFS = "resources/icon.ico"
}
// 默认隐藏窗口,CEF初始化时是在显示窗口时创建
// 1.默认不居中
// 2.窗口显示在屏幕之外,数值要大于窗口宽高
cef.BrowserWindow.Config.EnableCenterWindow = false
cef.BrowserWindow.Config.X = -1200
cef.BrowserWindow.Config.Y = -800
cef.BrowserWindow.SetBrowserInit(func(event *cef.BrowserEvent, window cef.IBrowserWindow) {
// chromium 创建完成之后再隐藏掉窗口
event.SetOnAfterCreated(func(sender lcl.IObject, browser *cef.ICefBrowser) bool {
window.RunOnMainThread(func() { // 在这UI线程执行
window.Hide()
})
// 5秒后显示窗口
go func() {
println("5秒后显示窗口")
time.Sleep(time.Second * 5)
window.RunOnMainThread(func() {
//在屏幕中间显示
window.SetCenterWindow(true)
window.Show()
})
}()
return false
})
})
//运行应用
cef.Run(cefApp)
}
......@@ -3,7 +3,7 @@ module github.com/energye/energy/v2
go 1.18
require (
github.com/energye/golcl v1.0.3
github.com/energye/golcl v1.0.4
github.com/energye/liblclbinres v1.0.2
github.com/godbus/dbus/v5 v5.1.0
github.com/jessevdk/go-flags v1.5.0
......