mirror of
https://gitee.com/dromara/electron-egg.git
synced 2026-06-14 03:28:15 +08:00
Merge branch 'dev_v3' into test_v3
This commit is contained in:
3
.gitignore
vendored
3
.gitignore
vendored
@@ -10,3 +10,6 @@ public/electron/
|
||||
pnpm-lock.yaml
|
||||
.yalc/
|
||||
yalc.lock
|
||||
go/public/
|
||||
build/extraResources/core.exe
|
||||
build/extraResources/goapp.exe
|
||||
|
||||
@@ -21,27 +21,67 @@ module.exports = {
|
||||
directory: './',
|
||||
cmd: 'electron',
|
||||
args: ['.', '--env=local'],
|
||||
},
|
||||
go: {
|
||||
directory: './go',
|
||||
cmd: 'go',
|
||||
args: ['run', './main.go', '--env=dev','--basedir=../', '--port=7073'],
|
||||
},
|
||||
},
|
||||
|
||||
/**
|
||||
* 构建
|
||||
* ee-bin build
|
||||
*/
|
||||
build: {
|
||||
frontend: {
|
||||
directory: './frontend',
|
||||
cmd: 'npm',
|
||||
args: ['run', 'build'],
|
||||
},
|
||||
go_build_w: {
|
||||
directory: './go',
|
||||
cmd: 'go',
|
||||
args: ['build', '-o', '../build/extraResources/goapp.exe'],
|
||||
},
|
||||
go_build_m: {
|
||||
directory: './go',
|
||||
cmd: 'go',
|
||||
args: ['build', '-o', '../build/extraResources/goapp'],
|
||||
},
|
||||
go_build_l: {
|
||||
directory: './go',
|
||||
cmd: 'go',
|
||||
args: ['build', '-o', '../build/extraResources/goapp'],
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* 前端构建
|
||||
* ee-bin build
|
||||
*/
|
||||
build: {
|
||||
directory: './frontend',
|
||||
cmd: 'npm',
|
||||
args: ['run', 'build'],
|
||||
},
|
||||
|
||||
/**
|
||||
* 移动资源
|
||||
* ee-bin rd
|
||||
* ee-bin move
|
||||
*/
|
||||
rd: {
|
||||
dist: './frontend/dist',
|
||||
target: './public/dist'
|
||||
},
|
||||
move: {
|
||||
frontend_dist: {
|
||||
dist: './frontend/dist',
|
||||
target: './public/dist'
|
||||
},
|
||||
go_static: {
|
||||
dist: './frontend/dist',
|
||||
target: './go/public/dist'
|
||||
},
|
||||
go_config: {
|
||||
dist: './go/config',
|
||||
target: './go/public/config'
|
||||
},
|
||||
go_package: {
|
||||
dist: './package.json',
|
||||
target: './go/public/package.json'
|
||||
},
|
||||
go_images: {
|
||||
dist: './public/images',
|
||||
target: './go/public/images'
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* 预发布模式(prod)
|
||||
@@ -79,25 +119,20 @@ module.exports = {
|
||||
* ee-bin exec
|
||||
*/
|
||||
exec: {
|
||||
go_dev: {
|
||||
go_test: {
|
||||
directory: './go',
|
||||
cmd: 'go',
|
||||
args: ['run', './main.go', '--env=dev'],
|
||||
args: ['run', './main.go', '--env=prod','--basedir=../', '--port=7073', '--debug=true'],
|
||||
},
|
||||
go_build_w: {
|
||||
directory: './go',
|
||||
cmd: 'go',
|
||||
args: ['build', '-o', '../build/extraResources/core.exe'],
|
||||
node_v: {
|
||||
directory: './',
|
||||
cmd: 'node',
|
||||
args: ['-v'],
|
||||
},
|
||||
go_build_m: {
|
||||
directory: './go',
|
||||
cmd: 'go',
|
||||
args: ['build', '-o core', '--env=prod'],
|
||||
npm_v: {
|
||||
directory: './',
|
||||
cmd: 'npm',
|
||||
args: ['-v'],
|
||||
},
|
||||
go_build_l: {
|
||||
directory: './go',
|
||||
cmd: 'go',
|
||||
args: ['build', '-o core', '--env=prod'],
|
||||
}
|
||||
},
|
||||
};
|
||||
@@ -29,7 +29,7 @@ module.exports = (appInfo) => {
|
||||
minWidth: 400,
|
||||
minHeight: 300,
|
||||
webPreferences: {
|
||||
webSecurity: false,
|
||||
//webSecurity: false,
|
||||
contextIsolation: false, // false -> 可在渲染进程中使用electron的api,true->需要bridge.js(contextBridge)
|
||||
nodeIntegration: true,
|
||||
//preload: path.join(appInfo.baseDir, 'preload', 'bridge.js'),
|
||||
@@ -116,8 +116,23 @@ module.exports = (appInfo) => {
|
||||
indexPath: '/public/dist/index.html',
|
||||
host: '127.0.0.1',
|
||||
port: 7072,
|
||||
loadingPage: '/public/html/loading.html',
|
||||
takeover: 'go'
|
||||
};
|
||||
|
||||
/**
|
||||
* Cross-language service
|
||||
* 跨语言服务
|
||||
* 例如:执行go的二进制程序
|
||||
*/
|
||||
config.cross = {
|
||||
go: {
|
||||
enable: false,
|
||||
name: 'goapp',
|
||||
args: ['--env=dev', '--port=7073'],
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* 硬件加速
|
||||
*/
|
||||
|
||||
36
go/api/example.go
Normal file
36
go/api/example.go
Normal file
@@ -0,0 +1,36 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/wallace5303/ee-go/eapp"
|
||||
"github.com/wallace5303/ee-go/ehelper"
|
||||
"github.com/wallace5303/ee-go/ehttp/router"
|
||||
"github.com/wallace5303/ee-go/elog"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
// 使用 router Ctx
|
||||
func Hello(c *router.Ctx) {
|
||||
ret := ehelper.GetJson()
|
||||
defer c.JSON(ret)
|
||||
|
||||
ret.Data = "hello electron-egg"
|
||||
elog.Logger.Info(" print Hello ")
|
||||
}
|
||||
|
||||
// 使用 gin Context
|
||||
func Info(gc *gin.Context) {
|
||||
ret := ehelper.GetJson()
|
||||
defer gc.JSON(http.StatusOK, ret)
|
||||
|
||||
elog.Logger.Info(" print info ")
|
||||
}
|
||||
|
||||
func Exit(c *router.Ctx) {
|
||||
ret := ehelper.GetJson()
|
||||
defer c.JSON(ret)
|
||||
|
||||
eapp.Close()
|
||||
}
|
||||
@@ -1,22 +0,0 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"ee-go/eruntime"
|
||||
"ee-go/eserver"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
func GetName(ctx *gin.Context) {
|
||||
ret := eserver.NewJson()
|
||||
defer ctx.JSON(http.StatusOK, ret)
|
||||
}
|
||||
|
||||
func Exit(ctx *gin.Context) {
|
||||
ret := eserver.NewJson()
|
||||
defer ctx.JSON(http.StatusOK, ret)
|
||||
|
||||
eruntime.Close()
|
||||
}
|
||||
@@ -6,12 +6,27 @@
|
||||
"max_size": 1024,
|
||||
"max_age": 10
|
||||
},
|
||||
"http": {
|
||||
"core_logger": {
|
||||
"output_json": false,
|
||||
"level": "info",
|
||||
"filename": "ee-go-core.log",
|
||||
"max_size": 1024,
|
||||
"max_age": 10
|
||||
},
|
||||
"http": {
|
||||
"enable": true,
|
||||
"protocol": "http://",
|
||||
"hostname": "127.0.0.1",
|
||||
"port": 7073,
|
||||
"indexPath": "",
|
||||
"index_path": "",
|
||||
"network": false
|
||||
},
|
||||
"static": {
|
||||
"enable": true,
|
||||
"package": "public/package.json",
|
||||
"config": "public/config",
|
||||
"dist": "public/dist",
|
||||
"html": "public/html",
|
||||
"ssl": "public/ssl"
|
||||
}
|
||||
}
|
||||
@@ -6,7 +6,7 @@
|
||||
"max_size": 1024,
|
||||
"max_age": 20
|
||||
},
|
||||
"http": {
|
||||
"http": {
|
||||
"enable": true,
|
||||
"protocol": "http://",
|
||||
"hostname": "127.0.0.1",
|
||||
|
||||
@@ -6,7 +6,14 @@
|
||||
"max_size": 1024,
|
||||
"max_age": 30
|
||||
},
|
||||
"http": {
|
||||
"core_logger": {
|
||||
"output_json": true,
|
||||
"level": "info",
|
||||
"filename": "ee-go-core.log",
|
||||
"max_size": 1024,
|
||||
"max_age": 10
|
||||
},
|
||||
"http": {
|
||||
"enable": true,
|
||||
"protocol": "http://",
|
||||
"hostname": "127.0.0.1",
|
||||
|
||||
@@ -2,11 +2,8 @@ module electron-egg
|
||||
|
||||
go 1.20
|
||||
|
||||
//ee-go v1.0.0
|
||||
require github.com/gin-gonic/gin v1.9.1
|
||||
|
||||
// replace ee-go => D:\www\bilibili\gofile\src\ee-core\ee-go
|
||||
|
||||
require (
|
||||
github.com/bytedance/sonic v1.9.1 // indirect
|
||||
github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311 // indirect
|
||||
|
||||
15
go/main.go
15
go/main.go
@@ -1,18 +1,25 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"ee-go/eboot"
|
||||
"embed"
|
||||
|
||||
"github.com/wallace5303/ee-go/eboot"
|
||||
|
||||
"electron-egg/router"
|
||||
)
|
||||
|
||||
var (
|
||||
//go:embed public/**
|
||||
staticFS embed.FS
|
||||
)
|
||||
|
||||
func main() {
|
||||
// Initialize ee-go
|
||||
eboot.Init()
|
||||
ego := eboot.New(staticFS)
|
||||
|
||||
// User business logic
|
||||
router.Load()
|
||||
router.Api()
|
||||
|
||||
// ee-go runtime
|
||||
eboot.Run()
|
||||
ego.Run()
|
||||
}
|
||||
|
||||
5
go/public/read.txt
Normal file
5
go/public/read.txt
Normal file
@@ -0,0 +1,5 @@
|
||||
该目录存放静态资源
|
||||
|
||||
move 命令会将 electron-egg/public 资源,移动到这里;
|
||||
|
||||
go程序构建时,会将该资源嵌入到 二进制文件中。
|
||||
@@ -3,10 +3,15 @@ package router
|
||||
import (
|
||||
"electron-egg/api"
|
||||
|
||||
"ee-go/eserver"
|
||||
eRouter "github.com/wallace5303/ee-go/ehttp/router"
|
||||
)
|
||||
|
||||
func Load() {
|
||||
eserver.Router.Handle("GET", "/api/user/getName", api.GetName)
|
||||
eserver.Router.Handle("GET", "/api/user/exit", api.Exit)
|
||||
func Api() {
|
||||
|
||||
// 注册路由
|
||||
eRouter.Handle("GET", "/api/hello", api.Hello)
|
||||
eRouter.Handle("GET", "/api/exit", api.Exit)
|
||||
|
||||
// 使用 gin 注册路由
|
||||
eRouter.GinRouter.GET("/api/info", api.Info)
|
||||
}
|
||||
|
||||
13
package.json
13
package.json
@@ -7,13 +7,14 @@
|
||||
"dev": "ee-bin dev",
|
||||
"dev-frontend": "ee-bin dev --serve=frontend",
|
||||
"dev-electron": "ee-bin dev --serve=electron",
|
||||
"dev-go": "ee-bin exec --command=go_dev",
|
||||
"build-frontend": "ee-bin build",
|
||||
"build-go-w": "ee-bin exec --command=go_build_w",
|
||||
"build-go-m": "ee-bin exec --command=go_build_m",
|
||||
"build-go-l": "ee-bin exec --command=go_build_l",
|
||||
"dev-go": "ee-bin dev --serve=go",
|
||||
"build-frontend": "ee-bin build --cmds=frontend",
|
||||
"build-go-w": "ee-bin build --cmds=go_build_w",
|
||||
"build-go-m": "ee-bin build --cmds=go_build_m",
|
||||
"build-go-l": "ee-bin build --cmds=go_build_l",
|
||||
"start": "ee-bin start",
|
||||
"rd": "ee-bin rd",
|
||||
"move": "ee-bin move --flag=go_static,go_config,go_package,go_images",
|
||||
"rd": "ee-bin move --flag=frontend_dist",
|
||||
"encrypt": "ee-bin encrypt",
|
||||
"clean": "ee-bin clean",
|
||||
"icon": "ee-bin icon",
|
||||
|
||||
94
public/html/loading.html
Normal file
94
public/html/loading.html
Normal file
@@ -0,0 +1,94 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="zh-CN">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no, maximum-scale=1.0, minimum-scale=1.0" />
|
||||
<style>
|
||||
#loadingPage {
|
||||
background-color: #dedede;
|
||||
font-size: 12px;
|
||||
}
|
||||
.base {
|
||||
left: 50%;
|
||||
position: absolute;
|
||||
top: 50%;
|
||||
transform: translate(-50%, -50%);
|
||||
}
|
||||
.desc {
|
||||
margin: 0, 0, 20px, 0;
|
||||
}
|
||||
.loading,
|
||||
.loading > div {
|
||||
position: relative;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
.loading {
|
||||
display: block;
|
||||
font-size: 0;
|
||||
color: #06b359;
|
||||
}
|
||||
.loading.la-dark {
|
||||
color: #07C160;
|
||||
}
|
||||
.loading > div {
|
||||
display: inline-block;
|
||||
float: none;
|
||||
background-color: currentColor;
|
||||
border: 0 solid currentColor;
|
||||
}
|
||||
.loading {
|
||||
width: 92px;
|
||||
height: 92px;
|
||||
}
|
||||
.loading > div {
|
||||
position: absolute;
|
||||
top: 50%;
|
||||
left: 50%;
|
||||
background: transparent;
|
||||
border-style: solid;
|
||||
border-width: 2px;
|
||||
border-radius: 100%;
|
||||
animation: ball-clip-rotate-multiple-rotate 1s ease-in-out infinite;
|
||||
}
|
||||
.loading > div:first-child {
|
||||
position: absolute;
|
||||
width: 92px;
|
||||
height: 92px;
|
||||
border-right-color: transparent;
|
||||
border-left-color: transparent;
|
||||
}
|
||||
.loading > div:last-child {
|
||||
width: 16px;
|
||||
height: 16px;
|
||||
border-top-color: transparent;
|
||||
border-bottom-color: transparent;
|
||||
animation-duration: 0.5s;
|
||||
animation-direction: reverse;
|
||||
}
|
||||
@keyframes ball-clip-rotate-multiple-rotate {
|
||||
0% {
|
||||
transform: translate(-50%, -50%) rotate(0deg);
|
||||
}
|
||||
|
||||
50% {
|
||||
transform: translate(-50%, -50%) rotate(180deg);
|
||||
}
|
||||
|
||||
100% {
|
||||
transform: translate(-50%, -50%) rotate(360deg);
|
||||
}
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div id="boot">
|
||||
<div class='base'>
|
||||
<div class="loading">
|
||||
<div></div>
|
||||
<div></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user