diff --git a/cef/cef-init.go b/cef/cef-init.go index a3b61a94..f1600b91 100644 --- a/cef/cef-init.go +++ b/cef/cef-init.go @@ -36,7 +36,7 @@ func SetOnException(exception ExceptionCallback) { //libs 内置到应用程序的类库 // //resources 内置到应用程序的资源文件 -func GlobalCEFInit(libs *embed.FS, resources *embed.FS) { +func GlobalInit(libs *embed.FS, resources *embed.FS) { macapp.MacApp.IsCEF(IsDarwin()) inits.Init(libs, resources) if Args.IsRender() { diff --git a/example/browser-control/control.go b/example/browser-control/control.go index c8095fca..8d20ccb8 100644 --- a/example/browser-control/control.go +++ b/example/browser-control/control.go @@ -14,11 +14,11 @@ var resources embed.FS var libs embed.FS func main() { - //开发环境中 MacOSX平台必须在"GlobalCEFInit"之前设置CEF + //开发环境中 MacOSX平台必须在"GlobalInit"之前设置CEF //设置使用CEF 和 CEF框架目录,生成开发执行应用程序包 //环境变量 ENERGY_HOME="/app/cefframework" 配置框架所在目录 //全局初始化 每个应用都必须调用的 - cef.GlobalCEFInit(&libs, &resources) + cef.GlobalInit(&libs, &resources) //可选的应用配置 cfg := cef.NewApplicationConfig() //指定chromium的二进制包框架根目录, diff --git a/example/browser-cookie/cookie.go b/example/browser-cookie/cookie.go index 4b661eda..99c39e99 100644 --- a/example/browser-cookie/cookie.go +++ b/example/browser-cookie/cookie.go @@ -19,7 +19,7 @@ var resources embed.FS //这个示例使用了几个事件来演示下载文件 func main() { //全局初始化 每个应用都必须调用的 - cef.GlobalCEFInit(nil, &resources) + cef.GlobalInit(nil, &resources) //创建应用 cefApp := cef.NewApplication(nil) //主窗口的配置 diff --git a/example/browser-dev-tools/dev-tools.go b/example/browser-dev-tools/dev-tools.go index f9a81994..6a685d3a 100644 --- a/example/browser-dev-tools/dev-tools.go +++ b/example/browser-dev-tools/dev-tools.go @@ -6,7 +6,7 @@ import ( func main() { //全局初始化 每个应用都必须调用的 - cef.GlobalCEFInit(nil, nil) + cef.GlobalInit(nil, nil) applicationConfig := cef.NewApplicationConfig() applicationConfig.SetRemoteDebuggingPort(8888) //远程端口方式, 需自定义端口号 //创建应用 diff --git a/example/browser-download/download.go b/example/browser-download/download.go index 38d9ed11..32961136 100644 --- a/example/browser-download/download.go +++ b/example/browser-download/download.go @@ -20,7 +20,7 @@ var resources embed.FS //并且设置event.SetOnDownloadUpdated获取下载进度信息 func main() { //全局初始化 每个应用都必须调用的 - cef.GlobalCEFInit(nil, &resources) + cef.GlobalInit(nil, &resources) //创建应用 cefApp := cef.NewApplication(nil) //主窗口的配置 diff --git a/example/browser-execute-dev-tools-method/dev-tools-method.go b/example/browser-execute-dev-tools-method/dev-tools-method.go index 7104d0ef..9c75dcd7 100644 --- a/example/browser-execute-dev-tools-method/dev-tools-method.go +++ b/example/browser-execute-dev-tools-method/dev-tools-method.go @@ -14,7 +14,7 @@ var resources embed.FS func main() { //全局初始化 每个应用都必须调用的 - cef.GlobalCEFInit(nil, &resources) + cef.GlobalInit(nil, &resources) //创建应用 cefApp := cef.NewApplication(nil) //主窗口的配置 diff --git a/example/browser-execute-javascript/execute-javascript.go b/example/browser-execute-javascript/execute-javascript.go index 342c9e5c..4264e99d 100644 --- a/example/browser-execute-javascript/execute-javascript.go +++ b/example/browser-execute-javascript/execute-javascript.go @@ -13,7 +13,7 @@ var resources embed.FS func main() { //全局初始化 每个应用都必须调用的 - cef.GlobalCEFInit(nil, &resources) + cef.GlobalInit(nil, &resources) //创建应用 cefApp := cef.NewApplication(nil) //指定一个URL地址,或本地html文件目录 diff --git a/example/browser-go-bind-js-var/go-bind-js-var.go b/example/browser-go-bind-js-var/go-bind-js-var.go index 339eda44..6050725e 100644 --- a/example/browser-go-bind-js-var/go-bind-js-var.go +++ b/example/browser-go-bind-js-var/go-bind-js-var.go @@ -13,7 +13,7 @@ var resources embed.FS func main() { //全局初始化 每个应用都必须调用的 - cef.GlobalCEFInit(nil, &resources) + cef.GlobalInit(nil, &resources) //创建应用 cefApp := cef.NewApplication(nil) //指定一个URL地址,或本地html文件目录 diff --git a/example/browser-internal-http-server/internal-http-server.go b/example/browser-internal-http-server/internal-http-server.go index 9a30ebb4..b60487c0 100644 --- a/example/browser-internal-http-server/internal-http-server.go +++ b/example/browser-internal-http-server/internal-http-server.go @@ -14,7 +14,7 @@ var resources embed.FS func main() { //全局初始化 每个应用都必须调用的 - cef.GlobalCEFInit(nil, &resources) + cef.GlobalInit(nil, &resources) //创建应用 cefApp := cef.NewApplication(nil) //主窗口的配置 diff --git a/example/browser-ipc-on-emit/go-to-js/go-to-js.go b/example/browser-ipc-on-emit/go-to-js/go-to-js.go index 8b233083..7254f663 100644 --- a/example/browser-ipc-on-emit/go-to-js/go-to-js.go +++ b/example/browser-ipc-on-emit/go-to-js/go-to-js.go @@ -15,7 +15,7 @@ var resources embed.FS func main() { //全局初始化 每个应用都必须调用的 - cef.GlobalCEFInit(nil, &resources) + cef.GlobalInit(nil, &resources) //创建应用 cefApp := cef.NewApplication(nil) //指定一个URL地址,或本地html文件目录 diff --git a/example/browser-ipc-on-emit/js-to-go/js-to-go.go b/example/browser-ipc-on-emit/js-to-go/js-to-go.go index cc33eac4..61b02f3b 100644 --- a/example/browser-ipc-on-emit/js-to-go/js-to-go.go +++ b/example/browser-ipc-on-emit/js-to-go/js-to-go.go @@ -14,7 +14,7 @@ var resources embed.FS func main() { //全局初始化 每个应用都必须调用的 - cef.GlobalCEFInit(nil, &resources) + cef.GlobalInit(nil, &resources) //创建应用 cefApp := cef.NewApplication(nil) //指定一个URL地址,或本地html文件目录 diff --git a/example/browser-key-event/key-event.go b/example/browser-key-event/key-event.go index bcfdbcda..f07e8113 100644 --- a/example/browser-key-event/key-event.go +++ b/example/browser-key-event/key-event.go @@ -13,7 +13,7 @@ var resources embed.FS func main() { //全局初始化 每个应用都必须调用的 - cef.GlobalCEFInit(nil, &resources) + cef.GlobalInit(nil, &resources) //创建应用 cefApp := cef.NewApplication(nil) //指定一个URL地址,或本地html文件目录 diff --git a/example/browser-zoom/zoom.go b/example/browser-zoom/zoom.go index 70ee5cc2..2678dd37 100644 --- a/example/browser-zoom/zoom.go +++ b/example/browser-zoom/zoom.go @@ -6,7 +6,7 @@ import ( func main() { //全局初始化 每个应用都必须调用的 - cef.GlobalCEFInit(nil, nil) + cef.GlobalInit(nil, nil) //创建应用 cefApp := cef.NewApplication(nil) //主窗口的配置 diff --git a/example/dev-test/browser-views-framework/views-framework.go b/example/dev-test/browser-views-framework/views-framework.go index 396829c4..f6d971a4 100644 --- a/example/dev-test/browser-views-framework/views-framework.go +++ b/example/dev-test/browser-views-framework/views-framework.go @@ -5,7 +5,6 @@ import ( "fmt" "github.com/energye/energy/cef" "github.com/energye/energy/common" - "github.com/energye/golcl/energy/inits" "github.com/energye/golcl/lcl" ) @@ -13,17 +12,13 @@ import ( var resources embed.FS func main() { - inits.Init(nil, &resources) + cef.GlobalInit(nil, &resources) fmt.Println("main", common.Args.ProcessType()) config := cef.NewApplicationConfig() config.SetMultiThreadedMessageLoop(false) config.SetExternalMessagePump(false) application := cef.NewCEFApplication(config) - application.SetOnContextCreated(func(browser *cef.ICefBrowser, frame *cef.ICefFrame, context *cef.ICefV8Context) bool { - fmt.Println("OnContextCreated") - return false - }) application.SetOnContextInitialized(func() { fmt.Println("OnContextInitialized()") component := lcl.NewComponent(nil) @@ -31,13 +26,7 @@ func main() { chromium := cef.NewChromium(component, chromiumConfig) browserViewComponent := cef.NewBrowserViewComponent(component) windowComponent := cef.NewWindowComponent(component) - chromium.SetOnBeforeClose(func(sender lcl.IObject, browser *cef.ICefBrowser) { - fmt.Println("OnBeforeClose") - }) - chromium.SetOnTitleChange(func(sender lcl.IObject, browser *cef.ICefBrowser, title string) { - fmt.Println("OnTitleChange", title) - windowComponent.SetTitle(title) - }) + chromium.SetOnBeforePopup(func(sender lcl.IObject, browser *cef.ICefBrowser, frame *cef.ICefFrame, beforePopupInfo *cef.BeforePopupInfo, client *cef.ICefClient, noJavascriptAccess *bool) bool { fmt.Println("OnBeforePopup TargetUrl:", beforePopupInfo.TargetUrl) @@ -57,6 +46,7 @@ func main() { windowComponent.SetAlwaysOnTop(true) //window.SetFullscreen(true) window.Show() + fmt.Println("SetOnWindowCreated end") }) windowComponent.SetOnCanClose(func(sender lcl.IObject, window *cef.ICefWindow, aResult *bool) { fmt.Println("OnCanClose") @@ -66,13 +56,18 @@ func main() { windowComponent.CreateTopLevelWindow() }) - application.SetOnGetDefaultClient(func(client *cef.ICefClient) { - fmt.Println("OnGetDefaultClient") - }) - process := application.StartMainProcess() + //application.SetOnGetDefaultClient(func(client *cef.ICefClient) { + // fmt.Println("OnGetDefaultClient") + //}) + var process bool + if !common.Args.IsMain() { + process = application.StartSubProcess() + } else { + process = application.StartMainProcess() + application.RunMessageLoop() + } fmt.Println("application.StartMainProcess()", process) if process { fmt.Println("application.RunMessageLoop()") - application.RunMessageLoop() } } diff --git a/example/dev-test/combination-sundry-browser/combination-sundry-browser.go b/example/dev-test/combination-sundry-browser/combination-sundry-browser.go index 3966195e..82c5b2d1 100644 --- a/example/dev-test/combination-sundry-browser/combination-sundry-browser.go +++ b/example/dev-test/combination-sundry-browser/combination-sundry-browser.go @@ -22,7 +22,7 @@ func main() { logger.SetLevel(logger.CefLog_Debug) //环境变量 ENERGY_HOME="/app/cefframework" 配置框架所在目录 //全局初始化 - cef.GlobalCEFInit(&libs, &resources) + cef.GlobalInit(&libs, &resources) fmt.Println("CEFVersion:", cef.CEFVersion(), "LibBuildVersion:", cef.LibBuildVersion()) //Render 子进程一些初始化配置 cefApp := src.AppRenderInit() diff --git a/example/dev-test/lcl-browser/lcl-browser.go b/example/dev-test/lcl-browser/lcl-browser.go index 463bf77a..8cc38015 100644 --- a/example/dev-test/lcl-browser/lcl-browser.go +++ b/example/dev-test/lcl-browser/lcl-browser.go @@ -15,7 +15,7 @@ var resources embed.FS func main() { //全局初始化 每个应用都必须调用的 - cef.GlobalCEFInit(nil, &resources) + cef.GlobalInit(nil, &resources) //创建应用 cefApp := cef.NewApplication(nil) //指定一个URL地址,或本地html文件目录 diff --git a/example/dev-test/vf-browser/vf-browser.go b/example/dev-test/vf-browser/vf-browser.go index 4b156991..c93b3a38 100644 --- a/example/dev-test/vf-browser/vf-browser.go +++ b/example/dev-test/vf-browser/vf-browser.go @@ -6,7 +6,6 @@ import ( "github.com/energye/energy/cef" "github.com/energye/energy/common" "github.com/energye/energy/common/assetserve" - sys_tray "github.com/energye/energy/example/dev-test/sys-tray" "github.com/energye/energy/ipc" "github.com/energye/golcl/lcl" ) @@ -15,20 +14,22 @@ import ( var resources embed.FS func main() { + fmt.Println("ARGS", common.Args.ProcessType()) //全局初始化 每个应用都必须调用的 - cef.GlobalCEFInit(nil, &resources) + cef.GlobalInit(nil, &resources) //创建应用 config := cef.NewApplicationConfig() config.SetMultiThreadedMessageLoop(false) config.SetExternalMessagePump(false) - config.SetRemoteDebuggingPort(33333) + config.SetRemoteDebuggingPort(0) + config.SetSingleProcess(true) cefApp := cef.NewApplication(config) //指定一个URL地址,或本地html文件目录 cef.BrowserWindow.Config.Url = "http://localhost:22022/index.html" cef.BrowserWindow.Config.IconFS = "resources/icon.png" cef.BrowserWindow.Config.CanDragFile = true cef.BrowserWindow.SetBrowserInit(func(event *cef.BrowserEvent, window cef.IBrowserWindow) { - window.DisableResize() + //window.DisableResize() window.SetTitle("这里改变了窗口标题") window.SetSize(1600, 900) fmt.Println("cef.BrowserWindow.SetViewFrameBrowserInit", window) @@ -63,7 +64,7 @@ func main() { bw := window.AsViewsFrameworkBrowserWindow().BrowserWindow() fmt.Println("handle", bw.WindowComponent().WindowHandle().ToPtr()) //cefTray(window) - go sys_tray.TrayMain() + //go sys_tray.TrayMain() fmt.Println("SetBrowserInitAfter 结束") }) //在主进程启动成功之后执行 @@ -78,7 +79,6 @@ func main() { server.Assets = &resources go server.StartHttpServer() }) - fmt.Println("ARGS", common.Args.ProcessType()) //运行应用 cef.Run(cefApp) } diff --git a/example/simple-macosx/simple.go b/example/simple-macosx/simple.go index 89dbed1f..296e177a 100644 --- a/example/simple-macosx/simple.go +++ b/example/simple-macosx/simple.go @@ -7,10 +7,10 @@ import ( ) func main() { - //开发环境中 MacOSX平台必须在"GlobalCEFInit"之前设置CEF + //开发环境中 MacOSX平台必须在"GlobalInit"之前设置CEF macapp.MacApp.IsCEF(common.IsDarwin()) //全局初始化 每个应用都必须调用的 - cef.GlobalCEFInit(nil, nil) + cef.GlobalInit(nil, nil) //创建应用 cefApp := cef.NewApplication(nil) //指定一个URL地址,或本地html文件目录 diff --git a/example/simple/simple.go b/example/simple/simple.go index 9c8ee201..7920d361 100644 --- a/example/simple/simple.go +++ b/example/simple/simple.go @@ -6,7 +6,7 @@ import ( func main() { //全局初始化 每个应用都必须调用的 - cef.GlobalCEFInit(nil, nil) + cef.GlobalInit(nil, nil) //创建应用 cefApp := cef.NewApplication(nil) //指定一个URL地址,或本地html文件目录 diff --git a/example/sub-process/main-process/main-process.go b/example/sub-process/main-process/main-process.go index caaadbfa..65bfe95b 100644 --- a/example/sub-process/main-process/main-process.go +++ b/example/sub-process/main-process/main-process.go @@ -21,7 +21,7 @@ import ( */ func main() { //MacOS通过指定 IsCEF ,在开发环境中自动生成可运行的程序包 - //MacOS配置要在 GlobalCEFInit 它之前 + //MacOS配置要在 GlobalInit 它之前 //特别说明MacOS:子进程不需要配置 if common.IsDarwin() { //自动生成mac app程序包 @@ -32,7 +32,7 @@ func main() { macapp.MacApp.SetBrowseSubprocessPath("/Users/zhangli/go/src/github.com/energye/energy/demos/demo-sub-process/sub-process/sub-process") } //CEF全局初始化 - cef.GlobalCEFInit(nil, nil) + cef.GlobalInit(nil, nil) //Cef应用的配置 执行程序如果在 chromium 目录中可不配置 cfg := cef.NewApplicationConfig() //配置chromium frameworks 编译好的二进制目录 diff --git a/example/sub-process/sub-process/sub-process.go b/example/sub-process/sub-process/sub-process.go index be96cec4..2b2e7ffa 100644 --- a/example/sub-process/sub-process/sub-process.go +++ b/example/sub-process/sub-process/sub-process.go @@ -14,7 +14,7 @@ import ( */ func main() { //全局配置初始化 - cef.GlobalCEFInit(nil, nil) + cef.GlobalInit(nil, nil) //IPC通信 src.IPCInit() //Cef应用的配置 执行程序如果在 chromium 目录中可不配置