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

command-line: 增加app init template

上级 4b7c0171
cmd/internal/assets/assets/icon.ico

264.1 KB | W: | H:

cmd/internal/assets/assets/icon.ico

43.6 KB | W: | H:

cmd/internal/assets/assets/icon.ico
cmd/internal/assets/assets/icon.ico
cmd/internal/assets/assets/icon.ico
cmd/internal/assets/assets/icon.ico
  • 2-up
  • Swipe
  • Onion skin
<!DOCTYPE html>
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Go Energy</title>
<style>
.logo {
width: 300px;
height: 300px;
margin: 40px auto 0;
}
.logo img {
width: 100%;
}
.module {
text-align: center;
padding: 0 20px;
margin: 0px auto;
color: #000;
}
.module .content {
margin-right: 20px;
text-align: center;
}
.module p {
color: #999;
}
</style>
</head>
<body>
index.html
<div class="logo">
<img src="icon.png">
</div>
<div class="module">
<div class="content">
<p style="font-weight: bold; font-size: 14px; color: #000;">Welcome to your new project!</p>
<p>OS Info: <span id="osInfo">--</span></p>
</div>
<div class="content">
<p style="font-weight: bold; font-size: 14px; color: #000">Getting start</p>
<a href="https://github.com/energye/energy">Github</a>
<a href="https://energy.yanghy.cn/course/100/0">Course</a>
<a href="https://energy.yanghy.cn/example/200/0">Example</a>
<a href="https://energy.yanghy.cn/document/300/0">Document</a>
</div>
</div>
<script>
// js on osInfo
ipc.on("osInfo", function (os) {
document.getElementById("osInfo").innerText = os;
});
// js emit send count++
let count = 0;
setInterval(function () {
count++
ipc.emit("count", [count]);
}, 1000)
</script>
</body>
</html>
\ No newline at end of file
</html>
......@@ -3,7 +3,10 @@ package main
import (
"embed"
"github.com/energye/energy/v2/cef"
"github.com/energye/energy/v2/cef/ipc"
"github.com/energye/energy/v2/pkgs/assetserve"
"github.com/energye/golcl/lcl"
"github.com/energye/golcl/lcl/rtl/version"
)
//go:embed resources
......@@ -13,7 +16,7 @@ func main() {
//Global initialization must be called
cef.GlobalInit(nil, &resources)
//Create an application
cefApp := cef.NewApplication()
app := cef.NewApplication()
//http's url
cef.BrowserWindow.Config.Url = "http://localhost:22022/index.html"
//Security key and value settings for built-in static resource services
......@@ -26,6 +29,30 @@ func main() {
server.Assets = &resources //Assets resources
go server.StartHttpServer()
})
// run main process and main thread
cef.BrowserWindow.SetBrowserInit(browserInit)
//run app
cef.Run(cefApp)
cef.Run(app)
}
// run main process and main thread
func browserInit(event *cef.BrowserEvent, window cef.IBrowserWindow) {
// index.html ipc.emit("count", [count++])
ipc.On("count", func(value int) {
println("count", value)
})
// page load end
event.SetOnLoadEnd(func(sender lcl.IObject, browser *cef.ICefBrowser, frame *cef.ICefFrame, httpStatusCode int32) {
// index.html, ipc.on("osInfo", function(){...})
println("osInfo", version.OSVersion.ToString())
ipc.Emit("osInfo", version.OSVersion.ToString())
var windowType string
if window.IsLCL() {
windowType = "LCL"
} else {
windowType = "VF"
}
// index.html, ipc.on("windowType", function(){...});
ipc.Emit("windowType", windowType)
})
}
......@@ -3,6 +3,9 @@ package main
import (
"embed"
"github.com/energye/energy/v2/cef"
"github.com/energye/energy/v2/cef/ipc"
"github.com/energye/golcl/lcl"
"github.com/energye/golcl/lcl/rtl/version"
)
//go:embed resources
......@@ -10,7 +13,7 @@ var resources embed.FS
func main() {
//Global initialization must be called
cef.GlobalInit(nil, nil)
cef.GlobalInit(nil, &resources)
//Create an application
app := cef.NewApplication()
//Local load resources
......@@ -18,6 +21,30 @@ func main() {
ResRootDir: "resources",
FS: &resources,
}.Build())
// run main process and main thread
cef.BrowserWindow.SetBrowserInit(browserInit)
//run app
cef.Run(app)
}
// run main process and main thread
func browserInit(event *cef.BrowserEvent, window cef.IBrowserWindow) {
// index.html ipc.emit("count", [count++])
ipc.On("count", func(value int) {
println("count", value)
})
// page load end
event.SetOnLoadEnd(func(sender lcl.IObject, browser *cef.ICefBrowser, frame *cef.ICefFrame, httpStatusCode int32) {
// index.html, ipc.on("osInfo", function(){...})
println("osInfo", version.OSVersion.ToString())
ipc.Emit("osInfo", version.OSVersion.ToString())
var windowType string
if window.IsLCL() {
windowType = "LCL"
} else {
windowType = "VF"
}
// index.html, ipc.on("windowType", function(){...});
ipc.Emit("windowType", windowType)
})
}
......@@ -39,7 +39,7 @@ func InitEnergyProject(c *command.Config) error {
term.Logger.Info("Website", term.Logger.Args("Github", "https://github.com/energye/energy", "ENERGY", "https://energy.yanghy.cn"))
term.Section.Println("Run Application")
tableData := pterm.TableData{
{"command-line"}, {"go run main.go"},
{"command"}, {"go run main.go"},
}
err := pterm.DefaultTable.WithHasHeader().WithHeaderRowSeparator("-").WithBoxed().WithData(tableData).Render()
if err != nil {
......@@ -47,7 +47,7 @@ func InitEnergyProject(c *command.Config) error {
}
term.Section.Println("Building Application")
tableData = pterm.TableData{
{"cmd name", "command-line"},
{"name", "command"},
}
tableData = append(tableData, []string{"go", `go build -ldflags "-s -w"`})
tableData = append(tableData, []string{"energy", `energy build .`})
......@@ -57,7 +57,7 @@ func InitEnergyProject(c *command.Config) error {
}
term.Section.Println("Make install package")
tableData = pterm.TableData{
{"command-line"}, {"energy package ."},
{"command"}, {"energy package ."},
}
err = pterm.DefaultTable.WithHasHeader().WithHeaderRowSeparator("-").WithBoxed().WithData(tableData).Render()
if err != nil {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册