[Electron] Fix initial default install location validation (#1592)

This commit is contained in:
Chenlei Hu
2024-11-18 20:10:22 -05:00
committed by GitHub
parent fc9e347055
commit 88164bdac5
3 changed files with 14 additions and 5 deletions

View File

@@ -85,6 +85,8 @@ onMounted(async () => {
appData.value = paths.appData appData.value = paths.appData
appPath.value = paths.appPath appPath.value = paths.appPath
installPath.value = paths.defaultInstallPath installPath.value = paths.defaultInstallPath
await validatePath(paths.defaultInstallPath)
}) })
const validatePath = async (path: string) => { const validatePath = async (path: string) => {

View File

@@ -8,7 +8,9 @@ import {
import LayoutDefault from '@/views/layouts/LayoutDefault.vue' import LayoutDefault from '@/views/layouts/LayoutDefault.vue'
import { isElectron } from './utils/envUtil' import { isElectron } from './utils/envUtil'
const isFileProtocol = () => window.location.protocol === 'file:' const isFileProtocol = window.location.protocol === 'file:'
const basePath = isElectron() ? '/' : window.location.pathname
const guardElectronAccess = ( const guardElectronAccess = (
to: RouteLocationNormalized, to: RouteLocationNormalized,
from: RouteLocationNormalized, from: RouteLocationNormalized,
@@ -22,12 +24,12 @@ const guardElectronAccess = (
} }
const router = createRouter({ const router = createRouter({
history: isFileProtocol() history: isFileProtocol
? createWebHashHistory() ? createWebHashHistory()
: // Base path must be specified to ensure correct relative paths : // Base path must be specified to ensure correct relative paths
// Example: For URL 'http://localhost:7801/ComfyBackendDirect', // Example: For URL 'http://localhost:7801/ComfyBackendDirect',
// we need this base path or assets will incorrectly resolve from 'http://localhost:7801/' // we need this base path or assets will incorrectly resolve from 'http://localhost:7801/'
createWebHistory(window.location.pathname), createWebHistory(basePath),
routes: [ routes: [
{ {
path: '/', path: '/',

View File

@@ -20,7 +20,7 @@ const mockElectronAPI: Plugin = {
Promise.resolve({ Promise.resolve({
appData: 'C:/Users/username/AppData/Roaming', appData: 'C:/Users/username/AppData/Roaming',
appPath: 'C:/Program Files/comfyui-electron/resources/app', appPath: 'C:/Program Files/comfyui-electron/resources/app',
defaultInstallPath: 'C:/Users/username/comfyui-electron' defaultInstallPath: 'bad'
}), }),
validateInstallPath: (path) => { validateInstallPath: (path) => {
if (path === 'bad') { if (path === 'bad') {
@@ -42,7 +42,12 @@ const mockElectronAPI: Plugin = {
} }
return { isValid: true } return { isValid: true }
}, },
showDirectoryPicker: () => Promise.resolve('C:/Users/username/comfyui-electron/1') showDirectoryPicker: () => Promise.resolve('C:/Users/username/comfyui-electron/1'),
DownloadManager: {
getAllDownloads: () => Promise.resolve([]),
onDownloadProgress: () => {}
},
getElectronVersion: () => Promise.resolve('1.0.0')
};` };`
} }
] ]