-
Notifications
You must be signed in to change notification settings - Fork 311
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
[refactor] アップデート通知ダイアログ周りをEditorHome.vueから分離 #1717
Merged
The head ref may contain hidden characters: "\u8272\u3005\u5B9F\u88C5\u3057\u3061\u3083\u3063\u305F\u3084\u3064"
Merged
Changes from 4 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
51a50f7
e2eテスト追加
Hiroshiba 392aa28
色々実装しちゃったやつ
Hiroshiba 63caae9
バグフィックス
Hiroshiba d0fa093
Merge branch 'アップデート通知ダイアログをテストする' into 色々実装しちゃったやつ
Hiroshiba 5013db1
assertNonNullable
Hiroshiba 6454dc5
UrlString
Hiroshiba db4610e
Merge remote-tracking branch 'upstream/main' into 色々実装しちゃったやつ
Hiroshiba File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
<!-- | ||
アップデート通知ダイアログのコンテナ。 | ||
スキップしたバージョンより新しいバージョンがあれば、ダイアログを表示する。 | ||
--> | ||
|
||
<template> | ||
<update-notification-dialog | ||
v-if="newUpdateResult.status == 'updateAvailable'" | ||
v-model="isDialogOpenComputed" | ||
:latest-version="newUpdateResult.latestVersion" | ||
:new-update-infos="newUpdateResult.newUpdateInfos" | ||
@skip-this-version-click="handleSkipThisVersionClick" | ||
/> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
import semver from "semver"; | ||
import { computed, watch } from "vue"; | ||
import UpdateNotificationDialog from "./Presentation.vue"; | ||
import { useFetchNewUpdateInfos } from "@/composables/useFetchNewUpdateInfos"; | ||
import { useStore } from "@/store"; | ||
import { UrlString } from "@/type/preload"; | ||
|
||
const props = | ||
defineProps<{ | ||
canOpenDialog: boolean; // ダイアログを開いても良いかどうか | ||
}>(); | ||
|
||
const store = useStore(); | ||
|
||
const isDialogOpenComputed = computed({ | ||
get: () => store.state.isUpdateNotificationDialogOpen, | ||
set: (val) => | ||
store.dispatch("SET_DIALOG_OPEN", { | ||
isUpdateNotificationDialogOpen: val, | ||
}), | ||
}); | ||
|
||
// エディタのアップデート確認 | ||
if (!import.meta.env.VITE_LATEST_UPDATE_INFOS_URL) { | ||
throw new Error( | ||
"環境変数VITE_LATEST_UPDATE_INFOS_URLが設定されていません。.envに記載してください。" | ||
); | ||
} | ||
|
||
// アプリのバージョンとスキップしたバージョンのうち、新しい方を返す | ||
const currentVersionGetter = async () => { | ||
const appVersion = await window.electron | ||
.getAppInfos() | ||
.then((obj) => obj.version); | ||
|
||
await store.dispatch("WAIT_VUEX_READY", { timeout: 15000 }); | ||
const skipUpdateVersion = store.state.skipUpdateVersion ?? "0.0.0"; | ||
if (semver.valid(skipUpdateVersion) == undefined) { | ||
throw new Error(`skipUpdateVersionが不正です: ${skipUpdateVersion}`); | ||
} | ||
|
||
return semver.gt(appVersion, skipUpdateVersion) | ||
? appVersion | ||
: skipUpdateVersion; | ||
}; | ||
|
||
// 新しいバージョンがあれば取得 | ||
const newUpdateResult = useFetchNewUpdateInfos( | ||
currentVersionGetter, | ||
UrlString(import.meta.env.VITE_LATEST_UPDATE_INFOS_URL) | ||
); | ||
|
||
// 新しいバージョンのアップデートがスキップされたときの処理 | ||
const handleSkipThisVersionClick = (version: string) => { | ||
store.dispatch("SET_ROOT_MISC_SETTING", { | ||
key: "skipUpdateVersion", | ||
value: version, | ||
}); | ||
}; | ||
|
||
// ダイアログを開くかどうか | ||
watch( | ||
() => [props.canOpenDialog, newUpdateResult], | ||
() => { | ||
if ( | ||
props.canOpenDialog && | ||
newUpdateResult.value.status == "updateAvailable" | ||
) { | ||
isDialogOpenComputed.value = true; | ||
} | ||
} | ||
); | ||
</script> |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import { test, expect } from "@playwright/test"; | ||
import dotenv from "dotenv"; | ||
import semver from "semver"; | ||
import { navigateToMain, gotoHome } from "../navigators"; | ||
import { getNewestQuasarDialog } from "../locators"; | ||
import { UpdateInfo } from "@/type/preload"; | ||
import { assertNonNullable } from "@/type/utility"; | ||
|
||
// アップデート通知が出る環境にする | ||
test.beforeEach(async ({ page }) => { | ||
dotenv.config(); | ||
|
||
// 動作環境より新しいバージョン | ||
const latestVersion = semver.inc( | ||
process.env.VITE_APP_VERSION ?? process.env.npm_package_version ?? "0.0.0", | ||
"major" | ||
); | ||
assertNonNullable(latestVersion); | ||
|
||
// アップデート情報を返すAPIのモック | ||
if (process.env.VITE_LATEST_UPDATE_INFOS_URL == undefined) { | ||
throw new Error("VITE_LATEST_UPDATE_INFOS_URL is not defined"); | ||
} | ||
page.route(process.env.VITE_LATEST_UPDATE_INFOS_URL, (route) => { | ||
const updateInfos: UpdateInfo[] = [ | ||
{ | ||
version: latestVersion, | ||
descriptions: [], | ||
contributors: [], | ||
}, | ||
]; | ||
route.fulfill({ | ||
status: 200, | ||
body: JSON.stringify(updateInfos), | ||
}); | ||
}); | ||
}); | ||
|
||
test.beforeEach(async ({ page }) => { | ||
await gotoHome({ page }); | ||
|
||
await navigateToMain(page); | ||
await page.waitForTimeout(100); | ||
}); | ||
|
||
test("アップデートが通知されたりスキップしたりできる", async ({ page }) => { | ||
await page.waitForTimeout(500); | ||
|
||
// 通知されている | ||
const dialog = getNewestQuasarDialog(page); | ||
await expect(dialog.getByText("アップデートのお知らせ")).toBeVisible(); | ||
|
||
// 普通に閉じると消える | ||
await dialog.getByRole("button", { name: "閉じる" }).click(); | ||
await page.waitForTimeout(500); | ||
await expect(dialog).not.toBeVisible(); | ||
|
||
// 再度開くとまた表示される | ||
await page.reload(); | ||
await expect(dialog.getByText("アップデートのお知らせ")).toBeVisible(); | ||
|
||
// スキップすると消える | ||
await dialog | ||
.getByRole("button", { name: "このバージョンをスキップ" }) | ||
.click(); | ||
await page.waitForTimeout(500); | ||
await expect(dialog).not.toBeVisible(); | ||
|
||
// 再度開いても表示されない(スキップされた) | ||
await page.reload(); | ||
await page.waitForTimeout(5000); // エンジン読み込み待機 | ||
await expect(dialog).not.toBeVisible(); | ||
}); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
コンポーネント名は2単語以上、という制約がディレクトリ区切りのコンポーネントにも採用されてしまうので、この2つだけは許容するようにしてみました。