Skip to content

Commit

Permalink
ヘルプでアップデートを確認できるようにする (#690)
Browse files Browse the repository at this point in the history
* add the ability to check for updates

* fix

* add wording

* fix

* fix

* fix

* fix

* fix

* fix

* remove unnecessary logs

* remove logger

* エラーを投げる
  • Loading branch information
sopisoft authored Feb 8, 2022
1 parent 0964592 commit 1f9749f
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 2 deletions.
85 changes: 85 additions & 0 deletions src/components/UpdateInfo.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -21,10 +26,90 @@ export default defineComponent({
const infos = ref<UpdateInfo[]>();
store.dispatch("GET_UPDATE_INFOS").then((obj) => (infos.value = obj));
let isCheckingFailed = ref<boolean>(false);
let isCheckingFinished = ref<boolean>(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 += `<h3>アップデートがあります!</h3>`;
html += `<h4>最新版のダウンロードページ</h4>`;
html += `<a href="https://voicevox.hiroshiba.jp/" target="_blank">https://voicevox.hiroshiba.jp/</a>`;
} else if (isCheckingFinishedComputed.value && !isUpdateAvailable.value) {
html += `<h3>お使いの VOICEBOX は最新です!</h3>`;
} else if (
!isCheckingFinishedComputed.value &&
!isCheckingFailedComputed.value
) {
html += `<h3>アップデートを確認中です…</h3>`;
} else {
html += `<h3>アップデートの確認に失敗しました…</h3>`;
}
html += `<hr />`;
html += `<h3>アップデート履歴</h3>`;
for (const info of infos.value) {
const version: string = info.version;
const descriptions: string[] = info.descriptions;
Expand Down
9 changes: 7 additions & 2 deletions src/store/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -404,15 +404,20 @@ 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;
if (!appVersion.every((item) => Number.isInteger(item))) return 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]) {
Expand Down

0 comments on commit 1f9749f

Please sign in to comment.