Files
ComfyUI_frontend/src/router.ts
filtered c39a03f5fd [Hotfix] Cherry-pick desktop dialogs framework to core/1.27 (#5634)
## Summary
Cherry-picked PR #5605 (Add desktop dialogs framework) to core/1.27
branch for hotfix release.

## Cherry-picked commits
- 09e7d1040: Add desktop dialogs framework (#5605)

## Changes
- Data-driven dialog structure in `desktopDialogs.ts`
- Dynamic dialog view component with i18n support
- Button action types: openUrl, close, cancel
- Button severity levels for styling (primary, secondary, danger, warn)
- Fallback invalid dialog for error handling
- i18n collection script updated for dialog strings

## Testing
- Typecheck passed ✓
- Cherry-pick applied cleanly without conflicts

## Impact
This adds the desktop dialog framework feature to the stable 1.27
branch, allowing desktop applications to display standardized dialogs.

┆Issue is synchronized with this [Notion
page](https://www.notion.so/PR-5634-Hotfix-Cherry-pick-desktop-dialogs-framework-to-core-1-27-2726d73d3650811188e7f7e58766d52f)
by [Unito](https://www.unito.io)
2025-09-17 23:26:40 -07:00

140 lines
3.9 KiB
TypeScript

import {
NavigationGuardNext,
RouteLocationNormalized,
createRouter,
createWebHashHistory,
createWebHistory
} from 'vue-router'
import LayoutDefault from '@/views/layouts/LayoutDefault.vue'
import { useUserStore } from './stores/userStore'
import { isElectron } from './utils/envUtil'
const isFileProtocol = window.location.protocol === 'file:'
const basePath = isElectron() ? '/' : window.location.pathname
const guardElectronAccess = (
_to: RouteLocationNormalized,
_from: RouteLocationNormalized,
next: NavigationGuardNext
) => {
if (isElectron()) {
next()
} else {
next('/')
}
}
const router = createRouter({
history: isFileProtocol
? createWebHashHistory()
: // Base path must be specified to ensure correct relative paths
// Example: For URL 'http://localhost:7801/ComfyBackendDirect',
// we need this base path or assets will incorrectly resolve from 'http://localhost:7801/'
createWebHistory(basePath),
routes: [
{
path: '/',
component: LayoutDefault,
children: [
{
path: '',
name: 'GraphView',
component: () => import('@/views/GraphView.vue'),
beforeEnter: async (_to, _from, next) => {
const userStore = useUserStore()
await userStore.initialize()
if (userStore.needsLogin) {
next('/user-select')
} else {
next()
}
}
},
{
path: 'user-select',
name: 'UserSelectView',
component: () => import('@/views/UserSelectView.vue')
},
{
path: 'server-start',
name: 'ServerStartView',
component: () => import('@/views/ServerStartView.vue'),
beforeEnter: guardElectronAccess
},
{
path: 'install',
name: 'InstallView',
component: () => import('@/views/InstallView.vue'),
beforeEnter: guardElectronAccess
},
{
path: 'welcome',
name: 'WelcomeView',
component: () => import('@/views/WelcomeView.vue'),
beforeEnter: guardElectronAccess
},
{
path: 'not-supported',
name: 'NotSupportedView',
component: () => import('@/views/NotSupportedView.vue'),
beforeEnter: guardElectronAccess
},
{
path: 'download-git',
name: 'DownloadGitView',
component: () => import('@/views/DownloadGitView.vue'),
beforeEnter: guardElectronAccess
},
{
path: 'manual-configuration',
name: 'ManualConfigurationView',
component: () => import('@/views/ManualConfigurationView.vue'),
beforeEnter: guardElectronAccess
},
{
path: '/metrics-consent',
name: 'MetricsConsentView',
component: () => import('@/views/MetricsConsentView.vue'),
beforeEnter: guardElectronAccess
},
{
path: 'desktop-start',
name: 'DesktopStartView',
component: () => import('@/views/DesktopStartView.vue'),
beforeEnter: guardElectronAccess
},
{
path: 'maintenance',
name: 'MaintenanceView',
component: () => import('@/views/MaintenanceView.vue'),
beforeEnter: guardElectronAccess
},
{
path: 'desktop-update',
name: 'DesktopUpdateView',
component: () => import('@/views/DesktopUpdateView.vue'),
beforeEnter: guardElectronAccess
},
{
path: 'desktop-dialog/:dialogId',
name: 'DesktopDialogView',
component: () => import('@/views/DesktopDialogView.vue'),
beforeEnter: guardElectronAccess
}
]
}
],
scrollBehavior(_to, _from, savedPosition) {
if (savedPosition) {
return savedPosition
} else {
return { top: 0 }
}
}
})
export default router