From c13f8277270423f40f343658668a53b3daca51d9 Mon Sep 17 00:00:00 2001 From: kakkokari-gtyih <67428053+kakkokari-gtyih@users.noreply.github.com> Date: Sun, 20 Oct 2024 18:25:46 +0900 Subject: [PATCH 1/4] =?UTF-8?q?enhance(frontend):=20=E3=80=8C=E5=8D=98?= =?UTF-8?q?=E3=81=AA=E3=82=8B=E3=83=A9=E3=83=83=E3=82=AD=E3=83=BC=E3=80=8D?= =?UTF-8?q?=E3=81=AE=E8=AA=BF=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/frontend/src/boot/main-boot.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/frontend/src/boot/main-boot.ts b/packages/frontend/src/boot/main-boot.ts index 76459ab330eb..36ed925182e9 100644 --- a/packages/frontend/src/boot/main-boot.ts +++ b/packages/frontend/src/boot/main-boot.ts @@ -232,7 +232,7 @@ export async function mainBoot() { if (!claimedAchievements.includes('justPlainLucky')) { window.setInterval(() => { - if (Math.floor(Math.random() * 20000) === 0) { + if (document.visibilityState === 'visible' && Math.floor(Math.random() * 20000) === 0) { claimAchievement('justPlainLucky'); } }, 1000 * 10); From b2d57badf974d8d27de5498408e11e41e44e8d29 Mon Sep 17 00:00:00 2001 From: kakkokari-gtyih <67428053+kakkokari-gtyih@users.noreply.github.com> Date: Sun, 20 Oct 2024 18:36:16 +0900 Subject: [PATCH 2/4] refactor --- packages/frontend/src/boot/main-boot.ts | 33 ++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/packages/frontend/src/boot/main-boot.ts b/packages/frontend/src/boot/main-boot.ts index 36ed925182e9..8847ebcc0f83 100644 --- a/packages/frontend/src/boot/main-boot.ts +++ b/packages/frontend/src/boot/main-boot.ts @@ -231,11 +231,38 @@ export async function mainBoot() { } if (!claimedAchievements.includes('justPlainLucky')) { - window.setInterval(() => { - if (document.visibilityState === 'visible' && Math.floor(Math.random() * 20000) === 0) { + let justPlainLuckyTimer: number | null = null; + let lastVisibilityChangedAt = Date.now(); + + function claimPlainLucky() { + if (document.visibilityState !== 'visible') { + if (justPlainLuckyTimer != null) window.clearTimeout(justPlainLuckyTimer); + return; + } + + if (Math.floor(Math.random() * 20000) === 0) { claimAchievement('justPlainLucky'); + } else { + justPlainLuckyTimer = window.setTimeout(claimPlainLucky, 1000 * 10); + } + } + + window.addEventListener('visibilitychange', () => { + if (document.visibilityState === 'visible') { + if ((Date.now() - lastVisibilityChangedAt) < 1000 * 10) { + justPlainLuckyTimer = window.setTimeout(claimPlainLucky, 1000 * 10); + } else { + claimPlainLucky(); + } + } else if (justPlainLuckyTimer != null) { + window.clearTimeout(justPlainLuckyTimer); + justPlainLuckyTimer = null; } - }, 1000 * 10); + + lastVisibilityChangedAt = Date.now(); + }, { passive: true }); + + claimPlainLucky(); } if (!claimedAchievements.includes('client30min')) { From 455f911aae8aceb6d20bfc2e06597c4ee2956bf0 Mon Sep 17 00:00:00 2001 From: kakkokari-gtyih <67428053+kakkokari-gtyih@users.noreply.github.com> Date: Sun, 20 Oct 2024 18:37:15 +0900 Subject: [PATCH 3/4] comment --- packages/frontend/src/boot/main-boot.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/packages/frontend/src/boot/main-boot.ts b/packages/frontend/src/boot/main-boot.ts index 8847ebcc0f83..cfe4e124be42 100644 --- a/packages/frontend/src/boot/main-boot.ts +++ b/packages/frontend/src/boot/main-boot.ts @@ -248,8 +248,11 @@ export async function mainBoot() { } window.addEventListener('visibilitychange', () => { + const now = Date.now(); + if (document.visibilityState === 'visible') { - if ((Date.now() - lastVisibilityChangedAt) < 1000 * 10) { + // タブを高速で切り替えたら取得処理が何度も走るのを防ぐ + if ((now - lastVisibilityChangedAt) < 1000 * 10) { justPlainLuckyTimer = window.setTimeout(claimPlainLucky, 1000 * 10); } else { claimPlainLucky(); @@ -259,7 +262,7 @@ export async function mainBoot() { justPlainLuckyTimer = null; } - lastVisibilityChangedAt = Date.now(); + lastVisibilityChangedAt = now; }, { passive: true }); claimPlainLucky(); From 769ae84bb123286a7cfea3a3d86373cbffe13b62 Mon Sep 17 00:00:00 2001 From: kakkokari-gtyih <67428053+kakkokari-gtyih@users.noreply.github.com> Date: Sun, 20 Oct 2024 18:37:46 +0900 Subject: [PATCH 4/4] Update Changelog --- CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 04ae102227c0..183c223e8cea 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,8 @@ ### Client - Enhance: Bull DashboardでRelationship Queueの状態も確認できるように (Cherry-picked from https://github.com/MisskeyIO/misskey/pull/751) -- Enhance: ドライブでソートができるように +- Enhance: ドライブでソートができるように +- Enhance: 「単なるラッキー」の取得条件を変更 - Fix: 通知の範囲指定の設定項目が必要ない通知設定でも範囲指定の設定がでている問題を修正 ### Server