Initial commit
This commit is contained in:
65
shared/utils/tabType.ts
Normal file
65
shared/utils/tabType.ts
Normal file
@@ -0,0 +1,65 @@
|
||||
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('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 '未知'
|
||||
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user