Skip to content

Commit

Permalink
enhance(frontend): 「単なるラッキー」の調整 (misskey-dev#14807)
Browse files Browse the repository at this point in the history
* enhance(frontend): 「単なるラッキー」の調整

* refactor

* comment

* Update Changelog

---------

Co-authored-by: syuilo <[email protected]>
  • Loading branch information
kakkokari-gtyih and syuilo authored Oct 23, 2024
1 parent 48d1539 commit 15ae160
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 3 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
### Client
- Enhance: Bull DashboardでRelationship Queueの状態も確認できるように
(Cherry-picked from https://github.com/MisskeyIO/misskey/pull/751)
- Enhance: ドライブでソートができるように
- Enhance: ドライブでソートができるように
- Enhance: 「単なるラッキー」の取得条件を変更
- Enhance: 投稿フォームでEscキーを押したときIME入力中ならフォームを閉じないように( #10866
- Fix: 通知の範囲指定の設定項目が必要ない通知設定でも範囲指定の設定がでている問題を修正
- Fix: Turnstileが失敗・期限切れした際にも成功扱いとなってしまう問題を修正
Expand Down
34 changes: 32 additions & 2 deletions packages/frontend/src/boot/main-boot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -231,11 +231,41 @@ export async function mainBoot() {
}

if (!claimedAchievements.includes('justPlainLucky')) {
window.setInterval(() => {
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', () => {
const now = Date.now();

if (document.visibilityState === 'visible') {
// タブを高速で切り替えたら取得処理が何度も走るのを防ぐ
if ((now - lastVisibilityChangedAt) < 1000 * 10) {
justPlainLuckyTimer = window.setTimeout(claimPlainLucky, 1000 * 10);
} else {
claimPlainLucky();
}
} else if (justPlainLuckyTimer != null) {
window.clearTimeout(justPlainLuckyTimer);
justPlainLuckyTimer = null;
}
}, 1000 * 10);

lastVisibilityChangedAt = now;
}, { passive: true });

claimPlainLucky();
}

if (!claimedAchievements.includes('client30min')) {
Expand Down

0 comments on commit 15ae160

Please sign in to comment.