diff --git a/electron/main/index.ts b/electron/main/index.ts index e33a816eb775ef0e92ba91ad8ea9ad0b6d9c78f6..9d5ae3af1dff42ef758ba8d913a6d07111d912e6 100644 --- a/electron/main/index.ts +++ b/electron/main/index.ts @@ -22,7 +22,7 @@ interface ICacheConf { theme: 'system' | 'light' | 'dark'; } -const commonCacheConf: Partial = {}; +let commonCacheConf: Partial = {}; const osLocale = processZhLocale( (app.getPreferredSystemLanguages()?.[0] ?? 'en').toLowerCase(), @@ -59,7 +59,7 @@ app.on('activate', () => { async function onReady() { try { await mkdirpIgnoreError(cachePath); - await getUserDefinedConf(commonCacheConfPath); + commonCacheConf = await getUserDefinedConf(commonCacheConfPath); const [nlsConfig, themeConfig] = await Promise.all([ resolveNlsConfiguration(), resolveThemeConfiguration(), @@ -166,6 +166,7 @@ function getUserDefinedConf(dir: string) { if (!fs.existsSync(dir)) { fs.writeFileSync(dir, JSON.stringify({})); } + return JSON.parse(fs.readFileSync(dir, 'utf-8')); } catch (error) { // Ignore error diff --git a/src/router/index.ts b/src/router/index.ts index e9d2db1edf05bf50146e5cda91eddc172bdf8bb3..e9124f977838c928c5a6f8e65783bfbf8f2521b0 100644 --- a/src/router/index.ts +++ b/src/router/index.ts @@ -11,6 +11,7 @@ import { createRouter, createWebHashHistory, RouteRecordRaw } from 'vue-router'; import NotFoundComponent from '@/views/404.vue'; import { qiankunWindow } from 'vite-plugin-qiankun/dist/helper'; import { dynamicRoutes } from './route'; +import { isElectron } from '@/utils/electron'; const staticRoutes: Array = [ { @@ -74,7 +75,8 @@ const staticRoutes: Array = [ }, ]; -const routes = [...staticRoutes, ...dynamicRoutes]; +const dynamic = isElectron ? dynamicRoutes : []; +const routes = [...staticRoutes, ...dynamic]; const router = createRouter({ history: createWebHashHistory( diff --git a/src/utils/electron.ts b/src/utils/electron.ts index 5bc4da7299fdbc7d6a136e416bd3340fe783f1b4..a72d74e58c88e5d15b0b57cb46704a9f7f3841be 100644 --- a/src/utils/electron.ts +++ b/src/utils/electron.ts @@ -9,6 +9,7 @@ export const electronProcess = window.eulercopilot ? window.eulercopilot.process : undefined; +export const isElectron = !!electronProcess; // 为了向后兼容,设置window.electronProcess if (window.eulercopilot && !window.electronProcess) { window.electronProcess = window.eulercopilot.process; diff --git a/src/views/chat/index.vue b/src/views/chat/index.vue index d18af468ca8fcc0e432d175ff00c58a18e1d96cf..f870de06a04ab2bc2739f1ce697f7962eb9b062a 100644 --- a/src/views/chat/index.vue +++ b/src/views/chat/index.vue @@ -9,6 +9,7 @@ import robotAvatar from '@/assets/svgs/robot.svg'; import { computed, ref, onBeforeMount, onBeforeUnmount, h } from 'vue'; import { fetchStream } from '@/utils/fetchStream'; import marked from '@/utils/marked'; +import { useHistorySessionStore } from '@/store/historySession'; const headerStyles = computed(() => { if (window.eulercopilot.process.platform === 'win32') { @@ -125,13 +126,14 @@ function useConversations() { } function onSend(q: string) { + const { currentSelectedSession } = useHistorySessionStore(); conversations.value.push({ id: `user-${conversations.value.length / 2 + 1}`, content: q, role: 'user', }); isStreaming.value = true; - queryStream(q, '1d190929-910d-49e7-8064-39f3bdbee695'); + queryStream(q, currentSelectedSession); } const markedContent = computed(