diff --git a/frontend/src/App.vue b/frontend/src/App.vue index bd7f8e6..2a2dec8 100644 --- a/frontend/src/App.vue +++ b/frontend/src/App.vue @@ -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 { diff --git a/frontend/src/components/ck/CKManager.vue b/frontend/src/components/ck/CKManager.vue index 42d3860..5806fda 100644 --- a/frontend/src/components/ck/CKManager.vue +++ b/frontend/src/components/ck/CKManager.vue @@ -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) diff --git a/frontend/src/composables/useAccounts.ts b/frontend/src/composables/useAccounts.ts index acd12a8..fc2a0a6 100644 --- a/frontend/src/composables/useAccounts.ts +++ b/frontend/src/composables/useAccounts.ts @@ -13,7 +13,7 @@ export interface AccountStatus { message?: string } -const App = window.go.main.App +const App = window.go.app.App const accounts = ref([]) const selectedIndices = ref>(new Set()) diff --git a/frontend/src/composables/useActivity.ts b/frontend/src/composables/useActivity.ts index 38fcca9..ff82c0e 100644 --- a/frontend/src/composables/useActivity.ts +++ b/frontend/src/composables/useActivity.ts @@ -12,8 +12,8 @@ const activities = ref([]) const currentActivity = ref(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() diff --git a/frontend/src/composables/useLogs.ts b/frontend/src/composables/useLogs.ts index cae982b..755334d 100644 --- a/frontend/src/composables/useLogs.ts +++ b/frontend/src/composables/useLogs.ts @@ -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([]) const results = ref>({}) diff --git a/frontend/src/composables/useProducts.ts b/frontend/src/composables/useProducts.ts index 08f2194..e89f42f 100644 --- a/frontend/src/composables/useProducts.ts +++ b/frontend/src/composables/useProducts.ts @@ -25,7 +25,7 @@ export interface ProductPayload { stale: boolean } -const App = window.go.main.App +const App = window.go.app.App const products = ref([]) const productInfo = ref(null) diff --git a/frontend/src/composables/useScheduler.ts b/frontend/src/composables/useScheduler.ts index b85bf2b..428c744 100644 --- a/frontend/src/composables/useScheduler.ts +++ b/frontend/src/composables/useScheduler.ts @@ -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) diff --git a/frontend/src/composables/useSettings.ts b/frontend/src/composables/useSettings.ts index 060e44c..1473646 100644 --- a/frontend/src/composables/useSettings.ts +++ b/frontend/src/composables/useSettings.ts @@ -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 }, diff --git a/frontend/src/env.d.ts b/frontend/src/env.d.ts index 0f829fd..26285b7 100644 --- a/frontend/src/env.d.ts +++ b/frontend/src/env.d.ts @@ -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 } } diff --git a/app.go b/internal/app/app.go similarity index 94% rename from app.go rename to internal/app/app.go index 7202134..6c0ff37 100644 --- a/app.go +++ b/internal/app/app.go @@ -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() } diff --git a/app_activity.go b/internal/app/app_activity.go similarity index 99% rename from app_activity.go rename to internal/app/app_activity.go index d2971ff..54b9179 100644 --- a/app_activity.go +++ b/internal/app/app_activity.go @@ -1,4 +1,4 @@ -package main +package app import ( "douyu_go/internal/activity" diff --git a/app_export.go b/internal/app/app_export.go similarity index 99% rename from app_export.go rename to internal/app/app_export.go index ea30f7b..0f00a52 100644 --- a/app_export.go +++ b/internal/app/app_export.go @@ -1,4 +1,4 @@ -package main +package app import ( "bufio" diff --git a/app_products.go b/internal/app/app_products.go similarity index 99% rename from app_products.go rename to internal/app/app_products.go index 5eac365..c9d1147 100644 --- a/app_products.go +++ b/internal/app/app_products.go @@ -1,4 +1,4 @@ -package main +package app import ( "time" diff --git a/app_seckill.go b/internal/app/app_seckill.go similarity index 99% rename from app_seckill.go rename to internal/app/app_seckill.go index e93de69..2712db8 100644 --- a/app_seckill.go +++ b/internal/app/app_seckill.go @@ -1,4 +1,4 @@ -package main +package app import ( "time" diff --git a/app_verify.go b/internal/app/app_verify.go similarity index 99% rename from app_verify.go rename to internal/app/app_verify.go index 758ec38..9d927f6 100644 --- a/app_verify.go +++ b/internal/app/app_verify.go @@ -1,4 +1,4 @@ -package main +package app import ( "fmt" diff --git a/main.go b/main.go index c5c194e..31442af 100644 --- a/main.go +++ b/main.go @@ -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 {