From 1f9749fbe91c08e80b3c9a7edc3c100ec97ba3d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=89=9B=E8=92=A1?= <53455523+gobosan@users.noreply.github.com> Date: Wed, 9 Feb 2022 08:59:33 +0900 Subject: [PATCH] =?UTF-8?q?=E3=83=98=E3=83=AB=E3=83=97=E3=81=A7=E3=82=A2?= =?UTF-8?q?=E3=83=83=E3=83=97=E3=83=87=E3=83=BC=E3=83=88=E3=82=92=E7=A2=BA?= =?UTF-8?q?=E8=AA=8D=E3=81=A7=E3=81=8D=E3=82=8B=E3=82=88=E3=81=86=E3=81=AB?= =?UTF-8?q?=E3=81=99=E3=82=8B=20(#690)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * add the ability to check for updates * fix * add wording * fix * fix * fix * fix * fix * fix * remove unnecessary logs * remove logger * エラーを投げる --- src/components/UpdateInfo.vue | 85 +++++++++++++++++++++++++++++++++++ src/store/project.ts | 9 +++- 2 files changed, 92 insertions(+), 2 deletions(-) diff --git a/src/components/UpdateInfo.vue b/src/components/UpdateInfo.vue index 25ab63ed30..ee63fd2971 100644 --- a/src/components/UpdateInfo.vue +++ b/src/components/UpdateInfo.vue @@ -13,6 +13,11 @@ import { useStore } from "@/store"; import { computed, defineComponent, ref } from "@vue/runtime-core"; import { UpdateInfo } from "../type/preload"; +import { + VersionType, + versionTextParse, + baseVersionIsLow, +} from "@/store/project"; export default defineComponent({ setup() { @@ -21,10 +26,90 @@ export default defineComponent({ const infos = ref(); store.dispatch("GET_UPDATE_INFOS").then((obj) => (infos.value = obj)); + let isCheckingFailed = ref(false); + + let isCheckingFinished = ref(false); + + const currentVersion = ref(""); + const latestVersion = ref(""); + window.electron + .getAppInfos() + .then((obj) => { + currentVersion.value = obj.version; + }) + .then(() => { + fetch("https://api.github.com/repos/VOICEVOX/voicevox/releases", { + method: "GET", + headers: { + "Content-Type": "application/json", + Accept: "application/json", + }, + }) + .then((response) => { + if (!response.ok) { + isCheckingFailed.value = true; + } else { + return response.json(); + } + }) + .then((json) => { + const obj = json.find( + (item: { prerelease: boolean; tag_name: string }) => { + return ( + !item.prerelease && + baseVersionIsLow( + versionTextParse(currentVersion.value) as VersionType, + versionTextParse(item.tag_name) as VersionType + ) + ); + } + ); + obj ? (latestVersion.value = obj.tag_name) : undefined; + isCheckingFinished.value = true; + }) + .catch((err) => { + throw new Error(err); + }); + }) + .catch(() => { + isCheckingFailed.value = true; + }); + + const isCheckingFailedComputed = computed(() => { + return isCheckingFailed.value; + }); + + const isCheckingFinishedComputed = computed(() => { + return isCheckingFinished.value; + }); + + const isUpdateAvailable = computed(() => { + return isCheckingFinished.value && latestVersion.value !== ""; + }); + const html = computed(() => { if (!infos.value) return ""; let html = ""; + + if (isUpdateAvailable.value) { + html += `

アップデートがあります!

`; + html += `

最新版のダウンロードページ

`; + html += `https://voicevox.hiroshiba.jp/`; + } else if (isCheckingFinishedComputed.value && !isUpdateAvailable.value) { + html += `

お使いの VOICEBOX は最新です!

`; + } else if ( + !isCheckingFinishedComputed.value && + !isCheckingFailedComputed.value + ) { + html += `

アップデートを確認中です…

`; + } else { + html += `

アップデートの確認に失敗しました…

`; + } + + html += `
`; + html += `

アップデート履歴

`; + for (const info of infos.value) { const version: string = info.version; const descriptions: string[] = info.descriptions; diff --git a/src/store/project.ts b/src/store/project.ts index fe7d3e55b6..5f9f762dff 100755 --- a/src/store/project.ts +++ b/src/store/project.ts @@ -404,7 +404,9 @@ interface ProjectType { export type VersionType = [number, number, number]; -const versionTextParse = (appVersionText: string): VersionType | undefined => { +export const versionTextParse = ( + appVersionText: string +): VersionType | undefined => { const textArray = appVersionText.split("."); if (textArray.length !== 3) return undefined; const appVersion = textArray.map(Number) as VersionType; @@ -412,7 +414,10 @@ const versionTextParse = (appVersionText: string): VersionType | undefined => { return appVersion; }; -const baseVersionIsLow = (base: VersionType, target: VersionType): boolean => { +export const baseVersionIsLow = ( + base: VersionType, + target: VersionType +): boolean => { let result = false; for (let i = 0; i < 3; i++) { if (base[i] > target[i]) {