提交 c1ba58bc 编写于 作者: yanghye's avatar yanghye

A: demo, window-for-hidden, window-for-minimize, default-hidden-window

上级 840f015c
......@@ -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
可将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)
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册