Commit fb08372c authored by ali's avatar ali

feat: 新增读取本地路径接口

parent ab4aa109
This diff is collapsed.
...@@ -31,6 +31,7 @@ ...@@ -31,6 +31,7 @@
"node": ">=18.0.0" "node": ">=18.0.0"
}, },
"dependencies": { "dependencies": {
"electron-store": "^8.1.0",
"flv.js": "^1.6.2", "flv.js": "^1.6.2",
"pinia": "^2.1.7", "pinia": "^2.1.7",
"pinia-plugin-persistedstate": "^3.2.0", "pinia-plugin-persistedstate": "^3.2.0",
......
import { BrowserWindow, ipcMain, shell, BrowserWindowConstructorOptions } from 'electron' import { BrowserWindow, ipcMain, shell, BrowserWindowConstructorOptions, app } from 'electron'
import Constants from './utils/Constants' import Constants from './utils/Constants'
/* /*
...@@ -8,6 +8,15 @@ export default class IPCs { ...@@ -8,6 +8,15 @@ export default class IPCs {
static browserWindows: Map<string, BrowserWindow[]> = new Map() static browserWindows: Map<string, BrowserWindow[]> = new Map()
static initialize(window: BrowserWindow): void { static initialize(window: BrowserWindow): void {
ipcMain.on('mesGetUserData', () => {
window.webContents.send('msgReceivedUserData', app.getPath('userData'));
})
ipcMain.on('mesGetAppData', () => {
window.webContents.send('msgReceivedAppData', app.getPath('appData'));
})
ipcMain.on('mesGetFilePath', () => { ipcMain.on('mesGetFilePath', () => {
if (Constants.IS_DEV_ENV) { if (Constants.IS_DEV_ENV) {
window.webContents.send('msgReceivedFilePath', `${Constants.APP_INDEX_URL_DEV}`) window.webContents.send('msgReceivedFilePath', `${Constants.APP_INDEX_URL_DEV}`)
......
...@@ -6,9 +6,11 @@ const mainAvailChannels: string[] = [ ...@@ -6,9 +6,11 @@ const mainAvailChannels: string[] = [
'msgRequestGetVersion', 'msgRequestGetVersion',
'msgOpenExternalLink', 'msgOpenExternalLink',
'openWindow', 'openWindow',
'openDevTools' 'openDevTools',
'mesGetUserData',
'mesGetAppData'
] ]
const rendererAvailChannels: string[] = ['msgReceivedVersion', 'msgReceivedFilePath'] const rendererAvailChannels: string[] = ['msgReceivedVersion', 'msgReceivedFilePath', 'msgReceivedUserData', 'msgReceivedAppData']
contextBridge.exposeInMainWorld('mainApi', { contextBridge.exposeInMainWorld('mainApi', {
send: (channel: string, ...data: any[]): void => { send: (channel: string, ...data: any[]): void => {
......
...@@ -2,23 +2,13 @@ ...@@ -2,23 +2,13 @@
import HeaderLayout from '@/renderer/components/layout/HeaderLayout.vue' import HeaderLayout from '@/renderer/components/layout/HeaderLayout.vue'
import { ref } from 'vue' import { ref } from 'vue'
import { useRouter } from 'vue-router' import { useRouter } from 'vue-router'
import useStore from '@/renderer/store'
import { storeToRefs } from 'pinia'
const { settings } = useStore()
const setting = storeToRefs(settings)
const router = useRouter() const router = useRouter()
const isHeader = ref(true) const isHeader = ref(true)
router.beforeEach(async (guard) => { router.beforeEach((to) => {
isHeader.value = isHeader.value =
typeof guard.meta.isHeader === 'boolean' ? (guard.meta.isHeader as boolean) : true typeof to.meta.isHeader === 'boolean' ? (to.meta.isHeader as boolean) : true
window.mainApi.send('mesGetFilePath')
window.mainApi.receive('msgReceivedFilePath', (event: Event, path: string) => {
setting.filePath.value = path
})
}) })
</script> </script>
......
...@@ -12,6 +12,24 @@ const setting = storeToRefs(settings) ...@@ -12,6 +12,24 @@ const setting = storeToRefs(settings)
settings.tts === 'xf_tts' && settings.getSource() settings.tts === 'xf_tts' && settings.getSource()
function init(){
window.mainApi.send('mesGetFilePath')
window.mainApi.receive('msgReceivedFilePath', (event: Event, path: string) => {
setting.filePath.value = path
})
window.mainApi.send('mesGetUserData')
window.mainApi.receive('msgReceivedUserData', (event: Event, path: string) => {
setting.userData.value = path
})
window.mainApi.send('mesGetAppData')
window.mainApi.receive('msgReceivedAppData', (event: Event, path: string) => {
setting.appData.value = path
})
};
init();
const handleRoute = (path: string): void => { const handleRoute = (path: string): void => {
router.push(path) router.push(path)
} }
......
...@@ -301,6 +301,7 @@ function initSocket(): Promise<WebSocket> { ...@@ -301,6 +301,7 @@ function initSocket(): Promise<WebSocket> {
} }
let isTTSRunning = false let isTTSRunning = false
const ttsAudios: HTMLAudioElement[] = []
async function runTTSTask(tasks: string[]) { async function runTTSTask(tasks: string[]) {
if (isTTSRunning) return if (isTTSRunning) return
isTTSRunning = true isTTSRunning = true
...@@ -313,6 +314,7 @@ async function runTTSTask(tasks: string[]) { ...@@ -313,6 +314,7 @@ async function runTTSTask(tasks: string[]) {
const res = await localTTS({ url: settings.ttsHost, text: task }) const res = await localTTS({ url: settings.ttsHost, text: task })
console.log('----------------> TTS:', res) console.log('----------------> TTS:', res)
console.timeEnd(task + ' TTS: ') console.timeEnd(task + ' TTS: ')
console.log('---------------->', ttsAudios);
} }
} catch (error) { } catch (error) {
console.error(error) console.error(error)
......
...@@ -6,6 +6,8 @@ const voskModelMap: Map<string, Model | null> = new Map() ...@@ -6,6 +6,8 @@ const voskModelMap: Map<string, Model | null> = new Map()
export type ISettings = { export type ISettings = {
filePath: string filePath: string
userData: string
appData: string
asr: 'vosk_asr' | 'xf_asr' asr: 'vosk_asr' | 'xf_asr'
voskModels: string[] voskModels: string[]
voskSelectModel: string voskSelectModel: string
...@@ -30,6 +32,8 @@ const useSettingsStore = defineStore('settings', { ...@@ -30,6 +32,8 @@ const useSettingsStore = defineStore('settings', {
state: () => state: () =>
({ ({
filePath: '', filePath: '',
userData: '',
appData: '',
asr: 'vosk_asr', asr: 'vosk_asr',
tts: 'xf_tts', tts: 'xf_tts',
voskModels: [ voskModels: [
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment