Files
XCDesktop/shared/utils/tabType.ts

76 lines
1.9 KiB
TypeScript

import type { TabType } from '../types/tab.js'
const KNOWN_MODULE_IDS = [
'home', 'settings', 'search', 'weread',
'recycle-bin', 'todo', 'time-tracking', 'pydemos'
] as const
export function getTabTypeFromPath(filePath: string | null): TabType {
if (!filePath) return 'other'
if (filePath.startsWith('file-transfer-panel')) {
return 'file-transfer'
}
if (filePath.startsWith('remote-git://')) {
return 'remote-git'
}
if (filePath.startsWith('remote-desktop://')) {
return 'remote-desktop'
}
if (filePath.startsWith('remote-') && filePath !== 'remote-tab') {
return 'remote-desktop'
}
if (filePath === 'remote-tab' || filePath === 'remote') {
return 'remote'
}
for (const moduleId of KNOWN_MODULE_IDS) {
if (filePath === `${moduleId}-tab` || filePath === moduleId) {
if (moduleId === 'home' || moduleId === 'settings' || moduleId === 'search' || moduleId === 'weread') {
return 'other'
}
return moduleId as TabType
}
}
if (filePath.endsWith('.md')) {
return 'markdown'
}
return 'other'
}
export function getFileNameFromPath(filePath: string | null): string {
if (!filePath) return '未知'
if (filePath.startsWith('file-transfer-panel')) {
const params = new URLSearchParams(filePath.split('?')[1] || '')
const deviceName = params.get('device') || ''
return deviceName ? `文件传输 - ${deviceName}` : '文件传输'
}
for (const moduleId of KNOWN_MODULE_IDS) {
if (filePath === `${moduleId}-tab` || filePath === moduleId) {
const names: Record<string, string> = {
'home': '首页',
'settings': '设置',
'search': '搜索',
'weread': '微信读书',
'recycle-bin': '回收站',
'todo': 'TODO',
'time-tracking': '时间统计',
'pydemos': 'Python Demo',
'remote': '远程桌面',
}
return names[moduleId] ?? moduleId
}
}
const parts = filePath.split('/')
return parts[parts.length - 1] || filePath
}