Commit fb08372c authored by ali's avatar ali

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

parent ab4aa109
This diff is collapsed.
......@@ -31,6 +31,7 @@
"node": ">=18.0.0"
},
"dependencies": {
"electron-store": "^8.1.0",
"flv.js": "^1.6.2",
"pinia": "^2.1.7",
"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'
/*
......@@ -8,6 +8,15 @@ export default class IPCs {
static browserWindows: Map<string, BrowserWindow[]> = new Map()
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', () => {
if (Constants.IS_DEV_ENV) {
window.webContents.send('msgReceivedFilePath', `${Constants.APP_INDEX_URL_DEV}`)
......
......@@ -6,9 +6,11 @@ const mainAvailChannels: string[] = [
'msgRequestGetVersion',
'msgOpenExternalLink',
'openWindow',
'openDevTools'
'openDevTools',
'mesGetUserData',
'mesGetAppData'
]
const rendererAvailChannels: string[] = ['msgReceivedVersion', 'msgReceivedFilePath']
const rendererAvailChannels: string[] = ['msgReceivedVersion', 'msgReceivedFilePath', 'msgReceivedUserData', 'msgReceivedAppData']
contextBridge.exposeInMainWorld('mainApi', {
send: (channel: string, ...data: any[]): void => {
......
......@@ -2,23 +2,13 @@
import HeaderLayout from '@/renderer/components/layout/HeaderLayout.vue'
import { ref } from 'vue'
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 isHeader = ref(true)
router.beforeEach(async (guard) => {
router.beforeEach((to) => {
isHeader.value =
typeof guard.meta.isHeader === 'boolean' ? (guard.meta.isHeader as boolean) : true
window.mainApi.send('mesGetFilePath')
window.mainApi.receive('msgReceivedFilePath', (event: Event, path: string) => {
setting.filePath.value = path
})
typeof to.meta.isHeader === 'boolean' ? (to.meta.isHeader as boolean) : true
})
</script>
......
......@@ -12,6 +12,24 @@ const setting = storeToRefs(settings)
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 => {
router.push(path)
}
......
......@@ -301,6 +301,7 @@ function initSocket(): Promise<WebSocket> {
}
let isTTSRunning = false
const ttsAudios: HTMLAudioElement[] = []
async function runTTSTask(tasks: string[]) {
if (isTTSRunning) return
isTTSRunning = true
......@@ -313,6 +314,7 @@ async function runTTSTask(tasks: string[]) {
const res = await localTTS({ url: settings.ttsHost, text: task })
console.log('----------------> TTS:', res)
console.timeEnd(task + ' TTS: ')
console.log('---------------->', ttsAudios);
}
} catch (error) {
console.error(error)
......
......@@ -6,6 +6,8 @@ const voskModelMap: Map<string, Model | null> = new Map()
export type ISettings = {
filePath: string
userData: string
appData: string
asr: 'vosk_asr' | 'xf_asr'
voskModels: string[]
voskSelectModel: string
......@@ -30,6 +32,8 @@ const useSettingsStore = defineStore('settings', {
state: () =>
({
filePath: '',
userData: '',
appData: '',
asr: 'vosk_asr',
tts: 'xf_tts',
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