重构: 应用代码移入 internal/app 包,根目录只留入口
根目录原 7 个 app*.go 平铺,现收进 internal/app/ 子包: - package main → package app - NewApp → New(导出) - startup/shutdown → Startup/Shutdown(导出,供 main.go 引用) - main.go 改为薄入口,仅导入 internal/app 并装配 Wails 前端同步更新(Wails 绑定路径 go/main → go/app): - window.go.main.App → window.go.app.App(10 处) - env.d.ts 类型声明路径 wailsjs/go/main/App → wailsjs/go/app/App 根目录 Go 文件从 7 个减至 1 个(main.go),元文件更清晰
This commit is contained in:
@@ -25,7 +25,7 @@ let timeTimer: number | null = null
|
||||
let logTimer: number | null = null
|
||||
let resultTimer: number | null = null
|
||||
|
||||
const App = window.go.main.App
|
||||
const App = window.go.app.App
|
||||
|
||||
const updateTime = async () => {
|
||||
try {
|
||||
|
||||
@@ -6,7 +6,7 @@ import { useToast } from '@/composables/useToast'
|
||||
const { selectedProductId, selectedProductName, selectedProduct } = useProducts()
|
||||
const { showToast } = useToast()
|
||||
|
||||
const App = window.go.main.App
|
||||
const App = window.go.app.App
|
||||
|
||||
// 状态
|
||||
const loading = ref(false)
|
||||
|
||||
@@ -13,7 +13,7 @@ export interface AccountStatus {
|
||||
message?: string
|
||||
}
|
||||
|
||||
const App = window.go.main.App
|
||||
const App = window.go.app.App
|
||||
|
||||
const accounts = ref<Account[]>([])
|
||||
const selectedIndices = ref<Set<number>>(new Set())
|
||||
|
||||
@@ -12,8 +12,8 @@ const activities = ref<ActivityItem[]>([])
|
||||
const currentActivity = ref<ActivityItem | null>(null)
|
||||
const switching = ref(false)
|
||||
|
||||
// 与项目其他 composable 一致,直接走 Wails 运行时注入的 window.go.main.App
|
||||
const App = window.go.main.App
|
||||
// 与项目其他 composable 一致,直接走 Wails 运行时注入的 window.go.app.App
|
||||
const App = window.go.app.App
|
||||
|
||||
export function useActivity() {
|
||||
const { showToast } = useToast()
|
||||
|
||||
@@ -20,7 +20,7 @@ export interface LogMessage {
|
||||
source: 'local' | 'server'
|
||||
}
|
||||
|
||||
const App = window.go.main.App
|
||||
const App = window.go.app.App
|
||||
|
||||
const logs = ref<LogMessage[]>([])
|
||||
const results = ref<Record<string, string>>({})
|
||||
|
||||
@@ -25,7 +25,7 @@ export interface ProductPayload {
|
||||
stale: boolean
|
||||
}
|
||||
|
||||
const App = window.go.main.App
|
||||
const App = window.go.app.App
|
||||
|
||||
const products = ref<Product[]>([])
|
||||
const productInfo = ref<ProductPayload | null>(null)
|
||||
|
||||
@@ -4,7 +4,7 @@ import { useAccounts } from './useAccounts'
|
||||
import { useProducts } from './useProducts'
|
||||
import { useLogs } from './useLogs'
|
||||
|
||||
const App = window.go.main.App
|
||||
const App = window.go.app.App
|
||||
|
||||
const scheduleActive = ref(false)
|
||||
const countdownSeconds = ref(0)
|
||||
|
||||
@@ -17,7 +17,7 @@ export interface Settings {
|
||||
seckillMode: number // 0=标准, 1=激进
|
||||
}
|
||||
|
||||
const App = window.go.main.App
|
||||
const App = window.go.app.App
|
||||
|
||||
const defaultRetryStages: RetryStage[] = [
|
||||
{ maxElapsed: 4, interval: 120 },
|
||||
|
||||
Vendored
+4
-4
@@ -6,16 +6,16 @@ declare module '*.vue' {
|
||||
export default component
|
||||
}
|
||||
|
||||
// 统一从 Wails 自动生成的强类型绑定派生 window.go.main.App 的类型声明,
|
||||
// 统一从 Wails 自动生成的强类型绑定派生 window.go.app.App 的类型声明,
|
||||
// 避免手写声明与后端契约漂移。后端方法签名变更后重新运行 `wails generate`
|
||||
// 会更新 wailsjs/go/main/App.d.ts,此处类型随之更新;若前端引用了已删除或
|
||||
// 会更新 wailsjs/go/app/App.d.ts,此处类型随之更新;若前端引用了已删除或
|
||||
// 已重命名的方法,TypeScript 编译(vue-tsc)会直接报错。
|
||||
import type * as GoApp from './wailsjs/go/main/App'
|
||||
import type * as GoApp from './wailsjs/go/app/App'
|
||||
|
||||
declare global {
|
||||
interface Window {
|
||||
go: {
|
||||
main: {
|
||||
app: {
|
||||
App: typeof GoApp
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package main
|
||||
package app
|
||||
|
||||
import (
|
||||
"context"
|
||||
@@ -81,13 +81,13 @@ func cloneConfig(c types.Config) types.Config {
|
||||
return cp
|
||||
}
|
||||
|
||||
// NewApp 创建 App 实例。
|
||||
func NewApp() *App {
|
||||
// New 创建 App 实例。
|
||||
func New() *App {
|
||||
return &App{}
|
||||
}
|
||||
|
||||
// startup Wails 应用启动时调用。
|
||||
func (a *App) startup(ctx context.Context) {
|
||||
// Startup Wails 应用启动时调用。
|
||||
func (a *App) Startup(ctx context.Context) {
|
||||
a.ctx = ctx
|
||||
|
||||
a.paths = config.DefaultAppPaths()
|
||||
@@ -131,8 +131,8 @@ func (a *App) startup(ctx context.Context) {
|
||||
logger.LogEvent("系统", "success", "应用启动完成 | 账号: %d", a.scheduler.AccountCount())
|
||||
}
|
||||
|
||||
// shutdown Wails 应用关闭时调用。
|
||||
func (a *App) shutdown(ctx context.Context) {
|
||||
// Shutdown Wails 应用关闭时调用。
|
||||
func (a *App) Shutdown(ctx context.Context) {
|
||||
if a.scheduler != nil {
|
||||
a.scheduler.Close()
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package main
|
||||
package app
|
||||
|
||||
import (
|
||||
"douyu_go/internal/activity"
|
||||
@@ -1,4 +1,4 @@
|
||||
package main
|
||||
package app
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
@@ -1,4 +1,4 @@
|
||||
package main
|
||||
package app
|
||||
|
||||
import (
|
||||
"time"
|
||||
@@ -1,4 +1,4 @@
|
||||
package main
|
||||
package app
|
||||
|
||||
import (
|
||||
"time"
|
||||
@@ -1,4 +1,4 @@
|
||||
package main
|
||||
package app
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
@@ -9,13 +9,15 @@ import (
|
||||
"github.com/wailsapp/wails/v2"
|
||||
"github.com/wailsapp/wails/v2/pkg/options"
|
||||
"github.com/wailsapp/wails/v2/pkg/options/assetserver"
|
||||
|
||||
"douyu_go/internal/app"
|
||||
)
|
||||
|
||||
//go:embed all:frontend/dist
|
||||
var assets embed.FS
|
||||
|
||||
func main() {
|
||||
app := NewApp()
|
||||
a := app.New()
|
||||
|
||||
err := wails.Run(&options.App{
|
||||
Title: "斗鱼抢购系统",
|
||||
@@ -26,10 +28,10 @@ func main() {
|
||||
AssetServer: &assetserver.Options{
|
||||
Assets: assets,
|
||||
},
|
||||
OnStartup: app.startup,
|
||||
OnShutdown: app.shutdown,
|
||||
OnStartup: a.Startup,
|
||||
OnShutdown: a.Shutdown,
|
||||
Bind: []interface{}{
|
||||
app,
|
||||
a,
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user