support switch profile display date

This commit is contained in:
pompurin404 2024-10-05 13:35:11 +08:00
parent 8d09bfb1a9
commit d2c92eedd3
No known key found for this signature in database
4 changed files with 27 additions and 15 deletions

View File

@ -4,10 +4,4 @@
### New Features ### New Features
- 修改应用在 macOS 和 Linux 下的显示名称为 `Mihomo Party` - 允许切换订阅卡片显示过期时间还是更新时间
- 默认禁用外部控制端口
### Bug Fixes
- 修复 TrafficMonitor 勾选内置网速显示后无法取消勾选的问题
- 修复 TrafficMonitor 显示宽度不正确的问题

View File

@ -20,6 +20,7 @@ import EditInfoModal from './edit-info-modal'
import { useSortable } from '@dnd-kit/sortable' import { useSortable } from '@dnd-kit/sortable'
import { CSS } from '@dnd-kit/utilities' import { CSS } from '@dnd-kit/utilities'
import { openFile } from '@renderer/utils/ipc' import { openFile } from '@renderer/utils/ipc'
import { useAppConfig } from '@renderer/hooks/use-app-config'
interface Props { interface Props {
info: IProfileItem info: IProfileItem
@ -51,6 +52,8 @@ const ProfileItem: React.FC<Props> = (props) => {
const extra = info?.extra const extra = info?.extra
const usage = (extra?.upload ?? 0) + (extra?.download ?? 0) const usage = (extra?.upload ?? 0) + (extra?.download ?? 0)
const total = extra?.total ?? 0 const total = extra?.total ?? 0
const { appConfig, patchAppConfig } = useAppConfig()
const { profileDisplayDate = 'expire' } = appConfig || {}
const [updating, setUpdating] = useState(false) const [updating, setUpdating] = useState(false)
const [selecting, setSelecting] = useState(false) const [selecting, setSelecting] = useState(false)
const [openInfoEditor, setOpenInfoEditor] = useState(false) const [openInfoEditor, setOpenInfoEditor] = useState(false)
@ -171,7 +174,7 @@ const ProfileItem: React.FC<Props> = (props) => {
<Card <Card
fullWidth fullWidth
isPressable isPressable
onPress={() => { onClick={() => {
if (disableSelect) return if (disableSelect) return
setSelecting(true) setSelecting(true)
onClick().finally(() => { onClick().finally(() => {
@ -240,12 +243,22 @@ const ProfileItem: React.FC<Props> = (props) => {
</div> </div>
{info.type === 'remote' && extra && ( {info.type === 'remote' && extra && (
<div <div
onClick={(e) => {
e.stopPropagation()
patchAppConfig({
profileDisplayDate: profileDisplayDate === 'expire' ? 'update' : 'expire'
})
}}
className={`mt-2 flex justify-between ${isCurrent ? 'text-primary-foreground' : 'text-foreground'}`} className={`mt-2 flex justify-between ${isCurrent ? 'text-primary-foreground' : 'text-foreground'}`}
> >
<small>{`${calcTraffic(usage)}/${calcTraffic(total)}`}</small> <small>{`${calcTraffic(usage)}/${calcTraffic(total)}`}</small>
<small> {profileDisplayDate === 'expire' ? (
{extra.expire ? dayjs.unix(extra.expire).format('YYYY-MM-DD') : '长期有效'} <small>
</small> {extra.expire ? dayjs.unix(extra.expire).format('YYYY-MM-DD') : '长期有效'}
</small>
) : (
<small>{dayjs(info.updated).fromNow()}</small>
)}
</div> </div>
)} )}
{info.type === 'local' && ( {info.type === 'local' && (

View File

@ -19,7 +19,7 @@ dayjs.locale('zh-cn')
const ProfileCard: React.FC = () => { const ProfileCard: React.FC = () => {
const { appConfig } = useAppConfig() const { appConfig } = useAppConfig()
const { profileCardStatus = 'col-span-2' } = appConfig || {} const { profileCardStatus = 'col-span-2', profileDisplayDate = 'expire' } = appConfig || {}
const location = useLocation() const location = useLocation()
const match = location.pathname.includes('/profiles') const match = location.pathname.includes('/profiles')
const [updating, setUpdating] = useState(false) const [updating, setUpdating] = useState(false)
@ -121,9 +121,13 @@ const ProfileCard: React.FC = () => {
className={`mt-2 flex justify-between ${match ? 'text-primary-foreground' : 'text-foreground'} `} className={`mt-2 flex justify-between ${match ? 'text-primary-foreground' : 'text-foreground'} `}
> >
<small>{`${calcTraffic(usage)}/${calcTraffic(total)}`}</small> <small>{`${calcTraffic(usage)}/${calcTraffic(total)}`}</small>
<small> {profileDisplayDate === 'expire' ? (
{extra.expire ? dayjs.unix(extra.expire).format('YYYY-MM-DD') : '长期有效'} <small>
</small> {extra.expire ? dayjs.unix(extra.expire).format('YYYY-MM-DD') : '长期有效'}
</small>
) : (
<small>{dayjs(info.updated).fromNow()}</small>
)}
</div> </div>
)} )}
{info.type === 'local' && ( {info.type === 'local' && (

View File

@ -207,6 +207,7 @@ interface IAppConfig {
core: 'mihomo' | 'mihomo-alpha' core: 'mihomo' | 'mihomo-alpha'
proxyDisplayMode: 'simple' | 'full' proxyDisplayMode: 'simple' | 'full'
proxyDisplayOrder: 'default' | 'delay' | 'name' proxyDisplayOrder: 'default' | 'delay' | 'name'
profileDisplayDate?: 'expire' | 'update'
envType?: ('bash' | 'cmd' | 'powershell')[] envType?: ('bash' | 'cmd' | 'powershell')[]
proxyCols: 'auto' | '1' | '2' | '3' | '4' proxyCols: 'auto' | '1' | '2' | '3' | '4'
connectionDirection: 'asc' | 'desc' connectionDirection: 'asc' | 'desc'