Skip to content

Commit

Permalink
语音列表缓存
Browse files Browse the repository at this point in the history
  • Loading branch information
liugaowei committed May 18, 2023
1 parent 1b47259 commit dd7051e
Show file tree
Hide file tree
Showing 5 changed files with 19,957 additions and 35 deletions.
8 changes: 5 additions & 3 deletions src/components/configpage/ConfigPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@
</el-form-item>
</el-form>

<Donate></Donate>
<Donate class="donate"></Donate>
</div>
</div>
</template>
Expand Down Expand Up @@ -220,11 +220,13 @@ const updateTitleStyle = () => {
display: flex;
justify-content: space-around;
}
.donate {
width: 420px;
}
.el-form {
margin-top: 7px;
border-right: 1px solid #dcdfe6;
width: 60%;
width: calc(100% - 410px);
padding-left: 10px;
}
:deep(.input-path .el-input-group__append) {
Expand Down
22 changes: 8 additions & 14 deletions src/components/configpage/Donate.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,8 @@
欢迎<span>Star</span>、<span>Fork</span>和<span>PR</span>。你的Star是对作者最好的鼓励:)
</h3>
<p style="margin: 0 10px; font-size: 11px">
有问题请在
<a href="https://jq.qq.com/?_wv=1027&k=bMNZfGxs" target="_blank"
>QQ群(752801820)</a
>
<a href="https://github.com/LokerL/tts-vue/issues" target="_blank"
>GitHub Issues</a
>
或者
<a href="https://gitee.com/LGW_space/tts-vue/issues" target="_blank"
>Gitee Issues</a
>
进行提问或反馈。
<p>使用遇到问题请仔细阅读【文档】→【使用指南】中的【功能介绍】和【常见问题】。</p>
<p>其他意见或建议可以在【文档】→【加入Q群】中艾特或私聊群主或者管理,也可以在github或者gitee提出issues。</p>
</p>
</div>

Expand Down Expand Up @@ -61,14 +50,19 @@ import GithubBtn from "./GithubBtn.vue";
</script>

<style scoped>
.donate {
width: 400px;
}
.donate .des {
margin-bottom: 10px;
}
h3 {
margin: 1px 10px;
font-size: 1em;
}
.des p {
margin: 0;
}
.btns {
margin-top: 10px;
display: flex;
Expand Down
21 changes: 4 additions & 17 deletions src/components/main/options-config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
const { ipcRenderer } = require("electron");
const fs = require("fs");
import { voices } from './../../global/voices';
let lang = {
AF_ZA: "南非荷兰语(南非)",
AM_ET: "阿姆哈拉语(埃塞俄比亚)",
Expand Down Expand Up @@ -170,12 +169,10 @@ let lang = {
};

let msVoicesList;
try {
msVoicesList = await ipcRenderer.invoke("voices");
localStorage.setItem("msVoicesList", JSON.stringify(msVoicesList));
} catch (error) {
console.error("获取语言列表网络请求失败(使用缓存列表):", error);
if (localStorage.getItem("msVoicesList") !== null) {
msVoicesList = JSON.parse(localStorage.getItem("msVoicesList") || "[]");
} else {
msVoicesList = voices;
}

const voicesList = msVoicesList.map((item: any) => {
Expand All @@ -195,21 +192,11 @@ const list = voicesList
})
.sort((a: any, b: any) => b.label.localeCompare(a.label, "en"));

// const set = new Set(list);
// const languageSelect = [...set].map((item: any) => {
// if (item.locale != "" && item.localeZH != "") {
// return {
// value: item.locale,
// label: item.localeZH,
// }
// }
// });
const tempMap = new Map();
const languageSelect = list.filter(
(item: any) => !tempMap.has(item.value) && tempMap.set(item.value, 1)
);

console.log(languageSelect);
const findVoicesByLocaleName = (localeName: any) => {
const voices = voicesList.filter((item: any) => item.locale == localeName);
return voices;
Expand Down
13 changes: 12 additions & 1 deletion src/global/initLocalStore.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
import { voices } from './voices';
const Store = require("electron-store");
const store = new Store();
const { ipcRenderer } = require("electron");
export default function initStore() {

export default async function initStore() {
try {
const msVoicesList = await ipcRenderer.invoke("voices");
localStorage.setItem("msVoicesList", JSON.stringify(msVoicesList));
} catch (error) {
// 如果网络请求失败并且localStorage的msVoicesList为空
if (localStorage.getItem("msVoicesList") == null) {
localStorage.setItem("msVoicesList", JSON.stringify(voices));
}
}

store.set("FormConfig.默认", {
languageSelect: "zh-CN",
Expand Down
Loading

0 comments on commit dd7051e

Please sign in to comment.