弹窗优化

This commit is contained in:
tianmo committed 2026-09-21 10:30:33 +08:00
1 parent be058c6c80
commit 650d9c0398
3 files changed
+40 -7

No files matched your search

+22 -6
View File
@@ -64,6 +64,7 @@
let doneCount = 0;
let lastHeight = 0;
let placedAt = null; // 上次由我们设置的位置,用来判断用户是不是手动拖过
let allowClose = false;
/** Eagle 的 userData 目录;eagle.app.userDataPath 注入得比较晚,所以留一个兜底。 */
function userDataPath() {
@@ -105,7 +106,8 @@
/** 窗口高度跟着内容走。 */
function fitHeight() {
const height = Math.ceil(document.body.scrollHeight);
// setSize 设置的是包含系统标题栏的外部高度,内容高度要补回窗口边框占用。
const height = Math.ceil(document.body.scrollHeight + Math.max(0, window.outerHeight - window.innerHeight));
if (Math.abs(height - lastHeight) < 2) return;
lastHeight = height;
eagle.window.setSize(WIDTH, height)
@@ -127,6 +129,22 @@
} catch (error) { /* 写不进去就等于没按 */ }
}
function requestStop() {
if (paused) return;
paused = true;
writeControl('pause');
syncButtons();
resumeEl.focus();
}
// 系统关闭按钮与页面里的「停止」走同一条暂停确认流程。
window.addEventListener('beforeunload', (event) => {
if (allowClose || finished) return;
event.preventDefault();
event.returnValue = false;
requestStop();
});
function render(state) {
const total = Math.max(1, state.total || 0);
const done = state.done || 0;
@@ -149,14 +167,11 @@
actionEl.addEventListener('click', () => {
if (finished) {
allowClose = true;
window.close();
return;
}
// 先让宿主暂停(它会在当前素材做完后停在原地),再就地问要不要继续。
paused = true;
writeControl('pause');
syncButtons();
resumeEl.focus(); // 默认选中「继续」
requestStop();
});
resumeEl.addEventListener('click', () => {
@@ -168,6 +183,7 @@
document.getElementById('cancel').addEventListener('click', () => {
// 同步写控制文件再关窗:窗口没了宿主也能读到 cancel,把剩余队列丢掉。
writeControl('cancel');
allowClose = true;
window.close();
});