From 88164bdac5e996d7432a16c15cb6416e8c3bb007 Mon Sep 17 00:00:00 2001 From: Chenlei Hu Date: Mon, 18 Nov 2024 20:10:22 -0500 Subject: [PATCH] [Electron] Fix initial default install location validation (#1592) --- src/components/install/InstallLocationPicker.vue | 2 ++ src/router.ts | 8 +++++--- vite.electron.config.mts | 9 +++++++-- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/components/install/InstallLocationPicker.vue b/src/components/install/InstallLocationPicker.vue index 8232a977b..9026eb08b 100644 --- a/src/components/install/InstallLocationPicker.vue +++ b/src/components/install/InstallLocationPicker.vue @@ -85,6 +85,8 @@ onMounted(async () => { appData.value = paths.appData appPath.value = paths.appPath installPath.value = paths.defaultInstallPath + + await validatePath(paths.defaultInstallPath) }) const validatePath = async (path: string) => { diff --git a/src/router.ts b/src/router.ts index 9fb37c080..6a5632f43 100644 --- a/src/router.ts +++ b/src/router.ts @@ -8,7 +8,9 @@ import { import LayoutDefault from '@/views/layouts/LayoutDefault.vue' 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 = ( to: RouteLocationNormalized, from: RouteLocationNormalized, @@ -22,12 +24,12 @@ const guardElectronAccess = ( } const router = createRouter({ - history: isFileProtocol() + 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(window.location.pathname), + createWebHistory(basePath), routes: [ { path: '/', diff --git a/vite.electron.config.mts b/vite.electron.config.mts index f97dc383f..079d7cce8 100644 --- a/vite.electron.config.mts +++ b/vite.electron.config.mts @@ -20,7 +20,7 @@ const mockElectronAPI: Plugin = { Promise.resolve({ appData: 'C:/Users/username/AppData/Roaming', appPath: 'C:/Program Files/comfyui-electron/resources/app', - defaultInstallPath: 'C:/Users/username/comfyui-electron' + defaultInstallPath: 'bad' }), validateInstallPath: (path) => { if (path === 'bad') { @@ -42,7 +42,12 @@ const mockElectronAPI: Plugin = { } 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') };` } ]