Initial commit
This commit is contained in:
34
desktop/framework/config/config.go
Normal file
34
desktop/framework/config/config.go
Normal file
@@ -0,0 +1,34 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file config.go
|
||||
* @author MakerYang
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
package Config
|
||||
|
||||
import (
|
||||
"embed"
|
||||
"encoding/json"
|
||||
"golang.org/x/sync/errgroup"
|
||||
)
|
||||
|
||||
var Get = &Data{}
|
||||
|
||||
type Data struct {
|
||||
Info struct {
|
||||
CompanyName string `json:"companyName"`
|
||||
ProductName string `json:"productName"`
|
||||
ProductVersion string `json:"productVersion"`
|
||||
} `json:"info"`
|
||||
Group errgroup.Group
|
||||
}
|
||||
|
||||
func Init(version embed.FS) {
|
||||
wails, _ := version.ReadFile("wails.json")
|
||||
var wailsJson Data
|
||||
json.Unmarshal(wails, &wailsJson)
|
||||
Get.Info.ProductVersion = wailsJson.Info.ProductVersion
|
||||
Get.Info.ProductName = wailsJson.Info.ProductName
|
||||
Get.Info.CompanyName = wailsJson.Info.CompanyName
|
||||
}
|
||||
62
desktop/framework/framework.go
Normal file
62
desktop/framework/framework.go
Normal file
@@ -0,0 +1,62 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file framework.go
|
||||
* @author MakerYang
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
package Framework
|
||||
|
||||
import (
|
||||
"cnc/framework/config"
|
||||
"cnc/framework/windows/start"
|
||||
"embed"
|
||||
"fmt"
|
||||
"github.com/gookit/color"
|
||||
"github.com/wailsapp/wails/v2"
|
||||
"github.com/wailsapp/wails/v2/pkg/options"
|
||||
"github.com/wailsapp/wails/v2/pkg/options/assetserver"
|
||||
"github.com/wailsapp/wails/v2/pkg/options/linux"
|
||||
"github.com/wailsapp/wails/v2/pkg/options/windows"
|
||||
)
|
||||
|
||||
func Init(template embed.FS, version embed.FS) {
|
||||
|
||||
Config.Init(version)
|
||||
|
||||
start := StartWindows.Init()
|
||||
|
||||
err := wails.Run(&options.App{
|
||||
Title: "",
|
||||
Width: 1200,
|
||||
Height: 768,
|
||||
MinWidth: 1200,
|
||||
MinHeight: 768,
|
||||
AssetServer: &assetserver.Options{
|
||||
Assets: template,
|
||||
},
|
||||
BackgroundColour: &options.RGBA{R: 255, G: 255, B: 255, A: 1},
|
||||
OnStartup: start.Startup,
|
||||
OnShutdown: start.Shutdown,
|
||||
Bind: []interface{}{
|
||||
start,
|
||||
},
|
||||
WindowStartState: options.Normal,
|
||||
Windows: &windows.Options{
|
||||
WebviewDisableRendererCodeIntegrity: true,
|
||||
DisableWindowIcon: true,
|
||||
},
|
||||
Linux: &linux.Options{
|
||||
Icon: []byte(""),
|
||||
WindowIsTranslucent: false,
|
||||
WebviewGpuPolicy: linux.WebviewGpuPolicyNever,
|
||||
},
|
||||
Debug: options.Debug{
|
||||
OpenInspectorOnStartup: false,
|
||||
},
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
fmt.Println("[desktop][framework]:" + color.Gray.Text(err.Error()))
|
||||
}
|
||||
}
|
||||
74
desktop/framework/windows/start/index.go
Normal file
74
desktop/framework/windows/start/index.go
Normal file
@@ -0,0 +1,74 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file index.go
|
||||
* @author MakerYang
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
package StartWindows
|
||||
|
||||
import (
|
||||
"cnc/framework/config"
|
||||
"context"
|
||||
"os"
|
||||
"runtime"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type Api struct {
|
||||
ctx context.Context
|
||||
}
|
||||
|
||||
type ReturnResponse struct {
|
||||
Code int `json:"code"`
|
||||
Data interface{} `json:"data"`
|
||||
Msg string `json:"msg"`
|
||||
}
|
||||
|
||||
func Init() *Api {
|
||||
return &Api{}
|
||||
}
|
||||
|
||||
func (start *Api) Startup(ctx context.Context) {
|
||||
start.ctx = ctx
|
||||
}
|
||||
|
||||
func (start *Api) Shutdown(ctx context.Context) {
|
||||
|
||||
}
|
||||
|
||||
func (start *Api) GetPlatform() string {
|
||||
platform := ""
|
||||
switch runtime.GOOS {
|
||||
case "windows":
|
||||
platform = "Windows"
|
||||
case "darwin":
|
||||
platform = "Darwin"
|
||||
case "linux":
|
||||
platform = "Linux"
|
||||
content, err := os.ReadFile("/etc/os-release")
|
||||
if err == nil {
|
||||
lines := strings.Split(string(content), "\n")
|
||||
for _, line := range lines {
|
||||
if strings.HasPrefix(line, "ID=") {
|
||||
switch {
|
||||
case strings.Contains(line, "ubuntu"):
|
||||
platform = "Ubuntu"
|
||||
case strings.Contains(line, "debian"):
|
||||
platform = "Debian"
|
||||
default:
|
||||
platform = "Linux"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
default:
|
||||
platform = "-"
|
||||
}
|
||||
|
||||
return platform
|
||||
}
|
||||
|
||||
func (start *Api) GetVersion() []string {
|
||||
return []string{Config.Get.Info.ProductName, Config.Get.Info.ProductVersion}
|
||||
}
|
||||
Reference in New Issue
Block a user