Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
energye
energy
提交
120fce2f
energy
项目概览
energye
/
energy
通知
13
Star
2
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
energy
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
120fce2f
编写于
11月 21, 2022
作者:
yanghye
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
update simple
上级
6ff8dcb1
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
3 addition
and
59 deletion
+3
-59
example/simple/simple.go
example/simple/simple.go
+3
-59
未找到文件。
example/simple/simple.go
浏览文件 @
120fce2f
package
main
import
(
"embed"
"fmt"
"github.com/energye/energy/cef"
"github.com/energye/energy/common"
"github.com/energye/energy/common/assetserve"
"github.com/energye/golcl/lcl"
"github.com/energye/golcl/pkgs/macapp"
)
//go:embed resources
var
resources
embed
.
FS
//go:embed libs
var
libs
embed
.
FS
//这是一个简单的窗口创建示例
func
main
()
{
//开发环境中 MacOSX平台必须在"GlobalCEFInit"之前设置CEF
//设置使用CEF 和 CEF框架目录,生成开发执行应用程序包
macapp
.
MacApp
.
IsCEF
(
common
.
IsDarwin
())
//环境变量 ENERGY_HOME="/app/cefframework" 配置框架所在目录
//全局初始化 每个应用都必须调用的
cef
.
GlobalCEFInit
(
&
libs
,
&
resources
)
//可选的应用配置
cfg
:=
cef
.
NewApplicationConfig
()
//指定chromium的二进制包框架根目录,
//不指定为当前程序执行目录
if
common
.
IsWindows
()
{
//SetFrameworkDirPath 或 配置环境变量 ENERGY_HOME
cfg
.
SetFrameworkDirPath
(
"D:
\\
app.exe
\\
energy
\\
105.0.5195.127
\\
dev
\\
chromium-64"
)
}
else
if
common
.
IsLinux
()
{
cfg
.
SetFrameworkDirPath
(
"/home/sxm/app/swt/energy/chromium"
)
}
cef
.
GlobalCEFInit
(
nil
,
nil
)
//创建应用
cefApp
:=
cef
.
NewApplication
(
cfg
)
//主窗口的配置
cefApp
:=
cef
.
NewApplication
(
nil
)
//指定一个URL地址,或本地html文件目录
cef
.
BrowserWindow
.
Config
.
DefaultUrl
=
"https://www.baidu.com/"
//窗口的标题
cef
.
BrowserWindow
.
Config
.
Title
=
"energy - 这是一个简单的窗口示例"
//窗口宽高
cef
.
BrowserWindow
.
Config
.
Width
=
1024
cef
.
BrowserWindow
.
Config
.
Height
=
768
//chromium配置
cef
.
BrowserWindow
.
Config
.
SetChromiumConfig
(
cef
.
NewChromiumConfig
())
//创建窗口时的回调函数 对浏览器事件设置,和窗口属性组件等创建和修改
cef
.
BrowserWindow
.
SetBrowserInit
(
func
(
event
*
cef
.
BrowserEvent
,
browserWindow
*
cef
.
TCefWindowInfo
)
{
//设置应用图标 这里加载的图标是内置到执行程序里的资源文件
lcl
.
Application
.
Icon
()
.
LoadFromFSFile
(
"resources/icon.ico"
)
fmt
.
Println
(
"SetBrowserInit"
)
})
//创建窗口之后对对主窗口的属性、组件或子窗口的创建
cef
.
BrowserWindow
.
SetBrowserInitAfter
(
func
(
browserWindow
*
cef
.
TCefWindowInfo
)
{
fmt
.
Println
(
"SetBrowserInitAfter"
)
})
//内置http服务链接安全配置
assetserve
.
AssetsServerHeaderKeyName
=
"energy"
assetserve
.
AssetsServerHeaderKeyValue
=
"energy"
cef
.
SetBrowserProcessStartAfterCallback
(
func
(
b
bool
)
{
fmt
.
Println
(
"主进程启动 创建一个内置http服务 然后使用 http://localhost/资源目录或资源名称"
)
//通过内置http服务加载资源
server
:=
assetserve
.
NewAssetsHttpServer
()
server
.
AssetsFSName
=
"resources"
//必须设置目录名
server
.
Assets
=
&
resources
go
server
.
StartHttpServer
()
})
cef
.
BrowserWindow
.
Config
.
DefaultUrl
=
"https://energy.yanghy.cn"
//运行应用
cef
.
Run
(
cefApp
)
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录