Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ヘルプでアップデートを確認できるようにする #690

Merged
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 82 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,87 @@ 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;
sopisoft marked this conversation as resolved.
Show resolved Hide resolved
})
.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(() => {
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