From 54b6ace138cda6633cfebab47a72f52edf5f4e10 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=89=9B=E8=92=A1?= Date: Sun, 6 Feb 2022 17:04:26 +0900 Subject: [PATCH 01/12] add the ability to check for updates --- src/components/UpdateInfo.vue | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/src/components/UpdateInfo.vue b/src/components/UpdateInfo.vue index 25ab63ed30..ecc1067c91 100644 --- a/src/components/UpdateInfo.vue +++ b/src/components/UpdateInfo.vue @@ -21,10 +21,39 @@ export default defineComponent({ const infos = ref(); store.dispatch("GET_UPDATE_INFOS").then((obj) => (infos.value = obj)); + const currentVersion = ref(""); + window.electron.getAppInfos().then((obj) => { + currentVersion.value = obj.version; + }); + + const latestVersion = ref(""); + let tags: string[] = []; + fetch("https://api.github.com/repos/VOICEVOX/voicevox/releases") + .then((res) => res.json()) + .then((obj) => { + obj.map((item: { prerelease: boolean; tag_name: string }) => { + if (item.prerelease == false) { + tags.push(item.tag_name); + } + }); + latestVersion.value = tags[0]; + }); + const html = computed(() => { if (!infos.value) return ""; let html = ""; + if (currentVersion.value === latestVersion.value) { + html += `

お使いの VOICEBOX は最新です!

`; + html += "
"; + } else { + html += `

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

`; + html += "

現在のバージョン:" + currentVersion.value + "

"; + html += "

最新のバージョン:" + latestVersion.value + "

"; + html += "

ダウンロードページ

"; + html += `https://voicevox.hiroshiba.jp/`; + html += "
"; + } for (const info of infos.value) { const version: string = info.version; const descriptions: string[] = info.descriptions; From cbc58ec840487344e20261436409aabd640d5d5a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=89=9B=E8=92=A1?= Date: Sun, 6 Feb 2022 17:21:10 +0900 Subject: [PATCH 02/12] fix --- src/components/UpdateInfo.vue | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/components/UpdateInfo.vue b/src/components/UpdateInfo.vue index ecc1067c91..cd0377ee93 100644 --- a/src/components/UpdateInfo.vue +++ b/src/components/UpdateInfo.vue @@ -45,12 +45,12 @@ export default defineComponent({ let html = ""; if (currentVersion.value === latestVersion.value) { html += `

お使いの VOICEBOX は最新です!

`; - html += "
"; + html += `
`; } else { html += `

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

`; - html += "

現在のバージョン:" + currentVersion.value + "

"; - html += "

最新のバージョン:" + latestVersion.value + "

"; - html += "

ダウンロードページ

"; + html += `

現在のバージョン:` + currentVersion.value + `

`; + html += `

最新のバージョン:` + latestVersion.value + `

`; + html += `

ダウンロードページ

`; html += `https://voicevox.hiroshiba.jp/`; html += "
"; } From be67eea1e28193b85e74e4699832e5a613ac5ee2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=89=9B=E8=92=A1?= Date: Sun, 6 Feb 2022 17:33:08 +0900 Subject: [PATCH 03/12] add wording --- src/components/UpdateInfo.vue | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/components/UpdateInfo.vue b/src/components/UpdateInfo.vue index cd0377ee93..613fdf494d 100644 --- a/src/components/UpdateInfo.vue +++ b/src/components/UpdateInfo.vue @@ -46,13 +46,15 @@ export default defineComponent({ if (currentVersion.value === latestVersion.value) { html += `

お使いの VOICEBOX は最新です!

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

変更履歴

`; } else { html += `

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

`; html += `

現在のバージョン:` + currentVersion.value + `

`; html += `

最新のバージョン:` + latestVersion.value + `

`; - html += `

ダウンロードページ

`; + html += `

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

`; html += `https://voicevox.hiroshiba.jp/`; html += "
"; + html += `

変更履歴

`; } for (const info of infos.value) { const version: string = info.version; From 8e17e6060c55f37efd17fb2ef57cd8d86ac008eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=89=9B=E8=92=A1?= Date: Sun, 6 Feb 2022 17:44:19 +0900 Subject: [PATCH 04/12] fix --- src/components/UpdateInfo.vue | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/components/UpdateInfo.vue b/src/components/UpdateInfo.vue index 613fdf494d..f7ae0e7d72 100644 --- a/src/components/UpdateInfo.vue +++ b/src/components/UpdateInfo.vue @@ -32,7 +32,7 @@ export default defineComponent({ .then((res) => res.json()) .then((obj) => { obj.map((item: { prerelease: boolean; tag_name: string }) => { - if (item.prerelease == false) { + if (item.prerelease === false) { tags.push(item.tag_name); } }); @@ -45,17 +45,15 @@ export default defineComponent({ let html = ""; if (currentVersion.value === latestVersion.value) { html += `

お使いの VOICEBOX は最新です!

`; - html += `
`; - html += `

変更履歴

`; } else { html += `

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

`; html += `

現在のバージョン:` + currentVersion.value + `

`; html += `

最新のバージョン:` + latestVersion.value + `

`; html += `

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

`; html += `https://voicevox.hiroshiba.jp/`; - html += "
"; - html += `

変更履歴

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

アップデート履歴

`; for (const info of infos.value) { const version: string = info.version; const descriptions: string[] = info.descriptions; From a9b68817c6ded758635db5abcdacfb2207fa6cd9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=89=9B=E8=92=A1?= Date: Sun, 6 Feb 2022 20:02:31 +0900 Subject: [PATCH 05/12] fix --- src/components/UpdateInfo.vue | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/components/UpdateInfo.vue b/src/components/UpdateInfo.vue index f7ae0e7d72..dc92e848fb 100644 --- a/src/components/UpdateInfo.vue +++ b/src/components/UpdateInfo.vue @@ -32,10 +32,10 @@ export default defineComponent({ .then((res) => res.json()) .then((obj) => { obj.map((item: { prerelease: boolean; tag_name: string }) => { - if (item.prerelease === false) { - tags.push(item.tag_name); - } + item.prerelease === false ? tags.push(item.tag_name) : undefined; }); + }) + .then(() => { latestVersion.value = tags[0]; }); @@ -43,17 +43,25 @@ export default defineComponent({ if (!infos.value) return ""; let html = ""; - if (currentVersion.value === latestVersion.value) { - html += `

お使いの VOICEBOX は最新です!

`; - } else { + + const isFetchingFinished = latestVersion.value.length > 0; + const isUpdateAvailable = currentVersion.value !== latestVersion.value; + + if (isFetchingFinished && isUpdateAvailable) { html += `

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

`; html += `

現在のバージョン:` + currentVersion.value + `

`; html += `

最新のバージョン:` + latestVersion.value + `

`; html += `

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

`; html += `https://voicevox.hiroshiba.jp/`; + } else if (isFetchingFinished) { + html += `

お使いの VOICEBOX は最新です!

`; + } else { + html += `

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

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

アップデート履歴

`; + for (const info of infos.value) { const version: string = info.version; const descriptions: string[] = info.descriptions; From daa29fc6c9145143b099234ddb6df26f5ecc0371 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=89=9B=E8=92=A1?= Date: Sun, 6 Feb 2022 20:24:44 +0900 Subject: [PATCH 06/12] fix --- src/components/UpdateInfo.vue | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/components/UpdateInfo.vue b/src/components/UpdateInfo.vue index dc92e848fb..f815afa71c 100644 --- a/src/components/UpdateInfo.vue +++ b/src/components/UpdateInfo.vue @@ -27,16 +27,16 @@ export default defineComponent({ }); const latestVersion = ref(""); - let tags: string[] = []; fetch("https://api.github.com/repos/VOICEVOX/voicevox/releases") .then((res) => res.json()) .then((obj) => { - obj.map((item: { prerelease: boolean; tag_name: string }) => { - item.prerelease === false ? tags.push(item.tag_name) : undefined; + obj.find((item: { prerelease: boolean }) => { + item.prerelease === false; }); + return obj; }) - .then(() => { - latestVersion.value = tags[0]; + .then((obj) => { + latestVersion.value = obj[0].tag_name; }); const html = computed(() => { From b31ca57b4577cd14cd41ff4ca2ce9668a6a903b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=89=9B=E8=92=A1?= Date: Sun, 6 Feb 2022 20:26:18 +0900 Subject: [PATCH 07/12] fix --- src/components/UpdateInfo.vue | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/components/UpdateInfo.vue b/src/components/UpdateInfo.vue index f815afa71c..5a44bc0890 100644 --- a/src/components/UpdateInfo.vue +++ b/src/components/UpdateInfo.vue @@ -33,9 +33,6 @@ export default defineComponent({ obj.find((item: { prerelease: boolean }) => { item.prerelease === false; }); - return obj; - }) - .then((obj) => { latestVersion.value = obj[0].tag_name; }); From 5de3449c82e4ddefb50923b494b13f53129a2b5c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=89=9B=E8=92=A1?= Date: Mon, 7 Feb 2022 14:15:26 +0900 Subject: [PATCH 08/12] fix --- src/components/UpdateInfo.vue | 76 +++++++++++++++++++++++++++++------ src/store/project.ts | 9 ++++- 2 files changed, 70 insertions(+), 15 deletions(-) diff --git a/src/components/UpdateInfo.vue b/src/components/UpdateInfo.vue index 5a44bc0890..f79215bef7 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,39 +26,84 @@ export default defineComponent({ const infos = ref(); store.dispatch("GET_UPDATE_INFOS").then((obj) => (infos.value = obj)); + let isCheckingFailed = ref(false); + const currentVersion = ref(""); window.electron.getAppInfos().then((obj) => { currentVersion.value = obj.version; }); const latestVersion = ref(""); - fetch("https://api.github.com/repos/VOICEVOX/voicevox/releases") - .then((res) => res.json()) + fetch("https://api.github.com/repos/VOICEVOX/voicevox/releases", { + method: "GET", + headers: { + "Content-Type": "application/json", + Accept: "application/json", + }, + }) + .then((response) => { + if (!response.ok) { + console.error("response.ok:", response.ok); + console.error("esponse.status:", response.status); + isCheckingFailed.value = true; + } + return response.json(); + }) .then((obj) => { - obj.find((item: { prerelease: boolean }) => { - item.prerelease === false; - }); + obj.find( + (item: { prerelease: boolean; tag_name: string }) => + item.prerelease === false && + baseVersionIsLow( + versionTextParse(currentVersion.value) as VersionType, + versionTextParse(item.tag_name) as VersionType + ) + ); latestVersion.value = obj[0].tag_name; + }) + .catch((err) => { + console.error(err); + isCheckingFailed.value = true; }); + const isCheckingUpdatesFailed = computed(() => { + return isCheckingFailed.value; + }); + + const isFetchingFinished = computed(() => { + if (!isCheckingUpdatesFailed.value && latestVersion.value.length > 0) { + return true; + } else { + return false; + } + }); + + const isUpdateAvailable = computed(() => { + if (isFetchingFinished.value) { + return baseVersionIsLow( + versionTextParse(currentVersion.value) as VersionType, + versionTextParse(latestVersion.value) as VersionType + ); + } + return false; + }); + const html = computed(() => { if (!infos.value) return ""; let html = ""; - const isFetchingFinished = latestVersion.value.length > 0; - const isUpdateAvailable = currentVersion.value !== latestVersion.value; - - if (isFetchingFinished && isUpdateAvailable) { + if (isUpdateAvailable.value) { html += `

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

`; - html += `

現在のバージョン:` + currentVersion.value + `

`; - html += `

最新のバージョン:` + latestVersion.value + `

`; + html += `

現在のバージョン:${currentVersion.value}

`; + html += `

最新のバージョン:${latestVersion.value}

`; html += `

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

`; html += `https://voicevox.hiroshiba.jp/`; - } else if (isFetchingFinished) { + } else if (isFetchingFinished.value) { html += `

お使いの VOICEBOX は最新です!

`; - } else { + } else if (!isCheckingUpdatesFailed.value) { html += `

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

`; + } else { + html += `

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

`; } html += `
`; 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]) { From 73796700d624e6af11832088d898a6a273c75cf6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=89=9B=E8=92=A1?= Date: Mon, 7 Feb 2022 16:22:09 +0900 Subject: [PATCH 09/12] fix --- src/components/UpdateInfo.vue | 100 +++++++++++++++++----------------- 1 file changed, 51 insertions(+), 49 deletions(-) diff --git a/src/components/UpdateInfo.vue b/src/components/UpdateInfo.vue index f79215bef7..7c8faf9b3b 100644 --- a/src/components/UpdateInfo.vue +++ b/src/components/UpdateInfo.vue @@ -28,63 +28,64 @@ export default defineComponent({ let isCheckingFailed = ref(false); - const currentVersion = ref(""); - window.electron.getAppInfos().then((obj) => { - currentVersion.value = obj.version; - }); + let isCheckingFinished = ref(false); + const currentVersion = ref(""); const latestVersion = ref(""); - fetch("https://api.github.com/repos/VOICEVOX/voicevox/releases", { - method: "GET", - headers: { - "Content-Type": "application/json", - Accept: "application/json", - }, - }) - .then((response) => { - if (!response.ok) { - console.error("response.ok:", response.ok); - console.error("esponse.status:", response.status); - isCheckingFailed.value = true; - } - return response.json(); - }) + window.electron + .getAppInfos() .then((obj) => { - obj.find( - (item: { prerelease: boolean; tag_name: string }) => - item.prerelease === false && - baseVersionIsLow( - versionTextParse(currentVersion.value) as VersionType, - versionTextParse(item.tag_name) as VersionType - ) - ); - latestVersion.value = obj[0].tag_name; + currentVersion.value = obj.version; }) - .catch((err) => { - console.error(err); - isCheckingFailed.value = true; + .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) { + console.error("response.ok:", response.ok); + console.error("esponse.status:", response.status); + 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 + ) + ); + } + ); + console.log("obj:", obj); + obj ? (latestVersion.value = obj.tag_name) : undefined; + isCheckingFinished.value = true; + }) + .catch((err) => { + console.error(err); + isCheckingFailed.value = true; + }); }); - const isCheckingUpdatesFailed = computed(() => { + const isCheckingFailedcomputed = computed(() => { return isCheckingFailed.value; }); - const isFetchingFinished = computed(() => { - if (!isCheckingUpdatesFailed.value && latestVersion.value.length > 0) { - return true; - } else { - return false; - } + const isCheckingFinishedComputed = computed(() => { + return isCheckingFinished.value; }); const isUpdateAvailable = computed(() => { - if (isFetchingFinished.value) { - return baseVersionIsLow( - versionTextParse(currentVersion.value) as VersionType, - versionTextParse(latestVersion.value) as VersionType - ); - } - return false; + return isCheckingFinished.value && latestVersion.value !== ""; }); const html = computed(() => { @@ -94,13 +95,14 @@ export default defineComponent({ if (isUpdateAvailable.value) { html += `

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

`; - html += `

現在のバージョン:${currentVersion.value}

`; - html += `

最新のバージョン:${latestVersion.value}

`; html += `

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

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

お使いの VOICEBOX は最新です!

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

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

`; } else { html += `

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

`; From b8969c08a93e3491b6db0175cb14f16cebf03a47 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=89=9B=E8=92=A1?= Date: Mon, 7 Feb 2022 17:13:41 +0900 Subject: [PATCH 10/12] remove unnecessary logs --- src/components/UpdateInfo.vue | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/components/UpdateInfo.vue b/src/components/UpdateInfo.vue index 7c8faf9b3b..d4336282eb 100644 --- a/src/components/UpdateInfo.vue +++ b/src/components/UpdateInfo.vue @@ -47,7 +47,6 @@ export default defineComponent({ }) .then((response) => { if (!response.ok) { - console.error("response.ok:", response.ok); console.error("esponse.status:", response.status); isCheckingFailed.value = true; } else { @@ -66,7 +65,6 @@ export default defineComponent({ ); } ); - console.log("obj:", obj); obj ? (latestVersion.value = obj.tag_name) : undefined; isCheckingFinished.value = true; }) From a713aab773f118311b2c2cada0c680b54f6912fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=89=9B=E8=92=A1?= Date: Tue, 8 Feb 2022 01:51:05 +0900 Subject: [PATCH 11/12] remove logger --- src/components/UpdateInfo.vue | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/components/UpdateInfo.vue b/src/components/UpdateInfo.vue index d4336282eb..f02db53fd4 100644 --- a/src/components/UpdateInfo.vue +++ b/src/components/UpdateInfo.vue @@ -47,7 +47,6 @@ export default defineComponent({ }) .then((response) => { if (!response.ok) { - console.error("esponse.status:", response.status); isCheckingFailed.value = true; } else { return response.json(); @@ -68,8 +67,7 @@ export default defineComponent({ obj ? (latestVersion.value = obj.tag_name) : undefined; isCheckingFinished.value = true; }) - .catch((err) => { - console.error(err); + .catch(() => { isCheckingFailed.value = true; }); }); From c8a725f159fc1b25f728c751188ed888aecb624f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=89=9B=E8=92=A1?= Date: Tue, 8 Feb 2022 10:59:39 +0900 Subject: [PATCH 12/12] =?UTF-8?q?=E3=82=A8=E3=83=A9=E3=83=BC=E3=82=92?= =?UTF-8?q?=E6=8A=95=E3=81=92=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/UpdateInfo.vue | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/components/UpdateInfo.vue b/src/components/UpdateInfo.vue index f02db53fd4..ee63fd2971 100644 --- a/src/components/UpdateInfo.vue +++ b/src/components/UpdateInfo.vue @@ -67,12 +67,15 @@ export default defineComponent({ obj ? (latestVersion.value = obj.tag_name) : undefined; isCheckingFinished.value = true; }) - .catch(() => { - isCheckingFailed.value = true; + .catch((err) => { + throw new Error(err); }); + }) + .catch(() => { + isCheckingFailed.value = true; }); - const isCheckingFailedcomputed = computed(() => { + const isCheckingFailedComputed = computed(() => { return isCheckingFailed.value; }); @@ -97,7 +100,7 @@ export default defineComponent({ html += `

お使いの VOICEBOX は最新です!

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

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

`; } else {