feat: add custom about dialog

This commit is contained in:
tiny-craft 2023-09-22 18:31:50 +08:00
parent 61be0165ea
commit eb9a0171d1
10 changed files with 123 additions and 19 deletions

View File

@ -85,7 +85,7 @@ func (p *preferencesService) GetFontList() (resp types.JSResp) {
return return
} }
func (p *preferencesService) SetClientVersion(ver string) { func (p *preferencesService) SetAppVersion(ver string) {
if !strings.HasPrefix(ver, "v") { if !strings.HasPrefix(ver, "v") {
p.clientVersion = "v" + ver p.clientVersion = "v" + ver
} else { } else {
@ -93,6 +93,14 @@ func (p *preferencesService) SetClientVersion(ver string) {
} }
} }
func (p *preferencesService) GetAppVersion() (resp types.JSResp) {
resp.Success = true
resp.Data = map[string]any{
"version": p.clientVersion,
}
return
}
type latestRelease struct { type latestRelease struct {
Name string `json:"name"` Name string `json:"name"`
TagName string `json:"tag_name"` TagName string `json:"tag_name"`

View File

@ -19,6 +19,7 @@ import { darkTheme } from 'naive-ui'
import KeyFilterDialog from './components/dialogs/KeyFilterDialog.vue' import KeyFilterDialog from './components/dialogs/KeyFilterDialog.vue'
import { WindowSetDarkTheme, WindowSetLightTheme } from 'wailsjs/runtime/runtime.js' import { WindowSetDarkTheme, WindowSetLightTheme } from 'wailsjs/runtime/runtime.js'
import { themeOverrides } from '@/utils/theme.js' import { themeOverrides } from '@/utils/theme.js'
import AboutDialog from '@/components/dialogs/AboutDialog.vue'
hljs.registerLanguage('json', json) hljs.registerLanguage('json', json)
hljs.registerLanguage('plaintext', plaintext) hljs.registerLanguage('plaintext', plaintext)
@ -57,9 +58,9 @@ watch(
<n-config-provider <n-config-provider
:hljs="hljs" :hljs="hljs"
:inline-theme-disabled="true" :inline-theme-disabled="true"
:locale="prefStore.themeLocale"
:theme="prefStore.isDark ? darkTheme : undefined" :theme="prefStore.isDark ? darkTheme : undefined"
:theme-overrides="themeOverrides" :theme-overrides="themeOverrides"
:locale="prefStore.themeLocale"
class="fill-height"> class="fill-height">
<n-dialog-provider> <n-dialog-provider>
<app-content :loading="initializing" /> <app-content :loading="initializing" />
@ -74,6 +75,7 @@ watch(
<delete-key-dialog /> <delete-key-dialog />
<set-ttl-dialog /> <set-ttl-dialog />
<preferences-dialog /> <preferences-dialog />
<about-dialog />
</n-dialog-provider> </n-dialog-provider>
</n-config-provider> </n-config-provider>
</template> </template>

View File

@ -13,7 +13,7 @@ import useConnectionStore from './stores/connections.js'
import ContentLogPane from './components/content/ContentLogPane.vue' import ContentLogPane from './components/content/ContentLogPane.vue'
import ContentValueTab from '@/components/content/ContentValueTab.vue' import ContentValueTab from '@/components/content/ContentValueTab.vue'
import ToolbarControlWidget from '@/components/common/ToolbarControlWidget.vue' import ToolbarControlWidget from '@/components/common/ToolbarControlWidget.vue'
import { WindowToggleMaximise } from 'wailsjs/runtime/runtime.js' import { WindowIsFullscreen, WindowToggleMaximise } from 'wailsjs/runtime/runtime.js'
import { isMacOS } from '@/utils/platform.js' import { isMacOS } from '@/utils/platform.js'
import iconUrl from '@/assets/images/icon.png' import iconUrl from '@/assets/images/icon.png'
@ -81,8 +81,7 @@ watch(
<n-spin <n-spin
:show="props.loading" :show="props.loading"
:theme-overrides="{ opacitySpinning: 0 }" :theme-overrides="{ opacitySpinning: 0 }"
style="border-radius: 10px" :style="{ backgroundColor: themeVars.bodyColor, borderRadius: WindowIsFullscreen() ? '0' : '10px' }">
:style="{ backgroundColor: themeVars.bodyColor }">
<div <div
id="app-content-wrapper" id="app-content-wrapper"
class="flex-box-v" class="flex-box-v"

View File

@ -0,0 +1,64 @@
<script setup>
import iconUrl from '@/assets/images/icon.png'
import useDialog from 'stores/dialog.js'
import { useThemeVars } from 'naive-ui'
import { BrowserOpenURL } from 'wailsjs/runtime/runtime.js'
import { GetAppVersion } from 'wailsjs/go/services/preferencesService.js'
import { ref, onMounted } from 'vue'
const themeVars = useThemeVars()
const dialogStore = useDialog()
const version = ref('')
onMounted(() => {
GetAppVersion().then(({ data }) => {
version.value = data.version
})
})
const onOpenSource = () => {
BrowserOpenURL('https://github.com/tiny-craft/tiny-rdm')
}
const onOpenWebsite = () => {
BrowserOpenURL('https://redis.tinycraft.cc/')
}
</script>
<template>
<n-modal v-model:show="dialogStore.aboutDialogVisible" :show-icon="false" preset="dialog" transform-origin="center">
<n-space vertical align="center" :wrap-item="false" :wrap="false" :size="10">
<n-avatar :size="120" color="#0000" :src="iconUrl"></n-avatar>
<div class="about-app-title">Tiny RDM</div>
<n-text>{{ version }}</n-text>
<n-space align="center" :wrap-item="false" :wrap="false" :size="5">
<n-text class="about-link" @click="onOpenSource">{{ $t('dialogue.about.source') }}</n-text>
<n-divider vertical />
<n-text class="about-link" @click="onOpenWebsite">{{ $t('dialogue.about.website') }}</n-text>
</n-space>
<div class="about-copyright" :style="{ color: themeVars.textColor3 }">
Copyright © 2023 Tinycraft.cc All rights reserved
</div>
</n-space>
</n-modal>
</template>
<style scoped lang="scss">
.about-app-title {
font-weight: bold;
font-size: 18px;
margin: 5px;
}
.about-link {
cursor: pointer;
&:hover {
text-decoration: underline;
}
}
.about-copyright {
font-size: 12px;
}
</style>

View File

@ -73,6 +73,14 @@ const preferencesOptions = computed(() => {
label: i18n.t('menu.check_update'), label: i18n.t('menu.check_update'),
key: 'update', key: 'update',
}, },
{
type: 'divider',
key: 'd1',
},
{
label: i18n.t('menu.about'),
key: 'about',
},
] ]
}) })
@ -90,6 +98,9 @@ const onSelectPreferenceMenu = (key) => {
case 'update': case 'update':
preferencesStore.checkForUpdate(true) preferencesStore.checkForUpdate(true)
break break
case 'about':
dialogStore.openAboutDialog()
break
} }
} }

