Skip to content

Commit

Permalink
U: 修改ipc Go文件名
Browse files Browse the repository at this point in the history
  • Loading branch information
sxmxta committed Nov 23, 2023
1 parent 9c33932 commit 01e1427
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 2 deletions.
20 changes: 20 additions & 0 deletions example/common/common.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package common

import (
"net"
)

// Port 获取并返回未使用的net socket端口
func Port() int {
//主进程获取端口号
addr, err := net.ResolveTCPAddr("tcp", "localhost:0")
if err != nil {
panic("Failed to Get unused Port number Error: " + err.Error())
}
listen, err := net.ListenTCP("tcp", addr)
if err != nil {
panic("Failed to Get unused Port number Error: " + err.Error())
}
defer listen.Close()
return listen.Addr().(*net.TCPAddr).Port
}
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/energye/energy/v2/cef/exception"
"github.com/energye/energy/v2/cef/ipc"
"github.com/energye/energy/v2/cef/ipc/context"
"github.com/energye/energy/v2/example/common"
"github.com/energye/energy/v2/pkgs/assetserve"
"strings"
)
Expand All @@ -23,8 +24,9 @@ func main() {
})
//创建应用
cefApp := cef.NewApplication()
port := common.Port()
//指定一个URL地址,或本地html文件目录
cef.BrowserWindow.Config.Url = "http://localhost:22022/go-to-js.html"
cef.BrowserWindow.Config.Url = fmt.Sprintf("http://localhost:%d/go-to-js.html", port)
cef.BrowserWindow.Config.Title = "Energy - go on event - js emit event"

//在go中监听一个事件, 不带返回值
Expand Down Expand Up @@ -99,7 +101,7 @@ func main() {
fmt.Println("主进程启动 创建一个内置http服务")
//通过内置http服务加载资源
server := assetserve.NewAssetsHttpServer()
server.PORT = 22022
server.PORT = port
server.AssetsFSName = "resources" //必须设置目录名
server.Assets = &resources
go server.StartHttpServer()
Expand Down
File renamed without changes.

0 comments on commit 01e1427

Please sign in to comment.