结构调整
This commit is contained in:
parent
0c1e773247
commit
079a556e7a
5
app/wails/frontend/wailsjs/go/config/Support.d.ts
vendored
Normal file
5
app/wails/frontend/wailsjs/go/config/Support.d.ts
vendored
Normal file
@ -0,0 +1,5 @@
|
||||
// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL
|
||||
// This file is automatically generated. DO NOT EDIT
|
||||
import {config} from '../models';
|
||||
|
||||
export function GetConfig():Promise<config.Config>;
|
7
app/wails/frontend/wailsjs/go/config/Support.js
Normal file
7
app/wails/frontend/wailsjs/go/config/Support.js
Normal file
@ -0,0 +1,7 @@
|
||||
// @ts-check
|
||||
// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL
|
||||
// This file is automatically generated. DO NOT EDIT
|
||||
|
||||
export function GetConfig() {
|
||||
return window['go']['config']['Support']['GetConfig']();
|
||||
}
|
@ -3,13 +3,13 @@
|
||||
// This file is automatically generated. DO NOT EDIT
|
||||
|
||||
export function Ctx() {
|
||||
return window['go']['app']['App']['Ctx']();
|
||||
return window['go']['core']['App']['Ctx']();
|
||||
}
|
||||
|
||||
export function ForceClose() {
|
||||
return window['go']['app']['App']['ForceClose']();
|
||||
return window['go']['core']['App']['ForceClose']();
|
||||
}
|
||||
|
||||
export function ReloadApp() {
|
||||
return window['go']['app']['App']['ReloadApp']();
|
||||
return window['go']['core']['App']['ReloadApp']();
|
||||
}
|
@ -1,3 +1,67 @@
|
||||
export namespace config {
|
||||
|
||||
export class DebuggerConfig {
|
||||
enable: boolean;
|
||||
|
||||
static createFrom(source: any = {}) {
|
||||
return new DebuggerConfig(source);
|
||||
}
|
||||
|
||||
constructor(source: any = {}) {
|
||||
if ('string' === typeof source) source = JSON.parse(source);
|
||||
this.enable = source["enable"];
|
||||
}
|
||||
}
|
||||
export class ServerConfig {
|
||||
host: string;
|
||||
port: number;
|
||||
|
||||
static createFrom(source: any = {}) {
|
||||
return new ServerConfig(source);
|
||||
}
|
||||
|
||||
constructor(source: any = {}) {
|
||||
if ('string' === typeof source) source = JSON.parse(source);
|
||||
this.host = source["host"];
|
||||
this.port = source["port"];
|
||||
}
|
||||
}
|
||||
export class Config {
|
||||
server?: ServerConfig;
|
||||
debug?: DebuggerConfig;
|
||||
|
||||
static createFrom(source: any = {}) {
|
||||
return new Config(source);
|
||||
}
|
||||
|
||||
constructor(source: any = {}) {
|
||||
if ('string' === typeof source) source = JSON.parse(source);
|
||||
this.server = this.convertValues(source["server"], ServerConfig);
|
||||
this.debug = this.convertValues(source["debug"], DebuggerConfig);
|
||||
}
|
||||
|
||||
convertValues(a: any, classs: any, asMap: boolean = false): any {
|
||||
if (!a) {
|
||||
return a;
|
||||
}
|
||||
if (a.slice) {
|
||||
return (a as any[]).map(elem => this.convertValues(elem, classs));
|
||||
} else if ("object" === typeof a) {
|
||||
if (asMap) {
|
||||
for (const key of Object.keys(a)) {
|
||||
a[key] = new classs(a[key]);
|
||||
}
|
||||
return a;
|
||||
}
|
||||
return new classs(a);
|
||||
}
|
||||
return a;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
export namespace cpu {
|
||||
|
||||
export class InfoStat {
|
||||
|
@ -2,27 +2,23 @@ package main
|
||||
|
||||
import (
|
||||
"embed"
|
||||
app2 "skapp/pkg/app"
|
||||
"skapp/pkg/app/dialog"
|
||||
"skapp/pkg/env"
|
||||
"skapp/pkg/sdk/system"
|
||||
systemUtils "skapp/pkg/system"
|
||||
"skapp/pkg/utils"
|
||||
|
||||
"github.com/wailsapp/wails/v2"
|
||||
"github.com/wailsapp/wails/v2/pkg/options"
|
||||
"github.com/wailsapp/wails/v2/pkg/options/assetserver"
|
||||
"skapp/pkg/core"
|
||||
"skapp/pkg/sdk/config"
|
||||
"skapp/pkg/sdk/dialog"
|
||||
"skapp/pkg/sdk/env"
|
||||
"skapp/pkg/sdk/system"
|
||||
"skapp/pkg/sdk/utils"
|
||||
)
|
||||
|
||||
//go:embed all:frontend/dist
|
||||
var assets embed.FS
|
||||
|
||||
func main() {
|
||||
defer func() {
|
||||
system.DestroyFileManager()
|
||||
}()
|
||||
// Create an instance of the app structure
|
||||
app := app2.NewApp()
|
||||
app := core.NewApp()
|
||||
|
||||
// Create application with options
|
||||
err := wails.Run(&options.App{
|
||||
@ -41,8 +37,9 @@ func main() {
|
||||
app,
|
||||
&env.Env{},
|
||||
&utils.Utils{},
|
||||
&systemUtils.InfoUtils{},
|
||||
&system.InfoUtils{},
|
||||
dialog.New(app),
|
||||
&config.Support{},
|
||||
},
|
||||
Debug: options.Debug{
|
||||
OpenInspectorOnStartup: true,
|
||||
|
@ -1,4 +1,4 @@
|
||||
package app
|
||||
package core
|
||||
|
||||
import (
|
||||
"context"
|
12
app/wails/pkg/sdk/config/config.go
Normal file
12
app/wails/pkg/sdk/config/config.go
Normal file
@ -0,0 +1,12 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"skapp/global"
|
||||
"skapp/pkg/config"
|
||||
)
|
||||
|
||||
type Support struct{}
|
||||
|
||||
func (s *Support) GetConfig() *config.Config {
|
||||
return global.Config
|
||||
}
|
@ -2,15 +2,15 @@ package dialog
|
||||
|
||||
import (
|
||||
"github.com/wailsapp/wails/v2/pkg/runtime"
|
||||
"skapp/pkg/app"
|
||||
"skapp/pkg/core"
|
||||
)
|
||||
|
||||
func New(app *app.App) *Support {
|
||||
func New(app *core.App) *Support {
|
||||
return &Support{app}
|
||||
}
|
||||
|
||||
type Support struct {
|
||||
app *app.App
|
||||
app *core.App
|
||||
}
|
||||
|
||||
func (s *Support) OpenFileDialog(dialogOptions runtime.OpenDialogOptions) string {
|
@ -1,168 +0,0 @@
|
||||
package file
|
||||
|
||||
import (
|
||||
"io/fs"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"skapp/pkg/logger"
|
||||
"sync"
|
||||
)
|
||||
|
||||
type Manager struct {
|
||||
FileManager *sync.Map
|
||||
lock *sync.RWMutex
|
||||
}
|
||||
|
||||
func NewManager() *Manager {
|
||||
return &Manager{
|
||||
FileManager: &sync.Map{},
|
||||
lock: &sync.RWMutex{},
|
||||
}
|
||||
}
|
||||
|
||||
func (m *Manager) Len() (count int64) {
|
||||
defer func() {
|
||||
m.lock.RUnlock()
|
||||
}()
|
||||
m.lock.RLock()
|
||||
|
||||
m.Each(func(file *os.File) bool {
|
||||
count++
|
||||
return true
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
func (m *Manager) Each(cb func(*os.File) bool) {
|
||||
defer func() {
|
||||
m.lock.RUnlock()
|
||||
}()
|
||||
m.lock.RLock()
|
||||
|
||||
m.FileManager.Range(func(key, value any) bool {
|
||||
flagManager := value.(*sync.Map)
|
||||
flagManager.Range(func(key, value any) bool {
|
||||
fileModeManager := value.(*sync.Map)
|
||||
fileModeManager.Range(func(key, value any) bool {
|
||||
f := (value).(*os.File)
|
||||
return cb(f)
|
||||
})
|
||||
return true
|
||||
})
|
||||
return true
|
||||
})
|
||||
}
|
||||
|
||||
func (m *Manager) Remove(path string, flag int, perm fs.FileMode) {
|
||||
if m.Get(path, flag, perm) == nil {
|
||||
return
|
||||
}
|
||||
|
||||
defer func() {
|
||||
m.lock.Unlock()
|
||||
}()
|
||||
m.lock.Lock()
|
||||
|
||||
absPath, err := filepath.Abs(path)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
logger.Log.Infof("Remove %+v %+v %+v\n", absPath, flag, perm)
|
||||
var value interface{}
|
||||
value, _ = m.FileManager.Load(absPath)
|
||||
flagManager := value.(*sync.Map)
|
||||
|
||||
value, _ = flagManager.Load(flag)
|
||||
fileModeManager := value.(*sync.Map)
|
||||
|
||||
value, _ = fileModeManager.LoadAndDelete(perm.String())
|
||||
f := value.(*os.File)
|
||||
_ = f.Close()
|
||||
}
|
||||
|
||||
func (m *Manager) Get(path string, flag int, perm fs.FileMode) *os.File {
|
||||
defer func() {
|
||||
m.lock.RUnlock()
|
||||
}()
|
||||
m.lock.RLock()
|
||||
|
||||
absPath, err := filepath.Abs(path)
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
logger.Log.Infof("Get %+v %+v %+v\n", absPath, flag, perm)
|
||||
value, ok := m.FileManager.Load(absPath)
|
||||
if !ok {
|
||||
return nil
|
||||
}
|
||||
|
||||
switch flagManager := value.(type) {
|
||||
case *sync.Map:
|
||||
value, ok := flagManager.Load(flag)
|
||||
if !ok {
|
||||
return nil
|
||||
}
|
||||
|
||||
switch fileModeManager := value.(type) {
|
||||
case *sync.Map:
|
||||
f, ok := fileModeManager.Load(perm.String())
|
||||
if !ok {
|
||||
return nil
|
||||
}
|
||||
|
||||
return f.(*os.File)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *Manager) Close() {
|
||||
m.Each(func(f *os.File) bool {
|
||||
_ = f.Close()
|
||||
return true
|
||||
})
|
||||
}
|
||||
|
||||
func (m *Manager) Set(file *os.File, path string, flag int, perm fs.FileMode) {
|
||||
defer func() {
|
||||
m.lock.Unlock()
|
||||
}()
|
||||
m.lock.Lock()
|
||||
|
||||
absPath, err := filepath.Abs(path)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
logger.Log.Infof("Set %+v %+v %+v\n", absPath, flag, perm)
|
||||
value, ok := m.FileManager.Load(path)
|
||||
if !ok {
|
||||
flagManager := sync.Map{}
|
||||
fileModeManager := sync.Map{}
|
||||
fileModeManager.Store(perm.String(), file)
|
||||
flagManager.Store(flag, &fileModeManager)
|
||||
m.FileManager.Store(absPath, &flagManager)
|
||||
return
|
||||
}
|
||||
|
||||
switch flagManager := value.(type) {
|
||||
case *sync.Map:
|
||||
value, ok := flagManager.Load(flag)
|
||||
if !ok {
|
||||
fileModeManager := sync.Map{}
|
||||
fileModeManager.Store(perm.String(), file)
|
||||
flagManager.Store(flag, &fileModeManager)
|
||||
}
|
||||
|
||||
switch fileModeManager := value.(type) {
|
||||
case *sync.Map:
|
||||
_, ok := fileModeManager.Load(perm.String())
|
||||
if !ok {
|
||||
fileModeManager.Store(perm.String(), file)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,11 +0,0 @@
|
||||
package system
|
||||
|
||||
import (
|
||||
"skapp/pkg/sdk/system/file"
|
||||
)
|
||||
|
||||
var FileManager = file.NewManager()
|
||||
|
||||
func DestroyFileManager() {
|
||||
FileManager.Close()
|
||||
}
|
@ -1,75 +0,0 @@
|
||||
package system
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"sync"
|
||||
"testing"
|
||||
)
|
||||
|
||||
var wg = sync.WaitGroup{}
|
||||
|
||||
func TestAppendFileManager(t *testing.T) {
|
||||
defer func() {
|
||||
DestroyFileManager()
|
||||
}()
|
||||
|
||||
path := "./io.go"
|
||||
absPath, err := filepath.Abs(path)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
_, err = os.Stat(absPath)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
f, err := os.OpenFile(absPath, os.O_RDONLY, 0644)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
FileManager.Set(f, absPath, os.O_RDONLY, 0644)
|
||||
|
||||
t.Logf("文件数量: %d", FileManager.Len())
|
||||
|
||||
for i := 0; i < 10; i++ {
|
||||
wg.Add(1)
|
||||
go func(i int, t *testing.T) {
|
||||
f := FileManager.Get(absPath, os.O_RDONLY, 0644)
|
||||
if f != nil {
|
||||
t.Log(f.Stat())
|
||||
}
|
||||
|
||||
if i == 5 {
|
||||
FileManager.Remove(absPath, os.O_RDONLY, 0644)
|
||||
}
|
||||
wg.Done()
|
||||
}(i, t)
|
||||
}
|
||||
|
||||
wg.Wait()
|
||||
}
|
||||
|
||||
func TestManager(t *testing.T) {
|
||||
path := "./io.go"
|
||||
absPath, err := filepath.Abs(path)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
_, err = os.Stat(absPath)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
f, err := os.OpenFile(absPath, os.O_RDONLY, 0644)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
FileManager.Set(f, absPath, os.O_RDONLY, 0644)
|
||||
|
||||
f = FileManager.Get(absPath, 0, 0644)
|
||||
t.Log(f.Name())
|
||||
}
|
@ -1,68 +1,4 @@
|
||||
package system
|
||||
|
||||
import (
|
||||
"io/fs"
|
||||
"os"
|
||||
"path/filepath"
|
||||
)
|
||||
|
||||
type System struct{}
|
||||
|
||||
func (s *System) GetFileInfo(path string) (os.FileInfo, error) {
|
||||
f, err := os.OpenFile(path, os.O_RDONLY, 0644)
|
||||
defer func(f *os.File) {
|
||||
_ = f.Close()
|
||||
}(f)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return f.Stat()
|
||||
}
|
||||
|
||||
func (s *System) OpenFile(path string, flag int, perm fs.FileMode) (*os.File, error) {
|
||||
absPath, err := filepath.Abs(path)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
_, err = os.Stat(absPath)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
f, err := os.OpenFile(absPath, flag, perm)
|
||||
FileManager.Set(f, absPath, flag, perm)
|
||||
return f, err
|
||||
}
|
||||
|
||||
func (s *System) ReadFile(path string, chunkId int64, chunkSize int64) ([]byte, error) {
|
||||
f := FileManager.Get(path, os.O_RDONLY, fs.FileMode(0644))
|
||||
if f == nil {
|
||||
return nil, os.ErrClosed
|
||||
}
|
||||
|
||||
info, err := f.Stat()
|
||||
size := info.Size()
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
offset := chunkId * chunkSize
|
||||
if offset+chunkSize > size {
|
||||
chunkSize = size - offset
|
||||
}
|
||||
|
||||
data := make([]byte, chunkSize)
|
||||
_, err = f.ReadAt(data, offset)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return data, nil
|
||||
}
|
||||
|
||||
func (s *System) CloseFile(path string, flag int, perm fs.FileMode) {
|
||||
FileManager.Remove(path, flag, perm)
|
||||
type InfoUtils struct {
|
||||
}
|
||||
|
@ -4,7 +4,7 @@ import (
|
||||
"fmt"
|
||||
"log"
|
||||
"path/filepath"
|
||||
"skapp/pkg/utils"
|
||||
"skapp/pkg/sdk/utils"
|
||||
"xorm.io/xorm"
|
||||
)
|
||||
|
||||
|
@ -1,4 +0,0 @@
|
||||
package system
|
||||
|
||||
type InfoUtils struct {
|
||||
}
|
Loading…
Reference in New Issue
Block a user