diff --git a/cmd/client/main.go b/cmd/client/main.go index 3b46a15..373c50a 100644 --- a/cmd/client/main.go +++ b/cmd/client/main.go @@ -13,9 +13,12 @@ import ( // 版本信息(通过 ldflags 注入) var Version string +var BuildTime string +var GitCommit string func init() { version.SetVersion(Version) + version.SetBuildInfo(GitCommit, BuildTime) } func main() { diff --git a/cmd/server/main.go b/cmd/server/main.go index df0d9db..4abc304 100644 --- a/cmd/server/main.go +++ b/cmd/server/main.go @@ -32,9 +32,12 @@ import ( // 版本信息(通过 ldflags 注入) var Version string +var BuildTime string +var GitCommit string func init() { version.SetVersion(Version) + version.SetBuildInfo(GitCommit, BuildTime) } func main() { diff --git a/pkg/version/version.go b/pkg/version/version.go index 70a2cd9..f930379 100644 --- a/pkg/version/version.go +++ b/pkg/version/version.go @@ -13,6 +13,8 @@ import ( // 版本信息 var Version = "1.0.0" +var GitCommit = "" +var BuildTime = "" // SetVersion 设置版本号(由 main 包在初始化时调用) func SetVersion(v string) { @@ -21,6 +23,16 @@ func SetVersion(v string) { } } +// SetBuildInfo 设置构建信息(由 main 包在初始化时调用) +func SetBuildInfo(gitCommit, buildTime string) { + if gitCommit != "" { + GitCommit = gitCommit + } + if buildTime != "" { + BuildTime = buildTime + } +} + // 仓库信息 const ( RepoURL = "https://git.92coco.cn/flik/GoTunnel" @@ -43,8 +55,8 @@ type Info struct { func GetInfo() Info { return Info{ Version: Version, - GitCommit: "", - BuildTime: "", + GitCommit: GitCommit, + BuildTime: BuildTime, GoVersion: runtime.Version(), OS: runtime.GOOS, Arch: runtime.GOARCH, diff --git a/web/src/App.vue b/web/src/App.vue index 5951a2a..70903f3 100644 --- a/web/src/App.vue +++ b/web/src/App.vue @@ -3,16 +3,20 @@ import { ref, onMounted, computed, watch } from 'vue' import { RouterView, useRouter, useRoute } from 'vue-router' import { HomeOutline, DesktopOutline, SettingsOutline, - PersonCircleOutline, LogOutOutline, LogoGithub, ServerOutline, CheckmarkCircleOutline, ArrowUpCircleOutline, CloseOutline + PersonCircleOutline, LogOutOutline, LogoGithub, ServerOutline, CheckmarkCircleOutline, ArrowUpCircleOutline, CloseOutline, + SunnyOutline, MoonOutline, ContrastOutline } from '@vicons/ionicons5' import { getServerStatus, getVersionInfo, checkServerUpdate, applyServerUpdate, removeToken, getToken, type UpdateInfo } from './api' import { useToast } from './composables/useToast' import { useConfirm } from './composables/useConfirm' +import { useTheme, type ThemeMode } from './composables/useTheme' const router = useRouter() const route = useRoute() const message = useToast() const dialog = useConfirm() +const { themeMode, setTheme } = useTheme() +const showThemeMenu = ref(false) const serverInfo = ref({ bind_addr: '', bind_port: 0 }) const clientCount = ref(0) const version = ref('') @@ -91,8 +95,23 @@ const toggleUserMenu = () => { showUserMenu.value = !showUserMenu.value } +const toggleThemeMenu = () => { + showThemeMenu.value = !showThemeMenu.value +} + +const selectTheme = (mode: ThemeMode) => { + setTheme(mode) + showThemeMenu.value = false +} + +const themeIcon = computed(() => { + if (themeMode.value === 'light') return SunnyOutline + if (themeMode.value === 'dark') return MoonOutline + return ContrastOutline +}) + const openUpdateModal = () => { - if (updateInfo.value) { + if (updateInfo.value && updateInfo.value.available) { showUpdateModal.value = true } } @@ -154,6 +173,25 @@ const handleApplyServerUpdate = () => {