Skip to content

Fix alertBeforeClose setting not taking effect without window reload#1781

Draft
Copilot wants to merge 6 commits intodevelopfrom
copilot/fix-exit-button-behavior
Draft

Fix alertBeforeClose setting not taking effect without window reload#1781
Copilot wants to merge 6 commits intodevelopfrom
copilot/fix-exit-button-behavior

Conversation

Copy link
Copy Markdown

Copilot AI commented Jan 18, 2026

The "閉じる前に確認ダイアログを表示する" setting was only checked once at window creation, so toggling it in options had no effect on already-open game windows.

Changes

src/injection/dmm.ts

  • Cache alertBeforeClose in module-level variable instead of checking once at init
  • Make beforeunload handler synchronous, reading cached value directly
  • Listen for /injected/dmm/config:update messages to update cache

src/page/components/options/FrameSettingView.tsx

  • Send config update message to open game window when setting changes
  • Pass alertBeforeClose value in message to avoid unnecessary config fetch

Before/After

// Before: checked once, never updated
const shouldAlert = configs.game.alertBeforeClose ?? true;
if (shouldAlert) setupBeforeUnloadHandler();

// After: cached value updated via messages
let cachedAlertBeforeClose = true;
window.addEventListener("beforeunload", (event) => {
  if (cachedAlertBeforeClose) {
    event.preventDefault();
    event.returnValue = "";
  }
});

Settings now apply immediately without requiring window reload.

Original prompt

This section details on the original issue you should resolve

<issue_title>✖️ボタンを押した時の挙動</issue_title>
<issue_description>### 改善カテゴリ

パフォーマンス: 表示速度や処理速度の改善

改善対象の画面・機能

ゲーム窓

現状

おま環かもしれませんが✖️ボタン押して終了しようとしたら
「アプリを終了しますか?」と聞いてくる。

改善案

押したら直ぐにアプリが終了するようにしてほしいです

改善による効果

熟練度残しを確実にしたいです。

緊急度

中: 不便だが使えている

参考画像

No response

補足情報

No response</issue_description>

Comments on the Issue (you are @copilot in this section)

@otiai10 @copilot 「閉じる前に確認ダイアログを出す」の設定のon/offが機能していない可能性がありますか?

💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

@otiai10
Copy link
Copy Markdown
Member

otiai10 commented Jan 18, 2026

@copilot 「閉じる前に確認ダイアログを出す」の設定のon/offが機能していない可能性がありますか?

Copilot AI and others added 5 commits January 18, 2026 00:24
Co-authored-by: otiai10 <931554+otiai10@users.noreply.github.com>
Co-authored-by: otiai10 <931554+otiai10@users.noreply.github.com>
Co-authored-by: otiai10 <931554+otiai10@users.noreply.github.com>
Co-authored-by: otiai10 <931554+otiai10@users.noreply.github.com>
Co-authored-by: otiai10 <931554+otiai10@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix exit button behavior to end app immediately Fix alertBeforeClose setting not taking effect without window reload Jan 18, 2026
Copilot AI requested a review from otiai10 January 18, 2026 00:33
Copy link
Copy Markdown
Author

Copilot AI commented Jan 18, 2026

@copilot 「閉じる前に確認ダイアログを出す」の設定のon/offが機能していない可能性がありますか?

はい、その通りです。設定のon/offが機能していませんでした。

問題点:

  • ゲーム窓起動時に一度だけ設定値を確認し、その時点でbeforeunloadハンドラーを登録するかどうかを決定していました
  • そのため、ゲーム窓を開いた後に設定を変更しても、既に開いているウィンドウには反映されませんでした

修正内容:

  • 設定値をキャッシュし、beforeunloadイベント発火時に同期的にチェックする方式に変更しました (コミット: 203c833)
  • 設定画面で変更した際に、開いているゲーム窓にメッセージを送信してキャッシュを更新する機能を追加しました (コミット: 29186da)

これにより、設定を変更した際にゲーム窓を開き直す必要がなくなり、即座に反映されるようになりました。

@codecov
Copy link
Copy Markdown

codecov bot commented Jan 18, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 3.37%. Comparing base (ef14aa0) to head (29186da).

Additional details and impacted files
@@           Coverage Diff           @@
##           develop   #1781   +/-   ##
=======================================
  Coverage     3.37%   3.37%           
=======================================
  Files           36      36           
  Lines         1361    1361           
  Branches        46      46           
=======================================
  Hits            46      46           
  Misses        1315    1315           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Copy Markdown
Member

@otiai10 otiai10 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#1781 (comment)

つまり、今までの実装でも、起動時の設定は反映できていた、ということですか?

@copilot

Copy link
Copy Markdown
Author

Copilot AI commented Jan 18, 2026

#1781 (comment)

つまり、今までの実装でも、起動時の設定は反映できていた、ということですか?...

はい、その通りです。

起動時の動作(従来の実装):

  • ゲーム窓を開いた時点で設定値を取得し、alertBeforeClosetrueの場合のみbeforeunloadハンドラーを登録していました
  • そのため、起動時の設定は正しく反映されていました

問題点:

  • 起動後に設定を変更しても、既に開いているゲーム窓には反映されませんでした
  • 例: 設定を「表示する」→「表示しない」に変更しても、開いたままのゲーム窓では依然として確認ダイアログが表示される

修正後:

  • 常にbeforeunloadハンドラーを登録し、イベント発火時にキャッシュされた設定値を確認する方式に変更
  • 設定変更時にメッセージで通知し、キャッシュを更新することで、開いたままの窓でも即座に反映されるようになりました

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

✖️ボタンを押した時の挙動

2 participants