View File

@ -181,6 +181,10 @@
"download_now": "Download", "download_now": "Download",
"later": "Later", "later": "Later",
"skip": "Skip This Update" "skip": "Skip This Update"
},
"about": {
"source": "Source Code",
"website": "Official Website"
} }
}, },
"menu": { "menu": {
@ -190,7 +194,8 @@
"close": "Close", "close": "Close",
"preferences": "Preferences", "preferences": "Preferences",
"help": "Help", "help": "Help",
"check_update": "Check for Updates..." "check_update": "Check for Updates...",
"about": "About"
}, },
"log": { "log": {
"launch_log": "Launch Log", "launch_log": "Launch Log",

View File

@ -182,6 +182,10 @@
"download_now": "立即下载", "download_now": "立即下载",
"later": "稍后提醒我", "later": "稍后提醒我",
"skip": "忽略本次更新" "skip": "忽略本次更新"
},
"about": {
"source": "源码地址",
"website": "官方网站"
} }
}, },
"menu": { "menu": {
@ -191,7 +195,8 @@
"close": "关闭", "close": "关闭",
"preferences": "偏好设置", "preferences": "偏好设置",
"help": "帮助", "help": "帮助",
"check_update": "检查更新..." "check_update": "检查更新...",
"about": "关于"
}, },
"log": { "log": {
"launch_log": "运行日志", "launch_log": "运行日志",

View File

@ -1,5 +1,5 @@
import { createPinia } from 'pinia' import { createPinia } from 'pinia'
import { createApp } from 'vue' import { createApp, nextTick } from 'vue'
import App from './App.vue' import App from './App.vue'
import './styles/style.scss' import './styles/style.scss'
import dayjs from 'dayjs' import dayjs from 'dayjs'
@ -24,15 +24,16 @@ async function setupApp() {
await setupDiscreteApi() await setupDiscreteApi()
app.config.errorHandler = (err, instance, info) => { app.config.errorHandler = (err, instance, info) => {
// TODO: add "send error message to author" later // TODO: add "send error message to author" later
nextTick().then(() => {
try { try {
const content = err.toString() const content = err.toString()
$notification.error({ $notification.error(content, {
title: i18n.global.t('common.error'), title: i18n.global.t('common.error'),
content, meta: 'Please see console output for more detail',
// meta: err.stack,
}) })
console.error(err) console.error(err)
} catch (e) {} } catch (e) {}
})
} }
app.config.warnHandler = (message) => { app.config.warnHandler = (message) => {
console.warn(message) console.warn(message)

View File

@ -66,6 +66,7 @@ const useDialogStore = defineStore('dialog', {
ttlDialogVisible: false, ttlDialogVisible: false,
preferencesDialogVisible: false, preferencesDialogVisible: false,
aboutDialogVisible: false,
}), }),
actions: { actions: {
openNewDialog() { openNewDialog() {
@ -211,6 +212,13 @@ const useDialogStore = defineStore('dialog', {
closePreferencesDialog() { closePreferencesDialog() {
this.preferencesDialogVisible = false this.preferencesDialogVisible = false
}, },
openAboutDialog() {
this.aboutDialogVisible = true
},
closeAboutDialog() {
this.aboutDialogVisible = false
},
}, },
}) })

View File

@ -27,13 +27,14 @@ func main() {
app := NewApp() app := NewApp()
connSvc := services.Connection() connSvc := services.Connection()
prefSvc := services.Preferences() prefSvc := services.Preferences()
prefSvc.SetClientVersion(version) prefSvc.SetAppVersion(version)
// menu // menu
appMenu := menu.NewMenu() appMenu := menu.NewMenu()
if runtime.GOOS == "darwin" { if runtime.GOOS == "darwin" {
appMenu.Append(menu.AppMenu()) appMenu.Append(menu.AppMenu())
appMenu.Append(menu.EditMenu()) appMenu.Append(menu.EditMenu())
appMenu.Append(menu.WindowMenu())
} }
// Create application with options // Create application with options