mirror of
https://github.com/ArvinLovegood/go-stock.git
synced 2025-07-19 00:00:09 +08:00
feat(frontend):实现暗黑主题切换即时生效不需要重启
- 在 about、fund、settings 和 stock 组件中添加 onBeforeUnmount 钩子,用于销毁消息实例 - 在 app.go 中添加 updateSettings 事件处理,根据配置切换暗黑主题 -优化 settings 组件,保存配置后发送 updateSettings 事件 -调整 stock 组件中 n-card 的属性,移除冗余代码
This commit is contained in:
parent
9ebb246e5c
commit
c5065b0504
34
app.go
34
app.go
@ -5,6 +5,7 @@ package main
|
||||
import (
|
||||
"context"
|
||||
"encoding/base64"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/PuerkitoBio/goquery"
|
||||
"github.com/coocood/freecache"
|
||||
@ -65,12 +66,41 @@ func (a *App) startup(ctx context.Context) {
|
||||
//}, func() {
|
||||
// onExit(a)
|
||||
//})
|
||||
runtime.EventsOn(ctx, "updateSettings", func(optionalData ...interface{}) {
|
||||
logger.SugaredLogger.Infof("updateSettings : %v\n", optionalData)
|
||||
config := &data.Settings{}
|
||||
setMap := optionalData[0].(map[string]interface{})
|
||||
|
||||
systray.Run(func() {
|
||||
// 将 map 转换为 JSON 字节切片
|
||||
jsonData, err := json.Marshal(setMap)
|
||||
if err != nil {
|
||||
logger.SugaredLogger.Errorf("Marshal error:%s", err.Error())
|
||||
return
|
||||
}
|
||||
// 将 JSON 字节切片解析到结构体中
|
||||
err = json.Unmarshal(jsonData, config)
|
||||
if err != nil {
|
||||
logger.SugaredLogger.Errorf("Unmarshal error:%s", err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
logger.SugaredLogger.Infof("updateSettings config:%+v", config)
|
||||
if config.DarkTheme {
|
||||
runtime.WindowSetBackgroundColour(ctx, 27, 38, 54, 1)
|
||||
runtime.WindowSetDarkTheme(ctx)
|
||||
} else {
|
||||
runtime.WindowSetBackgroundColour(ctx, 255, 255, 255, 1)
|
||||
runtime.WindowSetLightTheme(ctx)
|
||||
}
|
||||
runtime.WindowReloadApp(ctx)
|
||||
|
||||
})
|
||||
systray.RunWithExternalLoop(func() {
|
||||
onReady(a)
|
||||
}, func() {
|
||||
onExit(a)
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
func (a *App) CheckUpdate() {
|
||||
@ -816,7 +846,7 @@ func (a *App) UpdateConfig(settings *data.Settings) string {
|
||||
a.cron.Remove(entryID)
|
||||
}
|
||||
id, _ := a.cron.AddFunc(fmt.Sprintf("@every %ds", settings.RefreshInterval), func() {
|
||||
logger.SugaredLogger.Infof("MonitorStockPrices:%s", time.Now())
|
||||
//logger.SugaredLogger.Infof("MonitorStockPrices:%s", time.Now())
|
||||
MonitorStockPrices(a)
|
||||
})
|
||||
a.cronEntrys["MonitorStockPrices"] = id
|
||||
|
@ -2,7 +2,7 @@
|
||||
// import { MdPreview } from 'md-editor-v3';
|
||||
// preview.css相比style.css少了编辑器那部分样式
|
||||
import 'md-editor-v3/lib/preview.css';
|
||||
import {h, onMounted, ref} from 'vue';
|
||||
import {h, onBeforeUnmount, onMounted, ref} from 'vue';
|
||||
import {CheckUpdate, GetVersionInfo} from "../../wailsjs/go/main/App";
|
||||
import {EventsOn} from "../../wailsjs/runtime";
|
||||
import {NAvatar, NButton, useNotification} from "naive-ui";
|
||||
@ -23,8 +23,9 @@ onMounted(() => {
|
||||
wxpay.value=res.wxpay;
|
||||
});
|
||||
})
|
||||
|
||||
|
||||
onBeforeUnmount(() => {
|
||||
notify.destroyAll()
|
||||
})
|
||||
|
||||
EventsOn("updateVersion",async (msg) => {
|
||||
const githubTimeStr = msg.published_at;
|
||||
|
@ -89,6 +89,7 @@ onMounted(() => {
|
||||
onBeforeUnmount(() => {
|
||||
clearInterval(ticker.value)
|
||||
ws.value.close()
|
||||
message.destroyAll()
|
||||
})
|
||||
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
<script setup>
|
||||
|
||||
import {computed, onMounted, ref} from "vue";
|
||||
import {computed, onBeforeUnmount, onMounted, ref} from "vue";
|
||||
import {
|
||||
AddPrompt, DelPrompt,
|
||||
ExportConfig,
|
||||
@ -86,9 +86,12 @@ onMounted(()=>{
|
||||
promptTemplates.value=res
|
||||
})
|
||||
})
|
||||
|
||||
onBeforeUnmount(() => {
|
||||
message.destroyAll()
|
||||
})
|
||||
|
||||
function saveConfig(){
|
||||
|
||||
let config= new data.Settings({
|
||||
ID:formValue.value.ID,
|
||||
dingPushEnable:formValue.value.dingPush.enable,
|
||||
@ -114,9 +117,11 @@ function saveConfig(){
|
||||
darkTheme:formValue.value.darkTheme
|
||||
})
|
||||
|
||||
//console.log("Settings",config)
|
||||
|
||||
//console.log("Settings",config)
|
||||
UpdateConfig(config).then(res=>{
|
||||
message.success(res)
|
||||
EventsEmit("updateSettings", config);
|
||||
})
|
||||
}
|
||||
|
||||
@ -273,7 +278,7 @@ function deletePrompt(ID){
|
||||
</template>
|
||||
</n-input-number>
|
||||
</n-form-item-gi>
|
||||
<n-form-item-gi :span="5" label="暗黑主题(重启生效):" path="darkTheme" >
|
||||
<n-form-item-gi :span="5" label="暗黑主题:" path="darkTheme" >
|
||||
<n-switch v-model:value="formValue.darkTheme" />
|
||||
</n-form-item-gi>
|
||||
<n-form-item-gi :span="22" label="浏览器路径:" path="browserPath" >
|
||||
|
@ -60,12 +60,9 @@ const mdPreviewRef = ref(null)
|
||||
const mdEditorRef = ref(null)
|
||||
const tipsRef = ref(null)
|
||||
const message = useMessage()
|
||||
const modal = useModal()
|
||||
const notify = useNotification()
|
||||
const dialog = useDialog()
|
||||
const stocks=ref([])
|
||||
const results=ref({})
|
||||
//const ticker=ref({})
|
||||
const stockList=ref([])
|
||||
const followList=ref([])
|
||||
const options=ref([])
|
||||
@ -214,7 +211,8 @@ onBeforeUnmount(() => {
|
||||
// console.log(`the component is now unmounted.`)
|
||||
//clearInterval(ticker.value)
|
||||
ws.value.close()
|
||||
|
||||
message.destroyAll()
|
||||
notify.destroyAll()
|
||||
})
|
||||
|
||||
EventsOn("refresh",(data)=>{
|
||||
@ -865,7 +863,7 @@ function share(code,name){
|
||||
</vue-danmaku>
|
||||
<n-grid :x-gap="8" :cols="3" :y-gap="8" >
|
||||
<n-gi :id="result['股票代码']+'_gi'" v-for="result in sortedResults" style="margin-left: 2px;" >
|
||||
<n-card :id="result['股票代码']" :data-code="result['股票代码']" :bordered="true" :title="result['股票名称']+'_'+result.sort" :closable="false" @close="removeMonitor(result['股票代码'],result['股票名称'],result.key)">
|
||||
<n-card :data-sort="result.sort" :id="result['股票代码']" :data-code="result['股票代码']" :bordered="true" :title="result['股票名称']" :closable="false" @close="removeMonitor(result['股票代码'],result['股票名称'],result.key)">
|
||||
<n-grid :cols="1" :y-gap="6">
|
||||
<n-gi>
|
||||
<n-text :type="result.type" >
|
||||
|
Loading…
x
Reference in New Issue
Block a user