refactor(update):优化更新检查逻辑

- 修改 CheckUpdate 函数签名,添加 flag 参数
-根据 flag 参数控制是否显示"当前版本无更新"的通知
- 调整前端按钮点击事件,传递参数 1 给 CheckUpdate 函数
- 优化后端更新检查流程,减少不必要的通知推送
This commit is contained in:
ArvinLovegood 2025-07-17 17:31:40 +08:00
parent dda160069a
commit b98f829286
4 changed files with 16 additions and 13 deletions

21
app.go
View File

@ -144,7 +144,7 @@ func (a *App) CheckSponsorCode(sponsorCode string) map[string]any {
}
}
func (a *App) CheckUpdate() {
func (a *App) CheckUpdate(flag int) {
sponsorCode := strutil.Trim(a.GetConfig().SponsorCode)
if sponsorCode != "" {
encrypted, err := hex.DecodeString(sponsorCode)
@ -296,12 +296,15 @@ func (a *App) CheckUpdate() {
})
}
} else {
go runtime.EventsEmit(a.ctx, "newsPush", map[string]any{
"time": "当前版本:" + Version,
"isRed": false,
"source": "go-stock",
"content": "当前版本无更新",
})
if flag == 1 {
go runtime.EventsEmit(a.ctx, "newsPush", map[string]any{
"time": "当前版本:" + Version,
"isRed": false,
"source": "go-stock",
"content": "当前版本无更新",
})
}
}
}
@ -430,11 +433,11 @@ func (a *App) domReady(ctx context.Context) {
}
//检查新版本
go func() {
a.CheckUpdate()
a.CheckUpdate(0)
a.CheckStockBaseInfo(a.ctx)
a.cron.AddFunc("30 05 8,12,20 * * *", func() {
logger.SugaredLogger.Errorf("Checking for updates...")
a.CheckUpdate()
a.CheckUpdate(0)
})
}()

View File

@ -119,7 +119,7 @@ EventsOn("updateVersion",async (msg) => {
</n-badge>
</h1>
<n-gradient-text type="warning" v-if="vipLevel" >vip到期时间{{vipEndTime}}</n-gradient-text>
<n-button size="tiny" @click="CheckUpdate" type="info" tertiary >检查更新</n-button>
<n-button size="tiny" @click="CheckUpdate(1)" type="info" tertiary >检查更新</n-button>
<div style="justify-self: center;text-align: left" >
<p>自选股行情实时监控基于Wails和NaiveUI构建的AI赋能股票分析工具</p>
<p>目前已支持A股港股美股未来计划加入基金ETF等支持</p>

View File

@ -18,7 +18,7 @@ export function CheckSponsorCode(arg1:string):Promise<Record<string, any>>;
export function CheckStockBaseInfo(arg1:context.Context):Promise<void>;
export function CheckUpdate():Promise<void>;
export function CheckUpdate(arg1:number):Promise<void>;
export function ClsCalendar():Promise<Array<any>>;

View File

@ -30,8 +30,8 @@ export function CheckStockBaseInfo(arg1) {
return window['go']['main']['App']['CheckStockBaseInfo'](arg1);
}
export function CheckUpdate() {
return window['go']['main']['App']['CheckUpdate']();
export function CheckUpdate(arg1) {
return window['go']['main']['App']['CheckUpdate'](arg1);
}
export function ClsCalendar() {